mDescription = "Script for periodic off-peak updating of the search index"; $this->addOption( 's', 'starting timestamp', false, true ); $this->addOption( 'e', 'Ending timestamp', false, true ); $this->addOption( 'p', 'File for saving/loading timestamps, searchUpdate.WIKI_ID.pos by default', false, true ); $this->addOption( 'l', 'How long the searchindex and revision tables will be locked for', false, true ); } public function getDbType() { return Maintenance::DB_ADMIN; } public function execute() { $posFile = $this->getOption( 'p', 'searchUpdate.' . wfWikiId() . '.pos' ); $end = $this->getOption( 'e', wfTimestampNow() ); if ( $this->hasOption( 's' ) ) { $start = $this->getOption( 's' ); } elseif ( is_readable( 'searchUpdate.pos' ) ) { # B/c to the old position file name which was hardcoded # We can safely delete the file when we're done though. $start = file_get_contents( 'searchUpdate.pos' ); unlink( 'searchUpdate.pos' ); } elseif ( is_readable( $posFile ) ) { $start = file_get_contents( $posFile ); } else { $start = wfTimestamp( TS_MW, time() - 86400 ); } $lockTime = $this->getOption( 'l', 20 ); $this->doUpdateSearchIndex( $start, $end, $lockTime ); if ( is_writable( dirname( realpath( $posFile ) ) ) ) { $file = fopen( $posFile, 'w' ); if ( $file !== false ) { fwrite( $file, $end ); fclose( $file ); } else { $this->error( "*** Couldn't write to the $posFile!\n" ); } } else { $this->error( "*** Couldn't write to the $posFile!\n" ); } } private function doUpdateSearchIndex( $start, $end, $maxLockTime ) { global $wgDisableSearchUpdate; $wgDisableSearchUpdate = false; $dbw = wfGetDB( DB_MASTER ); $recentchanges = $dbw->tableName( 'recentchanges' ); $this->output( "Updating searchindex between $start and $end\n" ); # Select entries from recentchanges which are on top and between the specified times $start = $dbw->timestamp( $start ); $end = $dbw->timestamp( $end ); $page = $dbw->tableName( 'page' ); $sql = "SELECT rc_cur_id FROM $recentchanges JOIN $page ON rc_cur_id=page_id AND rc_this_oldid=page_latest WHERE rc_type != " . RC_LOG . " AND rc_timestamp BETWEEN '$start' AND '$end'"; $res = $dbw->query( $sql, __METHOD__ ); $this->updateSearchIndex( $maxLockTime, array( $this, 'searchIndexUpdateCallback' ), $dbw, $res ); $this->output( "Done\n" ); } public function searchIndexUpdateCallback( $dbw, $row ) { $this->updateSearchIndexForPage( $dbw, $row->rc_cur_id ); } } $maintClass = "UpdateSearchIndex"; require_once RUN_MAINTENANCE_IF_MAIN;