From 0b41d3c6124477790d6069e4be07aa1b16bcfe90 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 3 Jul 2025 12:21:00 +0300 Subject: [PATCH] createDerived method --- .../ORM/Repository/Option/SaveContext.php | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/application/Espo/Core/ORM/Repository/Option/SaveContext.php b/application/Espo/Core/ORM/Repository/Option/SaveContext.php index 3ff60b8149..22b5955647 100644 --- a/application/Espo/Core/ORM/Repository/Option/SaveContext.php +++ b/application/Espo/Core/ORM/Repository/Option/SaveContext.php @@ -34,6 +34,11 @@ use Espo\Core\Utils\Util; use Espo\ORM\Repository\Option\SaveOptions; /** + * A save context. + * + * If a save invokes another save, the context instance should not be re-used. + * If a save invokes a relate action, the context can be passed to that action. + * * @since 9.1.0 */ class SaveContext @@ -46,6 +51,9 @@ class SaveContext /** @var Closure[] */ private array $deferredActions = []; + /** + * @param ?string $id An action ID. + */ public function __construct( ?string $id = null, ) { @@ -53,7 +61,8 @@ class SaveContext } /** - * An action ID. + * An action ID. Used to group notifications. If a save invokes another save, the same ID can be re-used, + * but the context instance should not be re-used. Create a derived context for this. */ public function getId(): string { @@ -130,4 +139,14 @@ class SaveContext $this->deferredActions = []; } + + /** + * Create a derived context. To be used for nested saves. + * + * @since 9.2.0 + */ + public function createDerived(): self + { + return new self($this->id); + } }