Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/304627

Change subject: Make various MWCallableUpdate usages rollback-safe
......................................................................

Make various MWCallableUpdate usages rollback-safe

Support for this added to MWCallableUpdate and its helper method
in DeferredUpdates.

Bug: T141988
Change-Id: Ief150ea655036e2708557dd8ae847379edf21933
---
M includes/WatchedItemStore.php
M includes/changes/RecentChange.php
M includes/deferred/DeferredUpdates.php
M includes/deferred/MWCallableUpdate.php
M includes/page/WikiPage.php
M includes/revisiondelete/RevDelList.php
6 files changed, 60 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/27/304627/1

diff --git a/includes/WatchedItemStore.php b/includes/WatchedItemStore.php
index 89ca50c..b8a47fa 100644
--- a/includes/WatchedItemStore.php
+++ b/includes/WatchedItemStore.php
@@ -761,7 +761,9 @@
                                        $this->uncacheLinkTarget( $target );
 
                                        $this->reuseConnection( $dbw );
-                               }
+                               },
+                               DeferredUpdates::POSTSEND,
+                               $dbw
                        );
                }
 
diff --git a/includes/changes/RecentChange.php 
b/includes/changes/RecentChange.php
index 159cfd9..daf76df 100644
--- a/includes/changes/RecentChange.php
+++ b/includes/changes/RecentChange.php
@@ -589,16 +589,20 @@
                        'pageStatus' => 'changed'
                ];
 
-               DeferredUpdates::addCallableUpdate( function() use ( $rc, $tags 
) {
-                       $rc->save();
-                       if ( $rc->mAttribs['rc_patrolled'] ) {
-                               PatrolLog::record( $rc, true, 
$rc->getPerformer() );
-                       }
-                       if ( count( $tags ) ) {
-                               ChangeTags::addTags( $tags, 
$rc->mAttribs['rc_id'],
-                                       $rc->mAttribs['rc_this_oldid'], null, 
null );
-                       }
-               } );
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( $rc, $tags ) {
+                               $rc->save();
+                               if ( $rc->mAttribs['rc_patrolled'] ) {
+                                       PatrolLog::record( $rc, true, 
$rc->getPerformer() );
+                               }
+                               if ( count( $tags ) ) {
+                                       ChangeTags::addTags( $tags, 
$rc->mAttribs['rc_id'],
+                                               $rc->mAttribs['rc_this_oldid'], 
null, null );
+                               }
+                       },
+                       DeferredUpdates::POSTSEND,
+                       wfGetDB( DB_MASTER )
+               );
 
                return $rc;
        }
@@ -661,16 +665,20 @@
                        'pageStatus' => 'created'
                ];
 
-               DeferredUpdates::addCallableUpdate( function() use ( $rc, $tags 
) {
-                       $rc->save();
-                       if ( $rc->mAttribs['rc_patrolled'] ) {
-                               PatrolLog::record( $rc, true, 
$rc->getPerformer() );
-                       }
-                       if ( count( $tags ) ) {
-                               ChangeTags::addTags( $tags, 
$rc->mAttribs['rc_id'],
-                                       $rc->mAttribs['rc_this_oldid'], null, 
null );
-                       }
-               } );
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( $rc, $tags ) {
+                               $rc->save();
+                               if ( $rc->mAttribs['rc_patrolled'] ) {
+                                       PatrolLog::record( $rc, true, 
$rc->getPerformer() );
+                               }
+                               if ( count( $tags ) ) {
+                                       ChangeTags::addTags( $tags, 
$rc->mAttribs['rc_id'],
+                                               $rc->mAttribs['rc_this_oldid'], 
null, null );
+                               }
+                       },
+                       DeferredUpdates::POSTSEND,
+                       wfGetDB( DB_MASTER )
+               );
 
                return $rc;
        }
diff --git a/includes/deferred/DeferredUpdates.php 
b/includes/deferred/DeferredUpdates.php
index 9768838..ee14e1a 100644
--- a/includes/deferred/DeferredUpdates.php
+++ b/includes/deferred/DeferredUpdates.php
@@ -68,9 +68,12 @@
         *
         * @param callable $callable
         * @param integer $type DeferredUpdates constant (PRESEND or POSTSEND) 
(since 1.27)
+        * @param IDatabase|null $dbw Abort if this DB is rolled back 
[optional] (since 1.28)
         */
-       public static function addCallableUpdate( $callable, $type = 
self::POSTSEND ) {
-               self::addUpdate( new MWCallableUpdate( $callable, wfGetCaller() 
), $type );
+       public static function addCallableUpdate(
+               $callable, $type = self::POSTSEND, IDatabase $dbw = null
+       ) {
+               self::addUpdate( new MWCallableUpdate( $callable, 
wfGetCaller(), $dbw ), $type );
        }
 
        /**
diff --git a/includes/deferred/MWCallableUpdate.php 
b/includes/deferred/MWCallableUpdate.php
index d63c292..3c16f2b 100644
--- a/includes/deferred/MWCallableUpdate.php
+++ b/includes/deferred/MWCallableUpdate.php
@@ -12,14 +12,27 @@
        /**
         * @param callable $callback
         * @param string $fname Calling method
+        * @param IDatabase|null $dbw Abort if this DB is rolled back 
[optional] (since 1.28)
         */
-       public function __construct( callable $callback, $fname = 'unknown' ) {
+       public function __construct( callable $callback, $fname = 'unknown', 
IDatabase $dbw = null ) {
                $this->callback = $callback;
                $this->fname = $fname;
+
+               if ( $dbw && $dbw->trxLevel() ) {
+                       $dbw->onTransactionResolution( [ $this, 
'cancelOnRollback' ] );
+               }
        }
 
        public function doUpdate() {
-               call_user_func( $this->callback );
+               if ( $this->callback ) {
+                       call_user_func( $this->callback );
+               }
+       }
+
+       public function cancelOnRollback( $trigger ) {
+               if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
+                       $this->callback = null;
+               }
        }
 
        public function getOrigin() {
diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php
index 8eba1cc..8545c36 100644
--- a/includes/page/WikiPage.php
+++ b/includes/page/WikiPage.php
@@ -887,9 +887,13 @@
                // Update the DB post-send if the page has not cached since now
                $that = $this;
                $latest = $this->getLatest();
-               DeferredUpdates::addCallableUpdate( function() use ( $that, 
$retval, $latest ) {
-                       $that->insertRedirectEntry( $retval, $latest );
-               } );
+               DeferredUpdates::addCallableUpdate(
+                       function () use ( $that, $retval, $latest ) {
+                               $that->insertRedirectEntry( $retval, $latest );
+                       },
+                       DeferredUpdates::POSTSEND,
+                       wfGetDB( DB_MASTER )
+               );
 
                return $retval;
        }
diff --git a/includes/revisiondelete/RevDelList.php 
b/includes/revisiondelete/RevDelList.php
index d365bf6..48604e1 100644
--- a/includes/revisiondelete/RevDelList.php
+++ b/includes/revisiondelete/RevDelList.php
@@ -275,7 +275,8 @@
                        function () use ( $visibilityChangeMap ) {
                                $this->doPostCommitUpdates( 
$visibilityChangeMap );
                        },
-                       DeferredUpdates::PRESEND
+                       DeferredUpdates::PRESEND,
+                       $dbw
                );
 
                $dbw->endAtomic( __METHOD__ );

-- 
To view, visit https://gerrit.wikimedia.org/r/304627
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ief150ea655036e2708557dd8ae847379edf21933
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to