MediaWiki  master
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;
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
setBatchSize( $s=0)
Set the batch size.
const DB_MASTER
Definition: defines.php:26
Maintenance script to purge the module_deps database cache table for ResourceLoader.
const LIST_AND
Definition: Defines.php:39
addDescription( $text)
Set the description text.
$maintClass
output( $out, $channel=null)
Throw some output to the user.
const LIST_OR
Definition: Defines.php:42
getBatchSize()
Returns batch size.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.