Merge "revert gerrit change 29597 for TextContent constructor"
[lhc/web/wiklou.git] / maintenance / updateSearchIndex.php
index f58d22d..ac78484 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
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
  *
+ * @file
  * @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() {
@@ -54,14 +60,13 @@ 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 );
-               
+
                $this->doUpdateSearchIndex( $start, $end, $lockTime );
                if ( is_writable( dirname( realpath( $posFile ) ) ) ) {
                        $file = fopen( $posFile, 'w' );
@@ -69,13 +74,13 @@ class UpdateSearchIndex extends Maintenance {
                                fwrite( $file, $end );
                                fclose( $file );
                        } else {
-                               $this->output( "*** Couldn't write to the $posFile!" );
+                               $this->error( "*** Couldn't write to the $posFile!\n" );
                        }
                } else {
-                       $this->output( "*** Couldn't write to the $posFile!" );
+                       $this->error( "*** Couldn't write to the $posFile!\n" );
                }
        }
-       
+
        private function doUpdateSearchIndex( $start, $end, $maxLockTime ) {
                global $wgDisableSearchUpdate;
 
@@ -91,9 +96,9 @@ 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
+               $sql = "SELECT rc_cur_id FROM $recentchanges
                  JOIN $page ON rc_cur_id=page_id AND rc_this_oldid=page_latest
-                 WHERE rc_timestamp BETWEEN '$start' AND '$end'
+                 WHERE rc_type != " . RC_LOG . " AND rc_timestamp BETWEEN '$start' AND '$end'
                  ";
                $res = $dbw->query( $sql, __METHOD__ );
 
@@ -103,18 +108,9 @@ class UpdateSearchIndex extends Maintenance {
        }
 
        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 );
-                       $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( DO_MAINTENANCE );
+require_once( RUN_MAINTENANCE_IF_MAIN );