From 2ecfdc2d4bfb16c8684b54183f2d6c0e1c214c2b Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Fri, 24 Jun 2022 11:06:01 +0300 Subject: [PATCH] exceptions --- application/Espo/Core/Application.php | 1 - .../Espo/Core/Authentication/Logins/LDAP.php | 2 + .../Espo/Core/Console/Commands/Upgrade.php | 5 ++ application/Espo/Core/Controllers/Record.php | 27 ++++++++- .../Espo/Core/Controllers/RecordBase.php | 39 +++++++++++++ .../Espo/Core/Controllers/RecordTree.php | 5 ++ application/Espo/Core/Formula/Evaluator.php | 1 + .../Espo/Core/Formula/FunctionFactory.php | 1 + .../Espo/Core/Formula/Functions/Base.php | 1 + .../Core/Formula/Functions/BaseFunction.php | 1 + .../Functions/DatetimeGroup/DiffType.php | 2 + .../EntityGroup/GetLinkColumnType.php | 2 + .../EntityGroup/HasLinkMultipleIdType.php | 2 + .../EntityGroup/IsAttributeChangedType.php | 3 + .../EntityGroup/IsAttributeNotChangedType.php | 1 + .../Functions/EntityGroup/IsNewType.php | 1 + .../Functions/EntityGroup/IsRelatedType.php | 2 + .../EntityGroup/RemoveLinkMultipleIdType.php | 2 + .../Functions/EntityGroup/SumRelatedType.php | 2 + .../Functions/JsonGroup/RetrieveType.php | 2 + .../Formula/Functions/SetAttributeType.php | 2 + .../Functions/StringGroup/SplitType.php | 3 + application/Espo/Core/Formula/Manager.php | 1 + application/Espo/Core/Formula/Processor.php | 2 + .../Espo/Core/Record/SearchParamsFetcher.php | 10 ++++ application/Espo/Core/Record/Service.php | 56 +++++++++++++------ .../Espo/Core/Record/ServiceContainer.php | 1 - application/Espo/ORM/SqlExecutor.php | 3 + application/Espo/ORM/TransactionManager.php | 4 ++ application/Espo/Repositories/User.php | 5 +- application/Espo/Services/Email.php | 52 ++++++++++++----- application/Espo/Services/EmailTemplate.php | 2 + application/Espo/Services/Integration.php | 9 +++ application/Espo/Services/Layout.php | 19 ++++++- application/Espo/Services/Note.php | 1 + application/Espo/Services/Pdf.php | 22 +++++--- application/Espo/Services/Record.php | 3 +- application/Espo/Tools/Export/Export.php | 4 +- 38 files changed, 254 insertions(+), 47 deletions(-) diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 1c2c146d60..b5e4f41f51 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -160,7 +160,6 @@ class Application /** * Setup the system user. The system user is used when no user is logged in. - * @throws Exceptions\Error */ public function setupSystemUser(): void { diff --git a/application/Espo/Core/Authentication/Logins/LDAP.php b/application/Espo/Core/Authentication/Logins/LDAP.php index e9c874a594..a392e129c3 100644 --- a/application/Espo/Core/Authentication/Logins/LDAP.php +++ b/application/Espo/Core/Authentication/Logins/LDAP.php @@ -408,6 +408,8 @@ class LDAP implements Login /** * Find LDAP user DN by his username. + * + * @throws \Laminas\Ldap\Exception\LdapException */ private function findLdapUserDnByUsername(string $username): ?string { diff --git a/application/Espo/Core/Console/Commands/Upgrade.php b/application/Espo/Core/Console/Commands/Upgrade.php index 51da7122a6..58a1103dae 100644 --- a/application/Espo/Core/Console/Commands/Upgrade.php +++ b/application/Espo/Core/Console/Commands/Upgrade.php @@ -302,6 +302,9 @@ class Upgrade implements Command return $upgradeId; } + /** + * @throws Error + */ private function runUpgradeProcess(string $upgradeId, ?stdClass $params = null): void { $params = $params ?? (object) []; @@ -324,6 +327,7 @@ class Upgrade implements Command /** * @param string[] $stepList + * @throws Error */ private function runStepsInSingleProcess(string $upgradeId, array $stepList): void { @@ -350,6 +354,7 @@ class Upgrade implements Command /** * @param string[] $stepList + * @throws Error */ private function runSteps(string $upgradeId, array $stepList): void { diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index 347adf4688..7e5cbda039 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -31,6 +31,9 @@ namespace Espo\Core\Controllers; use Espo\Core\Exceptions\BadRequest; use Espo\Core\Api\Request; +use Espo\Core\Exceptions\Forbidden; +use Espo\Core\Exceptions\NotFound; +use Espo\Core\Exceptions\NotFoundSilent; use Espo\Core\Select\SearchParams; use Espo\Core\Utils\Json; @@ -40,6 +43,10 @@ class Record extends RecordBase { /** * List related records. + * + * @throws BadRequest + * @throws NotFound + * @throws Forbidden */ public function getActionListLinked(Request $request): stdClass { @@ -66,6 +73,10 @@ class Record extends RecordBase /** * Relate records. + * + * @throws BadRequest + * @throws Forbidden + * @throws NotFound */ public function postActionCreateLink(Request $request): bool { @@ -108,7 +119,11 @@ class Record extends RecordBase } /** - * Unrelate records. + * Un-relate records. + * + * @throws BadRequest + * @throws Forbidden + * @throws NotFound */ public function deleteActionRemoveLink(Request $request): bool { @@ -146,6 +161,10 @@ class Record extends RecordBase /** * Follow a record. + * + * @throws BadRequest + * @throws NotFoundSilent + * @throws Forbidden */ public function putActionFollow(Request $request): bool { @@ -162,6 +181,9 @@ class Record extends RecordBase /** * Unfollow a record. + * + * @throws NotFoundSilent + * @throws BadRequest */ public function deleteActionUnfollow(Request $request): bool { @@ -176,6 +198,9 @@ class Record extends RecordBase return true; } + /** + * @throws BadRequest + */ private function fetchMassLinkSearchParamsFromRequest(Request $request): SearchParams { $data = $request->getParsedBody(); diff --git a/application/Espo/Core/Controllers/RecordBase.php b/application/Espo/Core/Controllers/RecordBase.php index 397ce77099..8acca918a1 100644 --- a/application/Espo/Core/Controllers/RecordBase.php +++ b/application/Espo/Core/Controllers/RecordBase.php @@ -32,6 +32,9 @@ namespace Espo\Core\Controllers; use Espo\Core\Exceptions\Forbidden; use Espo\Core\Exceptions\BadRequest; +use Espo\Core\Exceptions\ForbiddenSilent; +use Espo\Core\Exceptions\NotFound; +use Espo\Core\Exceptions\NotFoundSilent; use Espo\Core\Record\ServiceContainer as RecordServiceContainer; use Espo\Core\Record\SearchParamsFetcher; use Espo\Core\Record\CreateParamsFetcher; @@ -163,6 +166,10 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac /** * Read a record. + * + * @throws NotFoundSilent + * @throws ForbiddenSilent + * @throws BadRequest */ public function getActionRead(Request $request, Response $response): stdClass { @@ -185,6 +192,10 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac /** * Create a record. + * + * @throws Forbidden + * @throws \Espo\Core\Exceptions\Conflict + * @throws BadRequest */ public function postActionCreate(Request $request, Response $response): stdClass { @@ -201,6 +212,12 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac return $entity->getValueMap(); } + /** + * @throws BadRequest + * @throws NotFound + * @throws Forbidden + * @throws \Espo\Core\Exceptions\Conflict + */ public function patchActionUpdate(Request $request, Response $response): stdClass { return $this->putActionUpdate($request, $response); @@ -208,6 +225,11 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac /** * Update a record. + * + * @throws BadRequest + * @throws NotFound + * @throws Forbidden + * @throws \Espo\Core\Exceptions\Conflict */ public function putActionUpdate(Request $request, Response $response): stdClass { @@ -232,6 +254,8 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac /** * List records. + * + * @throws Forbidden */ public function getActionList(Request $request, Response $response): stdClass { @@ -253,6 +277,10 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac /** * Delete a record. + * + * @throws Forbidden + * @throws BadRequest + * @throws NotFound */ public function deleteActionDelete(Request $request, Response $response): bool { @@ -278,6 +306,12 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac return $this->searchParamsFetcher->fetch($request); } + /** + * @throws BadRequest + * @throws Forbidden + * @throws NotFound + * @throws ForbiddenSilent + */ public function postActionGetDuplicateAttributes(Request $request): stdClass { $id = $request->getParsedBody()->id ?? null; @@ -289,6 +323,11 @@ class RecordBase extends Base implements Di\EntityManagerAware, Di\InjectableFac return $this->getRecordService()->getDuplicateAttributes($id); } + /** + * @throws BadRequest + * @throws Forbidden + * @throws NotFound + */ public function postActionRestoreDeleted(Request $request): bool { if (!$this->user->isAdmin()) { diff --git a/application/Espo/Core/Controllers/RecordTree.php b/application/Espo/Core/Controllers/RecordTree.php index 4f06980a4e..72b6ad2467 100644 --- a/application/Espo/Core/Controllers/RecordTree.php +++ b/application/Espo/Core/Controllers/RecordTree.php @@ -47,6 +47,11 @@ class RecordTree extends Record /** * Get a category tree. + * + * @throws BadRequest + * @throws Error + * @throws Forbidden + * @throws \Espo\Core\Exceptions\NotFound */ public function getActionListTree(Request $request): stdClass { diff --git a/application/Espo/Core/Formula/Evaluator.php b/application/Espo/Core/Formula/Evaluator.php index ae6ff8a209..e8cc97d5a4 100644 --- a/application/Espo/Core/Formula/Evaluator.php +++ b/application/Espo/Core/Formula/Evaluator.php @@ -72,6 +72,7 @@ class Evaluator /** * @return mixed + * @throws Exceptions\Error */ public function process(string $expression, ?Entity $entity = null, ?stdClass $variables = null) { diff --git a/application/Espo/Core/Formula/FunctionFactory.php b/application/Espo/Core/Formula/FunctionFactory.php index 90ef0ae950..f8c7071f4c 100644 --- a/application/Espo/Core/Formula/FunctionFactory.php +++ b/application/Espo/Core/Formula/FunctionFactory.php @@ -67,6 +67,7 @@ class FunctionFactory /** * @return \Espo\Core\Formula\Functions\BaseFunction|\Espo\Core\Formula\Functions\Base + * @throws UnknownFunction */ public function create(string $name, ?Entity $entity = null, ?stdClass $variables = null): object { diff --git a/application/Espo/Core/Formula/Functions/Base.php b/application/Espo/Core/Formula/Functions/Base.php index 64ac1fb435..7383f0713c 100644 --- a/application/Espo/Core/Formula/Functions/Base.php +++ b/application/Espo/Core/Formula/Functions/Base.php @@ -126,6 +126,7 @@ abstract class Base implements Injectable /** * @return mixed + * @throws \Espo\Core\Formula\Exceptions\Error */ public abstract function process(stdClass $item); diff --git a/application/Espo/Core/Formula/Functions/BaseFunction.php b/application/Espo/Core/Formula/Functions/BaseFunction.php index bce3643492..e213ec31a8 100644 --- a/application/Espo/Core/Formula/Functions/BaseFunction.php +++ b/application/Espo/Core/Formula/Functions/BaseFunction.php @@ -90,6 +90,7 @@ abstract class BaseFunction * Evaluates a function. * * @return mixed A result of the function. + * @throws \Espo\Core\Formula\Exceptions\Error */ public abstract function process(ArgumentList $args); diff --git a/application/Espo/Core/Formula/Functions/DatetimeGroup/DiffType.php b/application/Espo/Core/Formula/Functions/DatetimeGroup/DiffType.php index 6a63d51c32..a57ebbf5cc 100644 --- a/application/Espo/Core/Formula/Functions/DatetimeGroup/DiffType.php +++ b/application/Espo/Core/Formula/Functions/DatetimeGroup/DiffType.php @@ -52,6 +52,8 @@ class DiffType extends BaseFunction /** * @return ?int + * @throws \Espo\Core\Formula\Exceptions\TooFewArguments + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(ArgumentList $args) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php index bd8eb16448..12734330d4 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/GetLinkColumnType.php @@ -47,6 +47,8 @@ class GetLinkColumnType extends \Espo\Core\Formula\Functions\Base implements /** * @return mixed + * @throws Error + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php b/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php index 4e4093d8f7..b47a49b1c5 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/HasLinkMultipleIdType.php @@ -35,6 +35,8 @@ class HasLinkMultipleIdType extends \Espo\Core\Formula\Functions\Base { /** * @return bool + * @throws Error + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php index 7ca003905a..79cb074623 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeChangedType.php @@ -35,6 +35,8 @@ class IsAttributeChangedType extends \Espo\Core\Formula\Functions\Base { /** * @return bool + * @throws Error + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(\stdClass $item) { @@ -50,6 +52,7 @@ class IsAttributeChangedType extends \Espo\Core\Formula\Functions\Base /** * @param string $attribute * @return bool + * @throws Error */ protected function check($attribute) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php index 303b713ddd..b3e11bbf4d 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsAttributeNotChangedType.php @@ -34,6 +34,7 @@ class IsAttributeNotChangedType extends IsAttributeChangedType /** * @param string $attribute * @return bool + * @throws \Espo\Core\Exceptions\Error */ protected function check($attribute) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php index f61e0e8f2a..f0fbd89fce 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsNewType.php @@ -33,6 +33,7 @@ class IsNewType extends \Espo\Core\Formula\Functions\Base { /** * @return bool + * @throws \Espo\Core\Exceptions\Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php index c56744626d..065b9f197e 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/IsRelatedType.php @@ -47,6 +47,8 @@ class IsRelatedType extends \Espo\Core\Formula\Functions\Base implements /** * @return bool + * @throws \Espo\Core\Formula\Exceptions\Error + * @throws Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php b/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php index a252e3f8c1..6c83f9d1e3 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/RemoveLinkMultipleIdType.php @@ -35,6 +35,8 @@ class RemoveLinkMultipleIdType extends \Espo\Core\Formula\Functions\Base { /** * @return void + * @throws \Espo\Core\Formula\Exceptions\Error + * @throws Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php index b05474fe33..6c868dea08 100644 --- a/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php +++ b/application/Espo/Core/Formula/Functions/EntityGroup/SumRelatedType.php @@ -45,6 +45,8 @@ class SumRelatedType extends \Espo\Core\Formula\Functions\Base implements /** * @return float + * @throws Error + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/JsonGroup/RetrieveType.php b/application/Espo/Core/Formula/Functions/JsonGroup/RetrieveType.php index c158c938bb..01991a4939 100644 --- a/application/Espo/Core/Formula/Functions/JsonGroup/RetrieveType.php +++ b/application/Espo/Core/Formula/Functions/JsonGroup/RetrieveType.php @@ -38,6 +38,8 @@ class RetrieveType extends BaseFunction { /** * @return mixed + * @throws \Espo\Core\Formula\Exceptions\TooFewArguments + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(ArgumentList $args) { diff --git a/application/Espo/Core/Formula/Functions/SetAttributeType.php b/application/Espo/Core/Formula/Functions/SetAttributeType.php index 67c5f01f5e..8dbd44c749 100644 --- a/application/Espo/Core/Formula/Functions/SetAttributeType.php +++ b/application/Espo/Core/Formula/Functions/SetAttributeType.php @@ -35,6 +35,8 @@ class SetAttributeType extends Base { /** * @return mixed + * @throws \Espo\Core\Formula\Exceptions\Error + * @throws Error */ public function process(\stdClass $item) { diff --git a/application/Espo/Core/Formula/Functions/StringGroup/SplitType.php b/application/Espo/Core/Formula/Functions/StringGroup/SplitType.php index ada394a644..6c8f7f0c99 100644 --- a/application/Espo/Core/Formula/Functions/StringGroup/SplitType.php +++ b/application/Espo/Core/Formula/Functions/StringGroup/SplitType.php @@ -36,6 +36,9 @@ class SplitType extends BaseFunction { /** * @return string[] + * @throws \Espo\Core\Formula\Exceptions\TooFewArguments + * @throws \Espo\Core\Formula\Exceptions\BadArgumentType + * @throws \Espo\Core\Formula\Exceptions\Error */ public function process(ArgumentList $args) { diff --git a/application/Espo/Core/Formula/Manager.php b/application/Espo/Core/Formula/Manager.php index 08d88998bb..49a5659822 100644 --- a/application/Espo/Core/Formula/Manager.php +++ b/application/Espo/Core/Formula/Manager.php @@ -56,6 +56,7 @@ class Manager * Executes a script and returns its result. * * @return mixed + * @throws Exceptions\Error */ public function run(string $script, ?Entity $entity = null, ?stdClass $variables = null) { diff --git a/application/Espo/Core/Formula/Processor.php b/application/Espo/Core/Formula/Processor.php index 2f7c8bb1f5..2e4f4d4b30 100644 --- a/application/Espo/Core/Formula/Processor.php +++ b/application/Espo/Core/Formula/Processor.php @@ -74,6 +74,7 @@ class Processor * Evaluates an argument or argument list. * * @return mixed A result of evaluation. An array if an argument list was passed. + * @throws Error */ public function process(Evaluatable $item) { @@ -101,6 +102,7 @@ class Processor /** * @return mixed[] + * @throws Error */ private function processList(ArgumentList $args): array { diff --git a/application/Espo/Core/Record/SearchParamsFetcher.php b/application/Espo/Core/Record/SearchParamsFetcher.php index a7d790c51e..7db649025e 100644 --- a/application/Espo/Core/Record/SearchParamsFetcher.php +++ b/application/Espo/Core/Record/SearchParamsFetcher.php @@ -54,6 +54,10 @@ class SearchParamsFetcher $this->textMetadataProvider = $textMetadataProvider; } + /** + * @throws BadRequest + * @throws Forbidden + */ public function fetch(Request $request): SearchParams { return SearchParams::fromRaw( @@ -63,6 +67,8 @@ class SearchParamsFetcher /** * @return array + * @throws BadRequest + * @throws Forbidden */ private function fetchRaw(Request $request): array { @@ -77,6 +83,7 @@ class SearchParamsFetcher /** * @return array + * @throws BadRequest */ private function fetchRawJsonSearchParams(Request $request): array { @@ -166,6 +173,8 @@ class SearchParamsFetcher /** * @param array $params + * @throws BadRequest + * @throws Forbidden */ private function handleRawParams(array &$params, Request $request): void { @@ -207,6 +216,7 @@ class SearchParamsFetcher /** * @param array $params + * @throws Forbidden */ private function handleMaxSize(array &$params): void { diff --git a/application/Espo/Core/Record/Service.php b/application/Espo/Core/Record/Service.php index 6f9a0ba1d8..ace39cad87 100644 --- a/application/Espo/Core/Record/Service.php +++ b/application/Espo/Core/Record/Service.php @@ -539,6 +539,7 @@ class Service implements Crud, /** * @param TEntity $entity + * @throws \Espo\Core\Exceptions\Conflict */ protected function processConcurrencyControl(Entity $entity, stdClass $data, int $versionNumber): void { @@ -580,6 +581,7 @@ class Service implements Crud, /** * @param TEntity $entity + * @throws \Espo\Core\Exceptions\Conflict */ protected function processDuplicateCheck(Entity $entity, stdClass $data): void { @@ -662,9 +664,10 @@ class Service implements Crud, /** * Create a record. * - * @throws ForbiddenSilent If no create access. - * * @return TEntity + * @throws BadRequest + * @throws Forbidden If no create access. + * @throws \Espo\Core\Exceptions\Conflict */ public function create(stdClass $data, CreateParams $params): Entity { @@ -685,7 +688,6 @@ class Service implements Crud, } $this->processValidation($entity, $data); - $this->processAssignmentCheck($entity); if (!$params->skipDuplicateCheck()) { @@ -710,11 +712,11 @@ class Service implements Crud, /** * Update a record. * - * @throws BadRequest - * @throws NotFound If record not found. - * @throws Forbidden If no access. - * * @return TEntity + * @throws NotFound If record not found. + * @throws Forbidden If no access + * @throws \Espo\Core\Exceptions\Conflict + * @throws BadRequest */ public function update(string $id, stdClass $data, UpdateParams $params): Entity { @@ -748,7 +750,6 @@ class Service implements Crud, $entity->set($data); $this->processValidation($entity, $data); - $this->processAssignmentCheck($entity); $checkForDuplicates = @@ -760,15 +761,12 @@ class Service implements Crud, } $this->recordHookManager->processBeforeUpdate($entity, $params); - $this->beforeUpdateEntity($entity, $data); $this->entityManager->saveEntity($entity); $this->afterUpdateEntity($entity, $data); - $this->prepareEntityForOutput($entity); - $this->processActionHistoryRecord('update', $entity); return $entity; @@ -802,13 +800,9 @@ class Service implements Crud, } $this->recordHookManager->processBeforeDelete($entity, $params); - $this->beforeDeleteEntity($entity); - $this->getRepository()->remove($entity); - $this->afterDeleteEntity($entity); - $this->processActionHistoryRecord('delete', $entity); } @@ -904,7 +898,9 @@ class Service implements Crud, ->withDeleted() ->build(); - return $this->getRepository()->clone($query)->findOne(); + return $this->getRepository() + ->clone($query) + ->findOne(); } /** @@ -1215,6 +1211,11 @@ class Service implements Crud, $this->getRepository()->unrelate($entity, $link, $foreignEntity); } + /** + * @throws Forbidden + * @throws NotFound + * @throws ForbiddenSilent + */ public function linkFollowers(string $id, string $foreignId): void { if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { @@ -1280,6 +1281,11 @@ class Service implements Crud, } } + /** + * @throws Forbidden + * @throws NotFound + * @throws ForbiddenSilent + */ public function unlinkFollowers(string $id, string $foreignId): void { if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { @@ -1330,6 +1336,11 @@ class Service implements Crud, $this->getStreamService()->unfollowEntity($entity, $foreignId); } + /** + * @throws BadRequest + * @throws Forbidden + * @throws NotFound + */ public function massLink(string $id, string $link, SearchParams $searchParams): bool { if (!$this->acl->check($this->entityType, AclTable::ACTION_EDIT)) { @@ -1418,6 +1429,9 @@ class Service implements Crud, return false; } + /** + * @throws Forbidden + */ protected function processForbiddenLinkReadCheck(string $link): void { $forbiddenLinkList = $this->acl @@ -1440,6 +1454,9 @@ class Service implements Crud, } } + /** + * @throws Forbidden + */ protected function processForbiddenLinkEditCheck(string $link): void { $forbiddenLinkList = $this->acl @@ -1580,6 +1597,7 @@ class Service implements Crud, /** * Prepare an entity for output. Clears not allowed attributes. + * * @param TEntity $entity * @return void */ @@ -1632,6 +1650,12 @@ class Service implements Crud, return $this->injectableFactory->create(EntityDuplicator::class); } + /** + * @throws BadRequest + * @throws Forbidden + * @throws ForbiddenSilent + * @throws NotFound + */ public function getDuplicateAttributes(string $id): stdClass { if (!$id) { diff --git a/application/Espo/Core/Record/ServiceContainer.php b/application/Espo/Core/Record/ServiceContainer.php index 2f2358da39..632f89cbb5 100644 --- a/application/Espo/Core/Record/ServiceContainer.php +++ b/application/Espo/Core/Record/ServiceContainer.php @@ -55,7 +55,6 @@ class ServiceContainer /** * @return Service<\Espo\ORM\Entity> - * @throws Error */ public function get(string $entityType): Service { diff --git a/application/Espo/ORM/SqlExecutor.php b/application/Espo/ORM/SqlExecutor.php index 8d203b30df..6347951f0f 100644 --- a/application/Espo/ORM/SqlExecutor.php +++ b/application/Espo/ORM/SqlExecutor.php @@ -73,6 +73,9 @@ class SqlExecutor $counter--; if ($counter === 0 || !$this->isExceptionIsDeadlock($e)) { + /** + * @var PDOException $e + */ throw $e; } diff --git a/application/Espo/ORM/TransactionManager.php b/application/Espo/ORM/TransactionManager.php index edac2623b4..e40c51f930 100644 --- a/application/Espo/ORM/TransactionManager.php +++ b/application/Espo/ORM/TransactionManager.php @@ -32,6 +32,7 @@ namespace Espo\ORM; use Espo\ORM\QueryComposer\QueryComposer; use PDO; +use PDOException; use RuntimeException; use Throwable; use Closure; @@ -83,6 +84,9 @@ class TransactionManager catch (Throwable $e) { $this->rollback(); + /** + * @var PDOException $e + */ throw $e; } diff --git a/application/Espo/Repositories/User.php b/application/Espo/Repositories/User.php index 66bcb86174..8b0cebcbde 100644 --- a/application/Espo/Repositories/User.php +++ b/application/Espo/Repositories/User.php @@ -45,8 +45,11 @@ use Espo\Entities\UserData; class User extends Database { /** + * @param \Espo\Entities\User $entity * @param array $options * @return void + * @throws Conflict + * @throws Error */ protected function beforeSave(Entity $entity, array $options = []) { @@ -121,7 +124,7 @@ class User extends Database ->select(['id']) ->where([ 'userName' => $userName, - 'id!=' => $entity->id, + 'id!=' => $entity->getId(), ]) ->findOne(); diff --git a/application/Espo/Services/Email.php b/application/Espo/Services/Email.php index 492b2c516e..d83c57065e 100644 --- a/application/Espo/Services/Email.php +++ b/application/Espo/Services/Email.php @@ -165,6 +165,10 @@ class Email extends Record implements return SmtpParams::fromArray($smtpParams); } + /** + * @throws BadRequest + * @throws Error + */ public function sendEntity(EmailEntity $entity, ?User $user = null): void { @@ -420,6 +424,9 @@ class Email extends Record implements } } + /** + * @throws Error + */ public function validateEmailAddresses(EmailEntity $entity): void { $from = $entity->get('from'); @@ -449,13 +456,18 @@ class Email extends Record implements } } + /** + * @throws BadRequest + * @throws Error + * @throws \Espo\Core\Exceptions\ForbiddenSilent + */ public function create(stdClass $data, CreateParams $params): Entity { /** @var EmailEntity */ $entity = parent::create($data, $params); if ($entity->get('status') === EmailEntity::STATUS_SENDING) { - $this->sendEntity($entity, $this->getUser()); + $this->sendEntity($entity, $this->user); } return $entity; @@ -472,12 +484,16 @@ class Email extends Record implements } } + /** + * @throws BadRequest + * @throws Error + */ protected function afterUpdateEntity(Entity $entity, $data) { /** @var EmailEntity $entity */ if ($entity->get('status') === EmailEntity::STATUS_SENDING) { - $this->sendEntity($entity, $this->getUser()); + $this->sendEntity($entity, $this->user); } $this->loadAdditionalFields($entity); @@ -586,7 +602,7 @@ class Email extends Record implements public function markAllAsRead(?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -619,7 +635,7 @@ class Email extends Record implements public function markAsRead(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -640,7 +656,7 @@ class Email extends Record implements public function markAsNotRead(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -659,7 +675,7 @@ class Email extends Record implements public function markAsImportant(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -678,7 +694,7 @@ class Email extends Record implements public function markAsNotImportant(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -697,7 +713,7 @@ class Email extends Record implements public function moveToTrash(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -718,7 +734,7 @@ class Email extends Record implements public function retrieveFromTrash(string $id, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); $update = $this->entityManager->getQueryBuilder()->update() ->in('EmailUser') @@ -755,7 +771,7 @@ class Email extends Record implements public function moveToFolder(string $id, ?string $folderId, ?string $userId = null): bool { - $userId = $userId ?? $this->getUser()->getId(); + $userId = $userId ?? $this->user->getId(); if ($folderId === 'inbox') { $folderId = null; @@ -810,6 +826,11 @@ class Email extends Record implements return $fromAddress; } + /** + * @throws BadRequest + * @throws Forbidden + * @throws NotFound + */ public function getCopiedAttachments( string $id, ?string $parentType = null, @@ -889,6 +910,7 @@ class Email extends Record implements /** * @param array $data * @throws Forbidden + * @throws Error */ public function sendTestEmail(array $data): bool { @@ -904,7 +926,7 @@ class Email extends Record implements $fromAddress = $data['fromAddress'] ?? null; if ($userId) { - if ($userId !== $this->getUser()->getId() && !$this->getUser()->isAdmin()) { + if ($userId !== $this->user->getId() && !$this->user->isAdmin()) { throw new Forbidden(); } } @@ -968,7 +990,7 @@ class Email extends Record implements $skipFilter = false; - if ($this->getUser()->isAdmin()) { + if ($this->user->isAdmin()) { $skipFilter = true; } @@ -1024,7 +1046,7 @@ class Email extends Record implements ->from('Email') ->withAccessControlFilter(); - $draftsSelecBuilder = clone $selectBuilder; + $draftsSelectBuilder = clone $selectBuilder; $selectBuilder->withWhere( WhereItem::fromRaw([ @@ -1038,7 +1060,7 @@ class Email extends Record implements $emailFolderList = $this->entityManager ->getRDBRepository('EmailFolder') ->where([ - 'assignedUserId' => $this->getUser()->getId(), + 'assignedUserId' => $this->user->getId(), ]) ->find(); @@ -1050,7 +1072,7 @@ class Email extends Record implements $itemSelectBuilder = clone $selectBuilder; if ($folderId === 'drafts') { - $itemSelectBuilder = clone $draftsSelecBuilder; + $itemSelectBuilder = clone $draftsSelectBuilder; } $itemSelectBuilder->withWhere( diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index 7efce2f6ab..ab9f587f69 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -101,6 +101,8 @@ class EmailTemplate extends Record implements /** * @param array $params * @return array + * @throws \Espo\Core\Exceptions\ForbiddenSilent + * @throws NotFound */ public function parse(string $id, array $params = [], bool $copyAttachments = false): array { diff --git a/application/Espo/Services/Integration.php b/application/Espo/Services/Integration.php index b9adbd56ca..73571522ed 100644 --- a/application/Espo/Services/Integration.php +++ b/application/Espo/Services/Integration.php @@ -77,6 +77,7 @@ class Integration /** * @return void + * @throws Forbidden */ protected function processAccessCheck() { @@ -85,6 +86,10 @@ class Integration } } + /** + * @throws Forbidden + * @throws NotFound + */ public function read(string $id): Entity { $this->processAccessCheck(); @@ -98,6 +103,10 @@ class Integration return $entity; } + /** + * @throws Forbidden + * @throws NotFound + */ public function update(string $id, stdClass $data): Entity { $this->processAccessCheck(); diff --git a/application/Espo/Services/Layout.php b/application/Espo/Services/Layout.php index bd2606a7aa..ca3cecc10c 100644 --- a/application/Espo/Services/Layout.php +++ b/application/Espo/Services/Layout.php @@ -108,6 +108,8 @@ class Layout /** * @return array|stdClass|null + * @throws NotFound + * @throws Error */ public function getOriginal(string $scope, string $name, ?string $setId = null) { @@ -145,6 +147,7 @@ class Layout * @return mixed * @throws Forbidden * @throws NotFound + * @throws Error */ public function getForFrontend(string $scope, string $name) { @@ -257,6 +260,9 @@ class Layout return $data; } + /** + * @throws NotFound + */ protected function getRecordFromSet( string $scope, string $name, @@ -298,6 +304,8 @@ class Layout /** * @param mixed $data * @return mixed + * @throws NotFound + * @throws Error */ public function update(string $scope, string $name, ?string $setId, $data) { @@ -325,7 +333,6 @@ class Layout $layoutManager = $this->layoutManager; $layoutManager->set($data, $scope, $name); - $layoutManager->save(); $this->dataManager->updateCacheTimestamp(); @@ -335,6 +342,8 @@ class Layout /** * @return array|stdClass|null + * @throws NotFound + * @throws Error */ public function resetToDefault(string $scope, string $name, ?string $setId = null) { @@ -362,6 +371,10 @@ class Layout return $this->getOriginal($scope, $name); } + /** + * @throws Error + * @throws NotFound + */ protected function getOriginalBottomPanelsDetail(string $scope, ?string $setId = null): stdClass { $relationships = $this->getOriginal($scope, 'relationships') ?? []; @@ -398,6 +411,10 @@ class Layout return $result; } + /** + * @throws NotFound + * @throws Error + */ protected function getForFrontendBottomPanelsDetail(string $scope): stdClass { return $this->getOriginalBottomPanelsDetail($scope); diff --git a/application/Espo/Services/Note.php b/application/Espo/Services/Note.php index f0998ac3be..16ffd2acb1 100644 --- a/application/Espo/Services/Note.php +++ b/application/Espo/Services/Note.php @@ -94,6 +94,7 @@ class Note extends Record /** * @param NoteEntity $entity * @param stdClass $data + * @throws Forbidden */ protected function beforeCreateEntity(Entity $entity, $data) { diff --git a/application/Espo/Services/Pdf.php b/application/Espo/Services/Pdf.php index 53a2bec8af..7a8717b96a 100644 --- a/application/Espo/Services/Pdf.php +++ b/application/Espo/Services/Pdf.php @@ -82,7 +82,7 @@ class Pdf private $builder; - private $serviceContanier; + private $serviceContainer; private $dataLoaderManager; @@ -93,7 +93,7 @@ class Pdf Language $defaultLanguage, SelectBuilderFactory $selectBuilderFactory, Builder $builder, - ServiceContainer $serviceContanier, + ServiceContainer $serviceContainer, DataLoaderManager $dataLoaderManager ) { $this->config = $config; @@ -102,12 +102,13 @@ class Pdf $this->defaultLanguage = $defaultLanguage; $this->selectBuilderFactory = $selectBuilderFactory; $this->builder = $builder; - $this->serviceContanier = $serviceContanier; + $this->serviceContainer = $serviceContainer; $this->dataLoaderManager = $dataLoaderManager; } /** * @param iterable $entityList + * @throws Error */ public function generateMailMerge( string $entityType, @@ -127,7 +128,7 @@ class Pdf $idDataMap = IdDataMap::create(); - $service = $this->serviceContanier->get($entityType); + $service = $this->serviceContainer->get($entityType); foreach ($entityList as $entity) { $service->loadAdditionalFields($entity); @@ -185,7 +186,7 @@ class Pdf bool $checkAcl = false ): string { - $service = $this->serviceContanier->get($entityType); + $service = $this->serviceContainer->get($entityType); $maxCount = $this->config->get('massPrintPdfMaxCount'); @@ -309,6 +310,8 @@ class Pdf /** * Generate PDF. ACL check is processed if `$params` is null. + * + * @throws Error */ public function generate(Entity $entity, Template $template, ?Params $params = null, ?Data $data = null): string { @@ -324,8 +327,9 @@ class Pdf } /** - * @deprecated * @param ?array $additionalData + * @throws Error + * @deprecated */ public function buildFromTemplate( Entity $entity, @@ -338,8 +342,10 @@ class Pdf } /** - * @deprecated * @param ?array $additionalData + * @throws Error + * @throws Forbidden + * @deprecated */ private function buildFromTemplateInternal( Entity $entity, @@ -352,7 +358,7 @@ class Pdf $entityType = $entity->getEntityType(); - $service = $this->serviceContanier->get($entityType); + $service = $this->serviceContainer->get($entityType); $service->loadAdditionalFields($entity); diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index 1a17b3dcd1..beb80fbb08 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -260,9 +260,10 @@ class Record extends RecordService implements } /** - * @deprecated * @param array $params * @param Collection $collection + * @throws ForbiddenSilent + * @deprecated */ public function exportCollection(array $params, Collection $collection): string { diff --git a/application/Espo/Tools/Export/Export.php b/application/Espo/Tools/Export/Export.php index 1db5524f3b..8559d153f5 100644 --- a/application/Espo/Tools/Export/Export.php +++ b/application/Espo/Tools/Export/Export.php @@ -38,7 +38,6 @@ use Espo\ORM\BaseEntity; use Espo\Entities\User; use Espo\Core\{ - Exceptions\Error, Utils\Json, Select\SelectBuilderFactory, Acl, @@ -58,6 +57,7 @@ use Espo\{ }; use RuntimeException; +use LogicException; class Export { @@ -138,7 +138,7 @@ class Export public function run(): Result { if (!$this->params) { - throw new Error("No params set."); + throw new LogicException("No params set."); } $params = $this->params;