From d0b9ffed7601a49233f948ca432558256c01902a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Mon, 7 Dec 2015 16:26:07 -0800 Subject: [PATCH] Make TitleMoveComplete hook events apply in transactions * 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 | 1 + docs/hooks.txt | 10 +++++++++- includes/MovePage.php | 9 ++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/RELEASE-NOTES-1.27 b/RELEASE-NOTES-1.27 index 77f7e2fffb..b41b8c2ae0 100644 --- a/RELEASE-NOTES-1.27 +++ b/RELEASE-NOTES-1.27 @@ -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 ==== diff --git a/docs/hooks.txt b/docs/hooks.txt index 7c79e729a5..fe88fa7d56 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -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 diff --git a/includes/MovePage.php b/includes/MovePage.php index 736cd8d650..b91895508a 100644 --- a/includes/MovePage.php +++ b/includes/MovePage.php @@ -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 ); } ); -- 2.20.1