示例#1
0
文件: run.php 项目: MrAdder/phpbb
 /**
  * Executes the command cron:run.
  *
  * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks.
  * If the cron lock can not be obtained, an error message is printed
  *		and the exit status is set to 1.
  * If the verbose option is specified, each start of a task is printed.
  *		Otherwise there is no output.
  * If an argument is given to the command, only the task whose name matches the
  *		argument will be started. If verbose option is specified,
  *		an info message containing the name of the task is printed.
  * If no task matches the argument given, an error message is printed
  *		and the exit status is set to 2.
  *
  * @param InputInterface $input The input stream used to get the argument and verboe option.
  * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
  *
  * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->lock_db->acquire()) {
         $task_name = $input->getArgument('name');
         if ($task_name) {
             $exit_status = $this->run_one($input, $output, $task_name);
         } else {
             $exit_status = $this->run_all($input, $output);
         }
         $this->lock_db->release();
         return $exit_status;
     } else {
         throw new runtime_exception('CRON_LOCK_ERROR', array(), null, 1);
     }
 }
 /**
  * Executes the command cron:run.
  *
  * Tries to acquire the cron lock, then if no argument has been given runs all ready cron tasks.
  * If the cron lock can not be obtained, an error message is printed
  *		and the exit status is set to 1.
  * If the verbose option is specified, each start of a task is printed.
  *		Otherwise there is no output.
  * If an argument is given to the command, only the task whose name matches the
  *		argument will be started. If verbose option is specified,
  *		an info message containing the name of the task is printed.
  * If no task matches the argument given, an error message is printed
  *		and the exit status is set to 2.
  *
  * @param InputInterface $input The input stream used to get the argument and verboe option.
  * @param OutputInterface $output The output stream, used for printing verbose-mode and error information.
  *
  * @return int 0 if all is ok, 1 if a lock error occured and 2 if no task matching the argument was found.
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     if ($this->lock_db->acquire()) {
         $task_name = $input->getArgument('name');
         if ($task_name) {
             $exit_status = $this->run_one($input, $output, $task_name);
         } else {
             $exit_status = $this->run_all($input, $output);
         }
         $this->lock_db->release();
         return $exit_status;
     } else {
         $output->writeln('<error>' . $this->user->lang('CRON_LOCK_ERROR') . '</error>');
         return 1;
     }
 }
示例#3
0
文件: reparse.php 项目: bantu/phpbb
	/**
	* Executes the command reparser:reparse
	*
	* @param InputInterface $input
	* @param OutputInterface $output
	* @return integer
	*/
	protected function execute(InputInterface $input, OutputInterface $output)
	{
		$this->input = $input;
		$this->output = $output;
		$this->io = new SymfonyStyle($input, $output);

		if (!$this->reparse_lock->acquire())
		{
			throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
		}

		$name = $input->getArgument('reparser-name');
		if (isset($name))
		{
			// Allow "post_text" to be an alias for "text_reparser.post_text"
			if (!isset($this->reparsers[$name]))
			{
				$name = 'text_reparser.' . $name;
			}
			$this->reparse($name);
		}
		else
		{
			foreach ($this->reparsers as $name => $service)
			{
				$this->reparse($name);
			}
		}

		$this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));

		$this->reparse_lock->release();

		return 0;
	}
示例#4
0
 /**
  * Acquires a lock on the item table
  *
  * @return bool	True if the lock was acquired, false if it has been acquired previously
  *
  * @throws \RuntimeException If the lock could not be acquired
  */
 protected function acquire_lock()
 {
     if ($this->lock->owns_lock()) {
         return false;
     }
     if (!$this->lock->acquire()) {
         throw new \RuntimeException($this->message_prefix . 'LOCK_FAILED_ACQUIRE');
     }
     return true;
 }
示例#5
0
 /**
  * Runs the cron job after the response was sent
  *
  * @param PostResponseEvent	$event	The event
  */
 public function on_kernel_terminate(PostResponseEvent $event)
 {
     $request = $event->getRequest();
     $controller_name = $request->get('_route');
     if ($controller_name !== 'phpbb_cron_run') {
         return;
     }
     $cron_type = $request->get('cron_type');
     if ($this->cron_lock->acquire()) {
         $task = $this->cron_manager->find_task($cron_type);
         if ($task) {
             if ($task->is_parametrized()) {
                 $task->parse_parameters($this->request);
             }
             if ($task->is_ready()) {
                 $task->run();
             }
             $this->cron_lock->release();
         }
     }
 }
示例#6
0
文件: reparse.php 项目: phpbb/phpbb
 /**
  * Executes the command reparser:reparse
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return integer
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $this->io = new SymfonyStyle($input, $output);
     if (!$this->reparse_lock->acquire()) {
         throw new runtime_exception('REPARSE_LOCK_ERROR', array(), null, 1);
     }
     $name = $input->getArgument('reparser-name');
     if ($name) {
         $name = $this->reparser_manager->find_reparser($name);
         $this->reparse($name);
     } else {
         foreach ($this->reparsers as $name => $service) {
             $this->reparse($name);
         }
     }
     $this->io->success($this->user->lang('CLI_REPARSER_REPARSE_SUCCESS'));
     $this->reparse_lock->release();
     return 0;
 }
示例#7
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();
     }
 }