Devirk has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/294044

Change subject: Create a maintenance script to populate the Contributors Table
......................................................................

Create a maintenance script to populate the Contributors Table

Bug: T134938
Change-Id: Ib45acd2400ee5116c0a68ac7fe6556442097fe3f
---
M extension.json
M includes/ContributorsDB.php
M includes/sql/contributors.sql
M maintenance/PopulateContributorsTable.php
4 files changed, 70 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Contributors 
refs/changes/44/294044/1

diff --git a/extension.json b/extension.json
index 2f5cae0..3625369 100644
--- a/extension.json
+++ b/extension.json
@@ -23,7 +23,8 @@
        "AutoloadClasses": {
                "Contributors": "includes/Contributors.php",
                "SpecialContributors": "includes/SpecialContributors.php",
-               "ContributorsHooks": "includes/ContributorsHooks.php"
+               "ContributorsHooks": "includes/ContributorsHooks.php",
+               "GetContributorsData":"includes/ContributorsDB.php"
        },
        "Hooks": {
                "LoadExtensionSchemaUpdates": [
diff --git a/includes/ContributorsDB.php b/includes/ContributorsDB.php
index e69de29..1bc9095 100644
--- a/includes/ContributorsDB.php
+++ b/includes/ContributorsDB.php
@@ -0,0 +1,31 @@
+<?php
+
+
+class GetContributorsData {
+
+       /**
+        * @param $dbr
+        * @return mixed
+       */
+       public static function readDataFromDB($dbr) {
+               $res = $dbr->select('contributors', array('cn_id', 
'cn_page_id', 'cn_user_id', 'cn_user_text', 'cn_revisionCount'),
+               array("cn_page_id IS NOT NULL"), __METHOD__);
+               return $res;
+       }
+
+       /**
+       * @param $dbw
+       * @param $res
+       */
+       public static function writeDataIntoDB($dbw, $res) {
+               foreach ($res as $row) {
+                       $dbw->update('contributors',
+                       array('cn_id' => $row->cn_id),
+                       array('cn_page_id' => $row->cn_page_id),
+                       array('cn_user_id' => $row->cn_user_id),
+                       array('cn_user_text' => $row->cn_user_text),
+                       array('cn_revisionCount' => $row->cn_revisionCount),
+                       __METHOD__);
+               }
+       }
+}
\ No newline at end of file
diff --git a/includes/sql/contributors.sql b/includes/sql/contributors.sql
index 018ae86..d7f0a5b 100644
--- a/includes/sql/contributors.sql
+++ b/includes/sql/contributors.sql
@@ -3,7 +3,7 @@
   cn_page_id int unsigned NOT NULL,
   cn_user_id int unsigned NOT NULL,
   cn_user_text varchar(255) NOT NULL,
-  cn_revision_count int unsigned NOT NULL
+  cn_revisionCount int unsigned NOT NULL
 )/*$wgDBTableOptions*/;
 
 CREATE INDEX /*i*/cn_page_id ON /*_*/contributors (cn_page_id);
diff --git a/maintenance/PopulateContributorsTable.php 
b/maintenance/PopulateContributorsTable.php
index e69de29..c923e82 100644
--- a/maintenance/PopulateContributorsTable.php
+++ b/maintenance/PopulateContributorsTable.php
@@ -0,0 +1,36 @@
+<?php
+
+if (getenv('MW_INSTALL_PATH') !== false) {
+    require_once(getenv('MW_INSTALL_PATH') . '/maintenance/Maintenance.php');
+} else {
+    require_once(__DIR__ . '/../../../maintenance/Maintenance.php');
+}
+
+/**
+ * Maintenance script that populates the Contributors table with Contributor's 
data
+ *
+ * @ingroup Maintenance
+ */
+class PopulateContributorsTable extends Maintenance {
+
+       public function __construct() {
+               parent::__construct();
+               $this->addDescription(
+                       "Populates the contributor's table with contributor's 
data" );
+               $this->output( "Started processing... \n" );
+       }
+
+       public function execute() {
+               $dbr = $this->getDB( DB_SLAVE );
+               $dbw = $this->getDB( DB_MASTER );
+               $result=GetContributorsData::readDataFromDB($dbr);
+               if($result) {
+                       GetContributorsData::writeDataIntoDB($dbw,$result);
+               }
+
+       }
+}
+
+$maintClass = "PopulateContributorsTable";
+require_once RUN_MAINTENANCE_IF_MAIN;
+

-- 
To view, visit https://gerrit.wikimedia.org/r/294044
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib45acd2400ee5116c0a68ac7fe6556442097fe3f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Contributors
Gerrit-Branch: master
Gerrit-Owner: Devirk <[email protected]>

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

Reply via email to