]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - maintenance/updateSearchIndex.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / maintenance / updateSearchIndex.php
index 978631018946cce53db9bf6b0edd89bfa596dc28..cdb7d9f701be7532506567a1bdb7d48db40a7878 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Script for periodic off-peak updating of the search index
+ * Periodic off-peak updating of the search index.
  *
  * Usage: php updateSearchIndex.php [-s START] [-e END] [-p POSFILE] [-l LOCKTIME] [-q]
  * Where START is the starting timestamp
  * @ingroup Maintenance
  */
 
-require_once( dirname( __FILE__ ) . '/Maintenance.php' );
+require_once __DIR__ . '/Maintenance.php';
 
+/**
+ * Maintenance script for periodic off-peak updating of the search index.
+ *
+ * @ingroup Maintenance
+ */
 class UpdateSearchIndex extends Maintenance {
 
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Script for periodic off-peak updating of the search index";
+               $this->addDescription( '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 );
+               $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() {
@@ -46,7 +61,7 @@ class UpdateSearchIndex extends Maintenance {
        }
 
        public function execute() {
-               $posFile = $this->getOption( 'p', 'searchUpdate.' . wfWikiId() . '.pos' );
+               $posFile = $this->getOption( 'p', 'searchUpdate.' . wfWikiID() . '.pos' );
                $end = $this->getOption( 'e', wfTimestampNow() );
                if ( $this->hasOption( 's' ) ) {
                        $start = $this->getOption( 's' );
@@ -55,11 +70,10 @@ class UpdateSearchIndex extends Maintenance {
                        # 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 = @file_get_contents( $posFile );
-                       if ( !$start ) {
-                               $start = wfTimestamp( TS_MW, time() - 86400 );
-                       }
+                       $start = wfTimestamp( TS_MW, time() - 86400 );
                }
                $lockTime = $this->getOption( 'l', 20 );
 
@@ -70,10 +84,10 @@ class UpdateSearchIndex extends Maintenance {
                                fwrite( $file, $end );
                                fclose( $file );
                        } else {
-                               $this->output( "*** Couldn't write to the $posFile!\n" );
+                               $this->error( "*** Couldn't write to the $posFile!\n" );
                        }
                } else {
-                       $this->output( "*** Couldn't write to the $posFile!\n" );
+                       $this->error( "*** Couldn't write to the $posFile!\n" );
                }
        }
 
@@ -82,7 +96,7 @@ class UpdateSearchIndex extends Maintenance {
 
                $wgDisableSearchUpdate = false;
 
-               $dbw = wfGetDB( DB_MASTER );
+               $dbw = $this->getDB( DB_MASTER );
                $recentchanges = $dbw->tableName( 'recentchanges' );
 
                $this->output( "Updating searchindex between $start and $end\n" );
@@ -92,31 +106,20 @@ class UpdateSearchIndex extends Maintenance {
                $end = $dbw->timestamp( $end );
 
                $page = $dbw->tableName( 'page' );
-               $sql = "SELECT rc_cur_id,rc_type,rc_moved_to_ns,rc_moved_to_title FROM $recentchanges
-                 JOIN $page ON rc_cur_id=page_id AND rc_this_oldid=page_latest
-                 WHERE rc_timestamp BETWEEN '$start' AND '$end'
-                 ";
+               $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->updateSearchIndex( $maxLockTime, [ $this, 'searchIndexUpdateCallback' ], $dbw, $res );
 
                $this->output( "Done\n" );
        }
 
        public function searchIndexUpdateCallback( $dbw, $row ) {
-               if ( $row->rc_type == RC_MOVE || $row->rc_type == RC_MOVE_OVER_REDIRECT ) {
-                       # Rename searchindex entry
-                       $titleObj = Title::makeTitle( $row->rc_moved_to_ns, $row->rc_moved_to_title );
-                       $title = $titleObj->getPrefixedDBkey();
-                       $this->output( "$title..." );
-                       $u = new SearchUpdate( $row->rc_cur_id, $title, false );
-                       $u->doUpdate();
-                       $this->output( "\n" );
-               } elseif ( $row->rc_type !== RC_LOG ) {
-                       $this->updateSearchIndexForPage( $dbw, $row->rc_cur_id );
-               }
+               $this->updateSearchIndexForPage( $dbw, $row->rc_cur_id );
        }
 }
 
 $maintClass = "UpdateSearchIndex";
-require_once( RUN_MAINTENANCE_IF_MAIN );
+require_once RUN_MAINTENANCE_IF_MAIN;