Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 30 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
remove_attachment_flash | |
0.00% |
0 / 30 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
depends_on | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
update_data | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
remove_flash_group | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
20 |
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\v330; |
15 | |
16 | class remove_attachment_flash extends \phpbb\db\migration\migration |
17 | { |
18 | // Following constants were deprecated in 3.3 |
19 | // and moved from constants.php to compatibility_globals.php, |
20 | // thus define them as class constants |
21 | const ATTACHMENT_CATEGORY_FLASH = 5; |
22 | |
23 | protected $cat_id = array( |
24 | self::ATTACHMENT_CATEGORY_FLASH, |
25 | ); |
26 | |
27 | public static function depends_on() |
28 | { |
29 | return ['\phpbb\db\migration\data\v330\dev',]; |
30 | } |
31 | |
32 | public function update_data() |
33 | { |
34 | return array( |
35 | array('custom', array(array($this, 'remove_flash_group'))), |
36 | ); |
37 | } |
38 | |
39 | public function remove_flash_group() |
40 | { |
41 | // select group ids of outdated media |
42 | $sql = 'SELECT group_id |
43 | FROM ' . EXTENSION_GROUPS_TABLE . ' |
44 | WHERE ' . $this->db->sql_in_set('cat_id', $this->cat_id); |
45 | $result = $this->db->sql_query($sql); |
46 | |
47 | $group_ids = array(); |
48 | while ($group_id = (int) $this->db->sql_fetchfield('group_id')) |
49 | { |
50 | $group_ids[] = $group_id; |
51 | } |
52 | $this->db->sql_freeresult($result); |
53 | |
54 | // nothing to do, admin has removed all the outdated media extension groups |
55 | if (empty($group_ids)) |
56 | { |
57 | return true; |
58 | } |
59 | |
60 | // get the group id of downloadable files |
61 | $sql = 'SELECT group_id |
62 | FROM ' . EXTENSION_GROUPS_TABLE . " |
63 | WHERE group_name = 'DOWNLOADABLE_FILES'"; |
64 | $result = $this->db->sql_query($sql); |
65 | $download_id = (int) $this->db->sql_fetchfield('group_id'); |
66 | $this->db->sql_freeresult($result); |
67 | |
68 | if (empty($download_id)) |
69 | { |
70 | $sql = 'UPDATE ' . EXTENSIONS_TABLE . ' |
71 | SET group_id = 0 |
72 | WHERE ' . $this->db->sql_in_set('group_id', $group_ids); |
73 | } |
74 | else |
75 | { |
76 | // move outdated media extensions to downloadable files |
77 | $sql = 'UPDATE ' . EXTENSIONS_TABLE . " |
78 | SET group_id = $download_id" . ' |
79 | WHERE ' . $this->db->sql_in_set('group_id', $group_ids); |
80 | } |
81 | |
82 | $this->db->sql_query($sql); |
83 | |
84 | // delete the now empty, outdated media extension groups |
85 | $sql = 'DELETE FROM ' . EXTENSION_GROUPS_TABLE . ' |
86 | WHERE ' . $this->db->sql_in_set('group_id', $group_ids); |
87 | $this->db->sql_query($sql); |
88 | } |
89 | } |