Verzeichnisstruktur phpBB-3.1.0
- Veröffentlicht
- 27.10.2014
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
prune_forum.php
001 <?php
002 /**
003 *
004 * This file is part of the phpBB Forum Software package.
005 *
006 * @copyright (c) phpBB Limited <https://www.phpbb.com>
007 * @license GNU General Public License, version 2 (GPL-2.0)
008 *
009 * For full copyright and license information, please see
010 * the docs/CREDITS.txt file.
011 *
012 */
013
014 namespace phpbb\cron\task\core;
015
016 /**
017 * Prune one forum cron task.
018 *
019 * It is intended to be used when cron is invoked via web.
020 * This task can decide whether it should be run using data obtained by viewforum
021 * code, without making additional database queries.
022 */
023 class prune_forum extends \phpbb\cron\task\base implements \phpbb\cron\task\parametrized
024 {
025 protected $phpbb_root_path;
026 protected $php_ext;
027 protected $config;
028 protected $db;
029
030 /**
031 * If $forum_data is given, it is assumed to contain necessary information
032 * about a single forum that is to be pruned.
033 *
034 * If $forum_data is not given, forum id will be retrieved via request_var
035 * and a database query will be performed to load the necessary information
036 * about the forum.
037 */
038 protected $forum_data;
039
040 /**
041 * Constructor.
042 *
043 * @param string $phpbb_root_path The root path
044 * @param string $php_ext PHP file extension
045 * @param \phpbb\config\config $config The config
046 * @param \phpbb\db\driver\driver_interface $db The db connection
047 */
048 public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db)
049 {
050 $this->phpbb_root_path = $phpbb_root_path;
051 $this->php_ext = $php_ext;
052 $this->config = $config;
053 $this->db = $db;
054 }
055
056 /**
057 * Manually set forum data.
058 *
059 * @param array $forum_data Information about a forum to be pruned.
060 */
061 public function set_forum_data($forum_data)
062 {
063 $this->forum_data = $forum_data;
064 }
065
066 /**
067 * Runs this cron task.
068 *
069 * @return null
070 */
071 public function run()
072 {
073 if (!function_exists('auto_prune'))
074 {
075 include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
076 }
077
078 if ($this->forum_data['prune_days'])
079 {
080 auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq']);
081 }
082
083 if ($this->forum_data['prune_viewed'])
084 {
085 auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq']);
086 }
087 }
088
089 /**
090 * Returns whether this cron task can run, given current board configuration.
091 *
092 * This cron task will not run when system cron is utilised, as in
093 * such cases prune_all_forums task would run instead.
094 *
095 * Additionally, this task must be given the forum data, either via
096 * the constructor or parse_parameters method.
097 *
098 * @return bool
099 */
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 }
160