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