2010-10-27 20:08:04 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
2012-06-25 19:54:41 +00:00
|
|
|
* Remove cache entries for removed ResourceLoader modules from the database.
|
2010-10-27 20:08:04 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2010-11-06 12:03:39 +00:00
|
|
|
* @author Roan Kattouw
|
2010-10-27 20:08:04 +00:00
|
|
|
*/
|
|
|
|
|
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2010-10-27 20:08:04 +00:00
|
|
|
|
2012-06-25 19:54:41 +00:00
|
|
|
/**
|
|
|
|
|
* Maintenance script to remove cache entries for removed ResourceLoader modules
|
|
|
|
|
* from the database.
|
|
|
|
|
*
|
|
|
|
|
* @ingroup Maintenance
|
|
|
|
|
*/
|
2010-10-27 20:08:04 +00:00
|
|
|
class CleanupRemovedModules extends Maintenance {
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
$this->mDescription = 'Remove cache entries for removed ResourceLoader modules from the database';
|
|
|
|
|
$this->addOption( 'batchsize', 'Delete rows in batches of this size. Default: 500', false, true );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2015-12-31 00:07:37 +00:00
|
|
|
$dbw = $this->getDB( DB_MASTER );
|
2014-08-23 06:18:20 +00:00
|
|
|
$rl = new ResourceLoader( ConfigFactory::getDefaultInstance()->makeConfig( 'main' ) );
|
2011-01-12 19:03:59 +00:00
|
|
|
$moduleNames = $rl->getModuleNames();
|
2010-10-27 20:08:04 +00:00
|
|
|
$moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) );
|
|
|
|
|
$limit = max( 1, intval( $this->getOption( 'batchsize', 500 ) ) );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2010-10-27 20:08:04 +00:00
|
|
|
$this->output( "Cleaning up module_deps table...\n" );
|
|
|
|
|
$i = 1;
|
2011-01-12 02:16:56 +00:00
|
|
|
$modDeps = $dbw->tableName( 'module_deps' );
|
2010-10-27 20:08:04 +00:00
|
|
|
do {
|
|
|
|
|
// $dbw->delete() doesn't support LIMIT :(
|
|
|
|
|
$where = $moduleList ? "md_module NOT IN ($moduleList)" : '1=1';
|
2011-01-12 02:16:56 +00:00
|
|
|
$dbw->query( "DELETE FROM $modDeps WHERE $where LIMIT $limit", __METHOD__ );
|
2010-10-27 20:08:04 +00:00
|
|
|
$numRows = $dbw->affectedRows();
|
|
|
|
|
$this->output( "Batch $i: $numRows rows\n" );
|
|
|
|
|
$i++;
|
2015-03-03 17:45:30 +00:00
|
|
|
wfWaitForSlaves();
|
2013-04-18 18:48:44 +00:00
|
|
|
} while ( $numRows > 0 );
|
2010-10-27 20:08:04 +00:00
|
|
|
$this->output( "done\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$maintClass = "CleanupRemovedModules";
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|