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
|
|
|
*/
|
|
|
|
|
|
2017-02-10 18:09:05 +00:00
|
|
|
use Wikimedia\Rdbms\IDatabase;
|
2016-11-22 23:39:22 +00:00
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2013-05-17 00:16:59 +00:00
|
|
|
require_once __DIR__ . '/Maintenance.php';
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|
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();
|
2016-01-30 02:48:47 +00:00
|
|
|
$this->addDescription(
|
|
|
|
|
'Remove cache entries for removed ResourceLoader modules from the database' );
|
2017-02-24 22:56:31 +00:00
|
|
|
$this->setBatchSize( 500 );
|
2010-10-27 20:08:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
2017-02-24 22:56:31 +00:00
|
|
|
$this->output( "Cleaning up module_deps table...\n" );
|
|
|
|
|
|
2024-01-17 18:53:40 +00:00
|
|
|
$dbw = $this->getPrimaryDB();
|
2023-08-31 09:21:12 +00:00
|
|
|
$rl = $this->getServiceContainer()->getResourceLoader();
|
2011-01-12 19:03:59 +00:00
|
|
|
$moduleNames = $rl->getModuleNames();
|
2022-07-11 13:51:08 +00:00
|
|
|
$res = $dbw->newSelectQueryBuilder()
|
|
|
|
|
->select( [ 'md_module', 'md_skin' ] )
|
|
|
|
|
->from( 'module_deps' )
|
2024-07-07 20:44:22 +00:00
|
|
|
->where( $moduleNames ? $dbw->expr( 'md_module', '!=', $moduleNames ) : [] )
|
2022-07-11 13:51:08 +00:00
|
|
|
->caller( __METHOD__ )
|
|
|
|
|
->fetchResultSet();
|
2017-02-24 22:56:31 +00:00
|
|
|
$rows = iterator_to_array( $res, false );
|
2010-12-04 03:20:14 +00:00
|
|
|
|
2011-01-12 02:16:56 +00:00
|
|
|
$modDeps = $dbw->tableName( 'module_deps' );
|
2017-02-24 22:56:31 +00:00
|
|
|
$i = 1;
|
2017-11-05 08:09:51 +00:00
|
|
|
foreach ( array_chunk( $rows, $this->getBatchSize() ) as $chunk ) {
|
2017-02-24 22:56:31 +00:00
|
|
|
// WHERE ( mod=A AND skin=A ) OR ( mod=A AND skin=B) ..
|
2021-02-07 02:17:10 +00:00
|
|
|
$conds = array_map( static function ( stdClass $row ) use ( $dbw ) {
|
2017-02-24 22:56:31 +00:00
|
|
|
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__ );
|
2010-10-27 20:08:04 +00:00
|
|
|
$numRows = $dbw->affectedRows();
|
|
|
|
|
$this->output( "Batch $i: $numRows rows\n" );
|
2017-02-24 22:56:31 +00:00
|
|
|
$this->commitTransaction( $dbw, __METHOD__ );
|
|
|
|
|
|
2010-10-27 20:08:04 +00:00
|
|
|
$i++;
|
2017-02-24 22:56:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->output( "Done\n" );
|
2010-10-27 20:08:04 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreStart
|
2018-01-13 00:02:09 +00:00
|
|
|
$maintClass = CleanupRemovedModules::class;
|
2013-05-07 23:00:15 +00:00
|
|
|
require_once RUN_MAINTENANCE_IF_MAIN;
|
2024-08-27 12:00:25 +00:00
|
|
|
// @codeCoverageIgnoreEnd
|