Merge "Output PHP version before running PHPUnit tests"
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.php
index b6421f3..d61906c 100644 (file)
@@ -33,7 +33,7 @@ require_once __DIR__ . '/Maintenance.php';
 class RebuildRecentchanges extends Maintenance {
        public function __construct() {
                parent::__construct();
-               $this->mDescription = "Rebuild recent changes";
+               $this->addDescription( 'Rebuild recent changes' );
        }
 
        public function execute() {
@@ -41,6 +41,7 @@ class RebuildRecentchanges extends Maintenance {
                $this->rebuildRecentChangesTablePass2();
                $this->rebuildRecentChangesTablePass3();
                $this->rebuildRecentChangesTablePass4();
+               $this->rebuildRecentChangesTablePass5();
                $this->purgeFeeds();
                $this->output( "Done.\n" );
        }
@@ -281,6 +282,46 @@ class RebuildRecentchanges extends Maintenance {
                }
        }
 
+       /**
+        * Rebuild pass 5: Delete duplicate entries where we generate both a page revision and a log entry
+        * for a single action (upload only, at the moment, but potentially also move, protect, ...).
+        */
+       private function rebuildRecentChangesTablePass5() {
+               $dbw = wfGetDB( DB_MASTER );
+
+               $this->output( "Removing duplicate revision and logging entries...\n" );
+
+               $res = $dbw->select(
+                       array( 'logging', 'log_search' ),
+                       array( 'ls_value', 'ls_log_id' ),
+                       array(
+                               'ls_log_id = log_id',
+                               'ls_field' => 'associated_rev_id',
+                               'log_type' => 'upload',
+                       ),
+                       __METHOD__
+               );
+               foreach ( $res as $obj ) {
+                       $rev_id = $obj->ls_value;
+                       $log_id = $obj->ls_log_id;
+
+                       // Mark the logging row as having an associated rev id
+                       $dbw->update(
+                               'recentchanges',
+                               /*SET*/ array( 'rc_this_oldid' => $rev_id ),
+                               /*WHERE*/ array( 'rc_logid' => $log_id ),
+                               __METHOD__
+                       );
+
+                       // Delete the revision row
+                       $dbw->delete(
+                               'recentchanges',
+                               /*WHERE*/ array( 'rc_this_oldid' => $rev_id, 'rc_logid' => 0 ),
+                               __METHOD__
+                       );
+               }
+       }
+
        /**
         * Purge cached feeds in $messageMemc
         */