Conditions | 8 |
Paths | 20 |
Total Lines | 31 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
1 | <?php |
||
17 | public function migrateDatabase(): void |
||
18 | { |
||
19 | $indexedColumns = [ |
||
20 | 'is_approved', |
||
21 | 'is_flagged', |
||
22 | ]; |
||
23 | $indexes = glsr(Database::class)->dbGetResults( |
||
24 | glsr(Query::class)->sql("SHOW INDEXES FROM table|ratings") |
||
25 | ); |
||
26 | $isDirty = false; |
||
27 | foreach ($indexedColumns as $column) { |
||
28 | $indexExists = false; |
||
29 | foreach ($indexes as $index) { |
||
30 | if ("glsr_ratings_{$column}_index" === $index->Key_name && $column === $index->Column_name) { |
||
31 | $indexExists = true; |
||
32 | break; |
||
33 | } |
||
34 | } |
||
35 | if ($indexExists) { |
||
36 | continue; |
||
37 | } |
||
38 | $sql = glsr(Query::class)->sql(" |
||
39 | ALTER TABLE table|ratings ADD INDEX glsr_ratings_{$column}_index ({$column}) |
||
40 | "); |
||
41 | if (false === glsr(Database::class)->dbQuery($sql)) { |
||
42 | $isDirty = true; |
||
43 | glsr_log()->error("The ratings table could not be altered, the [is_approved] index was not added."); |
||
44 | } |
||
45 | } |
||
46 | if (!$isDirty) { |
||
47 | update_option(glsr()->prefix.'db_version', '1.4'); |
||
48 | } |
||
51 |