Merge "Provide a script to reset the page_random column"
[lhc/web/wiklou.git] / includes / MergeHistory.php
index 9d63869..0914a9b 100644 (file)
@@ -1,10 +1,6 @@
 <?php
 
 /**
- *
- *
- * Created on Dec 29, 2015
- *
  * Copyright © 2015 Geoffrey Mon <geofbot@gmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
@@ -24,6 +20,7 @@
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Timestamp\TimestampException;
 use Wikimedia\Rdbms\IDatabase;
 
@@ -170,7 +167,7 @@ class MergeHistory {
                // Convert into a Status object
                if ( $errors ) {
                        foreach ( $errors as $error ) {
-                               call_user_func_array( [ $status, 'fatal' ], $error );
+                               $status->fatal( ...$error );
                        }
                }
 
@@ -257,6 +254,8 @@ class MergeHistory {
                        return $permCheck;
                }
 
+               $this->dbw->startAtomic( __METHOD__ );
+
                $this->dbw->update(
                        'revision',
                        [ 'rev_page' => $this->dest->getArticleID() ],
@@ -267,17 +266,17 @@ class MergeHistory {
                // Check if this did anything
                $this->revisionsMerged = $this->dbw->affectedRows();
                if ( $this->revisionsMerged < 1 ) {
+                       $this->dbw->endAtomic( __METHOD__ );
                        $status->fatal( 'mergehistory-fail-no-change' );
+
                        return $status;
                }
 
                // Make the source page a redirect if no revisions are left
-               $haveRevisions = $this->dbw->selectField(
+               $haveRevisions = $this->dbw->lockForUpdate(
                        'revision',
-                       'rev_timestamp',
                        [ 'rev_page' => $this->source->getArticleID() ],
-                       __METHOD__,
-                       [ 'FOR UPDATE' ]
+                       __METHOD__
                );
                if ( !$haveRevisions ) {
                        if ( $reason ) {
@@ -335,6 +334,10 @@ class MergeHistory {
                }
                $this->dest->invalidateCache(); // update histories
 
+               // Duplicate watchers of the old article to the new article on history merge
+               $store = MediaWikiServices::getInstance()->getWatchedItemStore();
+               $store->duplicateAllAssociatedEntries( $this->source, $this->dest );
+
                // Update our logs
                $logEntry = new ManualLogEntry( 'merge', 'merge' );
                $logEntry->setPerformer( $user );
@@ -349,6 +352,8 @@ class MergeHistory {
 
                Hooks::run( 'ArticleMergeComplete', [ $this->source, $this->dest ] );
 
+               $this->dbw->endAtomic( __METHOD__ );
+
                return $status;
        }
 }