Addshore has submitted this change and it was merged.

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


Create a maintenance script to populate the Contributors Table

The User Id, Usertext, Page Id are taken from the revision
table and then grouped to get the revision count each user
has made to a page and all the information is then populated
to the contributors table .

Bug: T134938
Change-Id: Ib45acd2400ee5116c0a68ac7fe6556442097fe3f
---
A maintenance/PopulateContributorsTable.php
1 file changed, 82 insertions(+), 0 deletions(-)

Approvals:
  Addshore: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/PopulateContributorsTable.php 
b/maintenance/PopulateContributorsTable.php
new file mode 100644
index 0000000..5cd5dcc
--- /dev/null
+++ b/maintenance/PopulateContributorsTable.php
@@ -0,0 +1,82 @@
+<?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->setBatchSize( 100 );
+       }
+
+       public function execute() {
+               $this->output( "Started processing..\n" );
+               $dbw = $this->getDB( DB_MASTER );
+               $dbr = $this->getDB( DB_SLAVE );
+
+               $start = $dbr->selectField( 'revision', 'MIN(rev_page)', false, 
__METHOD__ );
+               if ( !$start ) {
+                       $this->output( "Nothing to do.\n" );
+
+                       return true;
+               }
+               $end = $dbr->selectField( 'revision', 'MAX(rev_page)', false, 
__METHOD__ );
+
+               $end += $this->mBatchSize - 1;
+               $blockStart = $start;
+               $blockEnd = $start + $this->mBatchSize - 1;
+               while ( $blockEnd <= $end ) {
+                       $this->output( "Getting Contributor's data..\n" );
+                       $cond =array( "rev_page BETWEEN $blockStart AND 
$blockEnd" );
+                       $res = $dbr->select(
+                               'revision',
+                               array( 'COUNT(*) AS cn_revision_count', 
'rev_user', 'rev_user_text', 'rev_page' ),
+                               $cond,
+                               __METHOD__,
+                               array( 'GROUP BY' => array( 'rev_page', 
'rev_user','rev_user_text' ) )
+                       );
+
+                       $this->output( "Writing data into Contributors Table.. 
\n" );
+
+                       foreach ( $res as $row ) {
+                               $dbw->upsert(
+                                       'contributors',
+                                       array(
+                                               'cn_page_id' => $row->rev_page,
+                                               'cn_user_id' => $row->rev_user,
+                                               'cn_user_text' => 
$row->rev_user_text,
+                                               'cn_revision_count' => 
$row->cn_revision_count
+                                       ),
+                                       array(
+                                               'cn_page_id',
+                                               'cn_user_id',
+                                               'cn_user_text'
+                                       ),
+                                       array(
+                                               'cn_page_id' => $row->rev_page,
+                                               'cn_user_id' => $row->rev_user,
+                                               'cn_user_text' => 
$row->rev_user_text,
+                                               'cn_revision_count' => 
$row->cn_revision_count
+                                       ),
+                                       __METHOD__
+                               );
+                       }
+                       $blockStart += $this->mBatchSize;
+                       $blockEnd += $this->mBatchSize;
+                       $this->output( "Process finished.\n" );
+               }
+       }
+}
+
+$maintClass = "PopulateContributorsTable";
+require_once RUN_MAINTENANCE_IF_MAIN;
\ No newline at end of file

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ib45acd2400ee5116c0a68ac7fe6556442097fe3f
Gerrit-PatchSet: 17
Gerrit-Project: mediawiki/extensions/Contributors
Gerrit-Branch: master
Gerrit-Owner: Devirk <devikrishna...@gmail.com>
Gerrit-Reviewer: 01tonythomas <01tonytho...@gmail.com>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipe...@gmail.com>
Gerrit-Reviewer: Niharika29 <nihar...@wikimedia.org>
Gerrit-Reviewer: Springle <sprin...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to