Page MenuHomeIn-Portal Phabricator

RunScheduledTaskCommand.php
No OneTemporary

File Metadata

Created
Sun, Aug 3, 9:42 AM

RunScheduledTaskCommand.php

<?php
/**
* @version $Id: RunScheduledTaskCommand.php 16252 2015-09-27 06:34:45Z alex $
* @package In-Portal
* @copyright Copyright (C) 1997 - 2015 Intechnic. All rights reserved.
* @license GNU/GPL
* In-Portal is Open Source software.
* This means that this software may have been modified pursuant
* the GNU General Public License, and as distributed it includes
* or is derivative of works licensed under the GNU General Public License
* or other free or open source software licenses.
* See http://www.in-portal.org/license for copyright notices and details.
*/
namespace InPortal\Core\kernel\Console\Command;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
defined('FULL_PATH') or die('restricted access!');
class RunScheduledTaskCommand extends AbstractCommand implements CompletionAwareInterface
{
/**
* Configures the current command.
*
* @return void
*/
protected function configure()
{
$this
->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);
}
}

Event Timeline