diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 9a11884f2e..087e32ec4a 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -97,6 +97,13 @@ class Application $slim->run(); } + public function runCron() + { + $auth = $this->getAuth(); + $auth->useNoAuth(); + // TODO cron manager + } + protected function routeHooks() { $container = $this->getContainer(); diff --git a/application/Espo/Core/Utils/Auth.php b/application/Espo/Core/Utils/Auth.php index fea1700005..f1e1605617 100644 --- a/application/Espo/Core/Utils/Auth.php +++ b/application/Espo/Core/Utils/Auth.php @@ -2,6 +2,8 @@ namespace Espo\Core\Utils; +use \Espo\Core\Exceptions\Error; + class Auth { protected $container; @@ -14,7 +16,13 @@ class Auth public function useNoAuth() { $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) diff --git a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json index efe39071fe..0d34666162 100644 --- a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json +++ b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json @@ -16,6 +16,10 @@ "type": "varchar", "required": true }, + "lastRun": { + "type": "datetime", + "readOnly": true + }, "createdAt": { "type": "datetime", "readOnly": true diff --git a/application/Espo/Services/User.php b/application/Espo/Services/User.php index 08d59f75c8..ac84e470eb 100644 --- a/application/Espo/Services/User.php +++ b/application/Espo/Services/User.php @@ -2,6 +2,8 @@ namespace Espo\Services; +use \Espo\Core\Exceptions\Forbidden; + class User extends Record { public function getEntity($id) @@ -30,10 +32,21 @@ class User extends Record public function updateEntity($id, $data) { + if ($id == 'system') { + $data['isAdmin'] = true; + } if (array_key_exists('password', $data)) { $data['password'] = md5($data['password']); } return parent::updateEntity($id, $data); } + + public function deleteEntity($id) + { + if ($id == 'system') { + throw new Forbidden(); + } + return parent::deleteEntity($id); + } } diff --git a/cron.php b/cron.php new file mode 100644 index 0000000000..692854467e --- /dev/null +++ b/cron.php @@ -0,0 +1,13 @@ +runCron(); +