Skip to content

EspoCRM – Open Source CRM Application

app params refresh with websocket

Yurii0d17d1229380
diff --git a/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterDelete.php b/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterDelete.php
index 33f383669c..b8c7003b4a 100644
--- a/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterDelete.php
+++ b/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterDelete.php
@@ -30,9 +30,9 @@
namespace Espo\Classes\RecordHooks\CurrencyRecordRate;
use Espo\Core\Exceptions\Conflict;
-use Espo\Core\Exceptions\Error;
use Espo\Core\Record\DeleteParams;
use Espo\Core\Record\Hook\DeleteHook;
+use Espo\Core\WebSocket\Submission;
use Espo\Entities\CurrencyRecordRate;
use Espo\ORM\Entity;
use Espo\Tools\Currency\Exceptions\NotEnabled;
@@ -45,6 +45,7 @@ class AfterDelete implements DeleteHook
{
public function __construct(
private RecordManager $recordManager,
+ private Submission $submission,
) {}
public function process(Entity $entity, DeleteParams $params): void
@@ -56,5 +57,7 @@ class AfterDelete implements DeleteHook
} catch (NotEnabled $e) {
throw new Conflict($e->getMessage(), previous: $e);
}
+
+ $this->submission->submit('appParamsUpdate');
}
}
diff --git a/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterSave.php b/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterSave.php
index ad761b4db1..f2b49ee778 100644
--- a/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterSave.php
+++ b/application/Espo/Classes/RecordHooks/CurrencyRecordRate/AfterSave.php
@@ -31,6 +31,7 @@ namespace Espo\Classes\RecordHooks\CurrencyRecordRate;
use Espo\Core\Exceptions\Conflict;
use Espo\Core\Record\Hook\SaveHook;
+use Espo\Core\WebSocket\Submission;
use Espo\Entities\CurrencyRecordRate;
use Espo\ORM\Entity;
use Espo\Tools\Currency\Exceptions\NotEnabled;
@@ -43,6 +44,7 @@ class AfterSave implements SaveHook
{
public function __construct(
private RecordManager $recordManager,
+ private Submission $submission,
) {}
public function process(Entity $entity): void
@@ -54,5 +56,7 @@ class AfterSave implements SaveHook
} catch (NotEnabled $e) {
throw new Conflict($e->getMessage(), previous: $e);
}
+
+ $this->submission->submit('appParamsUpdate');
}
}
diff --git a/application/Espo/Entities/Template.php b/application/Espo/Entities/Template.php
index d8646fdd9e..2197c1a822 100644
--- a/application/Espo/Entities/Template.php
+++ b/application/Espo/Entities/Template.php
@@ -38,9 +38,11 @@ class Template extends Entity
public const STATUS_ACTIVE = 'Active';
+ public const string FIELD_ENTITY_TYPE = 'entityType';
+
public function getTargetEntityType(): string
{
- $entityType = $this->get('entityType');
+ $entityType = $this->get(self::FIELD_ENTITY_TYPE);
if ($entityType === null) {
throw new UnexpectedValueException();
diff --git a/application/Espo/Hooks/Template/WebSocketSubmit.php b/application/Espo/Hooks/Template/WebSocketSubmit.php
new file mode 100644
index 0000000000..9393c2d9e7
--- /dev/null
+++ b/application/Espo/Hooks/Template/WebSocketSubmit.php
@@ -0,0 +1,72 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2025 EspoCRM, Inc.
+ * 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\Hooks\Template;
+
+use Espo\Core\Hook\Hook\AfterSave;
+use Espo\Core\WebSocket\Submission;
+use Espo\Entities\Template;
+use Espo\ORM\Entity;
+use Espo\ORM\EntityManager;
+use Espo\ORM\Name\Attribute;
+use Espo\ORM\Repository\Option\SaveOptions;
+
+/**
+ * Update app params when a first template is added.
+ *
+ * @implements AfterSave<Template>
+ */
+class WebSocketSubmit implements AfterSave
+{
+ public function __construct(
+ private Submission $submission,
+ private EntityManager $entityManager,
+ ) {}
+
+ public function afterSave(Entity $entity, SaveOptions $options): void
+ {
+ if (!$entity->isNew()) {
+ return;
+ }
+
+ $another = $this->entityManager
+ ->getRDBRepositoryByClass(Template::class)
+ ->where([
+ Attribute::ID . '!=' => $entity->getId(),
+ Template::FIELD_ENTITY_TYPE => $entity->getEntityType(),
+ ])
+ ->findOne();
+
+ if ($another) {
+ return;
+ }
+
+ $this->submission->submit('appParamsUpdate');
+ }
+}
diff --git a/application/Espo/Resources/metadata/app/webSocket.json b/application/Espo/Resources/metadata/app/webSocket.json
index 62c14dae1b..80bba55265 100644
--- a/application/Espo/Resources/metadata/app/webSocket.json
+++ b/application/Espo/Resources/metadata/app/webSocket.json
@@ -1,6 +1,7 @@
{
"categories": {
"newNotification": {},
+ "appParamsUpdate": {},
"recordUpdate": {
"paramList": ["scope", "id"],
"accessCheckCommand": "AclCheck --userId=:userId --scope=:scope --id=:id --action=read"
diff --git a/client/src/app.js b/client/src/app.js
index e88ed9f287..438c785e8e 100644
--- a/client/src/app.js
+++ b/client/src/app.js
@@ -557,6 +557,8 @@ class App {
this.acl.implementationClassMap = aclImplementationClassMap;
this.initRouter();
+
+ this.webSocketManager.subscribe('appParamsUpdate', () => this.appParams.load());
}
/**