EspoCRM – Open Source CRM Application
PHP calendarcontactscrmcrm-platformcrm-systemcustomer-portalcustomer-supportcustomizabledocumentsemail-marketingkanbanleadsopen-sourcephpplatformsales-automationsingle-page-applicationsupport
save context
Yuri Kuznetsov633ac6e63f57
diff --git a/application/Espo/Core/Controllers/RecordBase.php b/application/Espo/Core/Controllers/RecordBase.phpindex 434f24a391..1c17b619eb 100644--- a/application/Espo/Core/Controllers/RecordBase.php+++ b/application/Espo/Core/Controllers/RecordBase.php@@ -40,6 +40,7 @@ use Espo\Core\Record\ServiceContainer as RecordServiceContainer;use Espo\Core\Record\SearchParamsFetcher;use Espo\Core\Record\CreateParamsFetcher;use Espo\Core\Record\ReadParamsFetcher;+use Espo\Core\Record\UpdateContext;use Espo\Core\Record\UpdateParamsFetcher;use Espo\Core\Record\DeleteParamsFetcher;use Espo\Core\Record\FindParamsFetcher;@@ -222,8 +223,16 @@ class RecordBase extends Base implements$params = $this->updateParamsFetcher->fetch($request);+ $context = new UpdateContext();++ $params = $params->withContext($context);+$entity = $this->getRecordService()->update($id, $data, $params);+ if ($context->linkUpdated) {+ $response->setHeader('X-Record-Link-Updated', 'true');+ }+return $entity->getValueMap();}diff --git a/application/Espo/Core/ORM/Repository/Option/SaveContext.php b/application/Espo/Core/ORM/Repository/Option/SaveContext.phpnew file mode 100644index 0000000000..011ccf390e--- /dev/null+++ b/application/Espo/Core/ORM/Repository/Option/SaveContext.php@@ -0,0 +1,52 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\ORM\Repository\Option;++/**+ * @since 9.1.0+ */+class SaveContext+{+ public const NAME = 'context';++ private bool $linkUpdated = false;++ public function setLinkUpdated(): self+ {+ $this->linkUpdated = true;++ return $this;+ }++ public function isLinkUpdated(): bool+ {+ return $this->linkUpdated;+ }+}diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.phpindex b53b7293cc..7de9c6642b 100644--- a/application/Espo/Core/Record/Service.php+++ b/application/Espo/Core/Record/Service.php@@ -41,6 +41,7 @@ use Espo\Core\Exceptions\NotFoundSilent;use Espo\Core\FieldSanitize\SanitizeManager;use Espo\Core\ORM\Defs\AttributeParam;use Espo\Core\ORM\Entity as CoreEntity;+use Espo\Core\ORM\Repository\Option\SaveContext;use Espo\Core\ORM\Repository\Option\SaveOption;use Espo\Core\Record\Access\LinkCheck;use Espo\Core\Record\ActionHistory\Action;@@ -730,9 +731,12 @@ class Service implements Crud,/** @noinspection PhpDeprecationInspection */$this->beforeUpdateEntity($entity, $data);+ $context = new SaveContext();+$this->entityManager->saveEntity($entity, [SaveOption::API => true,SaveOption::KEEP_DIRTY => true,+ SaveContext::NAME => $context,]);$this->getRecordHookManager()->processAfterUpdate($entity, $params);@@ -749,6 +753,10 @@ class Service implements Crud,$this->prepareEntityForOutput($entity);$this->processActionHistoryRecord(Action::UPDATE, $entity);+ if ($context->isLinkUpdated() && $params->getContext()) {+ $params->getContext()->linkUpdated = true;+ }+return $entity;}diff --git a/application/Espo/Core/Record/UpdateContext.php b/application/Espo/Core/Record/UpdateContext.phpnew file mode 100644index 0000000000..603fae99ba--- /dev/null+++ b/application/Espo/Core/Record/UpdateContext.php@@ -0,0 +1,41 @@+<?php+/************************************************************************+ * This file is part of EspoCRM.+ *+ * EspoCRM – Open Source CRM application.+ * Copyright (C) 2014-2025 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko+ * Website: https://www.espocrm.com+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as published by+ * the Free Software Foundation, either version 3 of the License, or+ * (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ * The interactive user interfaces in modified source and object code versions+ * of this program must display Appropriate Legal Notices, as required under+ * Section 5 of the GNU Affero General Public License version 3.+ *+ * In accordance with Section 7(b) of the GNU Affero General Public License version 3,+ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word.+ ************************************************************************/++namespace Espo\Core\Record;++/**+ * @internal+ * @todo Remove in v10.0. Use UpdateResult.+ */+class UpdateContext+{+ public function __construct(+ public bool $linkUpdated = false,+ ) {}+}diff --git a/application/Espo/Core/Record/UpdateParams.php b/application/Espo/Core/Record/UpdateParams.phpindex e9f3e70900..508c099910 100644--- a/application/Espo/Core/Record/UpdateParams.php+++ b/application/Espo/Core/Record/UpdateParams.php@@ -37,6 +37,8 @@ class UpdateParamsprivate bool $skipDuplicateCheck = false;private ?int $versionNumber = null;+ private ?UpdateContext $context = null;+public function __construct() {}public function withSkipDuplicateCheck(bool $skipDuplicateCheck = true): self@@ -69,4 +71,25 @@ class UpdateParams{return new self();}++ /**+ * @internal+ * @todo Remove in v10.0.+ */+ public function withContext(?UpdateContext $context): self+ {+ $obj = clone $this;+ $obj->context = $context;++ return $obj;+ }++ /**+ * @internal+ * @todo Remove in v10.0.+ */+ public function getContext(): ?UpdateContext+ {+ return $this->context;+ }}