From 6bebdde04be9486fb308f778be0cf33d3b54dbef Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Tue, 25 Apr 2023 17:10:04 -0400 Subject: [PATCH 1/6] fix SQL --- SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql | 4 ++++ raisinbread/RB_files/RB_issues_history.sql | 9 ++++----- 2 files changed, 8 insertions(+), 5 deletions(-) create mode 100644 SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql diff --git a/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql b/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql new file mode 100644 index 00000000000..ef5a95fec83 --- /dev/null +++ b/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql @@ -0,0 +1,4 @@ +-- delete from issues_history any orphaned module IDs +DELETE FROM issues_history WHERE fieldChanged='module' AND issueID IN (SELECT issueID FROM issues WHERE module IS NULL); +-- set issues history module ID to correct moduleID, replacing old LorisMenu ID +UPDATE issues_history ih SET newValue=(SELECT i.module FROM issues i WHERE i.issueID=ih.issueID) WHERE fieldChanged='module'; diff --git a/raisinbread/RB_files/RB_issues_history.sql b/raisinbread/RB_files/RB_issues_history.sql index 314b3ec9cb8..bd12f73d592 100644 --- a/raisinbread/RB_files/RB_issues_history.sql +++ b/raisinbread/RB_files/RB_issues_history.sql @@ -22,7 +22,7 @@ INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldC INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (19,'admin','2016-09-02 20:30:38','assignee',16,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (20,'new issue to test assignee notification','2016-09-02 20:30:38','title',16,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (21,'Examiners','2016-09-02 20:30:38','category',16,'tester'); -INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (22,'21','2016-09-02 20:30:39','module',16,'tester'); +INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (22,'16','2016-09-02 20:30:39','module',16,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (23,'tester','2016-09-02 20:30:39','comment',16,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (24,'2016-09-02 12:30:38','2016-09-02 20:30:39','comment',16,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (25,'tester','2016-09-02 20:31:45','assignee',17,'tester'); @@ -39,13 +39,12 @@ INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldC INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (36,'3','2016-09-02 21:59:56','centerID',19,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (37,'testing if assignee gets email - new ticket','2016-09-02 21:59:56','title',19,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (38,'Examiners','2016-09-02 21:59:56','category',19,'tester'); -INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (39,'11','2016-09-02 21:59:56','module',19,'tester'); +INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (39,'17','2016-09-02 21:59:56','module',19,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (40,'tester','2016-09-02 22:02:29','assignee',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (41,'feedback','2016-09-02 22:02:29','status',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (42,'urgent','2016-09-02 22:02:30','priority',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (43,'testing if assignee gets email upon ticket update+re-assign','2016-09-02 22:02:30','title',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (44,'Imaging','2016-09-02 22:02:30','category',20,'tester'); -INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (45,'12','2016-09-02 22:02:30','module',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (46,'admin','2016-09-02 22:04:38','assignee',20,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (47,'tester','2016-09-02 23:45:40','assignee',21,'tester'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (48,'ticket to end all tickets ','2016-09-02 23:45:40','title',21,'tester'); @@ -62,12 +61,12 @@ INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldC INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (59,'2','2016-09-07 01:19:21','centerID',26,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (60,'testing site population','2016-09-07 01:19:21','title',26,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (61,'Behavioural Battery','2016-09-07 01:19:21','category',26,'admin'); -INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (62,'11','2016-09-07 01:19:21','module',26,'admin'); +INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (62,'17','2016-09-07 01:19:21','module',26,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (63,'test','2016-09-07 01:38:06','assignee',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (64,'3','2016-09-07 01:38:06','centerID',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (65,'test ticket with visit label','2016-09-07 01:38:06','title',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (66,'Behavioural Instruments','2016-09-07 01:38:06','category',27,'admin'); -INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (67,'10','2016-09-07 01:38:07','module',27,'admin'); +INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (67,'9','2016-09-07 01:38:07','module',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (68,'300002','2016-09-07 01:38:07','comment',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (69,'2','2016-09-07 01:39:23','sessionID',27,'admin'); INSERT INTO `issues_history` (`issueHistoryID`, `newValue`, `dateAdded`, `fieldChanged`, `issueID`, `addedBy`) VALUES (70,'2','2016-09-07 02:19:59','sessionID',27,'admin'); From 847c6b14b421234a0a6795bda4762364bf23b915 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Tue, 25 Apr 2023 18:08:11 -0400 Subject: [PATCH 2/6] use same logic to convert issue history --- .../Convert_LorisMenuID_to_ModuleID.php | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php index 8780f582ccb..73f76ed8aa6 100644 --- a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php +++ b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php @@ -119,6 +119,69 @@ $patch[$issueID] = $modulesTableID; } +// Use mapping arrays to replace old `LorisMenu` ID values in issues_history +// `newValue` column with new `modules` table ID values where fieldChanged = 'module'. +$result_history = $DB->pselect( + 'SELECT issueHistoryID, newValue as module FROM issues_history WHERE fieldChange=\'module\'', + [] +); +$issueHistoryMapping = []; +foreach ($result_history as $row) { + $issueHistoryMapping[$row['issueHistoryID']] = $row['module']; +} +unset($result_history); + +$correctHistoryMapping = []; +$incorrectHistoryMapping = []; +foreach ($issueHistoryMapping as $issueHistoryID => $menuTableID) { + // Using the menuTableID, look up the corresponding module name from the + // `LorisMenu` table. + // Using the module name, look up the new ID in the `modules` table. + if (!array_key_exists($menuTableID, $menuTableMapping)) { + echo "[!] Issue History ID: $issueHistoryID. Could not find key `$menuTableID` in ". + "LorisMenu mapping array\n"; + $incorrectHistoryMapping[] = $issueHistoryID; + continue; + } + if (!array_key_exists($menuTableMapping[$menuTableID], $modulesTableMapping)) { + echo "[!] Issue History ID: $issueHistoryID. Could not find key ". + "`$menuTableMapping[$menuTableID]` in modules mapping array\n"; + $incorrectHistoryMapping[] = $issueHistoryID; + continue; + } + $correctHistoryMapping[$issueHistoryID] + = $modulesTableMapping[$menuTableMapping[$menuTableID]]; +} + +// Now we have an array of issue history IDs mapped to the IDs in the `module` table +// matched based on the name of modules. This should fix the problem. + +$patch_history = []; +foreach ($correctHistoryMapping as $issueHistoryID => $modulesTableID) { + $result = $DB->pselect( + "SELECT ih.issueHistoryID,lm.Link as module FROM LorisMenu lm + INNER JOIN issues_history ih ON (ih.newValue=lm.ID AND ih.issueHistoryID=:ihd) + WHERE ih.fieldChanged='module'", + ['ihd' => $issueHistoryID] + ); + $idBefore = $result[0]['issueHistoryID']; + $moduleBefore = $result[0]['module']; + + $moduleAfter = $DB->pselectOne( + 'SELECT name FROM modules WHERE ID=:id', + ['id' => $modulesTableID] + ); + echo sprintf( + "Issue History ID: %s. Module before (`LorisMenu`): `%s`. Module after " + . "(`modules`): `%s`\n", + $idBefore, + $moduleBefore, + $moduleAfter + ); + + $patch_history[$issueHistoryID] = $modulesTableID; +} + if ($confirm) { foreach ($patch as $issueID=>$modulesTableID) { $DB->update('issues', ['module'=>$modulesTableID], ['issueID'=>$issueID]); @@ -126,6 +189,14 @@ foreach ($incorrectMapping as $issueID) { $DB->update('issues', ['module'=>null], ['issueID'=>$issueID]); } + + foreach ($patch_history as $issueHistoryID=>$modulesTableID) { + $DB->update('issues_history', ['newValue'=>$modulesTableID], ['issueHistoryID'=>$issueHistoryID]); + } + foreach ($incorrectHistoryMapping as $issueID) { + $DB->delete('issues_history', ['issueHistoryID'=>$issueHistoryID]); + } + echo "Done. Make sure to run the clean-up patch $cleanupPatch to complete ". "the process\n"; } else { @@ -137,12 +208,21 @@ echo "UPDATE `issues` SET module=NULL WHERE issueID=$issueID;\n"; } + foreach ($patch_history as $issueHistoryID=>$modulesTableID) { + echo "UPDATE `issues_history` SET newValue=$modulesTableID WHERE issueHistoryID=$issueHistoryID;\n"; + } + foreach ($incorrectHistoryMapping as $issueHistoryID) { + echo "DELETE FROM `issues_history` WHERE issueHistoryID=$issueHistoryID;\n"; + } + echo "ALTER TABLE `issues` ADD FOREIGN KEY (module) REFERENCES modules(ID);\n\n"; echo "Run this tool again with the argument 'confirm' to ". "perform the changes.\n". "Note: The module field for issues for which a mapping between LorisMenu and modules can not be found will be nullified.\n\n"; + "Note: The row of issues_history for which a mapping between LorisMenu and + modules can not be found will be deleted.\n\n"; } /** From 36eddc3d6c8cc74f5141ed92d252d4c26c4ca879 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Tue, 25 Apr 2023 18:21:17 -0400 Subject: [PATCH 3/6] typo --- tools/single_use/Convert_LorisMenuID_to_ModuleID.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php index 73f76ed8aa6..feb8c9c7584 100644 --- a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php +++ b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php @@ -122,7 +122,7 @@ // Use mapping arrays to replace old `LorisMenu` ID values in issues_history // `newValue` column with new `modules` table ID values where fieldChanged = 'module'. $result_history = $DB->pselect( - 'SELECT issueHistoryID, newValue as module FROM issues_history WHERE fieldChange=\'module\'', + 'SELECT issueHistoryID, newValue as module FROM issues_history WHERE fieldChanged=\'module\'', [] ); $issueHistoryMapping = []; From 1ffd5e575a2ae79f471b58b9bee5438f3342a48d Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Tue, 25 Apr 2023 18:25:38 -0400 Subject: [PATCH 4/6] fix note --- tools/single_use/Convert_LorisMenuID_to_ModuleID.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php index feb8c9c7584..3f719f9978e 100644 --- a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php +++ b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php @@ -220,7 +220,7 @@ echo "Run this tool again with the argument 'confirm' to ". "perform the changes.\n". "Note: The module field for issues for which a mapping between LorisMenu and - modules can not be found will be nullified.\n\n"; + modules can not be found will be nullified.\n". "Note: The row of issues_history for which a mapping between LorisMenu and modules can not be found will be deleted.\n\n"; } From 40c1105dc45167148b1bfc3fcb7d194e328268e6 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Tue, 25 Apr 2023 18:36:17 -0400 Subject: [PATCH 5/6] php lint --- .../Convert_LorisMenuID_to_ModuleID.php | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php index 3f719f9978e..ada85881b4c 100644 --- a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php +++ b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php @@ -120,11 +120,14 @@ } // Use mapping arrays to replace old `LorisMenu` ID values in issues_history -// `newValue` column with new `modules` table ID values where fieldChanged = 'module'. +// `newValue` column with new `modules` table ID values +// where fieldChanged = 'module'. $result_history = $DB->pselect( - 'SELECT issueHistoryID, newValue as module FROM issues_history WHERE fieldChanged=\'module\'', + 'SELECT issueHistoryID, newValue as module FROM issues_history + WHERE fieldChanged=\'module\'', [] ); + $issueHistoryMapping = []; foreach ($result_history as $row) { $issueHistoryMapping[$row['issueHistoryID']] = $row['module']; @@ -138,8 +141,8 @@ // `LorisMenu` table. // Using the module name, look up the new ID in the `modules` table. if (!array_key_exists($menuTableID, $menuTableMapping)) { - echo "[!] Issue History ID: $issueHistoryID. Could not find key `$menuTableID` in ". - "LorisMenu mapping array\n"; + echo "[!] Issue History ID: $issueHistoryID. Could not find key ". + "`$menuTableID` in LorisMenu mapping array\n"; $incorrectHistoryMapping[] = $issueHistoryID; continue; } @@ -160,7 +163,8 @@ foreach ($correctHistoryMapping as $issueHistoryID => $modulesTableID) { $result = $DB->pselect( "SELECT ih.issueHistoryID,lm.Link as module FROM LorisMenu lm - INNER JOIN issues_history ih ON (ih.newValue=lm.ID AND ih.issueHistoryID=:ihd) + INNER JOIN issues_history ih + ON (ih.newValue=lm.ID AND ih.issueHistoryID=:ihd) WHERE ih.fieldChanged='module'", ['ihd' => $issueHistoryID] ); @@ -191,7 +195,11 @@ } foreach ($patch_history as $issueHistoryID=>$modulesTableID) { - $DB->update('issues_history', ['newValue'=>$modulesTableID], ['issueHistoryID'=>$issueHistoryID]); + $DB->update( + 'issues_history', + ['newValue'=>$modulesTableID], + ['issueHistoryID'=>$issueHistoryID] + ); } foreach ($incorrectHistoryMapping as $issueID) { $DB->delete('issues_history', ['issueHistoryID'=>$issueHistoryID]); @@ -209,7 +217,8 @@ } foreach ($patch_history as $issueHistoryID=>$modulesTableID) { - echo "UPDATE `issues_history` SET newValue=$modulesTableID WHERE issueHistoryID=$issueHistoryID;\n"; + echo "UPDATE `issues_history` SET newValue=$modulesTableID ". + "WHERE issueHistoryID=$issueHistoryID;\n"; } foreach ($incorrectHistoryMapping as $issueHistoryID) { echo "DELETE FROM `issues_history` WHERE issueHistoryID=$issueHistoryID;\n"; From ade63a5eebfbe642ee7f37e38f16009c274cb0a5 Mon Sep 17 00:00:00 2001 From: zaliqarosli Date: Fri, 22 Dec 2023 15:29:00 -0500 Subject: [PATCH 6/6] rm tool script fixes + add note to patch --- .../2023-04-25-FixIssueWrongModuleID.sql | 4 + .../Convert_LorisMenuID_to_ModuleID.php | 91 +------------------ 2 files changed, 5 insertions(+), 90 deletions(-) diff --git a/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql b/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql index ef5a95fec83..ed2469b6403 100644 --- a/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql +++ b/SQL/New_patches/2023-04-25-FixIssueWrongModuleID.sql @@ -1,3 +1,7 @@ +-- NOTE: This SQL patch follows up the running of single use tool `tools/single_use/Convert_LorisMenuID_to_ModuleID.php` +-- that was necessary to upgrade the `issues` table from LORIS version 22 to version 23. The tool forgot +-- to include an upgrade of the `issues_history` table, which is now tackled by this SQL patch. + -- delete from issues_history any orphaned module IDs DELETE FROM issues_history WHERE fieldChanged='module' AND issueID IN (SELECT issueID FROM issues WHERE module IS NULL); -- set issues history module ID to correct moduleID, replacing old LorisMenu ID diff --git a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php index ada85881b4c..8780f582ccb 100644 --- a/tools/single_use/Convert_LorisMenuID_to_ModuleID.php +++ b/tools/single_use/Convert_LorisMenuID_to_ModuleID.php @@ -119,73 +119,6 @@ $patch[$issueID] = $modulesTableID; } -// Use mapping arrays to replace old `LorisMenu` ID values in issues_history -// `newValue` column with new `modules` table ID values -// where fieldChanged = 'module'. -$result_history = $DB->pselect( - 'SELECT issueHistoryID, newValue as module FROM issues_history - WHERE fieldChanged=\'module\'', - [] -); - -$issueHistoryMapping = []; -foreach ($result_history as $row) { - $issueHistoryMapping[$row['issueHistoryID']] = $row['module']; -} -unset($result_history); - -$correctHistoryMapping = []; -$incorrectHistoryMapping = []; -foreach ($issueHistoryMapping as $issueHistoryID => $menuTableID) { - // Using the menuTableID, look up the corresponding module name from the - // `LorisMenu` table. - // Using the module name, look up the new ID in the `modules` table. - if (!array_key_exists($menuTableID, $menuTableMapping)) { - echo "[!] Issue History ID: $issueHistoryID. Could not find key ". - "`$menuTableID` in LorisMenu mapping array\n"; - $incorrectHistoryMapping[] = $issueHistoryID; - continue; - } - if (!array_key_exists($menuTableMapping[$menuTableID], $modulesTableMapping)) { - echo "[!] Issue History ID: $issueHistoryID. Could not find key ". - "`$menuTableMapping[$menuTableID]` in modules mapping array\n"; - $incorrectHistoryMapping[] = $issueHistoryID; - continue; - } - $correctHistoryMapping[$issueHistoryID] - = $modulesTableMapping[$menuTableMapping[$menuTableID]]; -} - -// Now we have an array of issue history IDs mapped to the IDs in the `module` table -// matched based on the name of modules. This should fix the problem. - -$patch_history = []; -foreach ($correctHistoryMapping as $issueHistoryID => $modulesTableID) { - $result = $DB->pselect( - "SELECT ih.issueHistoryID,lm.Link as module FROM LorisMenu lm - INNER JOIN issues_history ih - ON (ih.newValue=lm.ID AND ih.issueHistoryID=:ihd) - WHERE ih.fieldChanged='module'", - ['ihd' => $issueHistoryID] - ); - $idBefore = $result[0]['issueHistoryID']; - $moduleBefore = $result[0]['module']; - - $moduleAfter = $DB->pselectOne( - 'SELECT name FROM modules WHERE ID=:id', - ['id' => $modulesTableID] - ); - echo sprintf( - "Issue History ID: %s. Module before (`LorisMenu`): `%s`. Module after " - . "(`modules`): `%s`\n", - $idBefore, - $moduleBefore, - $moduleAfter - ); - - $patch_history[$issueHistoryID] = $modulesTableID; -} - if ($confirm) { foreach ($patch as $issueID=>$modulesTableID) { $DB->update('issues', ['module'=>$modulesTableID], ['issueID'=>$issueID]); @@ -193,18 +126,6 @@ foreach ($incorrectMapping as $issueID) { $DB->update('issues', ['module'=>null], ['issueID'=>$issueID]); } - - foreach ($patch_history as $issueHistoryID=>$modulesTableID) { - $DB->update( - 'issues_history', - ['newValue'=>$modulesTableID], - ['issueHistoryID'=>$issueHistoryID] - ); - } - foreach ($incorrectHistoryMapping as $issueID) { - $DB->delete('issues_history', ['issueHistoryID'=>$issueHistoryID]); - } - echo "Done. Make sure to run the clean-up patch $cleanupPatch to complete ". "the process\n"; } else { @@ -216,22 +137,12 @@ echo "UPDATE `issues` SET module=NULL WHERE issueID=$issueID;\n"; } - foreach ($patch_history as $issueHistoryID=>$modulesTableID) { - echo "UPDATE `issues_history` SET newValue=$modulesTableID ". - "WHERE issueHistoryID=$issueHistoryID;\n"; - } - foreach ($incorrectHistoryMapping as $issueHistoryID) { - echo "DELETE FROM `issues_history` WHERE issueHistoryID=$issueHistoryID;\n"; - } - echo "ALTER TABLE `issues` ADD FOREIGN KEY (module) REFERENCES modules(ID);\n\n"; echo "Run this tool again with the argument 'confirm' to ". "perform the changes.\n". "Note: The module field for issues for which a mapping between LorisMenu and - modules can not be found will be nullified.\n". - "Note: The row of issues_history for which a mapping between LorisMenu and - modules can not be found will be deleted.\n\n"; + modules can not be found will be nullified.\n\n"; } /**