Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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: 09.10.2024, 12:55 - Dateigröße: 4.92 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 Symfony\Component\Console\Input\InputInterface;
017  use Symfony\Component\Console\Input\InputArgument;
018  use Symfony\Component\Console\Output\OutputInterface;
019   
020  class run extends \phpbb\console\command\command
021  {
022      /** @var \phpbb\cron\manager */
023      protected $cron_manager;
024   
025      /** @var \phpbb\lock\db */
026      protected $lock_db;
027   
028      /**
029      * Construct method
030      *
031      * @param \phpbb\user $user The user object (used to get language information)
032      * @param \phpbb\cron\manager $cron_manager The cron manager containing
033      *        the cron tasks to be executed.
034      * @param \phpbb\lock\db $lock_db The lock for accessing database.
035      */
036      public function __construct(\phpbb\user $user, \phpbb\cron\manager $cron_manager, \phpbb\lock\db $lock_db)
037      {
038          $this->cron_manager = $cron_manager;
039          $this->lock_db = $lock_db;
040          parent::__construct($user);
041      }
042   
043      /**
044      * Sets the command name and description
045      *
046      * @return null
047      */
048      protected function configure()
049      {
050          $this
051              ->setName('cron:run')
052              ->setDescription($this->user->lang('CLI_DESCRIPTION_CRON_RUN'))
053              ->addArgument('name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_CRON_RUN_ARGUMENT_1'))
054          ;
055      }
056   
057      /**
058      * Executes the command cron:run.
059      *
060      * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks.
061      * If the cron lock can not be obtained, an error message is printed
062      *        and the exit status is set to 1.
063      * If the verbose option is specified, each start of a task is printed.
064      *        Otherwise there is no output.
065      * If an argument is given to the command, only the task whose name matches the
066      *        argument will be started. If verbose option is specified,
067      *        an info message containing the name of the task is printed.
068      * If no task matches the argument given, an error message is printed
069      *        and the exit status is set to 2.
070      *
071      * @param InputInterface $input The input stream used to get the argument and verboe option.
072      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
073      *
074      * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found.
075      */
076      protected function execute(InputInterface $input, OutputInterface $output)
077      {
078          if ($this->lock_db->acquire())
079          {
080              $task_name = $input->getArgument('name');
081              if ($task_name)
082              {
083                  $exit_status = $this->run_one($input, $output, $task_name);
084              }
085              else
086              {
087                  $exit_status = $this->run_all($input, $output);
088              }
089   
090              $this->lock_db->release();
091              return $exit_status;
092          }
093          else
094          {
095              $output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>');
096              return 1;
097          }
098      }
099   
100      /**
101      * Executes all ready cron tasks.
102      *
103      * If verbose mode is set, an info message will be printed if there is no task to
104      *        be run, or else for each starting task.
105      *
106      * @see execute
107      * @param InputInterface $input The input stream used to get the argument and verbose option.
108      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
109      * @return int 0
110      */
111      protected function run_all(InputInterface $input, OutputInterface $output)
112      {
113          $run_tasks = $this->cron_manager->find_all_ready_tasks();
114   
115          if ($run_tasks)
116          {
117              foreach ($run_tasks as $task)
118              {
119                  if ($input->getOption('verbose'))
120                  {
121                      $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task->get_name()) . '</info>');
122                  }
123   
124                  $task->run();
125              }
126          }
127          else
128          {
129              if ($input->getOption('verbose'))
130              {
131                  $output->writeln('<info>' . $this->user->lang('CRON_NO_TASK') . '</info>');
132              }
133          }
134   
135          return 0;
136      }
137   
138      /**
139      * Executes a given cron task, if it is ready.
140      *
141      * If there is a task whose name matches $task_name, it is run and 0 is returned.
142      *        and if verbose mode is set, print an info message with the name of the task.
143      * If there is no task matching $task_name, the function prints an error message
144      *        and returns with status 2.
145      *
146      * @see execute
147      * @param string $task_name The name of the task that should be run.
148      * @param InputInterface $input The input stream used to get the argument and verbose option.
149      * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
150      * @return int 0 if all is well, 2 if no task matches $task_name.
151      */
152      protected function run_one(InputInterface $input, OutputInterface $output, $task_name)
153      {
154          $task = $this->cron_manager->find_task($task_name);
155          if ($task)
156          {
157              if ($input->getOption('verbose'))
158              {
159                  $output->writeln('<info>' . $this->user->lang('RUNNING_TASK', $task_name) . '</info>');
160              }
161   
162              $task->run();
163              return 0;
164          }
165          else
166          {
167              $output->writeln('<error>' . $this->user->lang('CRON_NO_SUCH_TASK', $task_name) . '</error>');
168              return 2;
169          }
170      }
171  }
172