MediaWiki  1.34.0
purgeModuleDeps.php
Go to the documentation of this file.
1 <?php
23 
24 require_once __DIR__ . '/Maintenance.php';
25 
32  public function __construct() {
33  parent::__construct();
34  $this->addDescription(
35  'Remove all cache entries for ResourceLoader modules from the database' );
36  $this->setBatchSize( 500 );
37  }
38 
39  public function execute() {
40  $this->output( "Cleaning up module_deps table...\n" );
41 
42  $dbw = $this->getDB( DB_MASTER );
43  $res = $dbw->select( 'module_deps', [ 'md_module', 'md_skin' ], [], __METHOD__ );
44  $rows = iterator_to_array( $res, false );
45 
46  $modDeps = $dbw->tableName( 'module_deps' );
47  $i = 1;
48  foreach ( array_chunk( $rows, $this->getBatchSize() ) as $chunk ) {
49  // WHERE ( mod=A AND skin=A ) OR ( mod=A AND skin=B) ..
50  $conds = array_map( function ( stdClass $row ) use ( $dbw ) {
51  return $dbw->makeList( (array)$row, IDatabase::LIST_AND );
52  }, $chunk );
53  $conds = $dbw->makeList( $conds, IDatabase::LIST_OR );
54 
55  $this->beginTransaction( $dbw, __METHOD__ );
56  $dbw->query( "DELETE FROM $modDeps WHERE $conds", __METHOD__ );
57  $numRows = $dbw->affectedRows();
58  $this->output( "Batch $i: $numRows rows\n" );
59  $this->commitTransaction( $dbw, __METHOD__ );
60 
61  $i++;
62  }
63 
64  $this->output( "Done\n" );
65  }
66 }
67 
68 $maintClass = PurgeModuleDeps::class;
69 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
PurgeModuleDeps\execute
execute()
Do the actual work.
Definition: purgeModuleDeps.php:39
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
$res
$res
Definition: testCompression.php:52
$maintClass
$maintClass
Definition: purgeModuleDeps.php:68
LIST_AND
const LIST_AND
Definition: Defines.php:39
Wikimedia\Rdbms\IDatabase
Basic database interface for live and lazy-loaded relation database handles.
Definition: IDatabase.php:38
Maintenance\beginTransaction
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
Definition: Maintenance.php:1426
LIST_OR
const LIST_OR
Definition: Defines.php:42
PurgeModuleDeps
Maintenance script to purge the module_deps database cache table for ResourceLoader.
Definition: purgeModuleDeps.php:31
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\commitTransaction
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
Definition: Maintenance.php:1441
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
PurgeModuleDeps\__construct
__construct()
Default constructor.
Definition: purgeModuleDeps.php:32
Maintenance\getBatchSize
getBatchSize()
Returns batch size.
Definition: Maintenance.php:386
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
Maintenance\setBatchSize
setBatchSize( $s=0)
Set the batch size.
Definition: Maintenance.php:394