Conditions | 5 |
Paths | 6 |
Total Lines | 23 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
17 | public function migrateDatabase(): bool |
||
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_ip_address_index', $keyNames)) { |
||
25 | $sql = glsr(Query::class)->sql(" |
||
26 | ALTER TABLE table|ratings ADD INDEX glsr_ratings_ip_address_index (ip_address) |
||
27 | "); |
||
28 | if (false === glsr(Database::class)->dbQuery($sql)) { |
||
29 | glsr_log()->error("The ratings table could not be altered, the [ip_address_index] index was not added."); |
||
30 | $isDirty = true; |
||
31 | } |
||
32 | } |
||
33 | glsr(TableStats::class)->create(); |
||
34 | glsr(TableStats::class)->addForeignConstraints(); |
||
35 | if (!glsr(TableStats::class)->exists() || $isDirty) { |
||
36 | return false; |
||
37 | } |
||
38 | update_option(glsr()->prefix.'db_version', '1.5'); |
||
39 | return true; |
||
40 | } |
||
42 |