Conditions | 6 |
Paths | 18 |
Total Lines | 27 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 1 |
1 | <?php |
||
17 | public function migrateDatabase(): void |
||
18 | { |
||
19 | $isDirty = false; |
||
20 | $indexes = glsr(Database::class)->dbGetResults( |
||
21 | glsr(Query::class)->sql("SHOW INDEXES FROM table|ratings") |
||
22 | ); |
||
23 | $keyNames = wp_list_pluck($indexes, 'Key_name'); |
||
24 | if (!in_array('glsr_ratings_rating_type_is_approved_index', $keyNames)) { |
||
25 | $sql = glsr(Query::class)->sql(" |
||
26 | ALTER TABLE table|ratings ADD INDEX glsr_ratings_rating_type_is_approved_index (rating,type,is_approved) |
||
27 | "); |
||
28 | if (false === glsr(Database::class)->dbQuery($sql)) { |
||
29 | $isDirty = true; |
||
30 | glsr_log()->error("The ratings table could not be altered, the [rating_type_is_approved] index was not added."); |
||
31 | } |
||
32 | } |
||
33 | if (!in_array('glsr_ratings_is_flagged_index', $keyNames)) { |
||
34 | $sql = glsr(Query::class)->sql(" |
||
35 | ALTER TABLE table|ratings ADD INDEX glsr_ratings_is_flagged_index (is_flagged) |
||
36 | "); |
||
37 | if (false === glsr(Database::class)->dbQuery($sql)) { |
||
38 | $isDirty = true; |
||
39 | glsr_log()->error("The ratings table could not be altered, the [is_flagged] index was not added."); |
||
40 | } |
||
41 | } |
||
42 | if (!$isDirty) { |
||
43 | update_option(glsr()->prefix.'db_version', '1.4'); |
||
44 | } |
||
47 |