-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TASK: Move transactional logic _on_ projection as it does not belong …
…to the subscription store ... which technically only coincidentally uses the same connection and dbal instance see neos/neos-development-collection#5321 (comment)
- Loading branch information
Showing
5 changed files
with
55 additions
and
16 deletions.
There are no files selected for viewing
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Neos\ContentRepository\Core\Infrastructure; | ||
|
||
use Neos\ContentRepository\Core\Projection\ProjectionInterface; | ||
|
||
/** | ||
* @phpstan-require-implements ProjectionInterface | ||
* @api to simplify creating a custom dbal projection | ||
*/ | ||
trait ProjectionTransactionTrait | ||
{ | ||
/** | ||
* DBAL default implementation for {@see ProjectionInterface::transactional()} | ||
*/ | ||
public function transactional(\Closure $closure): void | ||
{ | ||
if ($this->dbal->isTransactionActive() === false) { | ||
/** @phpstan-ignore argument.templateType */ | ||
$this->dbal->transactional($closure); | ||
return; | ||
} | ||
// technically we could leverage nested transactions from dbal, which effectively does the same. | ||
// but that requires us to enable this globally first via setNestTransactionsWithSavepoints also making this explicit is more transparent: | ||
$this->dbal->createSavepoint('PROJECTION'); | ||
try { | ||
$closure(); | ||
} catch (\Throwable $e) { | ||
// roll back the partially applied event on the projection | ||
$this->dbal->rollbackSavepoint('PROJECTION'); | ||
throw $e; | ||
} | ||
$this->dbal->releaseSavepoint('PROJECTION'); | ||
} | ||
} |
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