MediaWiki  1.23.8
cleanupRemovedModules.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
34 
35  public function __construct() {
36  parent::__construct();
37  $this->mDescription = 'Remove cache entries for removed ResourceLoader modules from the database';
38  $this->addOption( 'batchsize', 'Delete rows in batches of this size. Default: 500', false, true );
39  $this->addOption( 'max-slave-lag', 'If the slave lag exceeds this many seconds, wait until it drops below this value. Default: 5', false, true );
40  }
41 
42  public function execute() {
43  $dbw = wfGetDB( DB_MASTER );
44  $rl = new ResourceLoader();
45  $moduleNames = $rl->getModuleNames();
46  $moduleList = implode( ', ', array_map( array( $dbw, 'addQuotes' ), $moduleNames ) );
47  $limit = max( 1, intval( $this->getOption( 'batchsize', 500 ) ) );
48  $maxlag = intval( $this->getOption( 'max-slave-lag', 5 ) );
49 
50  $this->output( "Cleaning up module_deps table...\n" );
51  $i = 1;
52  $modDeps = $dbw->tableName( 'module_deps' );
53  do {
54  // $dbw->delete() doesn't support LIMIT :(
55  $where = $moduleList ? "md_module NOT IN ($moduleList)" : '1=1';
56  $dbw->query( "DELETE FROM $modDeps WHERE $where LIMIT $limit", __METHOD__ );
57  $numRows = $dbw->affectedRows();
58  $this->output( "Batch $i: $numRows rows\n" );
59  $i++;
60  wfWaitForSlaves( $maxlag );
61  } while ( $numRows > 0 );
62  $this->output( "done\n" );
63 
64  $this->output( "Cleaning up msg_resource table...\n" );
65  $i = 1;
66 
67  $mrRes = $dbw->tableName( 'msg_resource' );
68  do {
69  $where = $moduleList ? "mr_resource NOT IN ($moduleList)" : '1=1';
70  $dbw->query( "DELETE FROM $mrRes WHERE $where LIMIT $limit", __METHOD__ );
71  $numRows = $dbw->affectedRows();
72  $this->output( "Batch $i: $numRows rows\n" );
73  $i++;
74  wfWaitForSlaves( $maxlag );
75  } while ( $numRows > 0 );
76  $this->output( "done\n" );
77 
78  $this->output( "Cleaning up msg_resource_links table...\n" );
79  $i = 1;
80  $msgResLinks = $dbw->tableName( 'msg_resource_links' );
81  do {
82  $where = $moduleList ? "mrl_resource NOT IN ($moduleList)" : '1=1';
83  $dbw->query( "DELETE FROM $msgResLinks WHERE $where LIMIT $limit", __METHOD__ );
84  $numRows = $dbw->affectedRows();
85  $this->output( "Batch $i: $numRows rows\n" );
86  $i++;
87  wfWaitForSlaves( $maxlag );
88  } while ( $numRows > 0 );
89  $this->output( "done\n" );
90  }
91 }
92 
93 $maintClass = "CleanupRemovedModules";
94 require_once RUN_MAINTENANCE_IF_MAIN;
DB_MASTER
const DB_MASTER
Definition: Defines.php:56
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
wfGetDB
& wfGetDB( $db, $groups=array(), $wiki=false)
Get a Database object.
Definition: GlobalFunctions.php:3659
Maintenance\addOption
addOption( $name, $description, $required=false, $withArg=false, $shortName=false)
Add a parameter to the script.
Definition: Maintenance.php:169
RUN_MAINTENANCE_IF_MAIN
require_once RUN_MAINTENANCE_IF_MAIN
Definition: maintenance.txt:50
$limit
if( $sleep) $limit
Definition: importImages.php:99
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: maintenance.txt:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
wfWaitForSlaves
wfWaitForSlaves( $maxLag=false, $wiki=false, $cluster=false)
Modern version of wfWaitForSlaves().
Definition: GlobalFunctions.php:3804
$maintClass
$maintClass
Definition: cleanupRemovedModules.php:93
ResourceLoader
Dynamic JavaScript and CSS resource loading system.
Definition: ResourceLoader.php:31
Maintenance\getOption
getOption( $name, $default=null)
Get an option, or return the default.
Definition: Maintenance.php:191
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:314
CleanupRemovedModules\execute
execute()
Do the actual work.
Definition: cleanupRemovedModules.php:42
CleanupRemovedModules\__construct
__construct()
Default constructor.
Definition: cleanupRemovedModules.php:35
CleanupRemovedModules
Maintenance script to remove cache entries for removed ResourceLoader modules from the database.
Definition: cleanupRemovedModules.php:33