Example #1
0
 /**
  * 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;
     }
 }
Example #3
0
	/**
	* 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;
	}
 /**
  * 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();
         }
     }
 }
    /**
     * Regenerate left/right ids from parent/child relationship
     *
     * This method regenerates the left/right ids for the tree based on
     * the parent/child relations. This function executes three queries per
     * item, so it should only be called, when the set has one of the following
     * problems:
     *	- The set has a duplicated value inside the left/right id chain
     *	- The set has a missing value inside the left/right id chain
     *	- The set has items that do not have a left/right id set
     *
     * When regenerating the items, the items are sorted by parent id and their
     * current left id, so the current child/parent relationships are kept
     * and running the function on a working set will not change the order.
     *
     * @param int	$new_id		First left_id to be used (should start with 1)
     * @param int	$parent_id	parent_id of the current set (default = 0)
     * @param bool	$reset_ids	Should we reset all left_id/right_id on the first call?
     * @return	int		$new_id		The next left_id/right_id that should be used
     */
    public function regenerate_left_right_ids($new_id, $parent_id = 0, $reset_ids = false)
    {
        if ($acquired_new_lock = $this->acquire_lock()) {
            $this->db->sql_transaction('begin');
            if (!$reset_ids) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->column_item_parents . " = ''\n\t\t\t\t\t" . $this->get_sql_where('WHERE');
                $this->db->sql_query($sql);
            }
        }
        if ($reset_ids) {
            $sql = 'UPDATE ' . $this->table_name . '
				SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => 0, $this->column_right_id => 0, $this->column_item_parents => '')) . '
				' . $this->get_sql_where('WHERE');
            $this->db->sql_query($sql);
        }
        $sql = 'SELECT *
			FROM ' . $this->table_name . '
			WHERE ' . $this->column_parent_id . ' = ' . (int) $parent_id . '
				' . $this->get_sql_where('AND') . '
			ORDER BY ' . $this->column_left_id . ', ' . $this->column_item_id . ' ASC';
        $result = $this->db->sql_query($sql);
        $rows = $this->db->sql_fetchrowset($result);
        $this->db->sql_freeresult($result);
        foreach ($rows as $row) {
            // First we update the left_id for this module
            if ($row[$this->column_left_id] != $new_id) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->db->sql_build_array('UPDATE', array($this->column_left_id => $new_id)) . '
					WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id];
                $this->db->sql_query($sql);
            }
            $new_id++;
            // Then we go through any children and update their left/right id's
            $new_id = $this->regenerate_left_right_ids($new_id, $row[$this->column_item_id]);
            // Then we come back and update the right_id for this module
            if ($row[$this->column_right_id] != $new_id) {
                $sql = 'UPDATE ' . $this->table_name . '
					SET ' . $this->db->sql_build_array('UPDATE', array($this->column_right_id => $new_id)) . '
					WHERE ' . $this->column_item_id . ' = ' . (int) $row[$this->column_item_id];
                $this->db->sql_query($sql);
            }
            $new_id++;
        }
        if ($acquired_new_lock) {
            $this->db->sql_transaction('commit');
            $this->lock->release();
        }
        return $new_id;
    }
Example #6
0
 /**
  * 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;
 }
Example #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();
     }
 }