Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

run.php

Zuletzt modifiziert: 01.05.2026, 11:26 - Dateigröße: 4.96 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\console\command\cron;
 015   
 016  use phpbb\exception\runtime_exception;
 017  use Symfony\Component\Console\Input\InputInterface;
 018  use Symfony\Component\Console\Input\InputArgument;
 019  use Symfony\Component\Console\Output\OutputInterface;
 020   
 021  class run extends \phpbb\console\command\command
 022  {
 023      /** @var \phpbb\cron\manager */
 024      protected $cron_manager;
 025   
 026      /** @var \phpbb\lock\db */
 027      protected $lock_db;
 028   
 029      /**
 030      * Construct method
 031      *
 032      * @param \phpbb\user $user The user object (used to get language information)
 033      * @param \phpbb\cron\manager $cron_manager The cron manager containing
 034      *        the cron tasks to be executed.
 035      * @param \phpbb\lock\db $lock_db The lock for accessing database.
 036      */
 037      public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db)
 038      {
 039          $this->cron_manager = $cron_manager;
 040          $this->lock_db = $lock_db;
 041          parent::__construct($user);
 042      }
 043   
 044      /**
 045      * Sets the command name and description
 046      *
 047      * @return null
 048      */
 049      protected function configure()
 050      {
 051          $this
 052              ->setName('cron:run')
 053              ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_RUN'))
 054              ->setHelp($this->user->lang('CLI_HELP_CRON_RUN'))
 055              ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1'))
 056          ;
 057      }
 058   
 059      /**
 060      * Executes the command cron:run.
 061      *
 062      * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks.
 063      * If the cron lock can not be obtained, an error message is printed
 064      *        and the exit status is set to 1.
 065      * If the verbose option is specified, each start of a task is printed.
 066      *        Otherwise there is no output.
 067      * If an argument is given to the command, only the task whose name matches the
 068      *        argument will be started. If verbose option is specified,
 069      *        an info message containing the name of the task is printed.
 070      * If no task matches the argument given, an error message is printed
 071      *        and the exit status is set to 2.
 072      *
 073      * @param InputInterface $input The input stream used to get the argument and verboe option.
 074      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
 075      *
 076      * @return int 0 if all is ok, 1 if a lock error occurred and 2 if no task matching the argument was found.
 077      */
 078      protected function execute(InputInterface $input, OutputInterface $output)
 079      {
 080          if ($this->lock_db->acquire())
 081          {
 082              $task_name = $input->getArgument('name');
 083              if ($task_name)
 084              {
 085                  $exit_status = $this->run_one($input, $output, $task_name);
 086              }
 087              else
 088              {
 089                  $exit_status = $this->run_all($input, $output);
 090              }
 091   
 092              $this->lock_db->release();
 093              return $exit_status;
 094          }
 095          else
 096          {
 097              throw new runtime_exception('CRON_LOCK_ERROR', array(), null, 1);
 098          }
 099      }
 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      *
 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      * @param string $task_name The name of the task that should be run.
 152      *
 153      * @return int 0 if all is well, 2 if no task matches $task_name.
 154      */
 155      protected function run_one(InputInterface $input, OutputInterface $output, $task_name)
 156      {
 157          $task = $this->cron_manager->find_task($task_name);
 158          if ($task)
 159          {
 160              if ($input->getOption('verbose'))
 161              {
 162                  $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task_name) . '</info>');
 163              }
 164   
 165              $task->run();
 166              return 0;
 167          }
 168          else
 169          {
 170              throw new runtime_exception('CRON_NO_SUCH_TASK', array( $task_name), null, 2);
 171          }
 172      }
 173  }
 174