/**
  * shows all the cron jobs
  *
  */
 public function indexAction()
 {
     $this->view->acl = array('add' => false, 'edit' => false, 'toggle' => $this->_helper->hasAccess('toggle'), 'acl' => $this->_helper->hasAccess('index', 'ot_acl'));
     $role = new Ot_Model_DbTable_Role();
     $statusModel = new Ot_Model_DbTable_CronStatus();
     $statusMarkers = $statusModel->fetchAll();
     $cjStatus = array();
     foreach ($statusMarkers as $s) {
         $cjStatus[$s->jobKey] = array('status' => $s->status, 'lastRunDt' => $s->lastRunDt);
     }
     $jobs = array();
     $cjr = new Ot_Cron_JobRegister();
     $registeredJobs = $cjr->getJobs();
     foreach ($registeredJobs as $j) {
         $cschedule = $j->getSchedule();
         if (count(explode(' ', $cschedule)) == 5) {
             $cschedule .= ' *';
         }
         $parts = explode(' ', $cschedule);
         $parts[0] = preg_replace('/\\*\\//', '0-59/', $parts[0]);
         $parts[1] = preg_replace('/\\*\\//', '0-23/', $parts[1]);
         $parts[2] = preg_replace('/\\*\\//', '1-31/', $parts[2]);
         $parts[3] = preg_replace('/\\*\\//', '1-12/', $parts[3]);
         $parts[4] = preg_replace('/\\*\\//', '0-6/', $parts[4]);
         $cschedule = implode($parts, ' ');
         try {
             $schedule = Ot_Cron_Schedule::fromCronString($cschedule);
         } catch (Exception $e) {
             $schedule = null;
         }
         $jobs[] = array('job' => $j, 'isEnabled' => isset($cjStatus[$j->getKey()]) && $cjStatus[$j->getKey()]['status'] == 'enabled', 'lastRunDt' => isset($cjStatus[$j->getKey()]) ? $cjStatus[$j->getKey()]['lastRunDt'] : 0, 'schedule' => is_null($schedule) ? $cschedule : $schedule->asNaturalLanguage());
     }
     $this->view->assign(array('defaultRole' => $role->find($this->_helper->configVar('defaultRole')), 'guestHasAccess' => $this->_helper->hasAccess('index', 'ot_cronjob', $this->_helper->configVar('defaultRole')), 'cronjobs' => $jobs));
     $this->_helper->pageTitle('ot-cron-index:title');
 }
Beispiel #2
0
 public static final function fromCronString($cronSpec = '* * * * * *', $language = 'en')
 {
     // Split input liberal. Single or multiple Spaces, Tabs and Newlines are all allowed as separators.
     if (count($elements = preg_split('/\\s+/', $cronSpec)) < 5) {
         throw new Exception('Invalid specification.');
     }
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     // Named ranges in cron entries
     /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     $arrMonths = array('JAN' => 1, 'FEB' => 2, 'MAR' => 3, 'APR' => 4, 'MAY' => 5, 'JUN' => 6, 'JUL' => 7, 'AUG' => 8, 'SEP' => 9, 'OCT' => 10, 'NOV' => 11, 'DEC' => 12);
     $arrDaysOfWeek = array('SUN' => 0, 'MON' => 1, 'TUE' => 2, 'WED' => 3, 'THU' => 4, 'FRI' => 5, 'SAT' => 6);
     // Translate the cron specification into arrays that hold specifications of the actual dates
     $newCron = new Ot_Cron_Schedule($language);
     $newCron->_cronMinutes = $newCron->cronInterpret($elements[0], 0, 59, array(), 'minutes');
     $newCron->_cronHours = $newCron->cronInterpret($elements[1], 0, 23, array(), 'hours');
     $newCron->_cronDaysOfMonth = $newCron->cronInterpret($elements[2], 1, 31, array(), 'daysOfMonth');
     $newCron->_cronMonths = $newCron->cronInterpret($elements[3], 1, 12, $arrMonths, 'months');
     $newCron->_cronDaysOfWeek = $newCron->cronInterpret($elements[4], 0, 6, $arrDaysOfWeek, 'daysOfWeek');
     $newCron->_cronYears = $newCron->cronInterpret($elements[5], $newCron->RANGE_YEARS_MIN, $newCron->RANGE_YEARS_MAX, array(), 'years');
     $newCron->_minutes = $newCron->cronCreateItems($newCron->_cronMinutes);
     $newCron->_hours = $newCron->cronCreateItems($newCron->_cronHours);
     $newCron->_daysOfMonth = $newCron->cronCreateItems($newCron->_cronDaysOfMonth);
     $newCron->_months = $newCron->cronCreateItems($newCron->_cronMonths);
     $newCron->_daysOfWeek = $newCron->cronCreateItems($newCron->_cronDaysOfWeek);
     $newCron->_years = $newCron->cronCreateItems($newCron->_cronYears);
     return $newCron;
 }