X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/maintenance/purgeModuleDeps.php diff --git a/maintenance/purgeModuleDeps.php b/maintenance/purgeModuleDeps.php new file mode 100644 index 00000000..feeeb65b --- /dev/null +++ b/maintenance/purgeModuleDeps.php @@ -0,0 +1,72 @@ +addDescription( + 'Remove all cache entries for ResourceLoader modules from the database' ); + $this->setBatchSize( 500 ); + } + + public function execute() { + $this->output( "Cleaning up module_deps table...\n" ); + + $dbw = $this->getDB( DB_MASTER ); + $res = $dbw->select( 'module_deps', [ 'md_module', 'md_skin' ], [], __METHOD__ ); + $rows = iterator_to_array( $res, false ); + + $modDeps = $dbw->tableName( 'module_deps' ); + $i = 1; + foreach ( array_chunk( $rows, $this->mBatchSize ) as $chunk ) { + // WHERE ( mod=A AND skin=A ) OR ( mod=A AND skin=B) .. + $conds = array_map( function ( stdClass $row ) use ( $dbw ) { + return $dbw->makeList( (array)$row, IDatabase::LIST_AND ); + }, $chunk ); + $conds = $dbw->makeList( $conds, IDatabase::LIST_OR ); + + $this->beginTransaction( $dbw, __METHOD__ ); + $dbw->query( "DELETE FROM $modDeps WHERE $conds", __METHOD__ ); + $numRows = $dbw->affectedRows(); + $this->output( "Batch $i: $numRows rows\n" ); + $this->commitTransaction( $dbw, __METHOD__ ); + + $i++; + } + + $this->output( "Done\n" ); + } +} + +$maintClass = 'PurgeModuleDeps'; +require_once RUN_MAINTENANCE_IF_MAIN;