Make TitleMoveComplete hook events apply in transactions
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 8 Dec 2015 00:26:07 +0000 (16:26 -0800)
committerKrinkle <krinklemail@gmail.com>
Wed, 9 Dec 2015 18:23:49 +0000 (18:23 +0000)
* All updates for an event are atomic for the main DB.
* This follows-up 9e51328790c0a by reverting the auto-commit
  behavoir which was a side-effect of that change.
* Added TitleMoveCompleting hook with is a pre-commit version
  of the same hook. Various extension could benefit from the
  atomicity of running in the main transaction.

Change-Id: Ife5990bbedca1de78bcf83f2d6fdeeae8086ffad

RELEASE-NOTES-1.27
docs/hooks.txt
includes/MovePage.php

index 77f7e2f..b41b8c2 100644 (file)
@@ -96,6 +96,7 @@ production.
   authentication extensions.
 * $wgMaxUserDBWriteDuration added to limit huge user-generated transactions.
   Regular web request transactions that takes longer than this are aborted.
+* Added a new hook, 'TitleMoveCompleting', which runs before a page move is committed.
 
 === External library changes in 1.27 ===
 ==== Upgraded external libraries ====
index 7c79e72..fe88fa7 100644 (file)
@@ -3030,7 +3030,7 @@ $old: old title
 $nt: new title
 $user: user who does the move
 
-'TitleMoveComplete': After moving an article (title).
+'TitleMoveComplete': After moving an article (title), post-commit.
 &$old: old title
 &$nt: new title
 &$user: user who did the move
@@ -3038,6 +3038,14 @@ $pageid: database ID of the page that's been moved
 $redirid: database ID of the created redirect
 $reason: reason for the move
 
+'TitleMoveCompleting': After moving an article (title), pre-commit.
+$old: old title
+$nt: new title
+$user: user who did the move
+$pageid: database ID of the page that's been moved
+$redirid: database ID of the created redirect
+$reason: reason for the move
+
 'TitleQuickPermissions': Called from Title::checkQuickPermissions to add to
 or override the quick permissions check.
 $title: The Title object being accessed
index 736cd8d..b918955 100644 (file)
@@ -369,10 +369,17 @@ class MovePage {
                        WatchedItem::duplicateEntries( $this->oldTitle, $this->newTitle );
                }
 
+               Hooks::run(
+                       'TitleMoveCompleting',
+                       array( $this->oldTitle, $this->newTitle, $user, $pageid, $redirid, $reason )
+               );
+
                $dbw->endAtomic( __METHOD__ );
 
                $params = array( &$this->oldTitle, &$this->newTitle, &$user, $pageid, $redirid, $reason );
-               $dbw->onTransactionIdle( function () use ( $params ) {
+               $dbw->onTransactionIdle( function () use ( $params, $dbw ) {
+                       // Keep each single hook handler atomic
+                       $dbw->setFlag( DBO_TRX ); // flag is automatically reset by DB layer
                        Hooks::run( 'TitleMoveComplete', $params );
                } );