1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Migrations\AbstractMigration; |
4
|
|
|
use Cake\Log\Log; |
5
|
|
|
|
6
|
|
|
class FixStaleReportStates extends AbstractMigration |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* This migration changes the old report statuses to more |
10
|
|
|
* Github-related status |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
public function up() |
14
|
|
|
{ |
15
|
|
|
$this->_migrateBasedOnGithubLinked(); |
16
|
|
|
$this->_migrateToNewStatus(); |
17
|
|
|
$this->_migrateDuplicateReports(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
private function _migrateBasedOnGithubLinked() |
21
|
|
|
{ |
22
|
|
|
$sql = 'UPDATE `reports` SET `status` = \'forwarded\'' |
23
|
|
|
. ' WHERE `sourceforge_bug_id` IS NOT NULL AND `status` <> \'fixed\''; |
24
|
|
|
$rowsAffected = $this->execute($sql); |
25
|
|
|
|
26
|
|
|
Log::debug( |
27
|
|
|
$rowsAffected . ' reports are linked to a' |
28
|
|
|
. ' Github issue.' |
29
|
|
|
. ' These have been marked to have a \'forwarded\' status.' |
30
|
|
|
); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
private function _migrateToNewStatus() |
34
|
|
|
{ |
35
|
|
|
$statusMap = [ |
36
|
|
|
'fixed' => 'resolved', |
37
|
|
|
'open' => 'new', |
38
|
|
|
'out-of-date' => 'invalid', |
39
|
|
|
'works-for-me' => 'invalid', |
40
|
|
|
'wontfix' => 'invalid' |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
foreach ($statusMap as $oldStatus => $newStatus) { |
44
|
|
|
$sql = 'UPDATE `reports` SET `status` = \'' . $newStatus . '\'' |
45
|
|
|
. ' WHERE `status` = \'' . $oldStatus . '\''; |
46
|
|
|
$rowsAffected = $this->execute($sql); |
47
|
|
|
|
48
|
|
|
Log::debug( |
49
|
|
|
$rowsAffected . ' reports with \'' . $oldStatus . '\'' |
50
|
|
|
. ' were mapped to \'' . $newStatus . '\'.' |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
private function _migrateDuplicateReports() |
56
|
|
|
{ |
57
|
|
|
// Find the original reports and set the status |
58
|
|
|
// of their duplicate reports same as their status |
59
|
|
|
$sql = 'SELECT `id`, `status` FROM `reports` WHERE' |
60
|
|
|
. ' `related_to` IS NULL'; |
61
|
|
|
$origCount = 0; |
62
|
|
|
$result = $this->query($sql); |
63
|
|
|
$rowsAffected = 0; |
64
|
|
|
|
65
|
|
|
while ($row = $result->fetch()) { |
66
|
|
|
$update_sql = 'UPDATE `reports` SET `status` = \'' |
67
|
|
|
. $row['status'] . '\' WHERE `id` = \'' |
68
|
|
|
. $row['id'] . '\''; |
69
|
|
|
|
70
|
|
|
$rowsAffected += $this->execute($update_sql); |
71
|
|
|
$origCount++; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
Log::debug( |
75
|
|
|
$rowsAffected . ' duplicate reports were mapped to ' |
76
|
|
|
. ' same status as their ' . $origCount . ' original reports' |
77
|
|
|
); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|