Made WikiPage::doPurge() avoid calling commit()
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 17:33:58 +0000 (10:33 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 8 Apr 2015 17:33:58 +0000 (10:33 -0700)
* Calling commit() can cause imbalanced begin/commit problems

Change-Id: I55fec065de20653b216c8dfac7c361124c8fe10a

includes/page/WikiPage.php

index 5caffab..6242a54 100644 (file)
@@ -1150,28 +1150,24 @@ class WikiPage implements Page, IDBAccessObject {
         * @return bool
         */
        public function doPurge() {
-               global $wgUseSquid;
-
                if ( !Hooks::run( 'ArticlePurge', array( &$this ) ) ) {
                        return false;
                }
 
-               // Invalidate the cache
-               $this->mTitle->invalidateCache();
-
-               if ( $wgUseSquid ) {
-                       // Commit the transaction before the purge is sent
-                       $dbw = wfGetDB( DB_MASTER );
-                       $dbw->commit( __METHOD__ );
-
-                       // Send purge
-                       $update = SquidUpdate::newSimplePurge( $this->mTitle );
-                       $update->doUpdate();
-               }
+               $title = $this->mTitle;
+               wfGetDB( DB_MASTER )->onTransactionIdle( function() use ( $title ) {
+                       global $wgUseSquid;
+                       // Invalidate the cache in auto-commit mode
+                       $title->invalidateCache();
+                       if ( $wgUseSquid ) {
+                               // Send purge now that page_touched update was committed above
+                               $update = SquidUpdate::newSimplePurge( $title );
+                               $update->doUpdate();
+                       }
+               } );
 
                if ( $this->mTitle->getNamespace() == NS_MEDIAWIKI ) {
                        // @todo move this logic to MessageCache
-
                        if ( $this->exists() ) {
                                // NOTE: use transclusion text for messages.
                                //       This is consistent with  MessageCache::getMsgFromNamespace()
@@ -1188,6 +1184,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                        MessageCache::singleton()->replace( $this->mTitle->getDBkey(), $text );
                }
+
                return true;
        }