Completed
Pull Request — master (#147)
by Deven
03:16
created

FixLongPmaVersions::up()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
use Cake\ORM\TableRegistry;
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
        $rows = $this->fetchAll(
35
            'SELECT `id`, `pma_version` FROM `' . $table . '`',
36
            PDO::FETCH_ASSOC
0 ignored issues
show
Unused Code introduced by
The call to FixLongPmaVersions::fetchAll() has too many arguments starting with \PDO::FETCH_ASSOC.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37
        );
38
        $count = 0;
39
        foreach ($rows as $row) {
40
            $strippedVersionString = TableRegistry::get('Incidents')->getStrippedPmaVersion(
41
                $row['pma_version']
42
            );
43
44
            $this->execute('UPDATE ' . $table . ' SET `pma_version` = \''
45
                . $strippedVersionString . '\' WHERE `id` = \''
46
                . $row['id'] . '\''
47
            );
48
            if ($strippedVersionString !== $row['pma_version']) {
49
                ++$count;
50
            }
51
        }
52
53
        return $count;
54
    }
55
}
56