Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 55 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
soft_delete_mod_convert | |
0.00% |
0 / 55 |
|
0.00% |
0 / 6 |
156 | |
0.00% |
0 / 1 |
depends_on | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
effectively_installed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update_data | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
2 | |||
convert_posts | |
0.00% |
0 / 23 |
|
0.00% |
0 / 1 |
30 | |||
convert_topics | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
12 | |||
get_content_visibility | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
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\db\migration\data\v310; |
15 | |
16 | use phpbb\db\migration\container_aware_migration; |
17 | |
18 | /** |
19 | * Migration to convert the Soft Delete MOD for 3.0 |
20 | * |
21 | * https://www.phpbb.com/customise/db/mod/soft_delete/ |
22 | */ |
23 | class soft_delete_mod_convert extends container_aware_migration |
24 | { |
25 | public static function depends_on() |
26 | { |
27 | return array( |
28 | '\phpbb\db\migration\data\v310\alpha3', |
29 | ); |
30 | } |
31 | |
32 | public function effectively_installed() |
33 | { |
34 | return !$this->db_tools->sql_column_exists($this->table_prefix . 'posts', 'post_deleted'); |
35 | } |
36 | |
37 | public function update_data() |
38 | { |
39 | return array( |
40 | array('permission.remove', array('m_harddelete', true)), |
41 | array('permission.remove', array('m_harddelete', false)), |
42 | |
43 | array('custom', array(array($this, 'convert_posts'))), |
44 | array('custom', array(array($this, 'convert_topics'))), |
45 | ); |
46 | } |
47 | |
48 | public function convert_posts($start) |
49 | { |
50 | $content_visibility = $this->get_content_visibility(); |
51 | |
52 | $limit = 250; |
53 | $i = 0; |
54 | |
55 | $sql = 'SELECT p.*, t.topic_first_post_id, t.topic_last_post_id |
56 | FROM ' . $this->table_prefix . 'posts p, ' . $this->table_prefix . 'topics t |
57 | WHERE p.post_deleted > 0 |
58 | AND t.topic_id = p.topic_id'; |
59 | $result = $this->db->sql_query_limit($sql, $limit, $start); |
60 | |
61 | while ($row = $this->db->sql_fetchrow($result)) |
62 | { |
63 | $content_visibility->set_post_visibility( |
64 | ITEM_DELETED, |
65 | $row['post_id'], |
66 | $row['topic_id'], |
67 | $row['forum_id'], |
68 | $row['post_deleted'], |
69 | $row['post_deleted_time'], |
70 | '', |
71 | ($row['post_id'] == $row['topic_first_post_id']) ? true : false, |
72 | ($row['post_id'] == $row['topic_last_post_id']) ? true : false |
73 | ); |
74 | |
75 | $i++; |
76 | } |
77 | |
78 | $this->db->sql_freeresult($result); |
79 | |
80 | if ($i == $limit) |
81 | { |
82 | return $start + $i; |
83 | } |
84 | } |
85 | |
86 | public function convert_topics($start) |
87 | { |
88 | $content_visibility = $this->get_content_visibility(); |
89 | |
90 | $limit = 100; |
91 | $i = 0; |
92 | |
93 | $sql = 'SELECT * |
94 | FROM ' . $this->table_prefix . 'topics |
95 | WHERE topic_deleted > 0'; |
96 | $result = $this->db->sql_query_limit($sql, $limit, $start); |
97 | |
98 | while ($row = $this->db->sql_fetchrow($result)) |
99 | { |
100 | $content_visibility->set_topic_visibility( |
101 | ITEM_DELETED, |
102 | $row['topic_id'], |
103 | $row['forum_id'], |
104 | $row['topic_deleted'], |
105 | $row['topic_deleted_time'], |
106 | '' |
107 | ); |
108 | |
109 | $i++; |
110 | } |
111 | |
112 | $this->db->sql_freeresult($result); |
113 | |
114 | if ($i == $limit) |
115 | { |
116 | return $start + $i; |
117 | } |
118 | } |
119 | |
120 | /** |
121 | * @return \phpbb\content_visibility |
122 | */ |
123 | protected function get_content_visibility() |
124 | { |
125 | /** @var \phpbb\content_visibility $content_visibility */ |
126 | $content_visibility = $this->container->get('content.visibility'); |
127 | return $content_visibility; |
128 | } |
129 | } |