CSteipp has uploaded a new change for review.

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

Change subject: Add maintenance script to copy db tables
......................................................................

Add maintenance script to copy db tables

When migrating the central oauth wiki, this maintenance script can be
run repeatedly to ensure all of the data has been copied over.

Bug: 57336
Change-Id: Iebe9ce13f0df68081dbf8de34c975f5f0ac3a608
---
A maintenance/migrateCentralWiki.php
1 file changed, 78 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth 
refs/changes/31/121131/1

diff --git a/maintenance/migrateCentralWiki.php 
b/maintenance/migrateCentralWiki.php
new file mode 100644
index 0000000..05c1328
--- /dev/null
+++ b/maintenance/migrateCentralWiki.php
@@ -0,0 +1,78 @@
+<?php
+/**
+ * @ingroup Maintenance
+ */
+if ( getenv( 'MW_INSTALL_PATH' ) ) {
+       $IP = getenv( 'MW_INSTALL_PATH' );
+} else {
+       $IP = dirname(__FILE__).'/../../..';
+}
+
+require( __DIR__ . '/../lib/OAuth.php' );
+require_once( "$IP/maintenance/Maintenance.php" );
+
+class MigrateCentralWiki extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->mDescription = "Migrate central wiki from one wiki to 
another";
+               $this->addOption( 'old', 'Previous central wiki', true, true );
+               $this->addOption( 'target', 'New central wiki', true, true );
+               $this->addOption( 'table', 'Table name 
(oauth_registered_consumer or oauth_accepted_consumer)', true, true );
+       }
+
+       public function execute() {
+
+               $oldWiki = $this->getOption( 'old' );
+               $targetWiki = $this->getOption( 'target' );
+               $table = $this->getOption( 'table' );
+
+               if ( $table === 'oauth_registered_consumer' ) {
+                       $idKey = 'oarc_id';
+                       $cmrClass = 'MWOAuthConsumer';
+               } elseif ( $table === 'oauth_accepted_consumer' ) {
+                       $idKey = 'oaac_id';
+                       $cmrClass = 'MWOAuthConsumerAcceptance';
+               } else {
+                       $this->output( "Invalid table name. Must be one of 
'oauth_registered_consumer' or 'oauth_accepted_consumer'.\n" );
+                       return;
+               }
+
+               $oldDb = wfGetLB( $oldWiki )->getConnectionRef( DB_SLAVE, 
array(), $oldWiki );
+               $targetDb = wfGetLB( $targetWiki )->getConnectionRef( 
DB_MASTER, array(), $targetWiki );
+
+               $newMax = $targetDb->selectField(
+                       $table,
+                       "MAX($idKey)",
+                       array(),
+                       __METHOD__
+               );
+
+               $oldMax = $oldDb->selectField(
+                       $table,
+                       "MAX($idKey)",
+                       array(),
+                       __METHOD__
+               );
+
+               if ( $newMax >= $oldMax ) {
+                       $this->output( "Nothing to do.\n" );
+                       return;
+               }
+
+               for ( $currentId = $newMax + 1; $currentId <= $oldMax; 
++$currentId ) {
+                       $this->output( "Migrating grant $currentId..." );
+                       $cmr = $cmrClass::newFromId( $oldDb, $currentId );
+                       if ( $cmr ) {
+                               $cmrNew = $cmr->copy( $oldDb );
+                               $cmrNew->save( $targetDb );
+                               $this->output( "done.\n" );
+                       } else {
+                               $this->output( "missing.\n" );
+                       }
+               }
+       }
+
+}
+
+$maintClass = "MigrateCentralWiki";
+require_once( RUN_MAINTENANCE_IF_MAIN );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Iebe9ce13f0df68081dbf8de34c975f5f0ac3a608
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: CSteipp <[email protected]>

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

Reply via email to