Skip to content

Commit

Permalink
[9.x] Fixed WalletService::create() without db::transaction()
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Mar 15, 2023
1 parent b45381c commit 2f6355b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Internal/Service/DispatcherService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ final class DispatcherService implements DispatcherServiceInterface
private array $events = [];

public function __construct(
private Dispatcher $dispatcher
private Dispatcher $dispatcher,
private ConnectionServiceInterface $connectionService
) {
}

Expand Down Expand Up @@ -43,4 +44,11 @@ public function forgot(): void

$this->events = [];
}

public function lazyFlush(): void
{
if ($this->connectionService->get()->transactionLevel() === 0) {
$this->flush();
}
}
}
2 changes: 2 additions & 0 deletions src/Internal/Service/DispatcherServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public function dispatch(EventInterface $event): void;
public function forgot(): void;

public function flush(): void;

public function lazyFlush(): void;
}
1 change: 1 addition & 0 deletions src/Services/WalletService.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function create(Model $model, array $data): Wallet

$event = $this->walletCreatedEventAssembler->create($wallet);
$this->dispatcherService->dispatch($event);
$this->dispatcherService->lazyFlush();

return $wallet;
}
Expand Down

0 comments on commit 2f6355b

Please sign in to comment.