Index: branches/5.3.x/core/admin_templates/scheduled_tasks/scheduled_task_list.tpl =================================================================== diff -u -N -r15677 -r16188 --- branches/5.3.x/core/admin_templates/scheduled_tasks/scheduled_task_list.tpl (.../scheduled_task_list.tpl) (revision 15677) +++ branches/5.3.x/core/admin_templates/scheduled_tasks/scheduled_task_list.tpl (.../scheduled_task_list.tpl) (revision 16188) @@ -51,16 +51,6 @@ a_toolbar.AddButton( new ToolBarButton( - 'process', - '', - function() { - submit_event('scheduled-task', 'OnRun'); - } - ) - ); - - a_toolbar.AddButton( - new ToolBarButton( 'cancel', '', function() { @@ -94,6 +84,6 @@ - \ No newline at end of file + Index: branches/5.3.x/core/kernel/managers/scheduled_task_manager.php =================================================================== diff -u -N -r15945 -r16188 --- branches/5.3.x/core/kernel/managers/scheduled_task_manager.php (.../scheduled_task_manager.php) (revision 15945) +++ branches/5.3.x/core/kernel/managers/scheduled_task_manager.php (.../scheduled_task_manager.php) (revision 16188) @@ -1,6 +1,6 @@ LoadFromHash($scheduled_task_data); $event->redirect = false; + + // The fake MasterEvent is needed so that $event can access $scheduled_task! $event->MasterEvent = new kEvent('scheduled-task:OnRun'); $this->Application->HandleEvent($event); @@ -228,4 +230,4 @@ $scheduled_task_data = array_merge($scheduled_task_data, $fields_hash); } -} \ No newline at end of file +} Index: branches/5.3.x/core/install/cache/class_structure.php =================================================================== diff -u -N -r16181 -r16188 --- branches/5.3.x/core/install/cache/class_structure.php (.../class_structure.php) (revision 16181) +++ branches/5.3.x/core/install/cache/class_structure.php (.../class_structure.php) (revision 16188) @@ -88,6 +88,7 @@ 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\IConsoleCommand' => '/core/kernel/Console/Command/IConsoleCommand.php', 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\ResetCacheCommand' => '/core/kernel/Console/Command/ResetCacheCommand.php', 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\RunEventCommand' => '/core/kernel/Console/Command/RunEventCommand.php', + 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\RunScheduledTaskCommand' => '/core/kernel/Console/Command/RunScheduledTaskCommand.php', 'Intechnic\\InPortal\\Core\\kernel\\Console\\ConsoleApplication' => '/core/kernel/Console/ConsoleApplication.php', 'Intechnic\\InPortal\\Core\\kernel\\Console\\ConsoleCommandProvider' => '/core/kernel/Console/ConsoleCommandProvider.php', 'Intechnic\\InPortal\\Core\\kernel\\Console\\IConsoleCommandProvider' => '/core/kernel/Console/IConsoleCommandProvider.php', @@ -887,6 +888,14 @@ 1 => 'Stecman\\Component\\Symfony\\Console\\BashCompletion\\Completion\\CompletionAwareInterface', ), ), + 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\RunScheduledTaskCommand' => array( + 'type' => 1, + 'modifiers' => 0, + 'extends' => array( + 0 => 'Intechnic\\InPortal\\Core\\kernel\\Console\\Command\\AbstractCommand', + 1 => 'Stecman\\Component\\Symfony\\Console\\BashCompletion\\Completion\\CompletionAwareInterface', + ), + ), 'Intechnic\\InPortal\\Core\\kernel\\Console\\ConsoleApplication' => array( 'type' => 1, 'modifiers' => 0, Index: branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php =================================================================== diff -u -N --- branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php (revision 0) +++ branches/5.3.x/core/kernel/Console/Command/RunScheduledTaskCommand.php (revision 16188) @@ -0,0 +1,116 @@ +setName('scheduled-task:run') + ->setDescription('Runs scheduled task(-s)') + ->addArgument( + 'scheduled_task_name', + InputArgument::OPTIONAL, + 'Scheduled task name' + ); + } + + /** + * Executes the current command. + * + * @param InputInterface $input An InputInterface instance. + * @param OutputInterface $output An OutputInterface instance. + * + * @return null|integer + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $scheduled_task_name = $input->getArgument('scheduled_task_name'); + + if ( !$scheduled_task_name ) { + $this->Application->EventManager->runScheduledTasks(true); + + return 0; + } + + if ( !in_array($scheduled_task_name, $this->getScheduledTaskNames()) ) { + throw new \InvalidArgumentException('Scheduled task "' . $scheduled_task_name . '" not found'); + } + + $scheduled_tasks = $this->Application->EventManager->getScheduledTasks(); + $result = $this->Application->EventManager->runScheduledTask($scheduled_tasks[$scheduled_task_name]); + + return $result ? 0 : 64; + } + + /** + * Return possible values for the named option + * + * @param string $optionName Option name. + * @param CompletionContext $context Completion context. + * + * @return array + */ + public function completeOptionValues($optionName, CompletionContext $context) + { + return array(); + } + + /** + * Return possible values for the named argument. + * + * @param string $argumentName Argument name. + * @param CompletionContext $context Completion context. + * + * @return array + */ + public function completeArgumentValues($argumentName, CompletionContext $context) + { + if ( $argumentName === 'scheduled_task_name' ) { + return $this->getScheduledTaskNames(); + } + + return array(); + } + + /** + * Returns scheduled task names. + * + * @return array + */ + protected function getScheduledTaskNames() + { + $scheduled_tasks = $this->Application->EventManager->getScheduledTasks(); + + return array_keys($scheduled_tasks); + } + +} Index: branches/5.3.x/core/units/scheduled_tasks/scheduled_task_eh.php =================================================================== diff -u -N -r15945 -r16188 --- branches/5.3.x/core/units/scheduled_tasks/scheduled_task_eh.php (.../scheduled_task_eh.php) (revision 15945) +++ branches/5.3.x/core/units/scheduled_tasks/scheduled_task_eh.php (.../scheduled_task_eh.php) (revision 16188) @@ -1,6 +1,6 @@ Array ('self' => 'add|edit'), - 'OnRun' => Array ('self' => 'add|edit'), ); $this->permMapping = array_merge($this->permMapping, $permissions); @@ -178,37 +177,6 @@ } /** - * Runs selected scheduled tasks - * - * @param kEvent $event - */ - function OnRun($event) - { - $ids = $this->StoreSelectedIDs($event); - - if ($ids) { - $object = $event->getObject( Array ('skip_autoload' => true) ); - /* @var $object kDBItem */ - - $where_clause = Array ( - $object->TableName . '.' . $object->IDField . ' IN (' . implode(',', $ids) . ')', - $object->TableName . '.Status = ' . STATUS_ACTIVE, - $object->TableName . '.LastRunStatus <> ' . ScheduledTask::LAST_RUN_RUNNING, - ); - - $sql = $object->GetSelectSQL() . ' - WHERE (' . implode(') AND (', $where_clause) . ')'; - $scheduled_tasks = $this->Conn->Query($sql); - - foreach ($scheduled_tasks as $scheduled_task_data) { - $this->Application->EventManager->runScheduledTask($scheduled_task_data); - } - } - - $this->clearSelectedIDs($event); - } - - /** * Loads schedule from database to virtual fields * * @param kEvent $event @@ -303,4 +271,4 @@ $cron_helper->initUnit($event->Prefix, 'RunSchedule'); } - } \ No newline at end of file + } Index: branches/5.3.x/tools/cron.php =================================================================== diff -u -N -r15902 -r16188 --- branches/5.3.x/tools/cron.php (.../cron.php) (revision 15902) +++ branches/5.3.x/tools/cron.php (.../cron.php) (revision 16188) @@ -1,8 +1,8 @@ /tools/cron.php -O /dev/null > /dev/null 2>&1 +// Use above line to invoke from cron: // */1 * * * * /usr/bin/php /path/to/site/tools/cron.php > /dev/null 2>&1 -$start = microtime(true); -define('CRON', 1); -//define('ADMIN', 1); // don't ever define, because this would drastically break down all links built from cron -define('FULL_PATH', realpath(dirname(__FILE__) . '/..')); -define('CMD_MODE', isset($argv) && count($argv) ? 1 : 0); - -if ( CMD_MODE ) { - define('DBG_SKIP_REPORTING', 1); - $_SERVER['REQUEST_URI'] = 'CRON'; - $_SERVER['HTTP_USER_AGENT'] = 'gecko'; +if ( PHP_SAPI !== 'cli' ) { + echo 'This script is intended to be used from command-line only !'; + exit(64); } -include_once(FULL_PATH . '/core/kernel/startup.php'); +define('FULL_PATH', realpath(dirname(__FILE__) . '/..')); -$application =& kApplication::Instance(); -$application->Init(); - -// events from request are not processed, only predefined scheduled tasks -$application->EventManager->runScheduledTasks(true); - +$exit_code = 0; +passthru(FULL_PATH . '/in-portal scheduled-task:run', $exit_code); +exit($exit_code);