MediaWiki REL1_34
purgeModuleDeps.php
Go to the documentation of this file.
1<?php
23
24require_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;
69require_once RUN_MAINTENANCE_IF_MAIN;
getDB()
const RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
getBatchSize()
Returns batch size.
addDescription( $text)
Set the description text.
setBatchSize( $s=0)
Set the batch size.
Maintenance script to purge the module_deps database cache table for ResourceLoader.
execute()
Do the actual work.
__construct()
Default constructor.
Basic database interface for live and lazy-loaded relation database handles.
Definition IDatabase.php:38
$maintClass
const DB_MASTER
Definition defines.php:26