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

reparser.php

Zuletzt modifiziert: 09.10.2024, 12:55 - Dateigröße: 3.68 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\cron\task\text_reparser;
015   
016  /**
017   * Reparse text cron task
018   */
019  class reparser extends \phpbb\cron\task\base
020  {
021      const MIN = 1;
022      const SIZE = 100;
023   
024      /**
025       * @var \phpbb\config\config
026       */
027      protected $config;
028   
029      /**
030       * @var \phpbb\config\db_text
031       */
032      protected $config_text;
033   
034      /**
035       * @var \phpbb\lock\db
036       */
037      protected $reparse_lock;
038   
039      /**
040       * @var \phpbb\textreparser\manager
041       */
042      protected $reparser_manager;
043   
044      /**
045       * @var string
046       */
047      protected $reparser_name;
048   
049      /**
050       * @var \phpbb\di\service_collection
051       */
052      protected $reparsers;
053   
054      /**
055       * @var array
056       */
057      protected $resume_data;
058   
059      /**
060       * Constructor
061       *
062       * @param \phpbb\config\config            $config
063       * @param \phpbb\config\db_text            $config_text
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\config\config $config, \phpbb\config\db_text $config_text, \phpbb\lock\db $reparse_lock, \phpbb\textreparser\manager $reparser_manager, \phpbb\di\service_collection $reparsers)
069      {
070          $this->config = $config;
071          $this->config_text = $config_text;
072          $this->reparse_lock = $reparse_lock;
073          $this->reparser_manager = $reparser_manager;
074          $this->reparsers = $reparsers;
075      }
076   
077      /**
078       * Sets the reparser for this cron task
079       *
080       * @param string    $reparser
081       */
082      public function set_reparser($reparser)
083      {
084          $this->reparser_name = !isset($this->reparsers[$reparser]) ? $this->reparser_manager->find_reparser($reparser) : $reparser;
085   
086          if ($this->resume_data === null)
087          {
088              $this->reparser_manager->get_resume_data($this->reparser_name);
089          }
090      }
091   
092      /**
093       * {@inheritdoc}
094       */
095      public function is_runnable()
096      {
097          if ($this->resume_data === null)
098          {
099              $this->reparser_manager->get_resume_data($this->reparser_name);
100          }
101   
102          if (!isset($this->resume_data['range-max']) || $this->resume_data['range-max'] >= $this->resume_data['range-min'])
103          {
104              return true;
105          }
106   
107          return false;
108      }
109   
110      /**
111       * {@inheritdoc}
112       */
113      public function should_run()
114      {
115          if (!empty($this->config['reparse_lock']))
116          {
117              $last_run = explode(' ', $this->config['reparse_lock']);
118   
119              if ($last_run[0] + 3600 >= time())
120              {
121                  return false;
122              }
123          }
124   
125          if ($this->config[$this->reparser_name . '_cron_interval'])
126          {
127              return $this->config[$this->reparser_name . '_last_cron'] < time() - $this->config[$this->reparser_name . '_cron_interval'];
128          }
129   
130          return false;
131      }
132   
133      /**
134       * {@inheritdoc}
135       */
136      public function run()
137      {
138          if ($this->reparse_lock->acquire())
139          {
140              if ($this->resume_data === null)
141              {
142                  $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
143              }
144   
145              /**
146               * @var \phpbb\textreparser\reparser_interface $reparser
147               */
148              $reparser = $this->reparsers[$this->reparser_name];
149   
150              $min = isset($this->resume_data['range-min']) ? $this->resume_data['range-min'] : self::MIN;
151              $current = isset($this->resume_data['range-max']) ? $this->resume_data['range-max'] : $reparser->get_max_id();
152              $size = isset($this->resume_data['range-size']) ? $this->resume_data['range-size'] : self::SIZE;
153   
154              if ($current >= $min)
155              {
156                  $start = max($min, $current + 1 - $size);
157                  $end = max($min, $current);
158   
159                  $reparser->reparse_range($start, $end);
160   
161                  $this->reparser_manager->update_resume_data($this->reparser_name, $min, $start - 1, $size);
162              }
163   
164              $this->config->set($this->reparser_name . '_last_cron', time());
165              $this->reparse_lock->release();
166          }
167      }
168  }
169