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 |
softdelete_p1.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\db\migration\data\v310;
015
016 class softdelete_p1 extends \phpbb\db\migration\migration
017 {
018 public function effectively_installed()
019 {
020 return $this->db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_visibility');
021 }
022
023 static public function depends_on()
024 {
025 return array('\phpbb\db\migration\data\v310\dev');
026 }
027
028 public function update_schema()
029 {
030 return array(
031 'add_columns' => array(
032 $this->table_prefix . 'forums' => array(
033 'forum_posts_approved' => array('UINT', 0),
034 'forum_posts_unapproved' => array('UINT', 0),
035 'forum_posts_softdeleted' => array('UINT', 0),
036 'forum_topics_approved' => array('UINT', 0),
037 'forum_topics_unapproved' => array('UINT', 0),
038 'forum_topics_softdeleted' => array('UINT', 0),
039 ),
040 $this->table_prefix . 'posts' => array(
041 'post_visibility' => array('TINT:3', 0),
042 'post_delete_time' => array('TIMESTAMP', 0),
043 'post_delete_reason' => array('STEXT_UNI', ''),
044 'post_delete_user' => array('UINT', 0),
045 ),
046 $this->table_prefix . 'topics' => array(
047 'topic_visibility' => array('TINT:3', 0),
048 'topic_delete_time' => array('TIMESTAMP', 0),
049 'topic_delete_reason' => array('STEXT_UNI', ''),
050 'topic_delete_user' => array('UINT', 0),
051 'topic_posts_approved' => array('UINT', 0),
052 'topic_posts_unapproved' => array('UINT', 0),
053 'topic_posts_softdeleted' => array('UINT', 0),
054 ),
055 ),
056 'add_index' => array(
057 $this->table_prefix . 'posts' => array(
058 'post_visibility' => array('post_visibility'),
059 ),
060 $this->table_prefix . 'topics' => array(
061 'topic_visibility' => array('topic_visibility'),
062 'forum_vis_last' => array('forum_id', 'topic_visibility', 'topic_last_post_id'),
063 ),
064 ),
065 );
066 }
067
068 public function revert_schema()
069 {
070 return array(
071 'drop_columns' => array(
072 $this->table_prefix . 'forums' => array(
073 'forum_posts_approved',
074 'forum_posts_unapproved',
075 'forum_posts_softdeleted',
076 'forum_topics_approved',
077 'forum_topics_unapproved',
078 'forum_topics_softdeleted',
079 ),
080 $this->table_prefix . 'posts' => array(
081 'post_visibility',
082 'post_delete_time',
083 'post_delete_reason',
084 'post_delete_user',
085 ),
086 $this->table_prefix . 'topics' => array(
087 'topic_visibility',
088 'topic_delete_time',
089 'topic_delete_reason',
090 'topic_delete_user',
091 'topic_posts_approved',
092 'topic_posts_unapproved',
093 'topic_posts_softdeleted',
094 ),
095 ),
096 'drop_keys' => array(
097 $this->table_prefix . 'posts' => array('post_visibility'),
098 $this->table_prefix . 'topics' => array('topic_visibility', 'forum_vis_last'),
099 ),
100 );
101 }
102
103 public function update_data()
104 {
105 return array(
106 array('custom', array(array($this, 'update_post_visibility'))),
107 array('custom', array(array($this, 'update_topic_visibility'))),
108 array('custom', array(array($this, 'update_topics_post_counts'))),
109 array('custom', array(array($this, 'update_forums_topic_and_post_counts'))),
110
111 array('permission.add', array('f_softdelete', false)),
112 array('permission.add', array('m_softdelete', false)),
113 );
114 }
115
116 public function update_post_visibility()
117 {
118 $sql = 'UPDATE ' . $this->table_prefix . 'posts
119 SET post_visibility = post_approved';
120 $this->sql_query($sql);
121 }
122
123 public function update_topic_visibility()
124 {
125 $sql = 'UPDATE ' . $this->table_prefix . 'topics
126 SET topic_visibility = topic_approved';
127 $this->sql_query($sql);
128 }
129
130 public function update_topics_post_counts()
131 {
132 /*
133 * Using sql_case here to avoid "BIGINT UNSIGNED value is out of range" errors.
134 * As we update all topics in 2 queries, one broken topic would stop the conversion
135 * for all topics and the suppressed error will cause the admin to not even notice it.
136 */
137 $sql = 'UPDATE ' . $this->table_prefix . 'topics
138 SET topic_posts_approved = topic_replies + 1,
139 topic_posts_unapproved = ' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . '
140 WHERE topic_visibility = ' . ITEM_APPROVED;
141 $this->sql_query($sql);
142
143 $sql = 'UPDATE ' . $this->table_prefix . 'topics
144 SET topic_posts_approved = 0,
145 topic_posts_unapproved = (' . $this->db->sql_case('topic_replies_real > topic_replies', 'topic_replies_real - topic_replies', '0') . ') + 1
146 WHERE topic_visibility = ' . ITEM_UNAPPROVED;
147 $this->sql_query($sql);
148 }
149
150 public function update_forums_topic_and_post_counts($start)
151 {
152 $start = (int) $start;
153 $limit = 10;
154 $converted_forums = 0;
155
156 if (!$start)
157 {
158 // Preserve the forum_posts value for link forums as it represents redirects.
159 $sql = 'UPDATE ' . $this->table_prefix . 'forums
160 SET forum_posts_approved = forum_posts
161 WHERE forum_type = ' . FORUM_LINK;
162 $this->db->sql_query($sql);
163 }
164
165 $sql = 'SELECT forum_id, topic_visibility, COUNT(topic_id) AS sum_topics, SUM(topic_posts_approved) AS sum_posts_approved, SUM(topic_posts_unapproved) AS sum_posts_unapproved
166 FROM ' . $this->table_prefix . 'topics
167 GROUP BY forum_id, topic_visibility
168 ORDER BY forum_id, topic_visibility';
169 $result = $this->db->sql_query_limit($sql, $limit, $start);
170
171 $update_forums = array();
172 while ($row = $this->db->sql_fetchrow($result))
173 {
174 $converted_forums++;
175
176 $forum_id = (int) $row['forum_id'];
177 if (!isset($update_forums[$forum_id]))
178 {
179 $update_forums[$forum_id] = array(
180 'forum_posts_approved' => 0,
181 'forum_posts_unapproved' => 0,
182 'forum_topics_approved' => 0,
183 'forum_topics_unapproved' => 0,
184 );
185 }
186
187 $update_forums[$forum_id]['forum_posts_approved'] += (int) $row['sum_posts_approved'];
188 $update_forums[$forum_id]['forum_posts_unapproved'] += (int) $row['sum_posts_unapproved'];
189
190 $update_forums[$forum_id][(($row['topic_visibility'] == ITEM_APPROVED) ? 'forum_topics_approved' : 'forum_topics_unapproved')] += (int) $row['sum_topics'];
191 }
192 $this->db->sql_freeresult($result);
193
194 foreach ($update_forums as $forum_id => $forum_data)
195 {
196 $sql = 'UPDATE ' . FORUMS_TABLE . '
197 SET ' . $this->db->sql_build_array('UPDATE', $forum_data) . '
198 WHERE forum_id = ' . $forum_id;
199 $this->sql_query($sql);
200 }
201
202 if ($converted_forums < $limit)
203 {
204 // There are no more topics, we are done
205 return;
206 }
207
208 // There are still more topics to query, return the next start value
209 return $start + $limit;
210 }
211 }
212