Beispiel #1
0
 public function test_schedule_all()
 {
     $this->reparser_manager->schedule_all(180);
     $this->assertEquals(180, $this->config['test_reparser_cron_interval']);
     $this->assertEquals(180, $this->config['my_reparser_cron_interval']);
     $this->assertArrayNotHasKey('another_reparser_cron_interval', $this->config);
 }
Beispiel #2
0
	/**
	* Reparse all text handled by given reparser within given range
	*
	* @param string $name Reparser name
	*/
	protected function reparse($name)
	{
		$reparser = $this->reparsers[$name];
		$this->resume_data = $this->reparser_manager->get_resume_data($name);
		if ($this->input->getOption('dry-run'))
		{
			$reparser->disable_save();
		}
		else
		{
			$reparser->enable_save();
		}

		// Start at range-max if specified or at the highest ID otherwise
		$max  = $this->get_option('range-max');
		$min  = $this->get_option('range-min');
		$size = $this->get_option('range-size');

		// range-max has no default value, it must be computed for each reparser
		if ($max == null)
		{
			$max = $reparser->get_max_id();
		}

		if ($max < $min)
		{
			return;
		}

		$this->io->section($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $min, $max));

		$progress = $this->create_progress_bar($max, $this->io, $this->output, true);
		$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING_START', preg_replace('(^text_reparser\\.)', '', $name)));
		$progress->start();

		// Start from $max and decrement $current by $size until we reach $min
		$current = $max;
		while ($current >= $min)
		{
			$start = max($min, $current + 1 - $size);
			$end   = max($min, $current);

			$progress->setMessage($this->user->lang('CLI_REPARSER_REPARSE_REPARSING', preg_replace('(^text_reparser\\.)', '', $name), $start, $end));
			$reparser->reparse_range($start, $end);

			$current = $start - 1;
			$progress->setProgress($max + 1 - $start);

			$this->reparser_manager->update_resume_data($name, $min, $current, $size, !$this->input->getOption('dry-run'));
		}
		$progress->finish();

		$this->io->newLine(2);
	}
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function run()
 {
     if ($this->reparse_lock->acquire()) {
         if ($this->resume_data === null) {
             $this->resume_data = $this->reparser_manager->get_resume_data($this->reparser_name);
         }
         /**
          * @var \phpbb\textreparser\reparser_interface $reparser
          */
         $reparser = $this->reparsers[$this->reparser_name];
         $min = !empty($this->resume_data['range-min']) ? $this->resume_data['range-min'] : self::MIN;
         $current = !empty($this->resume_data['range-max']) ? $this->resume_data['range-max'] : $reparser->get_max_id();
         $size = !empty($this->resume_data['range-size']) ? $this->resume_data['range-size'] : self::SIZE;
         if ($current >= $min) {
             $start = max($min, $current + 1 - $size);
             $end = max($min, $current);
             $reparser->reparse_range($start, $end);
             $this->reparser_manager->update_resume_data($this->reparser_name, $min, $start - 1, $size);
         }
         $this->config->set($this->reparser_name . '_last_cron', time());
         $this->reparse_lock->release();
     }
 }