Test Failed
Push — develop ( 33b521...cdbd76 )
by Paul
10:16 queued 21s
created

Migrate_8_0_0::run()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Migrations;
4
5
use GeminiLabs\SiteReviews\Contracts\MigrateContract;
6
use GeminiLabs\SiteReviews\Database;
7
use GeminiLabs\SiteReviews\Database\Query;
8
use GeminiLabs\SiteReviews\Database\Tables\TableStats;
9
10
class Migrate_8_0_0 implements MigrateContract
11
{
12
    public function run(): bool
13
    {
14
        return $this->migrateDatabase();
15
    }
16
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
    }
41
}
42