r75575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r75574‎ | r75575 | r75576 >
Date:20:08, 27 October 2010
Author:catrope
Status:resolved (Comments)
Tags:
Comment:
Re-add maintenance script from r75555, not totally broken this time
Modified paths:
  • /trunk/phase3/maintenance/cleanupRemovedModules.php (added) (history)

Diff [purge]

Index: trunk/phase3/maintenance/cleanupRemovedModules.php
@@ -0,0 +1,84 @@
 2+<?php
 3+/**
 4+ * Maintenance script to create an account and grant it administrator rights
 5+ *
 6+ * This program is free software; you can redistribute it and/or modify
 7+ * it under the terms of the GNU General Public License as published by
 8+ * the Free Software Foundation; either version 2 of the License, or
 9+ * (at your option) any later version.
 10+ *
 11+ * This program is distributed in the hope that it will be useful,
 12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
 13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 14+ * GNU General Public License for more details.
 15+ *
 16+ * You should have received a copy of the GNU General Public License along
 17+ * with this program; if not, write to the Free Software Foundation, Inc.,
 18+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 19+ * http://www.gnu.org/copyleft/gpl.html
 20+ *
 21+ * @file
 22+ * @ingroup Maintenance
 23+ * @author Rob Church <robchur@gmail.com>
 24+ */
 25+
 26+require_once( dirname( __FILE__ ) . '/Maintenance.php' );
 27+
 28+class CleanupRemovedModules extends Maintenance {
 29+
 30+ public function __construct() {
 31+ parent::__construct();
 32+ $this->mDescription = 'Remove cache entries for removed ResourceLoader modules from the database';
 33+ $this->addOption( 'batchsize', 'Delete rows in batches of this size. Default: 500', false, true );
 34+ $this->addOption( 'max-slave-lag', 'If the slave lag exceeds this many seconds, wait until it drops below this value. Default: 5', false, true );
 35+ }
 36+
 37+ public function execute() {
 38+ $dbw = wfGetDB( DB_MASTER );
 39+ $rl = new ResourceLoader();
 40+ $moduleNames = array_keys( $rl->getModules() );
 41+ $moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) );
 42+ $limit = max( 1, intval( $this->getOption( 'batchsize', 500 ) ) );
 43+ $maxlag = intval( $this->getOption( 'max-slave-lag', 5 ) );
 44+
 45+ $this->output( "Cleaning up module_deps table...\n" );
 46+ $i = 1;
 47+ do {
 48+ // $dbw->delete() doesn't support LIMIT :(
 49+ $where = $moduleList ? "md_module NOT IN ($moduleList)" : '1=1';
 50+ $dbw->query( "DELETE FROM module_deps WHERE $where LIMIT $limit", __METHOD__ );
 51+ $numRows = $dbw->affectedRows();
 52+ $this->output( "Batch $i: $numRows rows\n" );
 53+ $i++;
 54+ wfWaitForSlaves( $maxlag );
 55+ } while( $numRows > 0 );
 56+ $this->output( "done\n" );
 57+
 58+ $this->output( "Cleaning up msg_resource table...\n" );
 59+ $i = 1;
 60+ do {
 61+ $where = $moduleList ? "mr_resource NOT IN ($moduleList)" : '1=1';
 62+ $dbw->query( "DELETE FROM msg_resource WHERE $where LIMIT $limit", __METHOD__ );
 63+ $numRows = $dbw->affectedRows();
 64+ $this->output( "Batch $i: $numRows rows\n" );
 65+ $i++;
 66+ wfWaitForSlaves( $maxlag );
 67+ } while( $numRows > 0 );
 68+ $this->output( "done\n" );
 69+
 70+ $this->output( "Cleaning up msg_resource_links table...\n" );
 71+ $i = 1;
 72+ do {
 73+ $where = $moduleList ? "mrl_resource NOT IN ($moduleList)" : '1=1';
 74+ $dbw->query( "DELETE FROM msg_resource_links WHERE $where LIMIT $limit", __METHOD__ );
 75+ $numRows = $dbw->affectedRows();
 76+ $this->output( "Batch $i: $numRows rows\n" );
 77+ $i++;
 78+ wfWaitForSlaves( $maxlag );
 79+ } while( $numRows > 0 );
 80+ $this->output( "done\n" );
 81+ }
 82+}
 83+
 84+$maintClass = "CleanupRemovedModules";
 85+require_once( DO_MAINTENANCE );
\ No newline at end of file
Property changes on: trunk/phase3/maintenance/cleanupRemovedModules.php
___________________________________________________________________
Added: svn:eol-style
186 + native

Follow-up revisions

RevisionCommit summaryAuthorDate
r80074Followup r75575...reedy02:12, 12 January 2011
r80075Follwup r75575, honour table prefixes. Bad Roan ;)reedy02:16, 12 January 2011
r80104Per CR on r75575, remove array_keys() as getModuleNames has array_key'd the r...reedy19:03, 12 January 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r75555Whitespace fixes for r75486catrope15:51, 27 October 2010

Comments

#Comment by Reedy (talk | contribs)   01:05, 7 January 2011
+ * Maintenance script to create an account and grant it administrator rights

Orly?

#Comment by Catrope (talk | contribs)   15:45, 8 January 2011

Already fixed in r76682.

#Comment by Reedy (talk | contribs)   02:14, 12 January 2011
reedy@ubuntu64-esxi:~/mediawiki/trunk/phase3/maintenance$ php cleanupRemovedModules.php 
Fatal error: Call to undefined method ResourceLoader::getModules() in /home/reedy/mediawiki/trunk/phase3/maintenance/cleanupRemovedModules.php on line 40

Fixed in r80074

reedy@ubuntu64-esxi:~/mediawiki/trunk/phase3/maintenance$ php cleanupRemovedModules.php 
Cleaning up module_deps table...
A database error has occurred.  Did you forget to run maintenance/update.php after upgrading?  See: [http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script http://www.mediawiki.org/wiki/Manual:Upgrading#Run_the_update_script]
Query: DELETE FROM module_deps WHERE md_module NOT IN ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '90') LIMIT 500
Function: CleanupRemovedModules::execute
Error: 1146 Table 'wikidb.module_deps' doesn't exist (localhost)

Not following table prefixes

#Comment by Catrope (talk | contribs)   18:53, 12 January 2011

The fact that it uses ('0', '1', '2', ... ) sounds like a keys-instead-of-values bug. Does this still happen on HEAD?

#Comment by Catrope (talk | contribs)   21:51, 12 January 2011

Fixed in r80104.

#Comment by Reedy (talk | contribs)   02:27, 12 January 2011

Marking resolved. Think all is well

Would be nice to use $dbw->delete(), but that doesn't do options :(

Status & tagging log