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

FixLongPmaVersions   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 48
rs 10
c 2
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A down() 0 2 1
A up() 0 9 1
A _sanitizeVersionsInTable() 0 23 3
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