Make sure emails from RecentChange::save() are for comitted rows
authorAaron Schulz <aschulz@wikimedia.org>
Mon, 12 Sep 2016 21:23:14 +0000 (14:23 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 12 Sep 2016 21:23:14 +0000 (14:23 -0700)
Change-Id: I9086a70348d2f0843527e3805e9f6aef3356ee03

includes/changes/RecentChange.php

index a5d1fc5..8e74674 100644 (file)
@@ -336,9 +336,13 @@ class RecentChange {
                        $title = $this->getTitle();
 
                        // Never send an RC notification email about categorization changes
-                       if ( $this->mAttribs['rc_type'] != RC_CATEGORIZE ) {
-                               if ( Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] ) ) {
-                                       # @todo FIXME: This would be better as an extension hook
+                       if (
+                               $this->mAttribs['rc_type'] != RC_CATEGORIZE &&
+                               Hooks::run( 'AbortEmailNotification', [ $editor, $title, $this ] )
+                       ) {
+                               // @FIXME: This would be better as an extension hook
+                               // Send emails or email jobs once this row is safely committed
+                               $dbw->onTransactionIdle( function () use ( $editor, $title ) {
                                        $enotif = new EmailNotification();
                                        $enotif->notifyOnPageChange(
                                                $editor,
@@ -349,7 +353,7 @@ class RecentChange {
                                                $this->mAttribs['rc_last_oldid'],
                                                $this->mExtra['pageStatus']
                                        );
-                               }
+                               } );
                        }
                }