type fixes

This commit is contained in:
Yuri Kuznetsov
2021-11-03 15:27:08 +02:00
parent 786e267e93
commit 9c677463f2
5 changed files with 40 additions and 25 deletions
@@ -33,7 +33,7 @@ use Espo\Core\InjectableFactory;
trait InjectableFactorySetter
{
/*
/**
* @var InjectableFactory
*/
protected $injectableFactory;
+8 -6
View File
@@ -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);
}
+18 -14
View File
@@ -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) {
+1 -1
View File
@@ -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();
+12 -3
View File
@@ -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();
}
}