r59732 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59731‎ | r59732 | r59733 >
Date:14:57, 4 December 2009
Author:demon
Status:ok
Tags:
Comment:
Change deleteSelfExternals to use Maintenance.php
Modified paths:
  • /trunk/phase3/maintenance/deleteSelfExternals.php (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/deleteSelfExternals.php
@@ -1,15 +1,54 @@
22 <?php
 3+/**
 4+ * We want to make this whole thing as seamless as possible to the
 5+ * end-user. Unfortunately, we can't do _all_ of the work in the class
 6+ * because A) included files are not in global scope, but in the scope
 7+ * of their caller, and B) MediaWiki has way too many globals. So instead
 8+ * we'll kinda fake it, and do the requires() inline. <3 PHP
 9+ *
 10+ * This program is free software; you can redistribute it and/or modify
 11+ * it under the terms of the GNU General Public License as published by
 12+ * the Free Software Foundation; either version 2 of the License, or
 13+ * (at your option) any later version.
 14+ *
 15+ * This program is distributed in the hope that it will be useful,
 16+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 17+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 18+ * GNU General Public License for more details.
 19+ *
 20+ * You should have received a copy of the GNU General Public License along
 21+ * with this program; if not, write to the Free Software Foundation, Inc.,
 22+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 23+ * http://www.gnu.org/copyleft/gpl.html
 24+ *
 25+ * @ingroup Maintenance
 26+ */
327
4 -require_once("commandLine.inc");
 28+require_once( "Maintenance.php" );
529
6 -print "Deleting self externals from $wgServer\n";
7 -$db = wfGetDB(DB_MASTER);
8 -while (1) {
9 - wfWaitForSlaves( 2 );
10 - $db->commit();
11 - $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE el_to"
12 - . $db->buildLike( $wgServer . '/', $db->anyString() ), 1000 );
13 - print "Deleting a batch\n";
14 - $db->query($q);
15 - if (!$db->affectedRows()) exit(0);
 30+
 31+class DeleteSelfExternals extends Maintenance {
 32+ public function __construct() {
 33+ parent::__construct();
 34+ $this->mDescription = 'Delete self-references to $wgServer from externallinks';
 35+ $this->mBatchSize = 1000;
 36+ }
 37+
 38+ public function execute() {
 39+ global $wgServer;
 40+ $this->output( "Deleting self externals from $wgServer\n" );
 41+ $db = wfGetDB(DB_MASTER);
 42+ while (1) {
 43+ wfWaitForSlaves( 2 );
 44+ $db->commit();
 45+ $q = $db->limitResult( "DELETE /* deleteSelfExternals */ FROM externallinks WHERE el_to"
 46+ . $db->buildLike( $wgServer . '/', $db->anyString() ), $this->mBatchSize );
 47+ $this->output( "Deleting a batch\n" );
 48+ $db->query($q);
 49+ if (!$db->affectedRows()) exit(0);
 50+ }
 51+ }
1652 }
 53+
 54+$maintClass = "DeleteSelfExternals";
 55+require_once( DO_MAINTENANCE );

Status & tagging log