MediaWiki
REL1_19
|
00001 <?php 00026 require_once( dirname( __FILE__ ) . '/Maintenance.php' ); 00027 00028 class CleanupRemovedModules extends Maintenance { 00029 00030 public function __construct() { 00031 parent::__construct(); 00032 $this->mDescription = 'Remove cache entries for removed ResourceLoader modules from the database'; 00033 $this->addOption( 'batchsize', 'Delete rows in batches of this size. Default: 500', false, true ); 00034 $this->addOption( 'max-slave-lag', 'If the slave lag exceeds this many seconds, wait until it drops below this value. Default: 5', false, true ); 00035 } 00036 00037 public function execute() { 00038 $dbw = wfGetDB( DB_MASTER ); 00039 $rl = new ResourceLoader(); 00040 $moduleNames = $rl->getModuleNames(); 00041 $moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) ); 00042 $limit = max( 1, intval( $this->getOption( 'batchsize', 500 ) ) ); 00043 $maxlag = intval( $this->getOption( 'max-slave-lag', 5 ) ); 00044 00045 $this->output( "Cleaning up module_deps table...\n" ); 00046 $i = 1; 00047 $modDeps = $dbw->tableName( 'module_deps' ); 00048 do { 00049 // $dbw->delete() doesn't support LIMIT :( 00050 $where = $moduleList ? "md_module NOT IN ($moduleList)" : '1=1'; 00051 $dbw->query( "DELETE FROM $modDeps WHERE $where LIMIT $limit", __METHOD__ ); 00052 $numRows = $dbw->affectedRows(); 00053 $this->output( "Batch $i: $numRows rows\n" ); 00054 $i++; 00055 wfWaitForSlaves( $maxlag ); 00056 } while( $numRows > 0 ); 00057 $this->output( "done\n" ); 00058 00059 $this->output( "Cleaning up msg_resource table...\n" ); 00060 $i = 1; 00061 00062 $mrRes = $dbw->tableName( 'msg_resource' ); 00063 do { 00064 $where = $moduleList ? "mr_resource NOT IN ($moduleList)" : '1=1'; 00065 $dbw->query( "DELETE FROM $mrRes WHERE $where LIMIT $limit", __METHOD__ ); 00066 $numRows = $dbw->affectedRows(); 00067 $this->output( "Batch $i: $numRows rows\n" ); 00068 $i++; 00069 wfWaitForSlaves( $maxlag ); 00070 } while( $numRows > 0 ); 00071 $this->output( "done\n" ); 00072 00073 $this->output( "Cleaning up msg_resource_links table...\n" ); 00074 $i = 1; 00075 $msgResLinks = $dbw->tableName( 'msg_resource_links' ); 00076 do { 00077 $where = $moduleList ? "mrl_resource NOT IN ($moduleList)" : '1=1'; 00078 $dbw->query( "DELETE FROM $msgResLinks WHERE $where LIMIT $limit", __METHOD__ ); 00079 $numRows = $dbw->affectedRows(); 00080 $this->output( "Batch $i: $numRows rows\n" ); 00081 $i++; 00082 wfWaitForSlaves( $maxlag ); 00083 } while( $numRows > 0 ); 00084 $this->output( "done\n" ); 00085 } 00086 } 00087 00088 $maintClass = "CleanupRemovedModules"; 00089 require_once( RUN_MAINTENANCE_IF_MAIN );