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_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->variable()
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 $log_prune = true;
079
080 if ($this->forum_data['prune_days'])
081 {
082 auto_prune($this->forum_data['forum_id'], 'posted', $this->forum_data['forum_flags'], $this->forum_data['prune_days'], $this->forum_data['prune_freq'], $log_prune);
083 $log_prune = false;
084 }
085
086 if ($this->forum_data['prune_viewed'])
087 {
088 auto_prune($this->forum_data['forum_id'], 'viewed', $this->forum_data['forum_flags'], $this->forum_data['prune_viewed'], $this->forum_data['prune_freq'], $log_prune);
089 }
090 }
091
092 /**
093 * Returns whether this cron task can run, given current board configuration.
094 *
095 * This cron task will not run when system cron is utilised, as in
096 * such cases prune_all_forums task would run instead.
097 *
098 * Additionally, this task must be given the forum data, either via
099 * the constructor or parse_parameters method.
100 *
101 * @return bool
102 */
103 public function is_runnable()
104 {
105 return !$this->config['use_system_cron'] && $this->forum_data;
106 }
107
108 /**
109 * Returns whether this cron task should run now, because enough time
110 * has passed since it was last run.
111 *
112 * Forum pruning interval is specified in the forum data.
113 *
114 * @return bool
115 */
116 public function should_run()
117 {
118 return $this->forum_data['enable_prune'] && $this->forum_data['prune_next'] < time();
119 }
120
121 /**
122 * Returns parameters of this cron task as an array.
123 * The array has one key, f, whose value is id of the forum to be pruned.
124 *
125 * @return array
126 */
127 public function get_parameters()
128 {
129 return array('f' => $this->forum_data['forum_id']);
130 }
131
132 /**
133 * Parses parameters found in $request, which is an instance of
134 * \phpbb\request\request_interface.
135 *
136 * It is expected to have a key f whose value is id of the forum to be pruned.
137 *
138 * @param \phpbb\request\request_interface $request Request object.
139 *
140 * @return null
141 */
142 public function parse_parameters(\phpbb\request\request_interface $request)
143 {
144 $this->forum_data = null;
145 if ($request->is_set('f'))
146 {
147 $forum_id = $request->variable('f', 0);
148
149 $sql = 'SELECT forum_id, prune_next, enable_prune, prune_days, prune_viewed, forum_flags, prune_freq
150 FROM ' . FORUMS_TABLE . "
151 WHERE forum_id = $forum_id";
152 $result = $this->db->sql_query($sql);
153 $row = $this->db->sql_fetchrow($result);
154 $this->db->sql_freeresult($result);
155
156 if ($row)
157 {
158 $this->forum_data = $row;
159 }
160 }
161 }
162 }
163