jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/327399 )
Change subject: Adding IGNORE in case 2 records for the same project are added
at once
......................................................................
Adding IGNORE in case 2 records for the same project are added at once
If duplicate assessment records for the same project are added to an
article, we should ignore the duplicates. Otherwise it causes
duplicate key errors.
Also adding more code comments.
Bug: T152080
Change-Id: I417f25bb52c9b064f736b00b756ec29217dd5f78
---
M PageAssessmentsBody.php
1 file changed, 11 insertions(+), 3 deletions(-)
Approvals:
jenkins-bot: Verified
Samwilson: Looks good to me, approved
diff --git a/PageAssessmentsBody.php b/PageAssessmentsBody.php
index baba514..0c3dde3 100644
--- a/PageAssessmentsBody.php
+++ b/PageAssessmentsBody.php
@@ -43,19 +43,25 @@
$pageId = $titleObj->getArticleID();
$revisionId = $titleObj->getLatestRevID();
- // Compile a list of projects to find out which ones to be
deleted afterwards
+ // Compile a list of projects found in the parserData to find
out which
+ // assessment records need to be inserted, deleted, or updated.
$projects = array();
foreach ( $assessmentData as $parserData ) {
+ // If the name of the project is set...
if ( isset( $parserData[0] ) && $parserData[0] !== '' )
{
- // For each project, get the corresponding ID
from page_assessments_projects table
+ // ...get the corresponding ID from
page_assessments_projects table.
$projectId = self::getProjectId( $parserData[0]
);
+ // If there is no existing project by that
name, add it to the table.
if ( $projectId === false ) {
$projectId = self::insertProject(
$parserData[0] );
}
+ // Add the project's ID to the array.
$projects[$parserData[0]] = $projectId;
}
}
+ // Get a list of all the projects previously assigned to the
page.
$projectsInDb = self::getAllProjects( $pageId,
self::READ_LATEST );
+
$toInsert = array_diff( $projects, $projectsInDb );
$toDelete = array_diff( $projectsInDb, $projects );
$toUpdate = array_intersect( $projects, $projectsInDb );
@@ -203,7 +209,9 @@
*/
public static function insertRecord( $values ) {
$dbw = wfGetDB( DB_MASTER );
- $dbw->insert( 'page_assessments', $values, __METHOD__ );
+ // Use IGNORE in case 2 records for the same project are added
at once.
+ // This normally shouldn't happen, but is possible. (See
T152080)
+ $dbw->insert( 'page_assessments', $values, __METHOD__, [
'IGNORE' ] );
return true;
}
--
To view, visit https://gerrit.wikimedia.org/r/327399
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I417f25bb52c9b064f736b00b756ec29217dd5f78
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>
Gerrit-Reviewer: Jcrespo <[email protected]>
Gerrit-Reviewer: MusikAnimal <[email protected]>
Gerrit-Reviewer: Niharika29 <[email protected]>
Gerrit-Reviewer: Samwilson <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits