Kaldari has uploaded a new change for review. ( 
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

Also adding more code comments.

Bug: T152080
Change-Id: I417f25bb52c9b064f736b00b756ec29217dd5f78
---
M PageAssessmentsBody.php
1 file changed, 11 insertions(+), 3 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageAssessments 
refs/changes/99/327399/1

diff --git a/PageAssessmentsBody.php b/PageAssessmentsBody.php
index baba514..b5b0438 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
+               // projects 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 this 
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: newchange
Gerrit-Change-Id: I417f25bb52c9b064f736b00b756ec29217dd5f78
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Kaldari <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to