[ Index ] |
PHP Cross Reference of phpBB-3.1.12-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * 4 * This file is part of the phpBB Forum Software package. 5 * 6 * @copyright (c) phpBB Limited <https://www.phpbb.com> 7 * @license GNU General Public License, version 2 (GPL-2.0) 8 * 9 * For full copyright and license information, please see 10 * the docs/CREDITS.txt file. 11 * 12 */ 13 14 namespace phpbb\console\command\cron; 15 16 use Symfony\Component\Console\Input\InputInterface; 17 use Symfony\Component\Console\Input\InputArgument; 18 use Symfony\Component\Console\Output\OutputInterface; 19 20 class run extends \phpbb\console\command\command 21 { 22 /** @var \phpbb\cron\manager */ 23 protected $cron_manager; 24 25 /** @var \phpbb\lock\db */ 26 protected $lock_db; 27 28 /** 29 * Construct method 30 * 31 * @param \phpbb\user $user The user object (used to get language information) 32 * @param \phpbb\cron\manager $cron_manager The cron manager containing 33 * the cron tasks to be executed. 34 * @param \phpbb\lock\db $lock_db The lock for accessing database. 35 */ 36 public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db) 37 { 38 $this->cron_manager = $cron_manager; 39 $this->lock_db = $lock_db; 40 parent::__construct($user); 41 } 42 43 /** 44 * Sets the command name and description 45 * 46 * @return null 47 */ 48 protected function configure() 49 { 50 $this 51 ->setName('cron:run') 52 ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_RUN')) 53 ->setHelp($this->user->lang('CLI_HELP_CRON_RUN')) 54 ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1')) 55 ; 56 } 57 58 /** 59 * Executes the command cron:run. 60 * 61 * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks. 62 * If the cron lock can not be obtained, an error message is printed 63 * and the exit status is set to 1. 64 * If the verbose option is specified, each start of a task is printed. 65 * Otherwise there is no output. 66 * If an argument is given to the command, only the task whose name matches the 67 * argument will be started. If verbose option is specified, 68 * an info message containing the name of the task is printed. 69 * If no task matches the argument given, an error message is printed 70 * and the exit status is set to 2. 71 * 72 * @param InputInterface $input The input stream used to get the argument and verboe option. 73 * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. 74 * 75 * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found. 76 */ 77 protected function execute(InputInterface $input, OutputInterface $output) 78 { 79 if ($this->lock_db->acquire()) 80 { 81 $task_name = $input->getArgument('name'); 82 if ($task_name) 83 { 84 $exit_status = $this->run_one($input, $output, $task_name); 85 } 86 else 87 { 88 $exit_status = $this->run_all($input, $output); 89 } 90 91 $this->lock_db->release(); 92 return $exit_status; 93 } 94 else 95 { 96 $output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>'); 97 return 1; 98 } 99 } 100 101 /** 102 * Executes all ready cron tasks. 103 * 104 * If verbose mode is set, an info message will be printed if there is no task to 105 * be run, or else for each starting task. 106 * 107 * @see execute 108 * @param InputInterface $input The input stream used to get the argument and verbose option. 109 * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. 110 * @return int 0 111 */ 112 protected function run_all(InputInterface $input, OutputInterface $output) 113 { 114 $run_tasks = $this->cron_manager->find_all_ready_tasks(); 115 116 if ($run_tasks) 117 { 118 foreach ($run_tasks as $task) 119 { 120 if ($input->getOption('verbose')) 121 { 122 $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task->get_name()) . '</info>'); 123 } 124 125 $task->run(); 126 } 127 } 128 else 129 { 130 if ($input->getOption('verbose')) 131 { 132 $output->writeln('<info>' . $this->user->lang('CRON_NO_TASK') . '</info>'); 133 } 134 } 135 136 return 0; 137 } 138 139 /** 140 * Executes a given cron task, if it is ready. 141 * 142 * If there is a task whose name matches $task_name, it is run and 0 is returned. 143 * and if verbose mode is set, print an info message with the name of the task. 144 * If there is no task matching $task_name, the function prints an error message 145 * and returns with status 2. 146 * 147 * @see execute 148 * @param string $task_name The name of the task that should be run. 149 * @param InputInterface $input The input stream used to get the argument and verbose option. 150 * @param OutputInterface $output The output stream, used for printing verbose-mode and error information. 151 * @return int 0 if all is well, 2 if no task matches $task_name. 152 */ 153 protected function run_one(InputInterface $input, OutputInterface $output, $task_name) 154 { 155 $task = $this->cron_manager->find_task($task_name); 156 if ($task) 157 { 158 if ($input->getOption('verbose')) 159 { 160 $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task_name) . '</info>'); 161 } 162 163 $task->run(); 164 return 0; 165 } 166 else 167 { 168 $output->writeln('<error>' . $this->user->lang('CRON_NO_SUCH_TASK', $task_name) . '</error>'); 169 return 2; 170 } 171 } 172 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Jan 11 00:25:41 2018 | Cross-referenced by PHPXref 0.7.1 |