Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

FixLongPmaVersions::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 9
rs 10
c 1
b 0
f 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Cake\ORM\Locator\TableLocator;
5
use Cake\Log\Log;
6
7
class FixLongPmaVersions extends AbstractMigration
8
{
9
10
    /**
11
     * This migration strips the phpMyAdmin version of Debian,
12
     * Ubuntu and other suffixes in version strings
13
     *
14
     */
15
    public function up()
16
    {
17
        // Strip phpMyAdmin versions in `reports` table
18
        $count = $this->_sanitizeVersionsInTable('reports');
19
        Log::debug($count . ' reports updated');
20
21
        // Strip phpMyAdmin versions in `incidents` table
22
        $count = $this->_sanitizeVersionsInTable('incidents');
23
        Log::debug($count . ' incidents updated');
24
    }
25
26
    public function down()
27
    {
28
        // Once applied, this migration can't be reversed
29
        // but the migration itself is idempotent
30
    }
31
32
    private function _sanitizeVersionsInTable($table)
33
    {
34
        $sql = 'SELECT `id`, `pma_version` FROM `' . $table . '`';
35
        $count = 0;
36
        $incidentsTable = TableRegistry::get('Incidents');
0 ignored issues
show
Bug introduced by
The type TableRegistry was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
37
        $result = $this->query($sql);
38
39
        while ($row = $result->fetch()) {
40
            $strippedVersionString
41
                = $incidentsTable->getStrippedPmaVersion(
42
                    $row['pma_version']
43
                );
44
45
            if ($strippedVersionString !== $row['pma_version']) {
46
                $this->execute('UPDATE ' . $table . ' SET `pma_version` = \''
47
                    . $strippedVersionString . '\' WHERE `id` = \''
48
                    . $row['id'] . '\'');
49
50
                ++$count;
51
            }
52
        }
53
54
        return $count;
55
    }
56
}
57