From 9c677463f230c2a75e5b17ff5ec8d45650fc03d9 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 3 Nov 2021 15:27:08 +0200 Subject: [PATCH] type fixes --- .../Espo/Core/Di/InjectableFactorySetter.php | 2 +- application/Espo/Repositories/Import.php | 14 ++++---- application/Espo/Services/ExternalAccount.php | 32 +++++++++++-------- application/Espo/Services/GlobalSearch.php | 2 +- application/Espo/Services/Import.php | 15 +++++++-- 5 files changed, 40 insertions(+), 25 deletions(-) diff --git a/application/Espo/Core/Di/InjectableFactorySetter.php b/application/Espo/Core/Di/InjectableFactorySetter.php index 6efae1395c..e6fc866f9a 100644 --- a/application/Espo/Core/Di/InjectableFactorySetter.php +++ b/application/Espo/Core/Di/InjectableFactorySetter.php @@ -33,7 +33,7 @@ use Espo\Core\InjectableFactory; trait InjectableFactorySetter { - /* + /** * @var InjectableFactory */ protected $injectableFactory; diff --git a/application/Espo/Repositories/Import.php b/application/Espo/Repositories/Import.php index dfa592e937..1d33f5bb8f 100644 --- a/application/Espo/Repositories/Import.php +++ b/application/Espo/Repositories/Import.php @@ -29,6 +29,8 @@ namespace Espo\Repositories; +use Espo\Entities\Import as ImportEntity; + use Espo\ORM\{ Entity, Query\Select as Query, @@ -39,22 +41,21 @@ use Espo\Core\Repositories\Database; class Import extends Database { - public function findResultRecords(Entity $entity, string $relationName, Query $query): Collection + public function findResultRecords(ImportEntity $entity, string $relationName, Query $query): Collection { $entityType = $entity->get('entityType'); $params = $params ?? []; - $modifiedQuery = $this->addImportEntityJoin($entity, $relationName, $query); return $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->clone($modifiedQuery) ->find(); } - protected function addImportEntityJoin(Entity $entity, string $link, Query $query): Query + protected function addImportEntityJoin(ImportEntity $entity, string $link, Query $query): Query { $entityType = $entity->get('entityType'); @@ -96,7 +97,7 @@ class Import extends Database return $builder->build(); } - public function countResultRecords(Entity $entity, string $relationName, ?Query $query = null): int + public function countResultRecords(ImportEntity $entity, string $relationName, ?Query $query = null): int { $entityType = $entity->get('entityType'); @@ -110,7 +111,7 @@ class Import extends Database $modifiedQuery = $this->addImportEntityJoin($entity, $relationName, $query); return $this->entityManager - ->getRepository($entityType) + ->getRDBRepository($entityType) ->clone($modifiedQuery) ->count(); } @@ -119,6 +120,7 @@ class Import extends Database { if ($entity->get('fileId')) { $attachment = $this->entityManager->getEntity('Attachment', $entity->get('fileId')); + if ($attachment) { $this->entityManager->removeEntity($attachment); } diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php index 4e4087db96..66df1afc03 100644 --- a/application/Espo/Services/ExternalAccount.php +++ b/application/Espo/Services/ExternalAccount.php @@ -43,6 +43,9 @@ use Espo\Core\Record\ReadParams; use Espo\Core\Di; +use Espo\Entities\ExternalAccount as ExternalAccountEntity; +use Espo\Entities\Integration as IntegrationEntity; + use Exception; class ExternalAccount extends Record implements Di\HookManagerAware @@ -51,31 +54,32 @@ class ExternalAccount extends Record implements Di\HookManagerAware protected function getClient(string $integration, string $id) { - $integrationEntity = $this->getEntityManager()->getEntity('Integration', $integration); + /** @var IntegrationEntity $integrationEntity */ + $integrationEntity = $this->entityManager->getEntity('Integration', $integration); if (!$integrationEntity) { throw new NotFound(); } - $d = $integrationEntity->toArray(); + $integrationEntity->toArray(); // ? if (!$integrationEntity->get('enabled')) { throw new Error("{$integration} is disabled."); } $factory = new ClientManager( - $this->getEntityManager(), - $this->getMetadata(), - $this->getConfig(), - $this->getInjection('injectableFactory') + $this->entityManager, + $this->metadata, + $this->config, + $this->injectableFactory ); return $factory->create($integration, $id); } - public function getExternalAccountEntity(string $integration, string $userId) + public function getExternalAccountEntity(string $integration, string $userId): ?ExternalAccountEntity { - return $this->getEntityManager()->getEntity('ExternalAccount', $integration . '__' . $userId); + return $this->entityManager->getEntity('ExternalAccount', $integration . '__' . $userId); } public function ping(string $integration, string $userId) @@ -104,7 +108,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware $entity->set('enabled', true); - $this->getEntityManager()->saveEntity($entity); + $this->entityManager->saveEntity($entity); $client = $this->getClient($integration, $userId); @@ -121,7 +125,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware $entity->set($name, $value); } - $this->getEntityManager()->saveEntity($entity); + $this->entityManager->saveEntity($entity); $this->hookManager->process('ExternalAccount', 'afterConnect', $entity, [ 'integration' => $integration, @@ -144,19 +148,19 @@ class ExternalAccount extends Record implements Di\HookManagerAware { list ($integration, $userId) = explode('__', $id); - if ($this->getUser()->id != $userId && !$this->getUser()->isAdmin()) { + if ($this->getUser()->id != $userId && !$this->user->isAdmin()) { throw new Forbidden(); } - $entity = $this->getEntityManager()->getEntity('ExternalAccount', $id); + $entity = $this->entityManager->getEntity('ExternalAccount', $id); if (!$entity) { throw new NotFoundSilent("Record does not exist."); } - list($integration, $id) = explode('__', $entity->id); + list($integration, $id) = explode('__', $entity->getId()); - $externalAccountSecretAttributeList = $this->getMetadata() + $externalAccountSecretAttributeList = $this->metadata ->get(['integrations', $integration, 'externalAccountSecretAttributeList']) ?? []; foreach ($externalAccountSecretAttributeList as $a) { diff --git a/application/Espo/Services/GlobalSearch.php b/application/Espo/Services/GlobalSearch.php index f22dfd2696..b2ced15d00 100644 --- a/application/Espo/Services/GlobalSearch.php +++ b/application/Espo/Services/GlobalSearch.php @@ -118,7 +118,7 @@ class GlobalSearch implements foreach ($rows as $row) { $entity = $this->entityManager - ->getRepository($row['entityType']) + ->getRDBRepository($row['entityType']) ->select(['id', 'name']) ->where(['id' => $row['id']]) ->findOne(); diff --git a/application/Espo/Services/Import.php b/application/Espo/Services/Import.php index 4a88d8a859..fc87006620 100644 --- a/application/Espo/Services/Import.php +++ b/application/Espo/Services/Import.php @@ -29,6 +29,9 @@ namespace Espo\Services; +use Espo\Repositories\Import as Repository; +use Espo\Entities\Import as ImportEntity; + use Espo\Core\{ Exceptions\Forbidden, Record\Collection as RecordCollection, @@ -46,7 +49,8 @@ class Import extends Record return parent::findLinked($id, $link, $searchParams); } - $entity = $this->getRepository()->get($id); + /** @var ImportEntity $entity */ + $entity = $this->getImportRepository()->get($id); $foreignEntityType = $entity->get('entityType'); @@ -65,7 +69,7 @@ class Import extends Record ->withSearchParams($searchParams) ->build(); - $collection = $this->getRepository()->findResultRecords($entity, $link, $query); + $collection = $this->getImportRepository()->findResultRecords($entity, $link, $query); $listLoadProcessor = $this->injectableFactory->create(ListLoadProcessor::class); @@ -76,8 +80,13 @@ class Import extends Record $recordService->prepareEntityForOutput($e); } - $total = $this->getRepository()->countResultRecords($entity, $link, $query); + $total = $this->getImportRepository()->countResultRecords($entity, $link, $query); return new RecordCollection($collection, $total); } + + private function getImportRepository(): Repository + { + return $this->getRepository(); + } }