Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

reparse.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 5.81 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\reparser;
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\Input\InputOption;
020  use Symfony\Component\Console\Output\OutputInterface;
021  use Symfony\Component\Console\Style\SymfonyStyle;
022   
023  class reparse extends \phpbb\console\command\command
024  {
025      /**
026      * @var InputInterface
027      */
028      protected $input;
029   
030      /**
031      * @var SymfonyStyle
032      */
033      protected $io;
034   
035      /**
036      * @var OutputInterface
037      */
038      protected $output;
039   
040      /**
041       * @var \phpbb\lock\db
042       */
043      protected $reparse_lock;
044   
045      /**
046       * @var \phpbb\textreparser\manager
047       */
048      protected $reparser_manager;
049   
050      /**
051      * @var \phpbb\di\service_collection
052      */
053      protected $reparsers;
054   
055      /**
056      * @var array The reparser's last $current ID as values
057      */
058      protected $resume_data;
059   
060      /**
061      * Constructor
062      *
063      * @param \phpbb\user $user
064      * @param \phpbb\lock\db $reparse_lock
065      * @param \phpbb\textreparser\manager $reparser_manager
066      * @param \phpbb\di\service_collection $reparsers
067      */
068      public function __construct(\phpbb\user $user, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers)
069      {
070          require_once __DIR__ . '/../../../../includes/functions_content.php';
071   
072          $this->reparse_lock = $reparse_lock;
073          $this->reparser_manager = $reparser_manager;
074          $this->reparsers = $reparsers;
075          parent::__construct($user);
076      }
077   
078      /**
079      * Sets the command name and description
080      *
081      * @return null
082      */
083      protected function configure()
084      {
085          $this
086              ->setName('reparser:reparse')
087              ->setDescription($this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE'))
088              ->addArgument('reparser-name', InputArgument::OPTIONAL, $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_ARG_1'))
089              ->addOption(
090                  'dry-run',
091                  null,
092                  InputOption::VALUE_NONE,
093                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_DRY_RUN')
094              )
095              ->addOption(
096                  'resume',
097                  null,
098                  InputOption::VALUE_NONE,
099                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME')
100              )
101              ->addOption(
102                  'range-min',
103                  null,
104                  InputOption::VALUE_REQUIRED,
105                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'),
106                  1
107              )
108              ->addOption(
109                  'range-max',
110                  null,
111                  InputOption::VALUE_REQUIRED,
112                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX')
113              )
114              ->addOption(
115                  'range-size',
116                  null,
117                  InputOption::VALUE_REQUIRED,
118                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'),
119                  100
120              );
121          ;
122      }
123   
124      /**
125      * Executes the command reparser:reparse
126      *
127      * @param InputInterface $input
128      * @param OutputInterface $output
129      * @return integer
130      */
131      protected function execute(InputInterface $input, OutputInterface $output)
132      {
133          $this->input = $input;
134          $this->output = $output;
135          $this->io = new SymfonyStyle($input, $output);
136   
137          if (!$this->reparse_lock->acquire())
138          {
139              throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
140          }
141   
142          $name = $input->getArgument('reparser-name');
143          if ($name)
144          {
145              $name = $this->reparser_manager->find_reparser($name);
146              $this->reparse($name);
147          }
148          else
149          {
150              foreach ($this->reparsers as $name => $service)
151              {
152                  $this->reparse($name);
153              }
154          }
155   
156          $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
157   
158          $this->reparse_lock->release();
159   
160          return 0;
161      }
162   
163      /**
164      * Get an option value, adjusted for given reparser
165      *
166      * Will use the last saved value if --resume is set and the option was not specified
167      * on the command line
168      *
169      * @param  string  $option_name   Option name
170      * @return integer
171      */
172      protected function get_option($option_name)
173      {
174          // Return the option from the resume_data if applicable
175          if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name))
176          {
177              return $this->resume_data[$option_name];
178          }
179   
180          return $this->input->getOption($option_name);
181      }
182   
183      /**
184      * Reparse all text handled by given reparser within given range
185      *
186      * @param string $name Reparser service name
187      */
188      protected function reparse($name)
189      {
190          $reparser = $this->reparsers[$name];
191          $this->resume_data = $this->reparser_manager->get_resume_data($name);
192          if ($this->input->getOption('dry-run'))
193          {
194              $reparser->disable_save();
195          }
196          else
197          {
198              $reparser->enable_save();
199          }
200   
201          // Start at range-max if specified or at the highest ID otherwise
202          $max  = $this->get_option('range-max');
203          $min  = $this->get_option('range-min');
204          $size = $this->get_option('range-size');
205   
206          // range-max has no default value, it must be computed for each reparser
207          if ($max === null)
208          {
209              $max = $reparser->get_max_id();
210          }
211   
212          if ($max < $min)
213          {
214              return;
215          }
216   
217          $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max));
218   
219          $progress = $this->create_progress_bar($max, $this->io, $this->output, true);
220          $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name()));
221          $progress->start();
222   
223          // Start from $max and decrement $current by $size until we reach $min
224          $current = $max;
225          while ($current >= $min)
226          {
227              $start = max($min, $current + 1 - $size);
228              $end   = max($min, $current);
229   
230              $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
231              $reparser->reparse_range($start, $end);
232   
233              $current = $start - 1;
234              $progress->setProgress($max + 1 - $start);
235   
236              $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run'));
237          }
238          $progress->finish();
239   
240          $this->io->newLine(2);
241      }
242  }
243