X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2FpopulateCategory.php;h=037849bd3c4c3f450902191225b3e26b35325b77;hb=96c5ca47255fca62c3d8fec95aa411699650ce0a;hp=2376ccef7f1b31c36340c28131c6bc60fb8fcc3c;hpb=659778619cc12d156d3547834c0f90f407584104;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/populateCategory.php b/maintenance/populateCategory.php index 2376ccef7f..037849bd3c 100644 --- a/maintenance/populateCategory.php +++ b/maintenance/populateCategory.php @@ -1,15 +1,34 @@ addOption( 'throttle', 'Wait this many milliseconds after each category. Default: 0', false, true ); $this->addOption( 'force', 'Run regardless of whether the database says it\'s been run already' ); } - + public function execute() { $begin = $this->getOption( 'begin', '' ); $maxSlaveLag = $this->getOption( 'max-slave-lag', 10 ); @@ -48,13 +67,13 @@ TEXT; private function doPopulateCategory( $begin, $maxlag, $throttle, $force ) { $dbw = wfGetDB( DB_MASTER ); - + if ( !$force ) { $row = $dbw->selectRow( 'updatelog', '1', array( 'ul_key' => 'populate category' ), - __FUNCTION__ + __METHOD__ ); if ( $row ) { $this->output( "Category table already populated. Use php " . @@ -63,24 +82,22 @@ TEXT; return true; } } - - $maxlag = intval( $maxlag ); + $throttle = intval( $throttle ); - $force = (bool)$force; if ( $begin !== '' ) { $where = 'cl_to > ' . $dbw->addQuotes( $begin ); } else { $where = null; } $i = 0; - + while ( true ) { # Find which category to update $row = $dbw->selectRow( 'categorylinks', 'cl_to', $where, - __FUNCTION__, + __METHOD__, array( 'ORDER BY' => 'cl_to' ) @@ -91,7 +108,7 @@ TEXT; } $name = $row->cl_to; $where = 'cl_to > ' . $dbw->addQuotes( $name ); - + # Use the row to update the category count $cat = Category::newFromName( $name ); if ( !is_object( $cat ) ) { @@ -99,30 +116,30 @@ TEXT; } else { $cat->refreshCounts(); } - + ++$i; if ( !( $i % self::REPORTING_INTERVAL ) ) { $this->output( "$name\n" ); - wfWaitForSlaves( $maxlag ); + wfWaitForSlaves(); } usleep( $throttle * 1000 ); } - + if ( $dbw->insert( 'updatelog', array( 'ul_key' => 'populate category' ), - __FUNCTION__, + __METHOD__, 'IGNORE' ) ) { - wfOut( "Category population complete.\n" ); + $this->output( "Category population complete.\n" ); return true; } else { - wfOut( "Could not insert category population row.\n" ); + $this->output( "Could not insert category population row.\n" ); return false; } } } $maintClass = "PopulateCategory"; -require_once( DO_MAINTENANCE ); +require_once( RUN_MAINTENANCE_IF_MAIN );