cron. first code

This commit is contained in:
Yuri Kuznetsov
2014-01-27 17:01:04 +02:00
parent b1214f9418
commit 2ac19d2eb9
5 changed files with 46 additions and 1 deletions
+7
View File
@@ -97,6 +97,13 @@ class Application
$slim->run(); $slim->run();
} }
public function runCron()
{
$auth = $this->getAuth();
$auth->useNoAuth();
// TODO cron manager
}
protected function routeHooks() protected function routeHooks()
{ {
$container = $this->getContainer(); $container = $this->getContainer();
+9 -1
View File
@@ -2,6 +2,8 @@
namespace Espo\Core\Utils; namespace Espo\Core\Utils;
use \Espo\Core\Exceptions\Error;
class Auth class Auth
{ {
protected $container; protected $container;
@@ -14,7 +16,13 @@ class Auth
public function useNoAuth() public function useNoAuth()
{ {
$entityManager = $this->container->get('entityManager'); $entityManager = $this->container->get('entityManager');
$this->container->setUser($entityManager->getEntity('User'));
$user = $entityManager->getRepository('User')->get('system');
if (!$user) {
throw new Error('System user is not found');
}
$this->container->setUser($user);
} }
public function login($username, $password) public function login($username, $password)
@@ -16,6 +16,10 @@
"type": "varchar", "type": "varchar",
"required": true "required": true
}, },
"lastRun": {
"type": "datetime",
"readOnly": true
},
"createdAt": { "createdAt": {
"type": "datetime", "type": "datetime",
"readOnly": true "readOnly": true
+13
View File
@@ -2,6 +2,8 @@
namespace Espo\Services; namespace Espo\Services;
use \Espo\Core\Exceptions\Forbidden;
class User extends Record class User extends Record
{ {
public function getEntity($id) public function getEntity($id)
@@ -30,10 +32,21 @@ class User extends Record
public function updateEntity($id, $data) public function updateEntity($id, $data)
{ {
if ($id == 'system') {
$data['isAdmin'] = true;
}
if (array_key_exists('password', $data)) { if (array_key_exists('password', $data)) {
$data['password'] = md5($data['password']); $data['password'] = md5($data['password']);
} }
return parent::updateEntity($id, $data); return parent::updateEntity($id, $data);
} }
public function deleteEntity($id)
{
if ($id == 'system') {
throw new Forbidden();
}
return parent::deleteEntity($id);
}
} }
+13
View File
@@ -0,0 +1,13 @@
<?php
$sapiName = php_sapi_name();
if (substr($sapiName, 0, 3) != 'cli') {
die("cron can be run only via CLI");
}
include "bootstrap.php";
$app = new \Espo\Core\Application();
$app->runCron();