Skip to content

EspoCRM – Open Source CRM Application

record service signture changes

Yuriic5f7bed0e59e
diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php
index 5de4b85e06..dd4379e4f8 100644
--- a/application/Espo/Core/Controllers/Record.php
+++ b/application/Espo/Core/Controllers/Record.php
@@ -90,7 +90,13 @@ class Record extends RecordBase
if (!empty($data->massRelate)) {
$searchParams = $this->fetchMassLinkSearchParamsFromRequest($request);
- return $this->getRecordService()->massLink($id, $link, $searchParams);
+ $result = $this->getRecordService()->massLink($id, $link, $searchParams);
+
+ if ($result->getAffectedCount() === 0) {
+ return false;
+ }
+
+ return true;
}
$foreignIdList = [];
diff --git a/application/Espo/Core/Record/LinkResult.php b/application/Espo/Core/Record/LinkResult.php
new file mode 100644
index 0000000000..63f146b016
--- /dev/null
+++ b/application/Espo/Core/Record/LinkResult.php
@@ -0,0 +1,36 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 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\Core\Record;
+
+/**
+ * @since 9.4.0
+ */
+class LinkResult
+{}
diff --git a/application/Espo/Core/Record/MassLinkResult.php b/application/Espo/Core/Record/MassLinkResult.php
new file mode 100644
index 0000000000..4f2767d46d
--- /dev/null
+++ b/application/Espo/Core/Record/MassLinkResult.php
@@ -0,0 +1,45 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 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\Core\Record;
+
+/**
+ * @since 9.4.0
+ */
+class MassLinkResult
+{
+ public function __construct(
+ private ?int $affectedCount = null,
+ ) {}
+
+ public function getAffectedCount(): ?int
+ {
+ return $this->affectedCount;
+ }
+}
diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php
index 7780a0f9bc..edb8f40b4e 100644
--- a/application/Espo/Core/Record/Service.php
+++ b/application/Espo/Core/Record/Service.php
@@ -214,9 +214,8 @@ class Service implements Crud,
* @throws NotFoundSilent If not found.
* @throws Forbidden If no read access.
* @noinspection PhpDocSignatureInspection
- * @todo In v10.0, return ReadResult instead of Entity.
*/
- public function read(string $id, ReadParams $params): ReadResult
+ public function read(string $id, ReadParams $params = new ReadParams()): ReadResult
{
if ($id === '') {
throw new InvalidArgumentException();
@@ -670,7 +669,7 @@ class Service implements Crud,
* @throws Forbidden If no create access.
* @throws Conflict
*/
- public function create(stdClass $data, CreateParams $params): CreateResult
+ public function create(stdClass $data, CreateParams $params = new CreateParams()): CreateResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_CREATE)) {
throw new ForbiddenSilent("No create access.");
@@ -736,7 +735,7 @@ class Service implements Crud,
* @throws Conflict
* @throws BadRequest
*/
- public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
+ public function update(string $id, stdClass $data, UpdateParams $params = new UpdateParams()): UpdateResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) {
throw new ForbiddenSilent("No edit access.");
@@ -829,7 +828,7 @@ class Service implements Crud,
* @throws NotFound
* @throws Conflict
*/
- public function delete(string $id, DeleteParams $params): DeleteResult
+ public function delete(string $id, DeleteParams $params = new DeleteParams()): DeleteResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_DELETE)) {
throw new ForbiddenSilent("No delete access.");
@@ -1122,7 +1121,7 @@ class Service implements Crud,
* @throws Forbidden
* @throws NotFound
*/
- public function link(string $id, string $link, string $foreignId): void
+ public function link(string $id, string $link, string $foreignId): LinkResult
{
if (!$this->acl->check($this->entityType)) {
throw new Forbidden();
@@ -1167,6 +1166,8 @@ class Service implements Crud,
->relate($foreignEntity, null, [SaveOption::API => true]);
$this->getRecordHookManager()->processAfterLink($entity, $link, $foreignEntity);
+
+ return new LinkResult();
}
/**
@@ -1176,7 +1177,7 @@ class Service implements Crud,
* @throws Forbidden
* @throws NotFound
*/
- public function unlink(string $id, string $link, string $foreignId): void
+ public function unlink(string $id, string $link, string $foreignId): UnlinkResult
{
if (!$this->acl->check($this->entityType)) {
throw new Forbidden();
@@ -1221,6 +1222,8 @@ class Service implements Crud,
->unrelate($foreignEntity, [SaveOption::API => true]);
$this->getRecordHookManager()->processAfterUnlink($entity, $link, $foreignEntity);
+
+ return new UnlinkResult();
}
@@ -1229,7 +1232,7 @@ class Service implements Crud,
* @throws Forbidden
* @throws NotFound
*/
- public function massLink(string $id, string $link, SearchParams $searchParams): bool
+ public function massLink(string $id, string $link, SearchParams $searchParams): MassLinkResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) {
throw new Forbidden();
@@ -1283,7 +1286,9 @@ class Service implements Crud,
->getRelation($entity, $link)
->massRelate($query, [SaveOption::API => true]);
- return true;
+ return new MassLinkResult(
+ affectedCount: null,
+ );
}
// @todo Apply access control filter if $accessActionRequired === 'read'. For better performance.
@@ -1308,11 +1313,9 @@ class Service implements Crud,
$countRelated++;
}
- if ($countRelated) {
- return true;
- }
-
- return false;
+ return new MassLinkResult(
+ affectedCount: $countRelated,
+ );
}
/**
@@ -1684,7 +1687,6 @@ class Service implements Crud,
/**
* @param TEntity $entity
- * @noinspection PhpDocSignatureInspection
* @throws Conflict
* @throws BadRequest
* @throws Forbidden
@@ -1697,67 +1699,57 @@ class Service implements Crud,
}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @param stdClass $data
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function beforeCreateEntity(Entity $entity, $data)
+ protected function beforeCreateEntity(Entity $entity, stdClass $data): void
{}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @param stdClass $data
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function afterCreateEntity(Entity $entity, $data)
+ protected function afterCreateEntity(Entity $entity, stdClass $data): void
{}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @param stdClass $data
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function beforeUpdateEntity(Entity $entity, $data)
+ protected function beforeUpdateEntity(Entity $entity, stdClass $data): void
{}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @param stdClass $data
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function afterUpdateEntity(Entity $entity, $data)
+ protected function afterUpdateEntity(Entity $entity, stdClass $data): void
{}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function beforeDeleteEntity(Entity $entity)
+ protected function beforeDeleteEntity(Entity $entity): void
{}
/**
+ * Use a recordDefs hook instead.
+ *
* @param TEntity $entity
- * @return void
- * @noinspection PhpDocSignatureInspection
- * @deprecated As of v8.2.
- * @todo Remove (or add types) in v10.0.
+ * @internal
*/
- protected function afterDeleteEntity(Entity $entity)
+ protected function afterDeleteEntity(Entity $entity): void
{}
private function createBinding(): BindingContainer
diff --git a/application/Espo/Core/Record/UnlinkResult.php b/application/Espo/Core/Record/UnlinkResult.php
new file mode 100644
index 0000000000..a5f8427b63
--- /dev/null
+++ b/application/Espo/Core/Record/UnlinkResult.php
@@ -0,0 +1,36 @@
+<?php
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM – Open Source CRM application.
+ * Copyright (C) 2014-2026 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\Core\Record;
+
+/**
+ * @since 9.4.0
+ */
+class UnlinkResult
+{}
diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php
index da997f30d2..9cf062217a 100644
--- a/application/Espo/Services/Email.php
+++ b/application/Espo/Services/Email.php
@@ -69,7 +69,7 @@ class Email extends Record
* @throws BadRequest
* @throws SendingError
*/
- public function create(stdClass $data, CreateParams $params): CreateResult
+ public function create(stdClass $data, CreateParams $params = new CreateParams()): CreateResult
{
$result = parent::create($data, $params);
diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php
index 377e3e3a81..5be020a485 100644
--- a/application/Espo/Services/ExternalAccount.php
+++ b/application/Espo/Services/ExternalAccount.php
@@ -150,7 +150,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware
return true;
}
- public function read(string $id, ReadParams $params): ReadResult
+ public function read(string $id, ReadParams $params = new ReadParams()): ReadResult
{
[, $userId] = explode('__', $id);
diff --git a/application/Espo/Services/RecordTree.php b/application/Espo/Services/RecordTree.php
index 8f47bec979..6e905a2e96 100644
--- a/application/Espo/Services/RecordTree.php
+++ b/application/Espo/Services/RecordTree.php
@@ -32,6 +32,7 @@ namespace Espo\Services;
use Espo\Core\Acl\Table;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Name\Field;
+use Espo\Core\Record\LinkResult;
use Espo\Core\Record\UpdateResult;
use Espo\Core\Templates\Entities\CategoryTree;
use Espo\ORM\Collection;
@@ -298,7 +299,7 @@ class RecordTree extends Record
* @throws Error
* @todo Refactor.
*/
- protected function beforeCreateEntity(Entity $entity, $data)
+ protected function beforeCreateEntity(Entity $entity, stdClass $data): void
{
parent::beforeCreateEntity($entity, $data);
@@ -319,7 +320,7 @@ class RecordTree extends Record
* @throws Forbidden
* @throws BadRequest
*/
- protected function beforeDeleteEntity(Entity $entity)
+ protected function beforeDeleteEntity(Entity $entity): void
{
parent::beforeDeleteEntity($entity);
@@ -345,7 +346,7 @@ class RecordTree extends Record
/**
* @throws Forbidden
*/
- protected function beforeUpdateEntity(Entity $entity, $data)
+ protected function beforeUpdateEntity(Entity $entity, stdClass $data): void
{
parent::beforeUpdateEntity($entity, $data);
@@ -366,7 +367,7 @@ class RecordTree extends Record
}
}
- public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
+ public function update(string $id, stdClass $data, UpdateParams $params = new UpdateParams()): UpdateResult
{
if (!empty($data->parentId) && $data->parentId === $id) {
throw new Forbidden();
@@ -375,13 +376,13 @@ class RecordTree extends Record
return parent::update($id, $data, $params);
}
- public function link(string $id, string $link, string $foreignId): void
+ public function link(string $id, string $link, string $foreignId): LinkResult
{
if ($id == $foreignId) {
throw new Forbidden();
}
- parent::link($id, $link, $foreignId);
+ return parent::link($id, $link, $foreignId);
}
/**
diff --git a/application/Espo/Services/User.php b/application/Espo/Services/User.php
index 2acd691bba..61842152da 100644
--- a/application/Espo/Services/User.php
+++ b/application/Espo/Services/User.php
@@ -81,7 +81,7 @@ class User extends Record implements LogAware
return $password;
}
- public function create(stdClass $data, CreateParams $params): CreateResult
+ public function create(stdClass $data, CreateParams $params = new CreateParams()): CreateResult
{
$newPassword = $this->fetchPassword($data);
@@ -128,7 +128,7 @@ class User extends Record implements LogAware
return $result;
}
- public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
+ public function update(string $id, stdClass $data, UpdateParams $params = new UpdateParams()): UpdateResult
{
$newPassword = null;