Index: branches/5.2.x/core/kernel/managers/scheduled_task_manager.php =================================================================== diff -u -N -r14880 -r15033 --- branches/5.2.x/core/kernel/managers/scheduled_task_manager.php (.../scheduled_task_manager.php) (revision 14880) +++ branches/5.2.x/core/kernel/managers/scheduled_task_manager.php (.../scheduled_task_manager.php) (revision 15033) @@ -1,6 +1,6 @@ before = $data['EventManager.beforeRegularEvents']; - $this->after = $data['EventManager.afterRegularEvents']; + $this->tasks = $data['EventManager.scheduledTasks']; } /** @@ -53,8 +44,7 @@ public function getToCache() { return Array ( - 'EventManager.beforeRegularEvents' => $this->before, - 'EventManager.afterRegularEvents' => $this->after, + 'EventManager.scheduledTasks' => $this->tasks, ); } @@ -69,11 +59,8 @@ { static $scheduled_tasks = null; - if ($from_cache) { - return Array ( - reBEFORE => $this->before, - reAFTER => $this->after, - ); + if ( $from_cache ) { + return $this->tasks; } if ( !isset($scheduled_tasks) ) { @@ -82,72 +69,35 @@ $sql = 'SELECT * FROM ' . $this->Application->getUnitOption('scheduled-task', 'TableName') . ' WHERE (Status = ' . STATUS_ACTIVE . ') AND ((LastRunStatus != ' . ScheduledTask::LAST_RUN_RUNNING . ') OR (' . $timeout_clause . '))'; - $all_scheduled_tasks = $this->Conn->Query($sql); - - $scheduled_tasks = Array ( - reBEFORE => Array (), - reAFTER => Array (), - ); - - foreach ($all_scheduled_tasks as $scheduled_task_data) { - $scheduled_tasks[ $scheduled_task_data['RunMode'] ][ $scheduled_task_data['Name'] ] = Array ( - 'EventName' => $scheduled_task_data['Event'], - 'RunInterval' => (int)$scheduled_task_data['RunInterval'], - 'LastRunOn' => (int)$scheduled_task_data['LastRunOn'], - 'NextRunOn' => (int)$scheduled_task_data['NextRunOn'], - 'Status' => $scheduled_task_data['Status'], - 'LastRunStatus' => $scheduled_task_data['LastRunStatus'], - 'SiteDomainLimitation' => $scheduled_task_data['SiteDomainLimitation'], - ); - } + $scheduled_tasks = $this->Conn->Query($sql, 'Name'); } return $scheduled_tasks; } /** - * Returns scheduled tasks by type - * - * @param int $type - * @return Array - * @access protected - */ - protected function &getByType($type) - { - if ($type == reBEFORE) { - return $this->before; - } - - return $this->after; - } - - /** * Add new scheduled task * * @param string $short_name name to be used to store last maintenance run info - * @param string $event_name + * @param string $event_string * @param int $run_interval run interval in seconds - * @param int $type before or after scheduled task * @param int $status * @access public */ - public function add($short_name, $event_name, $run_interval, $type = reBEFORE, $status = STATUS_ACTIVE) + public function add($short_name, $event_string, $run_interval, $status = STATUS_ACTIVE) { - $scheduled_tasks =& $this->getByType($type); - - $scheduled_tasks[$short_name] = Array ( - 'EventName' => $event_name, 'RunInterval' => $run_interval, 'Status' => $status + $this->tasks[$short_name] = Array ( + 'Event' => $event_string, 'RunInterval' => $run_interval, 'Status' => $status ); } /** * Run registered scheduled tasks with specified event type * - * @param int $event_type * @param bool $from_cron * @access public */ - public function runAll($event_type = reBEFORE, $from_cron = false) + public function runAll($from_cron = false) { if ( defined('IS_INSTALL') ) { return ; @@ -158,8 +108,7 @@ return ; } - $scheduled_tasks = $this->getAll(); - $events_source = $scheduled_tasks[$event_type]; + $events_source = $this->getAll(); $user_id = $this->Application->RecallVar('user_id'); $this->Application->StoreVar('user_id', USER_ROOT, true); // to prevent permission checking inside events, true for optional storage @@ -184,7 +133,7 @@ $this->update($short_name, Array ('LastTimeoutOn' => adodb_mktime())); } - $next_run = $event_data['NextRunOn']; + $next_run = (int)$event_data['NextRunOn']; if ($next_run && ($next_run > adodb_mktime())) { continue; @@ -206,7 +155,7 @@ */ public function run($scheduled_task_data) { - $event = new kEvent($scheduled_task_data['EventName']); + $event = new kEvent($scheduled_task_data['Event']); if ( !$this->Application->prefixRegistred($event->Prefix) ) { // don't process scheduled tasks, left from disabled modules