-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[10.x] Dispatch events based on a DB transaction result #48705
Merged
taylorotwell
merged 18 commits into
laravel:10.x
from
mateusjatenee:feature/transaction-aware-events
Oct 30, 2023
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
c4d4fc1
wip
mateusjatenee 8bea21a
Refactor
mateusjatenee 68c9605
Add EventFake support
mateusjatenee 1533420
remove strict types
mateusjatenee 40b5c69
Make styleCI happy
mateusjatenee a3fd202
Fix test
mateusjatenee 6b29903
Add missing test for EventFake
mateusjatenee e12daa5
Add test to handle nested transactions
mateusjatenee c307e84
fix typo
mateusjatenee 909d9c5
Make styleci happy
mateusjatenee b031d8f
formatting, inject manager resolver
taylorotwell 414bba1
formatting
taylorotwell b2f9f2e
formatting
taylorotwell e6e05a4
formatting
taylorotwell ede1587
formatting
taylorotwell 7ed5cef
more thorough solution
taylorotwell 984f9aa
Add additional test for nested transactions
mateusjatenee 300ee76
Add additional nested transaction test
mateusjatenee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
src/Illuminate/Contracts/Events/ShouldDispatchAfterCommit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Events; | ||
|
||
interface ShouldDispatchAfterCommit | ||
{ | ||
// | ||
} |
8 changes: 8 additions & 0 deletions
8
src/Illuminate/Contracts/Events/ShouldHandleEventsAfterCommit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Events; | ||
|
||
interface ShouldHandleEventsAfterCommit | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace Illuminate\Contracts\Queue; | ||
|
||
interface ShouldQueueAfterCommit extends ShouldQueue | ||
{ | ||
// | ||
} |
18 changes: 18 additions & 0 deletions
18
src/Illuminate/Database/Eloquent/BroadcastsEventsAfterCommit.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Illuminate\Database\Eloquent; | ||
|
||
trait BroadcastsEventsAfterCommit | ||
{ | ||
use BroadcastsEvents; | ||
|
||
/** | ||
* Determine if the model event broadcast queued job should be dispatched after all transactions are committed. | ||
* | ||
* @return bool | ||
*/ | ||
public function broadcastAfterCommit() | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this make Illuminate Events depends on Illuminate Database package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the current implementation, if there is no instance bound (in this case, TransactionManager), the events are immediately dispatched (the afterCommit logic is the responsibility of the projects using it).
https://github.com/laravel/framework/pull/48705/files#diff-260e35f57adc10558ea232b625f9143bab31003c4fa1b7a998ce6fae381667ebR563
Therefore, it does not depend on the Illuminate DB package.