1 | <?php |
||
2 | /** |
||
3 | * |
||
4 | * Advanced BBCode Box |
||
5 | * |
||
6 | * @copyright (c) 2018 Matt Friedman |
||
7 | * @license GNU General Public License, version 2 (GPL-2.0) |
||
8 | * |
||
9 | */ |
||
10 | |||
11 | namespace vse\abbc3\migrations; |
||
12 | |||
13 | use phpbb\db\migration\container_aware_migration; |
||
0 ignored issues
–
show
|
|||
14 | |||
15 | /** |
||
16 | * Class disable_bbcodes |
||
17 | * |
||
18 | * This is a specialized migration. It will set original (un-altered) ABBC3 BBCodes |
||
19 | * to be hidden from the posting pages when ABBC3 is removed. This will make it look |
||
20 | * like the default phpBB BBCode toolbar again, but ABBC3 BBCodes are not deleted |
||
21 | * so posts won't suddenly break. Users can manually re-enable the BBCodes they want to keep, |
||
22 | * delete the one's they do not, etc. If ABBC3 is re-installed again, it will attempt |
||
23 | * to re-enable them in the BBCode toolbar, restoring the ABBC3 BBCode toolbar appearance. |
||
24 | * |
||
25 | * @package vse\abbc3\migrations |
||
26 | */ |
||
27 | class disable_bbcodes extends container_aware_migration |
||
28 | { |
||
29 | /** @var \phpbb\config\db_text */ |
||
0 ignored issues
–
show
The type
phpbb\config\db_text was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths ![]() |
|||
30 | protected $configText; |
||
31 | |||
32 | /** |
||
33 | * {@inheritDoc} |
||
34 | */ |
||
35 | public function effectively_installed() |
||
36 | { |
||
37 | return $this->getConfigText()->get('abbc3_bbcodes') === null; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | */ |
||
43 | public function update_data() |
||
44 | { |
||
45 | return [ |
||
46 | ['custom', [[$this, 'display_bbcodes_on']]], |
||
47 | ['config_text.remove', ['abbc3_bbcodes']], |
||
48 | ]; |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | * |
||
54 | * This will leave behind an entry in the config_text table storing the |
||
55 | * IDs of the BBCodes that were hidden after uninstalling this extension. |
||
56 | * This data is used so if this extension is re-installed at a later time, |
||
57 | * it can re-display on posting page only the BBCodes it has hidden. |
||
58 | */ |
||
59 | public function revert_data() |
||
60 | { |
||
61 | return [ |
||
62 | ['custom', [[$this, 'display_bbcodes_off']]], // using a custom func because config_text.add was being called twice |
||
63 | ]; |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get ABBC3 BBCodes that were disabled from a previous extension purge, |
||
68 | * and re-display them on post. |
||
69 | */ |
||
70 | public function display_bbcodes_on() |
||
71 | { |
||
72 | $bbcodes = json_decode($this->getConfigText()->get('abbc3_bbcodes'), true); |
||
73 | |||
74 | if (is_array($bbcodes)) |
||
75 | { |
||
76 | $bbcodes = array_map('intval', $bbcodes); |
||
77 | |||
78 | $this->update_displayed_bbcodes($bbcodes, true); |
||
79 | } |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Set ABBC3 BBCodes Display on Post to 0, so they will no longer |
||
84 | * appear in posting buttons when extension is purged. |
||
85 | */ |
||
86 | public function display_bbcodes_off() |
||
87 | { |
||
88 | $bbcodes = []; |
||
89 | |||
90 | $sql = 'SELECT bbcode_id |
||
91 | FROM ' . BBCODES_TABLE . ' |
||
0 ignored issues
–
show
|
|||
92 | WHERE bbcode_helpline ' . $this->db->sql_like_expression('ABBC3_' . $this->db->get_any_char()) . ' |
||
93 | AND display_on_posting = 1'; |
||
94 | $this->db->sql_query($sql); |
||
95 | $result = $this->db->sql_query($sql); |
||
96 | while ($row = $this->db->sql_fetchrow($result)) |
||
97 | { |
||
98 | $bbcodes[] = $row['bbcode_id']; |
||
99 | } |
||
100 | $this->db->sql_freeresult($result); |
||
101 | |||
102 | $this->update_displayed_bbcodes($bbcodes, false); |
||
103 | |||
104 | $this->getConfigText()->set('abbc3_bbcodes', json_encode($bbcodes)); |
||
105 | } |
||
106 | |||
107 | /** |
||
108 | * Update the display on posting state for custom BBCodes |
||
109 | * |
||
110 | * @param array $bbcodes |
||
111 | * @param bool $display |
||
112 | */ |
||
113 | protected function update_displayed_bbcodes(array $bbcodes, $display) |
||
114 | { |
||
115 | if (!empty($bbcodes)) |
||
116 | { |
||
117 | $sql = 'UPDATE ' . BBCODES_TABLE . ' |
||
0 ignored issues
–
show
|
|||
118 | SET display_on_posting = ' . (int) $display . ' |
||
119 | WHERE ' . $this->db->sql_in_set('bbcode_id', $bbcodes); |
||
120 | $this->db->sql_query($sql); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * Get the config text object |
||
126 | * |
||
127 | * @return \phpbb\config\db_text |
||
128 | */ |
||
129 | protected function getConfigText() |
||
130 | { |
||
131 | if ($this->configText === null) |
||
132 | { |
||
133 | $this->configText = $this->container->get('config_text'); |
||
134 | } |
||
135 | |||
136 | return $this->configText; |
||
137 | } |
||
138 | } |
||
139 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths