4 * Rebuild the localisation cache. Useful if you disabled automatic updates
5 * using $wgLocalisationCacheConf['manualRecache'] = true;
8 * php rebuildLocalisationCache.php [--force] [--threads=N]
10 * Use --force to rebuild all files, even the ones that are not out of date.
11 * Use --threads=N to fork more threads.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26 * http://www.gnu.org/copyleft/gpl.html
28 * @ingroup Maintenance
31 require_once( dirname(__FILE__
) . '/Maintenance.php' );
33 class RebuildLocalisationCache
extends Maintenance
{
34 public function __construct() {
35 parent
::__construct();
36 $this->mDescription
= "Rebuild the localisation cache";
37 $this->addOption( 'force', 'Rebuild all files, even ones not out of date' );
38 $this->addOption( 'threads', 'Fork more than one thread', false, true );
41 public function execute() {
42 global $wgLocalisationCacheConf;
44 ini_set( 'memory_limit', '200M' );
46 $force = $this->hasOption('force');
47 $threads = $this->getOption( 'threads', 1 );
49 $conf = $wgLocalisationCacheConf;
50 $conf['manualRecache'] = false; // Allow fallbacks to create CDB files
52 $conf['forceRecache'] = true;
54 $lc = new LocalisationCache_BulkLoad( $conf );
56 $codes = array_keys( Language
::getLanguageNames( true ) );
59 // Initialise and split into chunks
61 $total = count($codes);
62 $chunks = array_chunk( $codes, ceil(count($codes)/$threads) );
64 foreach ( $chunks as $codes ) {
65 // Do not fork for only one thread
66 $pid = ( $threads > 1 ) ?
pcntl_fork() : -1;
69 // Child, reseed because there is no bug in PHP:
70 // http://bugs.php.net/bug.php?id=42465
72 $numRebuilt = $this->doRebuild( $codes, $lc, $force );
73 // Abuse the exit value for the count of rebuild languages
75 } elseif ($pid === -1) {
76 // Fork failed or one thread, do it serialized
77 $numRebuilt +
= $this->doRebuild( $codes, $lc, $force );
83 // Wait for all children
84 foreach ( $pids as $pid ) {
86 pcntl_waitpid($pid, $status);
87 // Fetch the count from the return value
88 $numRebuilt +
= pcntl_wexitstatus($status);
91 $this->output( "$numRebuilt languages rebuilt out of $total\n" );
92 if ( $numRebuilt === 0 ) {
93 $this->output( "Use --force to rebuild the caches which are still fresh.\n" );
98 * Helper function to rebuild list of languages codes. Prints the code
99 * for each language which is rebuilt.
100 * @param $codes list List of language codes to rebuild.
101 * @param $lc object Instance of LocalisationCache_BulkLoad (?)
102 * @param $force bool Rebuild up-to-date languages
103 * @return int Number of rebuilt languages
105 private function doRebuild( $codes, $lc, $force ) {
107 foreach ( $codes as $code ) {
108 if ( $force ||
$lc->isExpired( $code ) ) {
109 $this->output( "Rebuilding $code...\n" );
110 $lc->recache( $code );
118 $maintClass = "RebuildLocalisationCache";
119 require_once( DO_MAINTENANCE
);