[ Index ]

PHP Cross Reference of phpBB-3.1.12-deutsch

title

Body

[close]

/phpbb/cron/task/core/ -> prune_forum.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\core;
  15  
  16  /**
  17  * Prune one forum cron task.
  18  *
  19  * It is intended to be used when cron is invoked via web.
  20  * This task can decide whether it should be run using data obtained by viewforum
  21  * code, without making additional database queries.
  22  */
  23  class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\parametrized
  24  {
  25      protected $phpbb_root_path;
  26      protected $php_ext;
  27      protected $config;
  28      protected $db;
  29  
  30      /**
  31      * If $forum_data is given, it is assumed to contain necessary information
  32      * about a single forum that is to be pruned.
  33      *
  34      * If $forum_data is not given, forum id will be retrieved via request_var
  35      * and a database query will be performed to load the necessary information
  36      * about the forum.
  37      */
  38      protected $forum_data;
  39  
  40      /**
  41      * Constructor.
  42      *
  43      * @param string $phpbb_root_path The root path
  44      * @param string $php_ext PHP file extension
  45      * @param \phpbb\config\config $config The config
  46      * @param \phpbb\db\driver\driver_interface $db The db connection
  47      */
  48  	public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db)
  49      {
  50          $this->phpbb_root_path = $phpbb_root_path;
  51          $this->php_ext = $php_ext;
  52          $this->config = $config;
  53          $this->db = $db;
  54      }
  55  
  56      /**
  57      * Manually set forum data.
  58      *
  59      * @param array $forum_data Information about a forum to be pruned.
  60      */
  61  	public function set_forum_data($forum_data)
  62      {
  63          $this->forum_data = $forum_data;
  64      }
  65  
  66      /**
  67      * Runs this cron task.
  68      *
  69      * @return null
  70      */
  71  	public function run()
  72      {
  73          if (!function_exists('auto_prune'))
  74          {
  75              include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
  76          }
  77  
  78          if ($this->forum_data['prune_days'])
  79          {
  80              auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq']);
  81          }
  82  
  83          if ($this->forum_data['prune_viewed'])
  84          {
  85              auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq']);
  86          }
  87      }
  88  
  89      /**
  90      * Returns whether this cron task can run, given current board configuration.
  91      *
  92      * This cron task will not run when system cron is utilised, as in
  93      * such cases prune_all_forums task would run instead.
  94      *
  95      * Additionally, this task must be given the forum data, either via
  96      * the constructor or parse_parameters method.
  97      *
  98      * @return bool
  99      */
 100  	public function is_runnable()
 101      {
 102          return !$this->config['use_system_cron'] && $this->forum_data;
 103      }
 104  
 105      /**
 106      * Returns whether this cron task should run now, because enough time
 107      * has passed since it was last run.
 108      *
 109      * Forum pruning interval is specified in the forum data.
 110      *
 111      * @return bool
 112      */
 113  	public function should_run()
 114      {
 115          return $this->forum_data['enable_prune'] && $this->forum_data['prune_next'] < time();
 116      }
 117  
 118      /**
 119      * Returns parameters of this cron task as an array.
 120      * The array has one key, f, whose value is id of the forum to be pruned.
 121      *
 122      * @return array
 123      */
 124  	public function get_parameters()
 125      {
 126          return array('f' => $this->forum_data['forum_id']);
 127      }
 128  
 129      /**
 130      * Parses parameters found in $request, which is an instance of
 131      * \phpbb\request\request_interface.
 132      *
 133      * It is expected to have a key f whose value is id of the forum to be pruned.
 134      *
 135      * @param \phpbb\request\request_interface $request Request object.
 136      *
 137      * @return null
 138      */
 139  	public function parse_parameters(\phpbb\request\request_interface $request)
 140      {
 141          $this->forum_data = null;
 142          if ($request->is_set('f'))
 143          {
 144              $forum_id = $request->variable('f', 0);
 145  
 146              $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
 147                  FROM ' . FORUMS_TABLE . "
 148                  WHERE forum_id = $forum_id";
 149              $result = $this->db->sql_query($sql);
 150              $row = $this->db->sql_fetchrow($result);
 151              $this->db->sql_freeresult($result);
 152  
 153              if ($row)
 154              {
 155                  $this->forum_data = $row;
 156              }
 157          }
 158      }
 159  }


Generated: Thu Jan 11 00:25:41 2018 Cross-referenced by PHPXref 0.7.1