Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
remove_duplicate_migrations | |
0.00% |
0 / 28 |
|
0.00% |
0 / 3 |
240 | |
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 | |||
deduplicate_entries | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
182 |
1 | <?php |
2 | |
3 | /** |
4 | * |
5 | * This file is part of the phpBB Forum Software package. |
6 | * |
7 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
8 | * @license GNU General Public License, version 2 (GPL-2.0) |
9 | * |
10 | * For full copyright and license information, please see |
11 | * the docs/CREDITS.txt file. |
12 | * |
13 | */ |
14 | |
15 | namespace phpbb\db\migration\data\v31x; |
16 | |
17 | class remove_duplicate_migrations extends \phpbb\db\migration\migration |
18 | { |
19 | public static function depends_on() |
20 | { |
21 | return array('\phpbb\db\migration\data\v31x\v3110'); |
22 | } |
23 | |
24 | public function update_data() |
25 | { |
26 | return array( |
27 | array('custom', array(array($this, 'deduplicate_entries'))), |
28 | ); |
29 | } |
30 | |
31 | public function deduplicate_entries() |
32 | { |
33 | $migration_state = array(); |
34 | $duplicate_migrations = array(); |
35 | |
36 | $sql = "SELECT * |
37 | FROM " . $this->table_prefix . 'migrations'; |
38 | $result = $this->db->sql_query($sql); |
39 | |
40 | if (!$this->db->get_sql_error_triggered()) |
41 | { |
42 | while ($migration = $this->db->sql_fetchrow($result)) |
43 | { |
44 | $migration_state[$migration['migration_name']] = $migration; |
45 | |
46 | $migration_state[$migration['migration_name']]['migration_depends_on'] = unserialize($migration['migration_depends_on']); |
47 | } |
48 | } |
49 | |
50 | $this->db->sql_freeresult($result); |
51 | |
52 | /** |
53 | * @var string $name |
54 | * @var array $migration |
55 | */ |
56 | foreach ($migration_state as $name => $migration) |
57 | { |
58 | $prepended_name = ($name[0] == '\\' ? '' : '\\') . $name; |
59 | $prefixless_name = $name[0] == '\\' ? substr($name, 1) : $name; |
60 | |
61 | if ($prepended_name != $name && isset($migration_state[$prepended_name]) && $migration_state[$prepended_name]['migration_depends_on'] == $migration['migration_depends_on']) |
62 | { |
63 | $duplicate_migrations[] = $name; |
64 | unset($migration_state[$prepended_name]); |
65 | } |
66 | else if ($prefixless_name != $name && isset($migration_state[$prefixless_name]) && $migration_state[$prefixless_name]['migration_depends_on'] == $migration['migration_depends_on']) |
67 | { |
68 | $duplicate_migrations[] = $prefixless_name; |
69 | unset($migration_state[$prefixless_name]); |
70 | } |
71 | } |
72 | |
73 | if (count($duplicate_migrations)) |
74 | { |
75 | $sql = 'DELETE |
76 | FROM ' . $this->table_prefix . 'migrations |
77 | WHERE ' . $this->db->sql_in_set('migration_name', $duplicate_migrations); |
78 | $this->db->sql_query($sql); |
79 | } |
80 | } |
81 | } |