Reedy has uploaded a new change for review.

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


Change subject: Remove deleted wikis entries from CentralAuth tables
......................................................................

Remove deleted wikis entries from CentralAuth tables

Bug: 49858
Change-Id: I594cb4f06507081df9b0e5c532847d7f398103e3
---
A removeDeletedWikis.php
D removeDeletedWikisFromGlobalUsage.php
2 files changed, 87 insertions(+), 72 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikimediaMaintenance 
refs/changes/84/89484/1

diff --git a/removeDeletedWikis.php b/removeDeletedWikis.php
new file mode 100644
index 0000000..77676ff
--- /dev/null
+++ b/removeDeletedWikis.php
@@ -0,0 +1,87 @@
+<?php
+
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Maintenance
+ * @ingroup Wikimedia
+ */
+
+require_once( __DIR__ . '/WikimediaMaintenance.php' );
+
+class RemoveDeletedWikis extends WikimediaMaintenance {
+       function __construct() {
+               parent::__construct();
+               $this->mDescription = "Remove any remaining entries in 
globalimagelinks, localuser and localnames for deleted wikis.\n"
+                       . "This is probably best run against Commons due to 
globalusage tables";
+       }
+
+       function execute() {
+               $wikis = file( '/a/common/deleted.dblist' );
+               if ( $wikis === false ) {
+                       $this->error( 'Unable to open deleted.dblist', 1 );
+               }
+
+               $dbw = $this->getDB( DB_MASTER );
+               $cadbw = CentralAuthUser::getCentralDB();
+               foreach ( $wikis as $wiki ) {
+                       $wiki = rtrim( $wiki );
+                       $this->output( "$wiki:\n" );
+
+                       $this->doDeletes( $dbw, 'globalimagelinks', 'gil_wiki', 
$wiki );
+                       $this->doDeletes( $cadbw, 'localnames', 'ln_wiki', 
$wiki );
+                       $this->doDeletes( $cadbw, 'localuser', 'lu_wiki', $wiki 
);
+                       // @todo: Delete from wikisets
+               }
+               $this->output( "Done.\n" );
+       }
+
+       /**
+        * @param DatabaseBase $dbw
+        * @param string $table
+        * @param string $column
+        * @param string $wiki
+        */
+       function doDeletes( $dbw, $table, $column, $wiki ) {
+               if ( !$dbw->tableExists( $table ) ) {
+                       $this->error( "Maintenance script cannot be run on this 
wiki as there is no $table table", 1 );
+               }
+               $count = 0;
+               do {
+                       // https://bugzilla.wikimedia.org/show_bug.cgi?id=52868
+                       //$dbw->delete(
+                       //      $table,
+                       //      array( $column => $wiki ),
+                       //      __METHOD__,
+                       //      array( 'LIMIT' => 500 ),
+                       //);
+                       $wikiQuoted = $dbw->addQuotes( $wiki );
+                       $dbw->query(
+                               "DELETE FROM $table WHERE $column=$wikiQuoted 
LIMIT 500",
+                               __METHOD__
+                       );
+                       $affected = $dbw->affectedRows();
+                       $count += $affected;
+                       $this->output( "$count\n" );
+                       wfWaitForSlaves();
+               } while ( $affected === 500 );
+               $this->output( "$count $table rows deleted\n" );
+       }
+}
+
+$maintClass = 'RemoveDeletedWikis';
+require_once( DO_MAINTENANCE );
diff --git a/removeDeletedWikisFromGlobalUsage.php 
b/removeDeletedWikisFromGlobalUsage.php
deleted file mode 100644
index 39ccdce..0000000
--- a/removeDeletedWikisFromGlobalUsage.php
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-
-/**
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- * http://www.gnu.org/copyleft/gpl.html
- *
- * @file
- * @ingroup Maintenance
- * @ingroup Wikimedia
- */
-
-require_once( __DIR__ . '/WikimediaMaintenance.php' );
-
-class RemoveDeletedWikisFromGlobalUsage extends WikimediaMaintenance {
-       function __construct() {
-               parent::__construct();
-               $this->mDescription = 'Remove any remaining entries in 
globalimagelinks for deleted wikis';
-       }
-
-       function execute() {
-               $wikis = file( '/a/common/deleted.dblist' );
-               if ( $wikis === false ) {
-                       $this->error( 'Unable to open deleted.dblist', 1 );
-               }
-               $dbw = $this->getDB( DB_MASTER );
-               if ( !$dbw->tableExists( 'globalimagelinks' ) ) {
-                       $this->error( 'Maintenance script cannot be run on this 
wiki as there is no globalimagelinkstable', 1 );
-               }
-               foreach ( $wikis as $wiki ) {
-                       $count = 0;
-                       $wiki = rtrim( $wiki );
-                       $this->output( "$wiki:\n" );
-
-                       do {
-                               // 
https://bugzilla.wikimedia.org/show_bug.cgi?id=52868
-                               //$dbw->delete(
-                               //      'globalimagelinks',
-                               //      array( 'gil_wiki' => $wiki ),
-                               //      __METHOD__,
-                               //      array( 'LIMIT' => 500 ),
-                               //);
-                               $wikiQuoted = $dbw->addQuotes( $wiki );
-                               $dbw->query(
-                                       "DELETE FROM globalimagelinks WHERE 
gil_wiki=$wikiQuoted LIMIT 500",
-                                       __METHOD__
-                               );
-                               $affected = $dbw->affectedRows();
-                               $count += $affected;
-                               $this->output( "$count\n" );
-                               wfWaitForSlaves();
-                       } while ( $affected === 500 );
-
-                       $this->output( "$wiki: $count globalimagelinks rows 
deleted\n" );
-               }
-               $this->output( "Done.\n" );
-       }
-}
-
-$maintClass = 'RemoveDeletedWikisFromGlobalUsage';
-require_once( DO_MAINTENANCE );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I594cb4f06507081df9b0e5c532847d7f398103e3
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikimediaMaintenance
Gerrit-Branch: master
Gerrit-Owner: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to