Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
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_shadow_topics.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 of its shadow topics 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_shadow_topics 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 protected $log;
030 protected $user;
031
032 /**
033 * If $forum_data is given, it is assumed to contain necessary information
034 * about a single forum that is to be pruned.
035 *
036 * If $forum_data is not given, forum id will be retrieved via $request->variable()
037 * and a database query will be performed to load the necessary information
038 * about the forum.
039 */
040 protected $forum_data;
041
042 /**
043 * Constructor.
044 *
045 * @param string $phpbb_root_path The root path
046 * @param string $php_ext PHP file extension
047 * @param \phpbb\config\config $config The config
048 * @param \phpbb\db\driver\driver_interface $db The db connection
049 * @param \phpbb\log\log $log The phpBB log system
050 * @param \phpbb\user $user The phpBB user object
051 */
052 public function __construct($phpbb_root_path, $php_ext, \phpbb\config\config $config, \phpbb\db\driver\driver_interface $db, \phpbb\log\log $log, \phpbb\user $user)
053 {
054 $this->phpbb_root_path = $phpbb_root_path;
055 $this->php_ext = $php_ext;
056 $this->config = $config;
057 $this->db = $db;
058 $this->log = $log;
059 $this->user = $user;
060 }
061
062 /**
063 * Manually set forum data.
064 *
065 * @param array $forum_data Information about a forum to be pruned.
066 */
067 public function set_forum_data($forum_data)
068 {
069 $this->forum_data = $forum_data;
070 }
071
072 /**
073 * Runs this cron task.
074 *
075 * @return null
076 */
077 public function run()
078 {
079 if (!function_exists('auto_prune'))
080 {
081 include($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext);
082 }
083
084 if ($this->forum_data['prune_shadow_days'])
085 {
086 $this->auto_prune_shadow_topics($this->forum_data['forum_id'], 'shadow', $this->forum_data['forum_flags'], $this->forum_data['prune_shadow_days'], $this->forum_data['prune_shadow_freq']);
087 }
088 }
089
090 /**
091 * Returns whether this cron task can run, given current board configuration.
092 *
093 * This cron task will not run when system cron is utilised, as in
094 * such cases prune_all_forums task would run instead.
095 *
096 * Additionally, this task must be given the forum data, either via
097 * the constructor or parse_parameters method.
098 *
099 * @return bool
100 */
101 public function is_runnable()
102 {
103 return !$this->config['use_system_cron'] && $this->forum_data;
104 }
105
106 /**
107 * Returns whether this cron task should run now, because enough time
108 * has passed since it was last run.
109 *
110 * Forum pruning interval is specified in the forum data.
111 *
112 * @return bool
113 */
114 public function should_run()
115 {
116 return $this->forum_data['enable_shadow_prune'] && $this->forum_data['prune_shadow_next'] < time();
117 }
118
119 /**
120 * Returns parameters of this cron task as an array.
121 * The array has one key, f, whose value is id of the forum to be pruned.
122 *
123 * @return array
124 */
125 public function get_parameters()
126 {
127 return array('f' => $this->forum_data['forum_id']);
128 }
129
130 /**
131 * Parses parameters found in $request, which is an instance of
132 * \phpbb\request\request_interface.
133 *
134 * It is expected to have a key f whose value is id of the forum to be pruned.
135 *
136 * @param \phpbb\request\request_interface $request Request object.
137 *
138 * @return null
139 */
140 public function parse_parameters(\phpbb\request\request_interface $request)
141 {
142 $this->forum_data = null;
143 if ($request->is_set('f'))
144 {
145 $forum_id = $request->variable('f', 0);
146
147 $sql = 'SELECT forum_id, prune_shadow_next, enable_shadow_prune, prune_shadow_days, forum_flags, prune_shadow_freq
148 FROM ' . FORUMS_TABLE . "
149 WHERE forum_id = $forum_id";
150 $result = $this->db->sql_query($sql);
151 $row = $this->db->sql_fetchrow($result);
152 $this->db->sql_freeresult($result);
153
154 if ($row)
155 {
156 $this->forum_data = $row;
157 }
158 }
159 }
160
161 /**
162 * Automatically prune shadow topics
163 * Based on fuunction auto_prune()
164 * @param int $forum_id Forum ID of forum that should be pruned
165 * @param string $prune_mode Prune mode
166 * @param int $prune_flags Prune flags
167 * @param int $prune_days Prune date in days
168 * @param int $prune_freq Prune frequency
169 * @return null
170 */
171 protected function auto_prune_shadow_topics($forum_id, $prune_mode, $prune_flags, $prune_days, $prune_freq)
172 {
173 $sql = 'SELECT forum_name
174 FROM ' . FORUMS_TABLE . "
175 WHERE forum_id = $forum_id";
176 $result = $this->db->sql_query($sql, 3600);
177 $row = $this->db->sql_fetchrow($result);
178 $this->db->sql_freeresult($result);
179
180 if ($row)
181 {
182 $prune_date = time() - ($prune_days * 86400);
183 $next_prune = time() + ($prune_freq * 86400);
184
185 prune($forum_id, $prune_mode, $prune_date, $prune_flags, true);
186
187 $sql = 'UPDATE ' . FORUMS_TABLE . "
188 SET prune_shadow_next = $next_prune
189 WHERE forum_id = $forum_id";
190 $this->db->sql_query($sql);
191
192 $user_id = (empty($this->user->data)) ? ANONYMOUS : $this->user->data['user_id'];
193 $user_ip = (empty($this->user->ip)) ? '' : $this->user->ip;
194
195 $this->log->add('admin', $user_id, $user_ip, 'LOG_PRUNE_SHADOW', false, array($row['forum_name']));
196 }
197
198 return;
199 }
200 }
201