* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL * @license https://opensource.org/licenses/MIT The MIT License * * Don't forget to prefix your containers with your own identifier * to avoid any conflicts with others containers. */ require_once dirname(__FILE__) . '/../../bootstrap.php'; class RetailcrmJobsController extends RetailcrmAdminPostAbstractController { protected function postHandler() { if (!Tools::getIsset('jobName') && !Tools::getIsset('reset')) { throw new Exception('Invalid request data'); } if (Tools::getIsset('reset')) { return $this->resetJobManager(); } $jobName = Tools::getValue('jobName'); return $this->runJob($jobName); } protected function getHandler() { return [ 'success' => true, 'result' => RetailcrmSettingsHelper::getJobsInfo(), ]; } private function resetJobManager() { $errors = []; if (!RetailcrmJobManager::reset()) { $errors[] = 'Job manager internal state was NOT cleared.'; } if (!RetailcrmCli::clearCurrentJob(null)) { $errors[] = 'CLI job was NOT cleared'; } if (!empty($errors)) { throw new Exception(implode(' ', $errors)); } return RetailcrmJsonResponse::successfullResponse(); } private function runJob($jobName) { $result = RetailcrmJobManager::execManualJob($jobName); return [ 'success' => true, 'result' => $result, ]; } }