Skip to content

EspoCRM – Open Source CRM Application

Record service CRUD methods returning Result objects

Yuriief8274314186
diff --git a/application/Espo/Core/Action/Service.php b/application/Espo/Core/Action/Service.php
index 35ff72169e..30421f872b 100644
--- a/application/Espo/Core/Action/Service.php
+++ b/application/Espo/Core/Action/Service.php
@@ -36,6 +36,7 @@ use Espo\Core\Exceptions\Forbidden;
use Espo\Core\Exceptions\ForbiddenSilent;
use Espo\Core\Exceptions\NotFound;
use Espo\Core\Record\ReadParams;
+use Espo\Core\Record\ReadResult;
use Espo\Core\Record\ServiceContainer as RecordServiceContainer;
use Espo\ORM\Entity;
@@ -58,7 +59,7 @@ class Service
* @throws NotFound
* @throws Conflict
*/
- public function process(string $entityType, string $action, string $id, stdClass $data): Entity
+ public function process(string $entityType, string $action, string $id, stdClass $data): ReadResult
{
if (!$this->acl->checkScope($entityType)) {
throw new ForbiddenSilent();
diff --git a/application/Espo/Core/Controllers/RecordBase.php b/application/Espo/Core/Controllers/RecordBase.php
index 53c1635ff8..8427f6dc2f 100644
--- a/application/Espo/Core/Controllers/RecordBase.php
+++ b/application/Espo/Core/Controllers/RecordBase.php
@@ -40,7 +40,6 @@ 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;
@@ -159,9 +158,9 @@ class RecordBase extends Base implements
throw new BadRequest("No ID.");
}
- $entity = $this->getRecordService()->read($id, $params);
+ $result = $this->getRecordService()->read($id, $params);
- return $entity->getValueMap();
+ return $result->getValueMap();
}
/**
@@ -181,9 +180,9 @@ class RecordBase extends Base implements
$data = $request->getParsedBody();
$params = $this->createParamsFetcher->fetch($request);
- $entity = $this->getRecordService()->create($data, $params);
+ $result = $this->getRecordService()->create($data, $params);
- return $entity->getValueMap();
+ return $result->getValueMap();
}
/**
@@ -223,17 +222,13 @@ class RecordBase extends Base implements
$params = $this->updateParamsFetcher->fetch($request);
- $context = new UpdateContext();
+ $result = $this->getRecordService()->update($id, $data, $params);
- $params = $params->withContext($context);
-
- $entity = $this->getRecordService()->update($id, $data, $params);
-
- if ($context->linkUpdated) {
+ if ($result->isLinkUpdated()) {
$response->setHeader('X-Record-Link-Updated', 'true');
}
- return $entity->getValueMap();
+ return $result->getValueMap();
}
/**
diff --git a/application/Espo/Core/Record/CreateResult.php b/application/Espo/Core/Record/CreateResult.php
new file mode 100644
index 0000000000..f9b6a19773
--- /dev/null
+++ b/application/Espo/Core/Record/CreateResult.php
@@ -0,0 +1,76 @@
+<?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;
+
+use Espo\ORM\Entity;
+use stdClass;
+
+/**
+ * @template TEntity of Entity = Entity
+ * @since 9.4.0
+ */
+class CreateResult
+{
+ /**
+ * @param TEntity $entity
+ */
+ public function __construct(
+ private Entity $entity,
+ ) {}
+
+ public function getValueMap(): stdClass
+ {
+ return $this->entity->getValueMap();
+ }
+
+ /**
+ * @return TEntity
+ */
+ public function getEntity(): Entity
+ {
+ return $this->entity;
+ }
+
+ /**
+ * @deprecated Since 9.4.0. For bc. Use entity->get(...).
+ */
+ public function getId(): string
+ {
+ return $this->entity->getId();
+ }
+
+ /**
+ * @deprecated Since 9.4.0. For bc. Use entity->get(...).
+ */
+ public function get(string $name): mixed
+ {
+ return $this->entity->get($name);
+ }
+}
diff --git a/application/Espo/Core/Record/Crud.php b/application/Espo/Core/Record/Crud.php
index 8209e3ad3c..0242f5f638 100644
--- a/application/Espo/Core/Record/Crud.php
+++ b/application/Espo/Core/Record/Crud.php
@@ -41,26 +41,26 @@ interface Crud
/**
* Create a record.
*
- * @return TEntity
+ * @return CreateResult<TEntity>
*/
- public function create(stdClass $data, CreateParams $params): Entity;
+ public function create(stdClass $data, CreateParams $params): CreateResult;
/**
* Read a record.
*
- * @return TEntity
+ * @return ReadResult<TEntity>
*/
- public function read(string $id, ReadParams $params): Entity;
+ public function read(string $id, ReadParams $params): ReadResult;
/**
* Update a record.
*
- * @return TEntity
+ * @return UpdateResult<TEntity>
*/
- public function update(string $id, stdClass $data, UpdateParams $params): Entity;
+ public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult;
/**
* Delete a record.
*/
- public function delete(string $id, DeleteParams $params): void;
+ public function delete(string $id, DeleteParams $params): DeleteResult;
}
diff --git a/application/Espo/Core/Record/UpdateContext.php b/application/Espo/Core/Record/DeleteResult.php
similarity index 92%
rename from application/Espo/Core/Record/UpdateContext.php
rename to application/Espo/Core/Record/DeleteResult.php
index e0d6ee5166..64ddd3cbf9 100644
--- a/application/Espo/Core/Record/UpdateContext.php
+++ b/application/Espo/Core/Record/DeleteResult.php
@@ -30,12 +30,12 @@
namespace Espo\Core\Record;
/**
- * @internal
- * @todo Remove in v10.0. Use UpdateResult.
+ * For potential future use.
+ *
+ * @since 9.4.0
*/
-class UpdateContext
+class DeleteResult
{
public function __construct(
- public bool $linkUpdated = false,
) {}
}
diff --git a/application/Espo/Core/Record/ReadResult.php b/application/Espo/Core/Record/ReadResult.php
new file mode 100644
index 0000000000..c896b5f913
--- /dev/null
+++ b/application/Espo/Core/Record/ReadResult.php
@@ -0,0 +1,68 @@
+<?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;
+
+use Espo\ORM\Entity;
+use stdClass;
+
+/**
+ * @template TEntity of Entity = Entity
+ * @since 9.4.0
+ */
+readonly class ReadResult
+{
+ /**
+ * @param TEntity $entity
+ */
+ public function __construct(
+ private Entity $entity,
+ ) {}
+
+ /**
+ * @return TEntity
+ */
+ public function getEntity(): Entity
+ {
+ return $this->entity;
+ }
+
+ public function getValueMap(): stdClass
+ {
+ return $this->entity->getValueMap();
+ }
+
+ /**
+ * @deprecated Since 9.4.0. For bc. Use entity->get(...).
+ */
+ public function get(string $name): mixed
+ {
+ return $this->entity->get($name);
+ }
+}
diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php
index a0f999351c..7780a0f9bc 100644
--- a/application/Espo/Core/Record/Service.php
+++ b/application/Espo/Core/Record/Service.php
@@ -210,13 +210,13 @@ class Service implements Crud,
* Is not supposed to be directly used in customizations.
*
* @param non-empty-string $id
- * @return TEntity
+ * @return ReadResult<TEntity>
* @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): Entity
+ public function read(string $id, ReadParams $params): ReadResult
{
if ($id === '') {
throw new InvalidArgumentException();
@@ -235,7 +235,7 @@ class Service implements Crud,
$this->getRecordHookManager()->processBeforeRead($entity, $params);
$this->processActionHistoryRecord(Action::READ, $entity);
- return $entity;
+ return new ReadResult($entity);
}
/**
@@ -665,14 +665,12 @@ class Service implements Crud,
*
* Is not supposed to be directly used in customizations.
*
- * @return TEntity
+ * @return CreateResult<TEntity>
* @throws BadRequest
* @throws Forbidden If no create access.
* @throws Conflict
- * @noinspection PhpDocSignatureInspection
- * @todo In v10.0, return CreateResult instead of Entity.
*/
- public function create(stdClass $data, CreateParams $params): Entity
+ public function create(stdClass $data, CreateParams $params): CreateResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_CREATE)) {
throw new ForbiddenSilent("No create access.");
@@ -683,7 +681,7 @@ class Service implements Crud,
$this->filterCreateInput($data);
$this->sanitizeInput($data);
- $entity->set($data);
+ $entity->setMultiple($data);
$this->populateDefaults($entity, $data);
$this->getRecordHookManager()->processEarlyBeforeCreate($entity, $params);
@@ -724,7 +722,7 @@ class Service implements Crud,
$this->prepareEntityForOutput($entity);
$this->processActionHistoryRecord(Action::CREATE, $entity);
- return $entity;
+ return new CreateResult($entity);
}
/**
@@ -732,15 +730,13 @@ class Service implements Crud,
*
* Is not supposed to be directly used in customizations.
*
- * @return TEntity
+ * @return UpdateResult<TEntity>
* @throws NotFound If record not found.
* @throws Forbidden If no access.
* @throws Conflict
* @throws BadRequest
- * @noinspection PhpDocSignatureInspection
- * @todo In v10.0, return UpdateResult instead of Entity.
*/
- public function update(string $id, stdClass $data, UpdateParams $params): Entity
+ public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) {
throw new ForbiddenSilent("No edit access.");
@@ -771,7 +767,7 @@ class Service implements Crud,
throw new ForbiddenSilent("No edit access.");
}
- $entity->set($data);
+ $entity->setMultiple($data);
if ($params->getVersionNumber() !== null) {
$this->processConcurrencyControl($entity, $params->getVersionNumber());
@@ -817,11 +813,10 @@ class Service implements Crud,
$this->prepareEntityForOutput($entity);
$this->processActionHistoryRecord(Action::UPDATE, $entity);
- if ($context->isLinkUpdated() && $params->getContext()) {
- $params->getContext()->linkUpdated = true;
- }
-
- return $entity;
+ return new UpdateResult(
+ entity: $entity,
+ linkUpdated: $context->isLinkUpdated(),
+ );
}
/**
@@ -834,7 +829,7 @@ class Service implements Crud,
* @throws NotFound
* @throws Conflict
*/
- public function delete(string $id, DeleteParams $params): void
+ public function delete(string $id, DeleteParams $params): DeleteResult
{
if (!$this->acl->check($this->entityType, AclTable::ACTION_DELETE)) {
throw new ForbiddenSilent("No delete access.");
@@ -864,6 +859,8 @@ class Service implements Crud,
$this->afterDeleteEntity($entity);
$this->getRecordHookManager()->processAfterDelete($entity, $params);
$this->processActionHistoryRecord(Action::DELETE, $entity);
+
+ return new DeleteResult();
}
/**
diff --git a/application/Espo/Core/Record/UpdateParams.php b/application/Espo/Core/Record/UpdateParams.php
index 9f50e089aa..f481fb4895 100644
--- a/application/Espo/Core/Record/UpdateParams.php
+++ b/application/Espo/Core/Record/UpdateParams.php
@@ -37,8 +37,6 @@ class UpdateParams
private bool $skipDuplicateCheck = false;
private ?int $versionNumber = null;
- private ?UpdateContext $context = null;
-
public function __construct() {}
public function withSkipDuplicateCheck(bool $skipDuplicateCheck = true): self
@@ -71,25 +69,4 @@ 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;
- }
}
diff --git a/application/Espo/Core/Record/UpdateResult.php b/application/Espo/Core/Record/UpdateResult.php
new file mode 100644
index 0000000000..16ee68d052
--- /dev/null
+++ b/application/Espo/Core/Record/UpdateResult.php
@@ -0,0 +1,75 @@
+<?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;
+
+use Espo\ORM\Entity;
+use stdClass;
+
+/**
+ * @template TEntity of Entity = Entity
+ * @since 9.4.0
+ */
+class UpdateResult
+{
+ /**
+ * @param TEntity $entity An entity.
+ * @param bool $linkUpdated Whether the update caused link updates.
+ */
+ public function __construct(
+ private Entity $entity,
+ private bool $linkUpdated = false,
+ ) {}
+
+ /**
+ * @return TEntity
+ */
+ public function getEntity(): Entity
+ {
+ return $this->entity;
+ }
+
+ public function getValueMap(): stdClass
+ {
+ return $this->entity->getValueMap();
+ }
+
+ /**
+ * @deprecated Since 9.4.0. For bc. Use entity->get(...).
+ */
+ public function get(string $name): mixed
+ {
+ return $this->entity->get($name);
+ }
+
+ public function isLinkUpdated(): bool
+ {
+ return $this->linkUpdated;
+ }
+}
diff --git a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
index d5274b593f..8a499e9e2c 100644
--- a/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
+++ b/application/Espo/Modules/Crm/Tools/Lead/ConvertService.php
@@ -284,7 +284,7 @@ class ConvertService
$service = $this->recordServiceContainer->getByClass(Account::class);
- $account = $service->create($values, CreateParams::create()->withSkipDuplicateCheck());
+ $account = $service->create($values, CreateParams::create()->withSkipDuplicateCheck())->getEntity();
$lead->setCreatedAccount($account);
@@ -326,7 +326,7 @@ class ConvertService
$service = $this->recordServiceContainer->getByClass(Contact::class);
- $contact = $service->create($values, CreateParams::create()->withSkipDuplicateCheck());
+ $contact = $service->create($values, CreateParams::create()->withSkipDuplicateCheck())->getEntity();
$lead->set('createdContactId', $contact->getId());
@@ -373,7 +373,7 @@ class ConvertService
$service = $this->recordServiceContainer->getByClass(Opportunity::class);
- $opportunity = $service->create($values, CreateParams::create()->withSkipDuplicateCheck());
+ $opportunity = $service->create($values, CreateParams::create()->withSkipDuplicateCheck())->getEntity();
if ($contact) {
$this->entityManager
diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php
index de4249588c..da997f30d2 100644
--- a/application/Espo/Services/Email.php
+++ b/application/Espo/Services/Email.php
@@ -29,6 +29,7 @@
namespace Espo\Services;
+use Espo\Core\Record\CreateResult;
use Espo\Tools\Email\SendService;
use Espo\ORM\Entity;
use Espo\Entities\Email as EmailEntity;
@@ -68,15 +69,14 @@ class Email extends Record
* @throws BadRequest
* @throws SendingError
*/
- public function create(stdClass $data, CreateParams $params): Entity
+ public function create(stdClass $data, CreateParams $params): CreateResult
{
- /** @var EmailEntity $entity */
- $entity = parent::create($data, $params);
+ $result = parent::create($data, $params);
- if ($entity->getStatus() === EmailEntity::STATUS_SENDING) {
- $this->getSendService()->send($entity, $this->user);
+ if ($result->getEntity()->getStatus() === EmailEntity::STATUS_SENDING) {
+ $this->getSendService()->send($result->getEntity(), $this->user);
}
- return $entity;
+ return $result;
}
}
diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php
index 2afddd9d92..377e3e3a81 100644
--- a/application/Espo/Services/ExternalAccount.php
+++ b/application/Espo/Services/ExternalAccount.php
@@ -29,6 +29,7 @@
namespace Espo\Services;
+use Espo\Core\Record\ReadResult;
use Espo\ORM\Entity;
use Espo\Core\ExternalAccount\Clients\OAuth2Abstract;
use Espo\Core\ExternalAccount\ClientManager;
@@ -149,7 +150,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware
return true;
}
- public function read(string $id, ReadParams $params): Entity
+ public function read(string $id, ReadParams $params): ReadResult
{
[, $userId] = explode('__', $id);
@@ -157,7 +158,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware
throw new Forbidden();
}
- $entity = $this->entityManager->getEntityById(ExternalAccountEntity::ENTITY_TYPE, $id);
+ $entity = $this->entityManager->getRDBRepositoryByClass(ExternalAccountEntity::class)->getById($id);
if (!$entity) {
throw new NotFoundSilent();
@@ -172,6 +173,6 @@ class ExternalAccount extends Record implements Di\HookManagerAware
$entity->clear($a);
}
- return $entity;
+ return new ReadResult($entity);
}
}
diff --git a/application/Espo/Services/RecordTree.php b/application/Espo/Services/RecordTree.php
index d0bdc2d582..8f47bec979 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\UpdateResult;
use Espo\Core\Templates\Entities\CategoryTree;
use Espo\ORM\Collection;
use Espo\ORM\Entity;
@@ -365,7 +366,7 @@ class RecordTree extends Record
}
}
- public function update(string $id, stdClass $data, UpdateParams $params): Entity
+ public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
{
if (!empty($data->parentId) && $data->parentId === $id) {
throw new Forbidden();
diff --git a/application/Espo/Services/User.php b/application/Espo/Services/User.php
index 0428c10203..2acd691bba 100644
--- a/application/Espo/Services/User.php
+++ b/application/Espo/Services/User.php
@@ -32,6 +32,8 @@ namespace Espo\Services;
use Espo\Core\Di\LogAware;
use Espo\Core\Di\LogSetter;
use Espo\Core\Mail\Exceptions\SendingError;
+use Espo\Core\Record\CreateResult;
+use Espo\Core\Record\UpdateResult;
use Espo\Entities\User as UserEntity;
use Espo\Core\Exceptions\BadRequest;
use Espo\Core\Exceptions\Forbidden;
@@ -79,7 +81,7 @@ class User extends Record implements LogAware
return $password;
}
- public function create(stdClass $data, CreateParams $params): Entity
+ public function create(stdClass $data, CreateParams $params): CreateResult
{
$newPassword = $this->fetchPassword($data);
@@ -100,20 +102,22 @@ class User extends Record implements LogAware
$data->password = $this->hashPassword($newPassword);
- /** @var UserEntity $user */
- $user = parent::create($data, $params);
+ $result = parent::create($data, $params);
+
+ $user = $result->getEntity();
+
$sendAccessInfo = !empty($data->sendAccessInfo);
if (!$sendAccessInfo || !$user->isActive() || $user->isApi()) {
- return $user;
+ return $result;
}
try {
if ($passwordSpecified) {
$this->sendPassword($user, $newPassword);
- return $user;
+ return $result;
}
$this->getPasswordService()->sendAccessInfoForNewUser($user);
@@ -121,10 +125,10 @@ class User extends Record implements LogAware
$this->log->error("Could not send user access info. " . $e->getMessage());
}
- return $user;
+ return $result;
}
- public function update(string $id, stdClass $data, UpdateParams $params): Entity
+ public function update(string $id, stdClass $data, UpdateParams $params): UpdateResult
{
$newPassword = null;
@@ -144,8 +148,9 @@ class User extends Record implements LogAware
unset($data->type);
}
- /** @var UserEntity $user */
- $user = parent::update($id, $data, $params);
+ $result = parent::update($id, $data, $params);
+
+ $user = $result->getEntity();
if (!is_null($newPassword)) {
try {
@@ -155,7 +160,7 @@ class User extends Record implements LogAware
} catch (Exception) {}
}
- return $user;
+ return $result;
}
private function getPasswordService(): PasswordService
diff --git a/tests/integration/Espo/Account/CreateTest.php b/tests/integration/Espo/Account/CreateTest.php
index fefb8a4ada..b6fac875da 100644
--- a/tests/integration/Espo/Account/CreateTest.php
+++ b/tests/integration/Espo/Account/CreateTest.php
@@ -51,7 +51,7 @@ class CreateTest extends \tests\integration\Core\BaseTestCase
'phoneNumber' => '+14333633333',
], CreateParams::create());
- $this->assertInstanceOf('Espo\\ORM\\Entity', $entity);
+ $this->assertInstanceOf('Espo\\ORM\\Entity', $entity->getEntity());
$this->assertTrue(!empty($entity->getId()));
}
}
diff --git a/tests/integration/Espo/Record/AssignmentTest.php b/tests/integration/Espo/Record/AssignmentTest.php
index f50c5a83eb..2faadc12e1 100644
--- a/tests/integration/Espo/Record/AssignmentTest.php
+++ b/tests/integration/Espo/Record/AssignmentTest.php
@@ -70,7 +70,7 @@ class AssignmentTest extends BaseTestCase
->getByClass(Lead::class)
->create((object) [
'lastName' => 'Test 1',
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals($user1->getId(), $lead1->getAssignedUser()?->getId());
$this->assertEquals([$team1->getId()], $lead1->getLinkMultipleIdList('teams'));
diff --git a/tests/integration/Espo/Record/DefaultsPopulatorTest.php b/tests/integration/Espo/Record/DefaultsPopulatorTest.php
index 3541499613..42d4b85f4c 100644
--- a/tests/integration/Espo/Record/DefaultsPopulatorTest.php
+++ b/tests/integration/Espo/Record/DefaultsPopulatorTest.php
@@ -81,11 +81,11 @@ class DefaultsPopulatorTest extends BaseTestCase
$service = $this->getContainer()->getByClass(ServiceContainer::class)->getByClass(CaseObj::class);
- $case = $service->create((object) [
+ $result = $service->create((object) [
'name' => 'Test',
], CreateParams::create());
- $this->assertEquals($contact->getId(), $case->getContact()?->getId());
- $this->assertEquals($account->getId(), $case->getAccount()?->getId());
+ $this->assertEquals($contact->getId(), $result->getEntity()->getContact()?->getId());
+ $this->assertEquals($account->getId(), $result->getEntity()->getAccount()?->getId());
}
}
diff --git a/tests/integration/Espo/Record/EntityDuplicatorTest.php b/tests/integration/Espo/Record/EntityDuplicatorTest.php
index cf135265e4..177fe61106 100644
--- a/tests/integration/Espo/Record/EntityDuplicatorTest.php
+++ b/tests/integration/Espo/Record/EntityDuplicatorTest.php
@@ -74,7 +74,7 @@ class EntityDuplicatorTest extends BaseTestCase
'parentId' => $account->getId(),
'parentType' => $account->getEntityType(),
'assignedUserId' => $user->getId(),
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals($email->getId(), $task->get('emailId'));
diff --git a/tests/integration/Espo/Record/FieldValidationTest.php b/tests/integration/Espo/Record/FieldValidationTest.php
index 498355a677..756f83431e 100644
--- a/tests/integration/Espo/Record/FieldValidationTest.php
+++ b/tests/integration/Espo/Record/FieldValidationTest.php
@@ -95,7 +95,8 @@ class FieldValidationTest extends BaseTestCase
'name' => 'test'
],
CreateParams::create()
- );
+ )
+ ->getEntity();
$this->expectException(BadRequest::class);
@@ -549,7 +550,7 @@ class FieldValidationTest extends BaseTestCase
$account = $service->create((object) [
'name' => 'Test',
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$isThrown = false;
diff --git a/tests/integration/Espo/Record/LinkTest.php b/tests/integration/Espo/Record/LinkTest.php
index 3e1a511c63..9500b5610f 100644
--- a/tests/integration/Espo/Record/LinkTest.php
+++ b/tests/integration/Espo/Record/LinkTest.php
@@ -169,7 +169,7 @@ class LinkTest extends BaseTestCase
'accountId' => $account1->getId(),
'parentType' => $account1->getEntityType(),
'assignedUserId' => $user->getId(),
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$isThrown = false;
@@ -197,7 +197,7 @@ class LinkTest extends BaseTestCase
$taskService->update($task1->getId(), (object) [
'parentId' => $account2->getId(),
'parentType' => $account2->getEntityType(),
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
}
catch (Forbidden) {
$isThrown = true;
@@ -441,7 +441,7 @@ class LinkTest extends BaseTestCase
'name' => '1',
'contactId' => $contact->getId(),
'contactsIds' => [$contact->getId()],
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals(
(object) [
@@ -453,7 +453,7 @@ class LinkTest extends BaseTestCase
/** @noinspection PhpUnhandledExceptionInspection */
$case = $caseService->update($case->getId(), (object) [
'contactsIds' => [$contact->getId(), $contact1->getId()],
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals(
(object) [
diff --git a/tests/integration/Espo/Record/ReadOnlyTest.php b/tests/integration/Espo/Record/ReadOnlyTest.php
index ce5b808ba8..34d3934750 100644
--- a/tests/integration/Espo/Record/ReadOnlyTest.php
+++ b/tests/integration/Espo/Record/ReadOnlyTest.php
@@ -62,7 +62,7 @@ class ReadOnlyTest extends BaseTestCase
$account = $service->create((object) [
'name' => 'Test',
'type' => 'Customer',
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('Test', $account->get('name'));
$this->assertNull($account->get('type'));
@@ -70,7 +70,7 @@ class ReadOnlyTest extends BaseTestCase
$account = $service->update($account->getId(), (object) [
'name' => 'Test 1',
'billingAddressCity' => 'Hello',
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals('Test', $account->get('name'));
$this->assertEquals('Hello', $account->get('billingAddressCity'));
@@ -108,7 +108,7 @@ class ReadOnlyTest extends BaseTestCase
$account = $service->create((object) [
'name' => 'Test',
'description' => '1',
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$service->update($account->getId(), (object) [
'type' => 'Customer',
diff --git a/tests/integration/Espo/Record/RestoreDeletedTest.php b/tests/integration/Espo/Record/RestoreDeletedTest.php
index 3905878bc3..f2d6503481 100644
--- a/tests/integration/Espo/Record/RestoreDeletedTest.php
+++ b/tests/integration/Espo/Record/RestoreDeletedTest.php
@@ -46,7 +46,7 @@ class RestoreDeletedTest extends \tests\integration\Core\BaseTestCase
$account = $service->create((object) [
'name' => 'Test'
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$service->delete($account->getId(), DeleteParams::create());
@@ -67,13 +67,13 @@ class RestoreDeletedTest extends \tests\integration\Core\BaseTestCase
$account = $service->create((object) [
'name' => 'Test'
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$service->delete($account->getId(), DeleteParams::create());
$service->restoreDeleted($account->getId());
- $account = $service->read($account->getId(), ReadParams::create());
+ $account = $service->read($account->getId(), ReadParams::create())->getEntity();
$this->assertNotNull($account);
diff --git a/tests/integration/Espo/Record/SanitizeTest.php b/tests/integration/Espo/Record/SanitizeTest.php
index 354b688c80..83fd3efd84 100644
--- a/tests/integration/Espo/Record/SanitizeTest.php
+++ b/tests/integration/Espo/Record/SanitizeTest.php
@@ -78,7 +78,7 @@ class SanitizeTest extends BaseTestCase
' test ',
'hello',
],
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$numbers = $account->getPhoneNumberGroup()->getNumberList();
$this->assertCount(1, $numbers);
@@ -103,7 +103,7 @@ class SanitizeTest extends BaseTestCase
],
'description' => 'Test',
'cArray' => null,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('Test', $account->get('description'));
$this->assertEquals([], $account->get('cArray'));
@@ -141,7 +141,7 @@ class SanitizeTest extends BaseTestCase
'phoneNumber' => '+380904443366 # 1000',
],
],
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$numbers = $account->getPhoneNumberGroup()->getNumberList();
$this->assertCount(5, $numbers);
@@ -165,7 +165,7 @@ class SanitizeTest extends BaseTestCase
'dateStart' => '2030-12-10 10:11:12',
'dateEnd' => '2030-12-10T10:11:12-01:00',
'assignedUserId' => $user->getId(),
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('2030-12-10 10:11:12', $meeting->get('dateStart'));
$this->assertEquals('2030-12-10 11:11:12', $meeting->get('dateEnd'));
@@ -181,7 +181,7 @@ class SanitizeTest extends BaseTestCase
'dateStartDate' => '2030-12-10T10:11:12-01:00',
'dateEnd' => '2030-12-10T10:11:12-01:00',
'assignedUserId' => $user->getId(),
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('2030-12-10', $task->get('dateStartDate'));
$this->assertEquals('2030-12-10 11:11:12', $task->get('dateEnd'));
@@ -194,7 +194,7 @@ class SanitizeTest extends BaseTestCase
'name' => 'Test',
'dateStartDate' => '2030-12-10',
'assignedUserId' => $user->getId(),
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('2030-12-10', $task->get('dateStartDate'));
@@ -210,7 +210,7 @@ class SanitizeTest extends BaseTestCase
'assignedUserId' => $user->getId(),
'probability' => 10,
'amount' => 1.0,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('2030-12-10', $meeting->get('closeDate'));
@@ -224,7 +224,7 @@ class SanitizeTest extends BaseTestCase
'assignedUserId' => $user->getId(),
'probability' => 10,
'amount' => 1.0,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals('2030-12-10', $meeting->get('closeDate'));
}
diff --git a/tests/integration/Espo/Role/ServiceTest.php b/tests/integration/Espo/Role/ServiceTest.php
index 2ec8db6049..aedf32a411 100644
--- a/tests/integration/Espo/Role/ServiceTest.php
+++ b/tests/integration/Espo/Role/ServiceTest.php
@@ -73,7 +73,7 @@ class ServiceTest extends BaseTestCase
'name' => 'Test',
'data' => $data,
'fieldData' => $fieldData,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals($data, $role->get('data'));
$this->assertEquals($fieldData, $role->get('fieldData'));
@@ -82,7 +82,7 @@ class ServiceTest extends BaseTestCase
$role = $service->update($role->getId(), (object) [
'data' => (object) [],
'fieldData' => (object) [],
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals((object) [], $role->get('data'));
$this->assertEquals((object) [], $role->get('fieldData'));
@@ -91,7 +91,7 @@ class ServiceTest extends BaseTestCase
$role = $service->update($role->getId(), (object) [
'data' => $data,
'fieldData' => $fieldData,
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals($data, $role->get('data'));
$this->assertEquals($fieldData, $role->get('fieldData'));
@@ -129,7 +129,7 @@ class ServiceTest extends BaseTestCase
'name' => 'Test',
'data' => $data,
'fieldData' => $fieldData,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals($data, $role->get('data'));
$this->assertEquals($fieldData, $role->get('fieldData'));
@@ -138,7 +138,7 @@ class ServiceTest extends BaseTestCase
$role = $service->update($role->getId(), (object) [
'data' => (object) [],
'fieldData' => (object) [],
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals((object) [], $role->get('data'));
$this->assertEquals((object) [], $role->get('fieldData'));
@@ -147,7 +147,7 @@ class ServiceTest extends BaseTestCase
$role = $service->update($role->getId(), (object) [
'data' => $data,
'fieldData' => $fieldData,
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals($data, $role->get('data'));
$this->assertEquals($fieldData, $role->get('fieldData'));
diff --git a/tests/integration/Espo/Stream/AuditTest.php b/tests/integration/Espo/Stream/AuditTest.php
index bc1a45a2d6..0aa8d7cfd3 100644
--- a/tests/integration/Espo/Stream/AuditTest.php
+++ b/tests/integration/Espo/Stream/AuditTest.php
@@ -93,7 +93,7 @@ class AuditTest extends BaseTestCase
$article = $service->create((object) [
'name' => 'Test 1',
'publishDate' => '2025-01-01',
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
/** @noinspection PhpUnhandledExceptionInspection */
$service->update($article->getId(), (object) [
diff --git a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php b/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
index 5fed1613c2..f16f49c7f9 100644
--- a/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
+++ b/tests/integration/Espo/Tools/Pipeline/PipelineTest.php
@@ -95,7 +95,7 @@ class PipelineTest extends BaseTestCase
Field::NAME => 'Test 1',
Pipeline::FIELD_ENTITY_TYPE => Opportunity::ENTITY_TYPE,
Pipeline::FIELD_IS_AVAILABLE_FOR_ALL => false,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertCount(6, $pipeline1->getStages());
@@ -106,7 +106,7 @@ class PipelineTest extends BaseTestCase
Pipeline::FIELD_ENTITY_TYPE => Opportunity::ENTITY_TYPE,
Pipeline::FIELD_IS_AVAILABLE_FOR_ALL => false,
Field::TEAMS . 'Ids' => [$team->getId()],
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
foreach ($pipeline2->getStages() as $stage) {
$pipelineStageService->delete($stage->getId(), DeleteParams::create());
@@ -157,12 +157,12 @@ class PipelineTest extends BaseTestCase
Field::PIPELINE_STAGE . 'Id' => $pipeline1->getStages()[0]->getId(),
Opportunity::FIELD_CLOSED_DATE => Date::fromString('2026-01-01')->toString(),
Opportunity::FIELD_AMOUNT => 1000,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$opp = $oppService->update($opp->getId(), (object) [
Field::PIPELINE . 'Id' => $pipeline2->getId(),
Field::PIPELINE_STAGE . 'Id' => $pipeline2->getStages()[0]->getId(),
- ], UpdateParams::create());
+ ], UpdateParams::create())->getEntity();
$this->assertEquals('Prospecting', $opp->getStage());
@@ -174,7 +174,7 @@ class PipelineTest extends BaseTestCase
Field::PIPELINE_STAGE . 'Id' => $pipeline1->getStages()[4]->getId(),
Opportunity::FIELD_CLOSED_DATE => Date::fromString('2026-01-01')->toString(),
Opportunity::FIELD_AMOUNT => 1000,
- ], CreateParams::create());
+ ], CreateParams::create())->getEntity();
$this->assertEquals(Opportunity::STAGE_CLOSED_WON, $opp->getStage());