[ Index ]

PHP Cross Reference of phpBB-3.2.8-deutsch

title

Body

[close]

/phpbb/cron/task/text_reparser/ -> reparser.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\cron\task\text_reparser;
  15  
  16  /**
  17   * Reparse text cron task
  18   */
  19  class reparser extends \phpbb\cron\task\base
  20  {
  21      const MIN = 1;
  22      const SIZE = 100;
  23  
  24      /**
  25       * @var \phpbb\config\config
  26       */
  27      protected $config;
  28  
  29      /**
  30       * @var \phpbb\config\db_text
  31       */
  32      protected $config_text;
  33  
  34      /**
  35       * @var \phpbb\lock\db
  36       */
  37      protected $reparse_lock;
  38  
  39      /**
  40       * @var \phpbb\textreparser\manager
  41       */
  42      protected $reparser_manager;
  43  
  44      /**
  45       * @var string
  46       */
  47      protected $reparser_name;
  48  
  49      /**
  50       * @var \phpbb\di\service_collection
  51       */
  52      protected $reparsers;
  53  
  54      /**
  55       * @var array
  56       */
  57      protected $resume_data;
  58  
  59      /**
  60       * Constructor
  61       *
  62       * @param \phpbb\config\config            $config
  63       * @param \phpbb\config\db_text            $config_text
  64       * @param \phpbb\lock\db                $reparse_lock
  65       * @param \phpbb\textreparser\manager    $reparser_manager
  66       * @param \phpbb\di\service_collection    $reparsers
  67       */
  68  	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)
  69      {
  70          $this->config = $config;
  71          $this->config_text = $config_text;
  72          $this->reparse_lock = $reparse_lock;
  73          $this->reparser_manager = $reparser_manager;
  74          $this->reparsers = $reparsers;
  75      }
  76  
  77      /**
  78       * Sets the reparser for this cron task
  79       *
  80       * @param string    $reparser
  81       */
  82  	public function set_reparser($reparser)
  83      {
  84          $this->reparser_name = !isset($this->reparsers[$reparser]) ? $this->reparser_manager->find_reparser($reparser) : $reparser;
  85  
  86          if ($this->resume_data === null)
  87          {
  88              $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
  89          }
  90      }
  91  
  92      /**
  93       * {@inheritdoc}
  94       */
  95  	public function is_runnable()
  96      {
  97          if ($this->resume_data === null)
  98          {
  99              $this->resume_data = $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  }


Generated: Tue Apr 7 19:42:26 2020 Cross-referenced by PHPXref 0.7.1