Niharika29 has uploaded a new change for review.
https://gerrit.wikimedia.org/r/283196
Change subject: Move wikiprojects to a separate table in PageAssessments
extension
......................................................................
Move wikiprojects to a separate table in PageAssessments extension
Bug: T130844
Change-Id: Ic1b087839b0da2549b2faa96b199dee350075c8b
---
M PageAssessments.hooks.php
M PageAssessmentsBody.php
M db/addReviewsTable.sql
A db/addWikiprojectsTable.sql
4 files changed, 55 insertions(+), 3 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PageAssessments
refs/changes/96/283196/1
diff --git a/PageAssessments.hooks.php b/PageAssessments.hooks.php
index 7911098..b9c1fd9 100644
--- a/PageAssessments.hooks.php
+++ b/PageAssessments.hooks.php
@@ -55,6 +55,7 @@
public static function onLoadExtensionSchemaUpdates( DatabaseUpdater
$updater = null ) {
$dbDir = __DIR__ . '/db';
$updater->addExtensionUpdate( array( 'addTable',
'page_assessments', "$dbDir/addReviewsTable.sql", true ) );
+ $updater->addExtensionUpdate( array( 'addTable',
'page_assessments_wikiprojects', "$dbDir/addWikiprojectsTable.sql", true ) );
return true;
}
diff --git a/PageAssessmentsBody.php b/PageAssessmentsBody.php
index 8c16558..7e4d110 100644
--- a/PageAssessmentsBody.php
+++ b/PageAssessmentsBody.php
@@ -32,7 +32,8 @@
// Compile a list of projects to find out which ones to be
deleted afterwards
$projects = array();
foreach ( $assessmentData as $parserData ) {
- $projects[] = $parserData[0];
+ // For each project, get the corresponding ID from
page_assessments_wikiprojects table
+ $projects[] = PageAssessmentsBody::getProjectId(
$parserData[0] );
}
$projectsInDb = PageAssessmentsBody::getAllProjects( $pageId );
$toInsert = array_diff( $projects, $projectsInDb );
@@ -74,6 +75,49 @@
/**
+ * Get project ID for a give wikiproject title
+ * If project is not already in table, insert a new record and return ID
+ * @param string $project Project title
+ * @return int project ID
+ */
+ public static function getProjectId( $project ) {
+ $dbr = wfGetDB( DB_SLAVE );
+ $conds = array(
+ 'pa_project_title' => $project
+ );
+ $record = $dbr->select(
+ 'page_assessments_wikiprojects',
+ array( 'pa_project_id', 'pa_project_title' ),
+ $conds
+ );
+ foreach ( $record as $row ) {
+ if ( $row->pa_project_id ) {
+ // Return project ID if we found a match
+ return $row->pa_project_id;
+ }
+ }
+ // If we didn't find a match, insert the new project into the
table
+ $dbw = wfGetDB( DB_MASTER );
+ $values = array(
+ 'pa_project_title' => $project
+ );
+ $dbw->insert( 'page_assessments_wikiprojects', $values,
__METHOD__ );
+ // Fetch the project ID now and return it
+ $record = $dbr->select(
+ 'page_assessments_wikiprojects',
+ array( 'pa_project_id', 'pa_project_title' ),
+ $conds
+ );
+ foreach ( $record as $row ) {
+ if ( $row->pa_project_id ) {
+ // Return project ID if we found a match
+ return $row->pa_project_id;
+ }
+ }
+ }
+
+
+ /**
* Update record in DB if there are new values
* @param array $values New values to be entered into the DB
* @return bool true
diff --git a/db/addReviewsTable.sql b/db/addReviewsTable.sql
index 383276b..3f073af 100644
--- a/db/addReviewsTable.sql
+++ b/db/addReviewsTable.sql
@@ -2,11 +2,10 @@
CREATE TABLE IF NOT EXISTS /*_*/page_assessments (
pa_page_id INT UNSIGNED NOT NULL,
- pa_project VARCHAR(128) DEFAULT NULL,
+ pa_project INT UNSIGNED DEFAULT NULL,
pa_class VARCHAR(20) DEFAULT NULL,
pa_importance VARCHAR(20) DEFAULT NULL,
pa_page_revision INT UNSIGNED NOT NULL
)/*$wgDBTableOptions*/;
-CREATE INDEX /*i*/pa_project ON /*_*/ page_assessments (pa_project);
CREATE UNIQUE INDEX /*i*/pa_page_project ON /*_*/ page_assessments
(pa_page_id, pa_project);
diff --git a/db/addWikiprojectsTable.sql b/db/addWikiprojectsTable.sql
new file mode 100644
index 0000000..900a327
--- /dev/null
+++ b/db/addWikiprojectsTable.sql
@@ -0,0 +1,8 @@
+-- Add wikiprojects table
+
+CREATE TABLE IF NOT EXISTS /*_*/page_assessments_wikiprojects (
+ pa_project_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
+ pa_project_title VARCHAR(128) DEFAULT NULL,
+)/*$wgDBTableOptions*/;
+
+CREATE INDEX /*i*/pa_project ON /*_*/ page_assessments_wikiprojects
(pa_project);
--
To view, visit https://gerrit.wikimedia.org/r/283196
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic1b087839b0da2549b2faa96b199dee350075c8b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/PageAssessments
Gerrit-Branch: master
Gerrit-Owner: Niharika29 <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits