types
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
interface EntityManagerAware
|
||||
{
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\ORM\EntityManager;
|
||||
|
||||
trait EntityManagerSetter
|
||||
{
|
||||
|
||||
@@ -118,7 +118,7 @@ class RDBRepository implements Repository
|
||||
])
|
||||
->build();
|
||||
|
||||
/** @var T $entity */
|
||||
/** @var ?T $entity */
|
||||
$entity = $this->getMapper()->selectOne($selectQuery);
|
||||
|
||||
return $entity;
|
||||
@@ -126,6 +126,8 @@ class RDBRepository implements Repository
|
||||
|
||||
/**
|
||||
* Get an entity. If ID is NULL, a new entity is returned.
|
||||
*
|
||||
* @phpstan-return ?T
|
||||
*/
|
||||
public function get(?string $id = null): ?Entity
|
||||
{
|
||||
|
||||
@@ -30,9 +30,7 @@
|
||||
namespace Espo\Repositories;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Entities\Attachment as AttachmentEntity;
|
||||
|
||||
use Espo\Core\Repositories\Database;
|
||||
|
||||
use Espo\Core\Di;
|
||||
@@ -40,8 +38,7 @@ use Espo\Core\Di;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
|
||||
/**
|
||||
* @template T of \Espo\Entities\Attachment
|
||||
* @extends Database<\Espo\Entities\Attachment>
|
||||
* @extends Database<AttachmentEntity>
|
||||
*/
|
||||
class Attachment extends Database implements
|
||||
Di\FileManagerAware,
|
||||
@@ -105,16 +102,18 @@ class Attachment extends Database implements
|
||||
{
|
||||
parent::afterRemove($entity, $options);
|
||||
|
||||
$duplicateCount = $this->where([
|
||||
'OR' => [
|
||||
[
|
||||
'sourceId' => $entity->getSourceId()
|
||||
$duplicateCount = $this
|
||||
->where([
|
||||
'OR' => [
|
||||
[
|
||||
'sourceId' => $entity->getSourceId()
|
||||
],
|
||||
[
|
||||
'id' => $entity->getSourceId()
|
||||
]
|
||||
],
|
||||
[
|
||||
'id' => $entity->getSourceId()
|
||||
]
|
||||
],
|
||||
])->count();
|
||||
])
|
||||
->count();
|
||||
|
||||
if ($duplicateCount === 0) {
|
||||
$this->fileStorageManager->unlink($entity);
|
||||
@@ -136,10 +135,7 @@ class Attachment extends Database implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return AttachmentEntity
|
||||
*/
|
||||
public function getCopiedAttachment(AttachmentEntity $entity, $role = null)
|
||||
public function getCopiedAttachment(AttachmentEntity $entity, $role = null): AttachmentEntity
|
||||
{
|
||||
$attachment = $this->get();
|
||||
|
||||
|
||||
@@ -499,6 +499,7 @@ class Email extends Database implements
|
||||
|
||||
private function getEmailAddressRepository(): EmailAddressRepository
|
||||
{
|
||||
/** @var EmailAddressRepository */
|
||||
return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,6 +139,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements
|
||||
|
||||
public function getByAddress(string $address): ?EmailAddressEntity
|
||||
{
|
||||
/** @var ?EmailAddressEntity */
|
||||
return $this->where(['lower' => strtolower($address)])->findOne();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,13 +31,21 @@ namespace Espo\Repositories;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class ExternalAccount extends \Espo\Core\Repositories\Database
|
||||
use Espo\Core\Repositories\Database;
|
||||
|
||||
use Espo\Entities\ExternalAccount as ExternalAccountEntity;
|
||||
|
||||
/**
|
||||
* @extends Database<ExternalAccountEntity>
|
||||
*/
|
||||
class ExternalAccount extends Database
|
||||
{
|
||||
public function getById(string $id): ?Entity
|
||||
{
|
||||
$entity = parent::getById($id);
|
||||
|
||||
if (!$entity) {
|
||||
/** @var ExternalAccountEntity */
|
||||
$entity = $this->get();
|
||||
|
||||
$entity->set('id', $id);
|
||||
|
||||
@@ -31,13 +31,21 @@ namespace Espo\Repositories;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Integration extends \Espo\Core\Repositories\Database
|
||||
use Espo\Core\Repositories\Database;
|
||||
|
||||
use Espo\Entities\Integration as IntegrationEntity;
|
||||
|
||||
/**
|
||||
* @extends Database<IntegrationEntity>
|
||||
*/
|
||||
class Integration extends Database
|
||||
{
|
||||
public function getById(string $id): ?Entity
|
||||
{
|
||||
$entity = parent::getById($id);
|
||||
|
||||
if (!$entity) {
|
||||
/** @var IntegrationEntity */
|
||||
$entity = $this->get();
|
||||
|
||||
$entity->set('id', $id);
|
||||
|
||||
@@ -37,6 +37,10 @@ use Espo\Core\Repositories\Database;
|
||||
|
||||
use Espo\Core\Di;
|
||||
|
||||
/**
|
||||
* @template T of PhoneNumberEntity
|
||||
* @extends Database<PhoneNumberEntity>
|
||||
*/
|
||||
class PhoneNumber extends Database implements
|
||||
|
||||
Di\ApplicationStateAware,
|
||||
@@ -131,6 +135,7 @@ class PhoneNumber extends Database implements
|
||||
|
||||
public function getByNumber(string $number): ?PhoneNumberEntity
|
||||
{
|
||||
/** @var ?PhoneNumberEntity */
|
||||
return $this->where(['name' => $number])->findOne();
|
||||
}
|
||||
|
||||
|
||||
@@ -168,6 +168,7 @@ class User extends Database
|
||||
|
||||
private function getUserDataRepository(): UserDataRepository
|
||||
{
|
||||
/** @var UserDataRepository */
|
||||
return $this->entityManager->getRepository(UserData::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ class UserData extends \Espo\Core\Repositories\Database
|
||||
{
|
||||
public function getByUserId(string $userId): ?UserDataEntity
|
||||
{
|
||||
/** @var ?UserDataEntity */
|
||||
$userData = $this
|
||||
->where(['userId' => $userId])
|
||||
->findOne();
|
||||
@@ -51,6 +52,7 @@ class UserData extends \Espo\Core\Repositories\Database
|
||||
return null;
|
||||
}
|
||||
|
||||
/** @var ?UserDataEntity */
|
||||
$userData = $this->getNew();
|
||||
|
||||
$userData->set('userId', $userId);
|
||||
|
||||
@@ -372,7 +372,7 @@ class App
|
||||
private function convertPHPSizeToBytes($size)
|
||||
{
|
||||
if (is_numeric($size)) {
|
||||
return $size;
|
||||
return (int) $size;
|
||||
}
|
||||
|
||||
if ($size === false) {
|
||||
@@ -569,11 +569,13 @@ class App
|
||||
|
||||
private function getPhoneNumberRepository(): PhoneNumberRepository
|
||||
{
|
||||
/** @var PhoneNumberRepository */
|
||||
return $this->entityManager->getRepository(PhoneNumber::ENTITY_TYPE);
|
||||
}
|
||||
|
||||
private function getArrayValueRepository(): ArrayValueRepository
|
||||
{
|
||||
/** @var ArrayValueRepository */
|
||||
return $this->entityManager->getRepository(ArrayValue::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -482,6 +482,7 @@ class Attachment extends Record
|
||||
|
||||
private function getAttachmentRepository(): AttachmentRepository
|
||||
{
|
||||
/** @var AttachmentRepository */
|
||||
return $this->getRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1032,16 +1032,19 @@ class Email extends Record implements
|
||||
|
||||
private function getEmailAccountService(): EmailAccountService
|
||||
{
|
||||
/** @var EmailAccountService */
|
||||
return $this->injectableFactory->create(EmailAccountService::class);
|
||||
}
|
||||
|
||||
private function getInboundEmailService(): InboundEmailService
|
||||
{
|
||||
/** @var InboundEmailService */
|
||||
return $this->injectableFactory->create(InboundEmailService::class);
|
||||
}
|
||||
|
||||
private function getUserDataRepository(): UserDataRepository
|
||||
{
|
||||
/** @var UserDataRepository */
|
||||
return $this->entityManager->getRepository(UserData::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -720,6 +720,7 @@ class EmailAccount extends Record implements
|
||||
|
||||
private function getUserDataRepository(): UserDataRepository
|
||||
{
|
||||
/** @var UserDataRepository */
|
||||
return $this->entityManager->getRepository(UserData::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +280,7 @@ class EmailAddress extends Record
|
||||
|
||||
private function getEmailAddressRepository(): Repository
|
||||
{
|
||||
/** @var Repository */
|
||||
return $this->entityManager->getRepository(EmailAddressEntity::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ class EmailTemplate extends Record implements
|
||||
|
||||
private function getEmailAddressRepository(): EmailAddressRepository
|
||||
{
|
||||
/** @var EmailAddressRepository */
|
||||
return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,6 +79,7 @@ class ExternalAccount extends Record implements Di\HookManagerAware
|
||||
|
||||
public function getExternalAccountEntity(string $integration, string $userId): ?ExternalAccountEntity
|
||||
{
|
||||
/** @var ?ExternalAccountEntity */
|
||||
return $this->entityManager->getEntity('ExternalAccount', $integration . '__' . $userId);
|
||||
}
|
||||
|
||||
|
||||
@@ -69,6 +69,7 @@ class Import extends Record
|
||||
->withSearchParams($searchParams)
|
||||
->build();
|
||||
|
||||
/** @var iterable<\Espo\ORM\Entity> */
|
||||
$collection = $this->getImportRepository()->findResultRecords($entity, $link, $query);
|
||||
|
||||
$listLoadProcessor = $this->injectableFactory->create(ListLoadProcessor::class);
|
||||
@@ -87,6 +88,7 @@ class Import extends Record
|
||||
|
||||
private function getImportRepository(): Repository
|
||||
{
|
||||
/** @var Repository */
|
||||
return $this->getRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1105,6 +1105,7 @@ class InboundEmail extends RecordService implements
|
||||
|
||||
public function findAccountForSending(string $emailAddress): ?InboundEmailEntity
|
||||
{
|
||||
/** @var ?InboundEmailEntity */
|
||||
$inboundEmail = $this->entityManager
|
||||
->getRDBRepository('InboundEmail')
|
||||
->where([
|
||||
@@ -1150,6 +1151,7 @@ class InboundEmail extends RecordService implements
|
||||
'distinct' => true,
|
||||
];
|
||||
|
||||
/** @var ?InboundEmailEntity */
|
||||
return $this->entityManager->getRDBRepository('InboundEmail')->findOne($selectParams);;
|
||||
}
|
||||
|
||||
@@ -1163,6 +1165,7 @@ class InboundEmail extends RecordService implements
|
||||
]
|
||||
];
|
||||
|
||||
/** @var ?InboundEmailEntity */
|
||||
return $this->entityManager->getRDBRepository('InboundEmail')->findOne($selectParams);
|
||||
}
|
||||
|
||||
@@ -1371,6 +1374,7 @@ class InboundEmail extends RecordService implements
|
||||
|
||||
private function getEmailTemplateService(): EmailTemplateService
|
||||
{
|
||||
/** @var EmailTemplateService */
|
||||
return $this->injectableFactory->create(EmailTemplateService::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -354,6 +354,7 @@ class Note extends Record
|
||||
|
||||
private function getUserRepository(): UserRepository
|
||||
{
|
||||
/** @var UserRepository */
|
||||
return $this->entityManager->getRepository(UserEntity::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,6 +75,7 @@ class Portal extends Record implements
|
||||
|
||||
private function getPortalRepository(): Repository
|
||||
{
|
||||
/** @var Repository */
|
||||
return $this->getRepository();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,6 +134,7 @@ class Preferences
|
||||
|
||||
$user = $this->entityManager->getEntity('User', $userId);
|
||||
|
||||
/** @var PreferencesEntity */
|
||||
$entity = $this->entityManager->getEntity('Preferences', $userId);
|
||||
|
||||
if (!$entity || !$user) {
|
||||
@@ -213,6 +214,7 @@ class Preferences
|
||||
|
||||
private function getRepository(): Repository
|
||||
{
|
||||
/** @var Repository */
|
||||
return $this->entityManager->getRepository(PreferencesEntity::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,6 +297,7 @@ class Settings
|
||||
|
||||
private function getPortalRepository(): PortalRepository
|
||||
{
|
||||
/** @var PortalRepository */
|
||||
return $this->entityManager->getRepository(Portal::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2245,6 +2245,7 @@ class Stream
|
||||
|
||||
private function getEmailAddressRepository(): EmailAddressRepository
|
||||
{
|
||||
/** @var EmailAddressRepository */
|
||||
return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,6 +263,7 @@ class UserSecurity
|
||||
|
||||
private function getUserDataRepository(): UserDataRepository
|
||||
{
|
||||
/** @var UserDataRepository */
|
||||
return $this->entityManager->getRepository(UserData::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -887,6 +887,7 @@ class Processor
|
||||
|
||||
private function getPortalRepository(): PortalRepository
|
||||
{
|
||||
/** @var PortalRepository */
|
||||
return $this->entityManager->getRepository('Portal');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,6 +420,7 @@ class Processor
|
||||
|
||||
private function getEmailAddressRepository(): EmailAddressRepository
|
||||
{
|
||||
/** @var EmailAddressRepository */
|
||||
return $this->entityManager->getRepository(EmailAddress::ENTITY_TYPE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ class Export
|
||||
private $params;
|
||||
|
||||
/**
|
||||
* @var Collection
|
||||
* @phpstan-var (Collection&iterable<Entity>)|null $collection
|
||||
*/
|
||||
private $collection = null;
|
||||
|
||||
@@ -115,6 +115,9 @@ class Export
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-param Collection&iterable<Entity> $collection
|
||||
*/
|
||||
public function setCollection(Collection $collection): self
|
||||
{
|
||||
$this->collection = $collection;
|
||||
@@ -337,6 +340,9 @@ class Export
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-return Collection&iterable<Entity>
|
||||
*/
|
||||
private function getCollection(Params $params): Collection
|
||||
{
|
||||
if ($this->collection) {
|
||||
@@ -358,8 +364,9 @@ class Export
|
||||
|
||||
$query = $builder->build();
|
||||
|
||||
/** @phpstan-var Collection&iterable<Entity> */
|
||||
return $this->entityManager
|
||||
->getRepository($entityType)
|
||||
->getRDBRepository($entityType)
|
||||
->clone($query)
|
||||
->sth()
|
||||
->find();
|
||||
|
||||
@@ -401,11 +401,12 @@ class NoteHookProcessor
|
||||
}
|
||||
|
||||
/**
|
||||
* @phpstan-return Collection
|
||||
* @phpstan-return Collection&iterable<User>
|
||||
* @return User[]
|
||||
*/
|
||||
private function getSubscriberList(string $parentType, string $parentId, bool $isInternal = false): Collection
|
||||
{
|
||||
/** @var Collection&iterable<User> */
|
||||
return $this->streamService->getSubscriberList($parentType, $parentId, $isInternal);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@ class TcpdfCollectionPrinter implements CollectionPrinter
|
||||
|
||||
public function print(Template $template, Collection $collection, Params $params, IdDataMap $dataMap): Contents
|
||||
{
|
||||
/** @var iterable<\Espo\ORM\Entity> $collection */
|
||||
|
||||
$pdf = new Tcpdf();
|
||||
|
||||
$pdf->setUseGroupNumbers(true);
|
||||
|
||||
Reference in New Issue
Block a user