'* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', 'windows' => '{PHP-BINARY} -f {FULL-CRON-PATH}', 'mac' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', 'default' => '* * * * * cd {DOCUMENT_ROOT}; {PHP-BIN-DIR} -f {CRON-FILE} > /dev/null 2>&1', ]; protected $classFinder; protected $language; protected $entityManager; public function __construct(ClassFinder $classFinder, EntityManager $entityManager, Language $language) { $this->classFinder = $classFinder; $this->entityManager = $entityManager; $this->language = $language; $this->systemUtil = new System(); } protected function getContainer() { return $this->container; } protected function getSystemUtil() { return $this->systemUtil; } public function getAvailableList() { $map = $this->classFinder->getMap('Jobs'); $list = array_keys($map); return $list; } public function getJobClassName(string $name) : ?string { $name = ucfirst($name); $className = $this->classFinder->find('Jobs', $name); return $className; } public function getSetupMessage() { $language = $this->language; $OS = $this->getSystemUtil()->getOS(); $desc = $language->translate('cronSetup', 'options', 'ScheduledJob'); $data = array( 'PHP-BIN-DIR' => $this->getSystemUtil()->getPhpBin(), 'PHP-BINARY' => $this->getSystemUtil()->getPhpBinary(), 'CRON-FILE' => $this->cronFile, 'DOCUMENT_ROOT' => $this->getSystemUtil()->getRootDir(), 'FULL-CRON-PATH' => Util::concatPath($this->getSystemUtil()->getRootDir(), $this->cronFile), ); $message = isset($desc[$OS]) ? $desc[$OS] : $desc['default']; $command = isset($this->cronSetup[$OS]) ? $this->cronSetup[$OS] : $this->cronSetup['default']; foreach ($data as $name => $value) { $command = str_replace('{'.$name.'}', $value, $command); } return [ 'message' => $message, 'command' => $command, ]; } /** * Check if crontab is configured properly. * * @return boolean */ public function isCronConfigured() { $r1From = new \DateTime('-' . $this->checkingCronPeriod); $r1To = new \DateTime('+' . $this->checkingCronPeriod); $r2From = new \DateTime('- 1 hour'); $r2To = new \DateTime(); $format = \Espo\Core\Utils\DateTime::$systemDateTimeFormat; $selectParams = [ 'select' => ['id'], 'leftJoins' => ['scheduledJob'], 'whereClause' => [ 'OR' => [ [ ['executedAt>=' => $r2From->format($format)] , ['executedAt<=' => $r2To->format($format)], ], [ ['executeTime>=' => $r1From->format($format)], ['executeTime<='=> $r1To->format($format)], 'scheduledJob.job' => 'Dummy', ] ] ] ]; return !!$this->entityManager->getRepository('Job')->findOne($selectParams); } }