Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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: 02.04.2025, 15:02 - Dateigröße: 6.07 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                  'force-bbcode-reparsing',
097                  null,
098                  InputOption::VALUE_NONE,
099                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_FORCE_BBCODE')
100              )
101              ->addOption(
102                  'resume',
103                  null,
104                  InputOption::VALUE_NONE,
105                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RESUME')
106              )
107              ->addOption(
108                  'range-min',
109                  null,
110                  InputOption::VALUE_REQUIRED,
111                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MIN'),
112                  1
113              )
114              ->addOption(
115                  'range-max',
116                  null,
117                  InputOption::VALUE_REQUIRED,
118                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_MAX')
119              )
120              ->addOption(
121                  'range-size',
122                  null,
123                  InputOption::VALUE_REQUIRED,
124                  $this->user->lang('CLI_DESCRIPTION_REPARSER_REPARSE_OPT_RANGE_SIZE'),
125                  100
126              );
127          ;
128      }
129   
130      /**
131      * Executes the command reparser:reparse
132      *
133      * @param InputInterface $input
134      * @param OutputInterface $output
135      * @return integer
136      */
137      protected function execute(InputInterface $input, OutputInterface $output)
138      {
139          $this->input = $input;
140          $this->output = $output;
141          $this->io = new SymfonyStyle($input, $output);
142   
143          if (!$this->reparse_lock->acquire())
144          {
145              throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
146          }
147   
148          $name = $input->getArgument('reparser-name');
149          if ($name)
150          {
151              $name = $this->reparser_manager->find_reparser($name);
152              $this->reparse($name);
153          }
154          else
155          {
156              foreach ($this->reparsers as $name => $service)
157              {
158                  $this->reparse($name);
159              }
160          }
161   
162          $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
163   
164          $this->reparse_lock->release();
165   
166          return 0;
167      }
168   
169      /**
170      * Get an option value, adjusted for given reparser
171      *
172      * Will use the last saved value if --resume is set and the option was not specified
173      * on the command line
174      *
175      * @param  string  $option_name   Option name
176      * @return integer
177      */
178      protected function get_option($option_name)
179      {
180          // Return the option from the resume_data if applicable
181          if ($this->input->getOption('resume') && isset($this->resume_data[$option_name]) && !$this->input->hasParameterOption('--' . $option_name))
182          {
183              return $this->resume_data[$option_name];
184          }
185   
186          return $this->input->getOption($option_name);
187      }
188   
189      /**
190      * Reparse all text handled by given reparser within given range
191      *
192      * @param string $name Reparser service name
193      */
194      protected function reparse($name)
195      {
196          $reparser = $this->reparsers[$name];
197          $this->resume_data = $this->reparser_manager->get_resume_data($name);
198          if ($this->input->getOption('dry-run'))
199          {
200              $reparser->disable_save();
201          }
202          else
203          {
204              $reparser->enable_save();
205          }
206   
207          // Start at range-max if specified or at the highest ID otherwise
208          $max  = $this->get_option('range-max');
209          $min  = $this->get_option('range-min');
210          $size = $this->get_option('range-size');
211   
212          // range-max has no default value, it must be computed for each reparser
213          if ($max === null)
214          {
215              $max = $reparser->get_max_id();
216          }
217   
218          if ($max < $min)
219          {
220              return;
221          }
222   
223          $this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $min, $max));
224   
225          $progress = $this->create_progress_bar($max, $this->io, $this->output, true);
226          $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', $reparser->get_name()));
227          $progress->start();
228   
229          // Start from $max and decrement $current by $size until we reach $min
230          $current = $max;
231   
232          $force_bbcode_reparsing = (bool) $this->get_option('force-bbcode-reparsing');
233          while ($current >= $min)
234          {
235              $start = max($min, $current + 1 - $size);
236              $end   = max($min, $current);
237   
238              $progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', $reparser->get_name(), $start, $end));
239              $reparser->reparse_range($start, $end, $force_bbcode_reparsing);
240   
241              $current = $start - 1;
242              $progress->setProgress($max + 1 - $start);
243   
244              $this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run'));
245          }
246          $progress->finish();
247   
248          $this->io->newLine(2);
249      }
250  }
251