X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FrebuildLocalisationCache.php;h=f89877eabbc0174cfd317b81f50c333fcf9ee028;hb=11ee7f78da9776db26098642a151a288f98bea14;hp=b04639c0e1337c51ad1f791628d5fca29a46fa7e;hpb=13e33c28983461d5b8bdc1dece0cd0a35347a261;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/rebuildLocalisationCache.php b/maintenance/rebuildLocalisationCache.php index b04639c0e1..4213d5f85d 100644 --- a/maintenance/rebuildLocalisationCache.php +++ b/maintenance/rebuildLocalisationCache.php @@ -39,7 +39,7 @@ require_once __DIR__ . '/Maintenance.php'; class RebuildLocalisationCache extends Maintenance { public function __construct() { parent::__construct(); - $this->mDescription = "Rebuild the localisation cache"; + $this->addDescription( 'Rebuild the localisation cache' ); $this->addOption( 'force', 'Rebuild all files, even ones not out of date' ); $this->addOption( 'threads', 'Fork more than one thread', false, true ); $this->addOption( 'outdir', 'Override the output directory (normally $wgCacheDirectory)', @@ -48,14 +48,6 @@ class RebuildLocalisationCache extends Maintenance { false, true ); } - public function memoryLimit() { - if ( $this->hasOption( 'memory-limit' ) ) { - return parent::memoryLimit(); - } - - return '1000M'; - } - public function finalSetup() { # This script needs to be run to build the inital l10n cache. But if # $wgLanguageCode is not 'en', it won't be able to run because there is @@ -100,7 +92,7 @@ class RebuildLocalisationCache extends Maintenance { explode( ',', $this->getOption( 'lang' ) ) ); # Bailed out if nothing is left if ( count( $codes ) == 0 ) { - $this->error( 'None of the languages specified exists.', 1 ); + $this->fatalError( 'None of the languages specified exists.' ); } } else { # By default get all languages @@ -112,18 +104,19 @@ class RebuildLocalisationCache extends Maintenance { $numRebuilt = 0; $total = count( $codes ); $chunks = array_chunk( $codes, ceil( count( $codes ) / $threads ) ); - $pids = array(); + $pids = []; + $parentStatus = 0; foreach ( $chunks as $codes ) { // Do not fork for only one thread $pid = ( $threads > 1 ) ? pcntl_fork() : -1; if ( $pid === 0 ) { // Child, reseed because there is no bug in PHP: - // http://bugs.php.net/bug.php?id=42465 + // https://bugs.php.net/bug.php?id=42465 mt_srand( getmypid() ); - $numRebuilt = $this->doRebuild( $codes, $lc, $force ); - // Abuse the exit value for the count of rebuild languages - exit( $numRebuilt ); + + $this->doRebuild( $codes, $lc, $force ); + exit( 0 ); } elseif ( $pid === -1 ) { // Fork failed or one thread, do it serialized $numRebuilt += $this->doRebuild( $codes, $lc, $force ); @@ -136,13 +129,20 @@ class RebuildLocalisationCache extends Maintenance { foreach ( $pids as $pid ) { $status = 0; pcntl_waitpid( $pid, $status ); - // Fetch the count from the return value - $numRebuilt += pcntl_wexitstatus( $status ); + if ( pcntl_wexitstatus( $status ) ) { + // Pass a fatal error code through to the caller + $parentStatus = pcntl_wexitstatus( $status ); + } } - $this->output( "$numRebuilt languages rebuilt out of $total\n" ); - if ( $numRebuilt === 0 ) { - $this->output( "Use --force to rebuild the caches which are still fresh.\n" ); + if ( !$pids ) { + $this->output( "$numRebuilt languages rebuilt out of $total\n" ); + if ( $numRebuilt === 0 ) { + $this->output( "Use --force to rebuild the caches which are still fresh.\n" ); + } + } + if ( $parentStatus ) { + exit( $parentStatus ); } } @@ -177,5 +177,5 @@ class RebuildLocalisationCache extends Maintenance { } } -$maintClass = "RebuildLocalisationCache"; +$maintClass = RebuildLocalisationCache::class; require_once RUN_MAINTENANCE_IF_MAIN;