From e183f39dfde825bf2bf003fd36dfc5d48052de90 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Wed, 21 Apr 2021 15:19:37 +0300 Subject: [PATCH] cs fix --- application/Espo/Controllers/Action.php | 2 +- application/Espo/Entities/Attachment.php | 4 +- application/Espo/Entities/Email.php | 18 +-- application/Espo/Entities/Job.php | 20 +-- application/Espo/Entities/User.php | 18 +-- application/Espo/EntryPoints/Attachment.php | 2 +- application/Espo/EntryPoints/Avatar.php | 4 +- .../Espo/EntryPoints/ChangePassword.php | 2 +- application/Espo/EntryPoints/ConfirmOptIn.php | 2 +- application/Espo/EntryPoints/Download.php | 2 +- application/Espo/EntryPoints/Image.php | 6 +- application/Espo/EntryPoints/LogoImage.php | 2 +- .../Espo/EntryPoints/OauthCallback.php | 2 +- application/Espo/EntryPoints/Pdf.php | 2 +- application/Espo/Jobs/AuthTokenControl.php | 2 +- application/Espo/Jobs/CheckEmailAccounts.php | 4 +- application/Espo/Jobs/CheckInboundEmails.php | 4 +- .../Espo/Jobs/CheckNewExtensionVersion.php | 2 +- application/Espo/Jobs/CheckNewVersion.php | 3 +- application/Espo/Jobs/Dummy.php | 2 +- application/Espo/Jobs/ProcessJobQueueE0.php | 2 +- application/Espo/Jobs/ProcessJobQueueQ0.php | 2 +- application/Espo/Jobs/ProcessJobQueueQ1.php | 2 +- application/Espo/Jobs/ProcessWebhookQueue.php | 4 +- .../Espo/Jobs/SendEmailNotifications.php | 2 +- application/Espo/Repositories/Attachment.php | 10 +- application/Espo/Repositories/Email.php | 124 ++++++++++++++---- .../Espo/Repositories/ExternalAccount.php | 4 +- application/Espo/Repositories/Import.php | 6 +- application/Espo/Repositories/Integration.php | 4 +- application/Espo/Repositories/LayoutSet.php | 21 ++- application/Espo/Repositories/Portal.php | 5 +- application/Espo/Repositories/Preferences.php | 8 +- application/Espo/Repositories/User.php | 2 +- application/Espo/Repositories/UserData.php | 19 ++- application/Espo/Repositories/Webhook.php | 1 + 36 files changed, 215 insertions(+), 104 deletions(-) diff --git a/application/Espo/Controllers/Action.php b/application/Espo/Controllers/Action.php index a5b7fda762..ca73f72e3a 100644 --- a/application/Espo/Controllers/Action.php +++ b/application/Espo/Controllers/Action.php @@ -46,7 +46,7 @@ class Action $this->recordServiceContainer = $recordServiceContainer; } - public function postActionProcess(Request $request) : StdClass + public function postActionProcess(Request $request): StdClass { $body = $request->getParsedBody(); diff --git a/application/Espo/Entities/Attachment.php b/application/Espo/Entities/Attachment.php index 9cc4c77d1f..5ee08ead7c 100644 --- a/application/Espo/Entities/Attachment.php +++ b/application/Espo/Entities/Attachment.php @@ -33,7 +33,7 @@ use Espo\Core\ORM\Entity; class Attachment extends Entity { - public function getSourceId() : ?string + public function getSourceId(): ?string { $sourceId = $this->get('sourceId'); @@ -44,7 +44,7 @@ class Attachment extends Entity return $sourceId; } - public function getStorage() : ?string + public function getStorage(): ?string { return $this->get('storage'); } diff --git a/application/Espo/Entities/Email.php b/application/Espo/Entities/Email.php index 87ca06e009..8265425c6d 100644 --- a/application/Espo/Entities/Email.php +++ b/application/Espo/Entities/Email.php @@ -136,12 +136,12 @@ class Email extends \Espo\Core\ORM\Entity } } - public function isManuallyArchived() : bool + public function isManuallyArchived(): bool { return $this->get('status') === 'Archived' && $this->get('createdById') !== 'system'; } - public function addAttachment(Attachment $attachment) : void + public function addAttachment(Attachment $attachment): void { if (!$this->id) { return; @@ -158,12 +158,12 @@ class Email extends \Espo\Core\ORM\Entity return $this->getBodyPlain(); } - public function hasBodyPlain() : bool + public function hasBodyPlain(): bool { return $this->hasInContainer('bodyPlain') && $this->getFromContainer('bodyPlain'); } - public function getBodyPlain() : ?string + public function getBodyPlain(): ?string { if ($this->getFromContainer('bodyPlain')) { return $this->getFromContainer('bodyPlain'); @@ -238,7 +238,7 @@ class Email extends \Espo\Core\ORM\Entity return $body; } - public function getInlineAttachments() : array + public function getInlineAttachments(): array { $idList = []; @@ -277,7 +277,7 @@ class Email extends \Espo\Core\ORM\Entity return $attachmentList; } - public function getToList() : array + public function getToList(): array { $value = $this->get('to'); @@ -292,7 +292,7 @@ class Email extends \Espo\Core\ORM\Entity return []; } - public function getCcList() : array + public function getCcList(): array { $value = $this->get('cc'); @@ -307,7 +307,7 @@ class Email extends \Espo\Core\ORM\Entity return []; } - public function getBccList() : array + public function getBccList(): array { $value = $this->get('bcc'); @@ -337,7 +337,7 @@ class Email extends \Espo\Core\ORM\Entity return []; } - public function setDummyMessageId() : void + public function setDummyMessageId(): void { $this->set('messageId', 'dummy:' . Util::generateId()); } diff --git a/application/Espo/Entities/Job.php b/application/Espo/Entities/Job.php index 7732984fee..5435fbf431 100644 --- a/application/Espo/Entities/Job.php +++ b/application/Espo/Entities/Job.php @@ -38,7 +38,7 @@ class Job extends Entity /** * Get a status. */ - public function getStatus() : string + public function getStatus(): string { return $this->get('status'); } @@ -46,7 +46,7 @@ class Job extends Entity /** * Get a job name. */ - public function getJob() : ?string + public function getJob(): ?string { return $this->get('job'); } @@ -54,7 +54,7 @@ class Job extends Entity /** * Get a scheduled job name. */ - public function getScheduledJobJob() : ?string + public function getScheduledJobJob(): ?string { return $this->get('scheduledJobJob'); } @@ -62,7 +62,7 @@ class Job extends Entity /** * Get a target type. */ - public function getTargetType() : ?string + public function getTargetType(): ?string { return $this->get('targetType'); } @@ -70,7 +70,7 @@ class Job extends Entity /** * Get a target ID. */ - public function getTargetId() : ?string + public function getTargetId(): ?string { return $this->get('targetId'); } @@ -78,7 +78,7 @@ class Job extends Entity /** * Get data. */ - public function getData() : StdClass + public function getData(): StdClass { return $this->get('data') ?? (object) []; } @@ -86,7 +86,7 @@ class Job extends Entity /** * Get a service name. */ - public function getServiceName() : ?string + public function getServiceName(): ?string { return $this->get('serviceName'); } @@ -94,7 +94,7 @@ class Job extends Entity /** * Get a method name. */ - public function getMethodName() : ?string + public function getMethodName(): ?string { return $this->get('methodName'); } @@ -102,7 +102,7 @@ class Job extends Entity /** * Get a scheduled job ID. */ - public function getScheduledJobId() : ?string + public function getScheduledJobId(): ?string { return $this->get('scheduledJobId'); } @@ -110,7 +110,7 @@ class Job extends Entity /** * Get a started date-time. */ - public function getStartedAt() : ?string + public function getStartedAt(): ?string { return $this->get('startedAt'); } diff --git a/application/Espo/Entities/User.php b/application/Espo/Entities/User.php index 1c3083ec84..247f251d07 100644 --- a/application/Espo/Entities/User.php +++ b/application/Espo/Entities/User.php @@ -33,47 +33,47 @@ use Espo\Core\Entities\Person; class User extends Person { - public function isActive() : bool + public function isActive(): bool { return (bool) $this->get('isActive'); } - public function isAdmin() : bool + public function isAdmin(): bool { return $this->get('type') === 'admin' || $this->isSystem() || $this->isSuperAdmin(); } - public function isPortal() : bool + public function isPortal(): bool { return $this->get('type') === 'portal'; } - public function isPortalUser() : bool + public function isPortalUser(): bool { return $this->isPortal(); } - public function isRegular() : bool + public function isRegular(): bool { return $this->get('type') === 'regular' || ($this->has('type') && !$this->get('type')); } - public function isApi() : bool + public function isApi(): bool { return $this->get('type') === 'api'; } - public function isSystem() : bool + public function isSystem(): bool { return $this->get('type') === 'system'; } - public function isSuperAdmin() : bool + public function isSuperAdmin(): bool { return $this->get('type') === 'super-admin'; } - public function getTeamIdList() : array + public function getTeamIdList(): array { return $this->getLinkMultipleIdList('teams'); } diff --git a/application/Espo/EntryPoints/Attachment.php b/application/Espo/EntryPoints/Attachment.php index edea4f7705..07c973f5d5 100644 --- a/application/Espo/EntryPoints/Attachment.php +++ b/application/Espo/EntryPoints/Attachment.php @@ -63,7 +63,7 @@ class Attachment implements EntryPoint $this->acl = $acl; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $id = $request->getQueryParam('id'); diff --git a/application/Espo/EntryPoints/Avatar.php b/application/Espo/EntryPoints/Avatar.php index 45a4bdf8e5..099a22607f 100644 --- a/application/Espo/EntryPoints/Avatar.php +++ b/application/Espo/EntryPoints/Avatar.php @@ -77,7 +77,7 @@ class Avatar extends Image implements Di\MetadataAware return $colorList[$index]; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $userId = $request->get('id'); @@ -132,7 +132,7 @@ class Avatar extends Image implements Di\MetadataAware $response->writeBody($imgContent); } - protected function renderBlank(Response $response) : void + protected function renderBlank(Response $response): void { ob_start(); diff --git a/application/Espo/EntryPoints/ChangePassword.php b/application/Espo/EntryPoints/ChangePassword.php index be7a838735..b3f085b5f1 100644 --- a/application/Espo/EntryPoints/ChangePassword.php +++ b/application/Espo/EntryPoints/ChangePassword.php @@ -59,7 +59,7 @@ class ChangePassword implements EntryPoint $this->entityManager = $entityManager; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $requestId = $request->getQueryParam('id'); diff --git a/application/Espo/EntryPoints/ConfirmOptIn.php b/application/Espo/EntryPoints/ConfirmOptIn.php index 6d7ff6a280..71748ebe52 100644 --- a/application/Espo/EntryPoints/ConfirmOptIn.php +++ b/application/Espo/EntryPoints/ConfirmOptIn.php @@ -54,7 +54,7 @@ class ConfirmOptIn implements EntryPoint $this->serviceFactory = $serviceFactory; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $id = $request->get('id'); diff --git a/application/Espo/EntryPoints/Download.php b/application/Espo/EntryPoints/Download.php index 1b1267ead1..6228c5c0c5 100644 --- a/application/Espo/EntryPoints/Download.php +++ b/application/Espo/EntryPoints/Download.php @@ -67,7 +67,7 @@ class Download implements EntryPoint $this->entityManager = $entityManager; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $id = $request->getQueryParam('id'); diff --git a/application/Espo/EntryPoints/Image.php b/application/Espo/EntryPoints/Image.php index cd58586c79..56cf8cd9f7 100644 --- a/application/Espo/EntryPoints/Image.php +++ b/application/Espo/EntryPoints/Image.php @@ -99,7 +99,7 @@ class Image implements EntryPoint $this->config = $config; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $id = $request->getQueryParam('id'); $size = $request->getQueryParam('size') ?? null; @@ -111,7 +111,7 @@ class Image implements EntryPoint $this->show($response, $id, $size, false); } - protected function show(Response $response, string $id, ?string $size, bool $disableAccessCheck = false) : void + protected function show(Response $response, string $id, ?string $size, bool $disableAccessCheck = false): void { $attachment = $this->entityManager->getEntity('Attachment', $id); @@ -171,7 +171,7 @@ class Image implements EntryPoint ->setHeader('Content-Length', (string) $fileSize); } - protected function getThumbContents(Attachment $attachment, string $size) : string + protected function getThumbContents(Attachment $attachment, string $size): string { if (!array_key_exists($size, $this->imageSizes)) { throw new Error("Bad size."); diff --git a/application/Espo/EntryPoints/LogoImage.php b/application/Espo/EntryPoints/LogoImage.php index 8b8fcc27a2..0c161efeaa 100644 --- a/application/Espo/EntryPoints/LogoImage.php +++ b/application/Espo/EntryPoints/LogoImage.php @@ -47,7 +47,7 @@ class LogoImage extends Image implements Di\ConfigAware protected $allowedFieldList = ['companyLogo']; - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $id = $request->get('id'); $size = $request->get('size') ?? null; diff --git a/application/Espo/EntryPoints/OauthCallback.php b/application/Espo/EntryPoints/OauthCallback.php index 81538a5090..99ab546369 100644 --- a/application/Espo/EntryPoints/OauthCallback.php +++ b/application/Espo/EntryPoints/OauthCallback.php @@ -40,7 +40,7 @@ class OauthCallback implements EntryPoint { use NoAuth; - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { echo "If this window is not closed automatically, it's probable that URL you use to access ". "EspoCRM doesn't match URL specified at Administration > Settings > Site URL."; diff --git a/application/Espo/EntryPoints/Pdf.php b/application/Espo/EntryPoints/Pdf.php index b3d69ac453..ef015aff76 100644 --- a/application/Espo/EntryPoints/Pdf.php +++ b/application/Espo/EntryPoints/Pdf.php @@ -51,7 +51,7 @@ class Pdf implements EntryPoint $this->serviceFactory = $serviceFactory; } - public function run(Request $request, Response $response) : void + public function run(Request $request, Response $response): void { $entityId = $request->getQueryParam('entityId'); $entityType = $request->getQueryParam('entityType'); diff --git a/application/Espo/Jobs/AuthTokenControl.php b/application/Espo/Jobs/AuthTokenControl.php index 329314c964..50000f560f 100644 --- a/application/Espo/Jobs/AuthTokenControl.php +++ b/application/Espo/Jobs/AuthTokenControl.php @@ -49,7 +49,7 @@ class AuthTokenControl implements Job $this->entityManager = $entityManager; } - public function run() : void + public function run(): void { $authTokenLifetime = $this->config->get('authTokenLifetime'); $authTokenMaxIdleTime = $this->config->get('authTokenMaxIdleTime'); diff --git a/application/Espo/Jobs/CheckEmailAccounts.php b/application/Espo/Jobs/CheckEmailAccounts.php index c4e07dc7e4..7985f5aa18 100644 --- a/application/Espo/Jobs/CheckEmailAccounts.php +++ b/application/Espo/Jobs/CheckEmailAccounts.php @@ -55,7 +55,7 @@ class CheckEmailAccounts implements JobTargeted $this->entityManager = $entityManager; } - public function run(string $targetType, string $targetId, StdClass $data) : void + public function run(string $targetType, string $targetId, StdClass $data): void { if (!$targetId) { throw new Error(); @@ -81,7 +81,7 @@ class CheckEmailAccounts implements JobTargeted } } - public function prepare(ScheduledJob $scheduledJob, string $executeTime) : void + public function prepare(ScheduledJob $scheduledJob, string $executeTime): void { $collection = $this->entityManager->getRepository('EmailAccount') ->join('assignedUser', 'assignedUserAdditional') diff --git a/application/Espo/Jobs/CheckInboundEmails.php b/application/Espo/Jobs/CheckInboundEmails.php index ae016c0fc5..bfd90f2d0c 100644 --- a/application/Espo/Jobs/CheckInboundEmails.php +++ b/application/Espo/Jobs/CheckInboundEmails.php @@ -55,7 +55,7 @@ class CheckInboundEmails implements JobTargeted $this->entityManager = $entityManager; } - public function run(string $targetType, string $targetId, StdClass $data) : void + public function run(string $targetType, string $targetId, StdClass $data): void { if (!$targetId) { throw new Error(); @@ -80,7 +80,7 @@ class CheckInboundEmails implements JobTargeted } } - public function prepare(ScheduledJob $scheduledJob, string $executeTime) : void + public function prepare(ScheduledJob $scheduledJob, string $executeTime): void { $collection = $this->entityManager ->getRepository('InboundEmail') diff --git a/application/Espo/Jobs/CheckNewExtensionVersion.php b/application/Espo/Jobs/CheckNewExtensionVersion.php index 8f0f80bb0c..a1a9925369 100644 --- a/application/Espo/Jobs/CheckNewExtensionVersion.php +++ b/application/Espo/Jobs/CheckNewExtensionVersion.php @@ -31,7 +31,7 @@ namespace Espo\Jobs; class CheckNewExtensionVersion extends CheckNewVersion { - public function run() : void + public function run(): void { if ( !$this->config->get('adminNotifications') || diff --git a/application/Espo/Jobs/CheckNewVersion.php b/application/Espo/Jobs/CheckNewVersion.php index 843d3b8c32..ffde647670 100644 --- a/application/Espo/Jobs/CheckNewVersion.php +++ b/application/Espo/Jobs/CheckNewVersion.php @@ -50,13 +50,14 @@ class CheckNewVersion implements Job $this->entityManager = $entityManager; } - public function run() : void + public function run(): void { if (!$this->config->get('adminNotifications') || !$this->config->get('adminNotificationsNewVersion')) { return; } $job = $this->entityManager->getEntity('Job'); + $job->set([ 'name' => 'Check for New Version (job)', 'serviceName' => 'AdminNotifications', diff --git a/application/Espo/Jobs/Dummy.php b/application/Espo/Jobs/Dummy.php index bf777cd3f7..860da849dd 100644 --- a/application/Espo/Jobs/Dummy.php +++ b/application/Espo/Jobs/Dummy.php @@ -35,7 +35,7 @@ use Espo\Core\{ class Dummy implements Job { - public function run() : void + public function run(): void { } } diff --git a/application/Espo/Jobs/ProcessJobQueueE0.php b/application/Espo/Jobs/ProcessJobQueueE0.php index b271f4742f..0fee47ac0c 100644 --- a/application/Espo/Jobs/ProcessJobQueueE0.php +++ b/application/Espo/Jobs/ProcessJobQueueE0.php @@ -47,7 +47,7 @@ class ProcessJobQueueE0 implements Job $this->config = $config; } - public function run() : void + public function run(): void { $limit = $this->config->get('jobE0MaxPortion', 100); diff --git a/application/Espo/Jobs/ProcessJobQueueQ0.php b/application/Espo/Jobs/ProcessJobQueueQ0.php index 0a07205298..c369ab4a13 100644 --- a/application/Espo/Jobs/ProcessJobQueueQ0.php +++ b/application/Espo/Jobs/ProcessJobQueueQ0.php @@ -47,7 +47,7 @@ class ProcessJobQueueQ0 implements Job $this->config = $config; } - public function run() : void + public function run(): void { $limit = $this->config->get('jobQ0MaxPortion', 200); diff --git a/application/Espo/Jobs/ProcessJobQueueQ1.php b/application/Espo/Jobs/ProcessJobQueueQ1.php index 34c14ce83d..5414910e24 100644 --- a/application/Espo/Jobs/ProcessJobQueueQ1.php +++ b/application/Espo/Jobs/ProcessJobQueueQ1.php @@ -47,7 +47,7 @@ class ProcessJobQueueQ1 implements Job $this->config = $config; } - public function run() : void + public function run(): void { $limit = $this->config->get('jobQ1MaxPortion', 500); diff --git a/application/Espo/Jobs/ProcessWebhookQueue.php b/application/Espo/Jobs/ProcessWebhookQueue.php index f7d05f15ef..3a552d5584 100644 --- a/application/Espo/Jobs/ProcessWebhookQueue.php +++ b/application/Espo/Jobs/ProcessWebhookQueue.php @@ -41,7 +41,9 @@ use Espo\Core\{ class ProcessWebhookQueue implements Job { protected $config; + protected $entityManager; + protected $aclManager; public function __construct(Config $config, EntityManager $entityManager, AclManager $aclManager) @@ -51,7 +53,7 @@ class ProcessWebhookQueue implements Job $this->aclManager = $aclManager; } - public function run() : void + public function run(): void { $sender = new Sender($this->config); diff --git a/application/Espo/Jobs/SendEmailNotifications.php b/application/Espo/Jobs/SendEmailNotifications.php index 302c38d706..bc83045081 100644 --- a/application/Espo/Jobs/SendEmailNotifications.php +++ b/application/Espo/Jobs/SendEmailNotifications.php @@ -42,7 +42,7 @@ class SendEmailNotifications implements Job $this->processor = $processor; } - public function run() : void + public function run(): void { $this->processor->process(); } diff --git a/application/Espo/Repositories/Attachment.php b/application/Espo/Repositories/Attachment.php index b9e400a4f7..350fe09b18 100644 --- a/application/Espo/Repositories/Attachment.php +++ b/application/Espo/Repositories/Attachment.php @@ -75,7 +75,7 @@ class Attachment extends \Espo\Core\Repositories\Database implements } } - protected function processBeforeSaveNew(Entity $entity) : void + protected function processBeforeSaveNew(Entity $entity): void { if (!$entity->get('storage')) { $defaultStorage = $this->config->get('defaultFileStorage'); @@ -152,22 +152,22 @@ class Attachment extends \Espo\Core\Repositories\Database implements return $attachment; } - public function getContents(AttachmentEntity $entity) : string + public function getContents(AttachmentEntity $entity): string { return $this->fileStorageManager->getContents($entity); } - public function getStream(AttachmentEntity $entity) : StreamInterface + public function getStream(AttachmentEntity $entity): StreamInterface { return $this->fileStorageManager->getStream($entity); } - public function getSize(AttachmentEntity $entity) : int + public function getSize(AttachmentEntity $entity): int { return $this->fileStorageManager->getSize($entity); } - public function getFilePath(AttachmentEntity $entity) : string + public function getFilePath(AttachmentEntity $entity): string { return $this->fileStorageManager->getLocalFilePath($entity); } diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index f950334aca..1d3cc3a9d1 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -50,9 +50,12 @@ class Email extends \Espo\Core\Repositories\Database implements $idList = []; if (!empty($addressValue)) { - $addressList = array_map(function ($item) { - return trim($item); - }, explode(';', $addressValue)); + $addressList = array_map( + function ($item) { + return trim($item); + }, + explode(';', $addressValue) + ); $addressList = array_filter($addressList, function ($item) { return filter_var($item, FILTER_VALIDATE_EMAIL); @@ -72,10 +75,13 @@ class Email extends \Espo\Core\Repositories\Database implements protected function addUserByEmailAddressId(Entity $entity, $emailAddressId, $addAssignedUser = false) { - $userList = $this->getEntityManager()->getRepository('EmailAddress')->getEntityListByAddressId($emailAddressId, null, 'User', true); + $userList = $this->getEntityManager() + ->getRepository('EmailAddress') + ->getEntityListByAddressId($emailAddressId, null, 'User', true); foreach ($userList as $user) { $entity->addLinkMultipleId('users', $user->id); + if ($addAssignedUser) { $entity->addLinkMultipleId('assignedUsers', $user->id); } @@ -86,12 +92,18 @@ class Email extends \Espo\Core\Repositories\Database implements { if ($entity->get('fromEmailAddressName')) { $entity->set('from', $entity->get('fromEmailAddressName')); + return; } + if ($entity->get('fromEmailAddressId')) { - $ea = $this->getEntityManager()->getRepository('EmailAddress')->get($entity->get('fromEmailAddressId')); + $ea = $this->getEntityManager() + ->getRepository('EmailAddress') + ->get($entity->get('fromEmailAddressId')); + if ($ea) { $entity->set('from', $ea->get('name')); + return; } } @@ -107,11 +119,14 @@ class Email extends \Espo\Core\Repositories\Database implements { $entity->loadLinkMultipleField('toEmailAddresses'); $names = $entity->get('toEmailAddressesNames'); + if (!empty($names)) { - $arr = array(); + $arr = []; + foreach ($names as $id => $address) { $arr[] = $address; } + $entity->set('to', implode(';', $arr)); } } @@ -120,8 +135,10 @@ class Email extends \Espo\Core\Repositories\Database implements { $entity->loadLinkMultipleField('ccEmailAddresses'); $names = $entity->get('ccEmailAddressesNames'); + if (!empty($names)) { - $arr = array(); + $arr = []; + foreach ($names as $id => $address) { $arr[] = $address; } @@ -133,11 +150,14 @@ class Email extends \Espo\Core\Repositories\Database implements { $entity->loadLinkMultipleField('bccEmailAddresses'); $names = $entity->get('bccEmailAddressesNames'); + if (!empty($names)) { - $arr = array(); + $arr = []; + foreach ($names as $id => $address) { $arr[] = $address; } + $entity->set('bcc', implode(';', $arr)); } } @@ -146,24 +166,29 @@ class Email extends \Espo\Core\Repositories\Database implements { $entity->loadLinkMultipleField('replyToEmailAddresses'); $names = $entity->get('replyToEmailAddressesNames'); + if (!empty($names)) { - $arr = array(); + $arr = []; + foreach ($names as $id => $address) { $arr[] = $address; } + $entity->set('replyTo', implode(';', $arr)); } } public function loadNameHash(Entity $entity, array $fieldList = ['from', 'to', 'cc', 'bcc', 'replyTo']) { - $addressList = array(); + $addressList = []; + if (in_array('from', $fieldList) && $entity->get('from')) { $addressList[] = $entity->get('from'); } if (in_array('to', $fieldList)) { $arr = explode(';', $entity->get('to')); + foreach ($arr as $address) { if (!in_array($address, $addressList)) { $addressList[] = $address; @@ -173,6 +198,7 @@ class Email extends \Espo\Core\Repositories\Database implements if (in_array('cc', $fieldList)) { $arr = explode(';', $entity->get('cc')); + foreach ($arr as $address) { if (!in_array($address, $addressList)) { $addressList[] = $address; @@ -181,14 +207,17 @@ class Email extends \Espo\Core\Repositories\Database implements } if (in_array('bcc', $fieldList)) { $arr = explode(';', $entity->get('bcc')); + foreach ($arr as $address) { if (!in_array($address, $addressList)) { $addressList[] = $address; } } } + if (in_array('replyTo', $fieldList)) { $arr = explode(';', $entity->get('replyTo')); + foreach ($arr as $address) { if (!in_array($address, $addressList)) { $addressList[] = $address; @@ -199,19 +228,29 @@ class Email extends \Espo\Core\Repositories\Database implements $nameHash = (object) []; $typeHash = (object) []; $idHash = (object) []; + foreach ($addressList as $address) { - $p = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($address); + $p = $this->getEntityManager() + ->getRepository('EmailAddress') + ->getEntityByAddress($address); + if (!$p) { - $p = $this->getEntityManager()->getRepository('InboundEmail')->where(array('emailAddress' => $address))->findOne(); + $p = $this->getEntityManager() + ->getRepository('InboundEmail') + ->where(array('emailAddress' => $address)) + ->findOne(); } + if ($p) { $nameHash->$address = $p->get('name'); $typeHash->$address = $p->getEntityType(); + $idHash->$address = $p->id; } } $addressNameMap = $entity->get('addressNameMap'); + if (is_object($addressNameMap)) { foreach (get_object_vars($addressNameMap) as $key => $value) { if (!isset($nameHash->$key)) { @@ -238,24 +277,40 @@ class Email extends \Espo\Core\Repositories\Database implements } } - if ($entity->has('from') || $entity->has('to') || $entity->has('cc') || $entity->has('bcc') || $entity->has('replyTo')) { + if ( + $entity->has('from') || + $entity->has('to') || + $entity->has('cc') || + $entity->has('bcc') || + $entity->has('replyTo') + ) { if (!$entity->has('usersIds')) { $entity->loadLinkMultipleField('users'); } if ($entity->has('from')) { $from = trim($entity->get('from')); + if (!empty($from)) { - $ids = $this->getEntityManager()->getRepository('EmailAddress')->getIds([$from]); + $ids = $this->getEntityManager() + ->getRepository('EmailAddress') + ->getIds([$from]); + if (!empty($ids)) { $entity->set('fromEmailAddressId', $ids[0]); $entity->set('fromEmailAddressName', $from); + $this->addUserByEmailAddressId($entity, $ids[0], true); if (!$entity->get('sentById')) { - $user = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddressId( - $entity->get('fromEmailAddressId'), 'User', true - ); + $user = $this->getEntityManager() + ->getRepository('EmailAddress') + ->getEntityByAddressId( + $entity->get('fromEmailAddressId'), + 'User', + true + ); + if ($user) { $entity->set('sentById', $user->id); } @@ -316,18 +371,28 @@ class Email extends \Espo\Core\Repositories\Database implements $parentId = $entity->get('parentId'); $parentType = $entity->get('parentType'); + if ($parentId && $parentType) { $parent = $this->getEntityManager()->getEntity($parentType, $parentId); + if ($parent) { $accountId = null; + if ($parent->getEntityType() == 'Account') { $accountId = $parent->id; } - if (!$accountId && $parent->get('accountId') && $parent->getRelationParam('account', 'entity') == 'Account') { + + if ( + !$accountId && + $parent->get('accountId') && + $parent->getRelationParam('account', 'entity') == 'Account' + ) { $accountId = $parent->get('accountId'); } + if ($accountId) { $account = $this->getEntityManager()->getEntity('Account', $accountId); + if ($account) { $entity->set('accountId', $accountId); $entity->set('accountName', $account->get('name')); @@ -341,16 +406,22 @@ class Email extends \Espo\Core\Repositories\Database implements { foreach ($entity->getLinkMultipleIdList('users') as $userId) { if ($entity->get('status') === 'Sent') { - if ($entity->get('sentById') && $entity->get('sentById') === $userId) continue; + if ($entity->get('sentById') && $entity->get('sentById') === $userId) { + continue; + } } $filter = $this->getEmailFilterManager()->getMatchingFilter($entity, $userId); + if ($filter) { $action = $filter->get('action'); + if ($action === 'Skip') { $entity->setLinkMultipleColumn('users', 'inTrash', $userId, true); - } else if ($action === 'Move to Folder') { + } + else if ($action === 'Move to Folder') { $folderId = $filter->get('emailFolderId'); + if ($folderId) { $entity->setLinkMultipleColumn('users', 'folderId', $userId, $folderId); } @@ -364,15 +435,24 @@ class Email extends \Espo\Core\Repositories\Database implements parent::afterSave($entity, $options); if (!$entity->isNew()) { - if ($entity->get('parentType') && $entity->get('parentId') && $entity->isAttributeChanged('parentId')) { + if ( + $entity->get('parentType') && + $entity->get('parentId') && + $entity->isAttributeChanged('parentId') + ) { $replyList = $this->findRelated($entity, 'replies'); + foreach ($replyList as $reply) { - if ($reply->id === $entity->id) continue; + if ($reply->id === $entity->id) { + continue; + } + if (!$reply->get('parentId')) { $reply->set([ 'parentId' => $entity->get('parentId'), 'parentType' => $entity->get('parentType') ]); + $this->getEntityManager()->saveEntity($reply); } } diff --git a/application/Espo/Repositories/ExternalAccount.php b/application/Espo/Repositories/ExternalAccount.php index bb4cee62bd..81efb49ecd 100644 --- a/application/Espo/Repositories/ExternalAccount.php +++ b/application/Espo/Repositories/ExternalAccount.php @@ -33,13 +33,15 @@ use Espo\ORM\Entity; class ExternalAccount extends \Espo\Core\Repositories\Database { - public function get(?string $id = null) : ?Entity + public function get(?string $id = null): ?Entity { $entity = parent::get($id); + if (empty($entity) && !empty($id)) { $entity = $this->get(); $entity->id = $id; } + return $entity; } } diff --git a/application/Espo/Repositories/Import.php b/application/Espo/Repositories/Import.php index eaae30cd6f..67fcfdd48f 100644 --- a/application/Espo/Repositories/Import.php +++ b/application/Espo/Repositories/Import.php @@ -39,7 +39,7 @@ use Espo\Core\Repositories\Database; class Import extends Database { - public function findResultRecords(Entity $entity, string $relationName, Query $query) : Collection + public function findResultRecords(Entity $entity, string $relationName, Query $query): Collection { $entityType = $entity->get('entityType'); @@ -54,7 +54,7 @@ class Import extends Database ->find(); } - protected function addImportEntityJoin(Entity $entity, string $link, Query $query) : Query + protected function addImportEntityJoin(Entity $entity, string $link, Query $query): Query { $entityType = $entity->get('entityType'); @@ -96,7 +96,7 @@ class Import extends Database return $builder->build(); } - public function countResultRecords(Entity $entity, string $relationName, ?Query $query = null) : int + public function countResultRecords(Entity $entity, string $relationName, ?Query $query = null): int { $entityType = $entity->get('entityType'); diff --git a/application/Espo/Repositories/Integration.php b/application/Espo/Repositories/Integration.php index 2a7567e774..e7e7cc9998 100644 --- a/application/Espo/Repositories/Integration.php +++ b/application/Espo/Repositories/Integration.php @@ -33,13 +33,15 @@ use Espo\ORM\Entity; class Integration extends \Espo\Core\Repositories\Database { - public function get(?string $id = null) : ?Entity + public function get(?string $id = null): ?Entity { $entity = parent::get($id); + if (empty($entity) && !empty($id)) { $entity = $this->get(); $entity->id = $id; } + return $entity; } } diff --git a/application/Espo/Repositories/LayoutSet.php b/application/Espo/Repositories/LayoutSet.php index 937b6ba838..cac4ca0800 100644 --- a/application/Espo/Repositories/LayoutSet.php +++ b/application/Espo/Repositories/LayoutSet.php @@ -43,10 +43,14 @@ class LayoutSet extends \Espo\Core\Repositories\Database foreach ($listBefore as $name) { if (!in_array($name, $listNow)) { - $layout = $this->getEntityManager()->getRepository('LayoutRecord')->where([ - 'layoutSetId' => $entity->id, - 'name' => $name, - ])->findOne(); + $layout = $this->getEntityManager() + ->getRepository('LayoutRecord') + ->where([ + 'layoutSetId' => $entity->id, + 'name' => $name, + ]) + ->findOne(); + if ($layout) { $this->getEntityManager()->removeEntity($layout); } @@ -57,9 +61,12 @@ class LayoutSet extends \Espo\Core\Repositories\Database protected function afterRemove(Entity $entity, array $options = []) { - $layoutList = $this->getEntityManager()->getRepository('LayoutRecord')->where([ - 'layoutSetId' => $entity->id, - ])->find(); + $layoutList = $this->getEntityManager() + ->getRepository('LayoutRecord') + ->where([ + 'layoutSetId' => $entity->id, + ]) + ->find(); foreach ($layoutList as $layout) { $this->getEntityManager()->removeEntity($layout); diff --git a/application/Espo/Repositories/Portal.php b/application/Espo/Repositories/Portal.php index 9261ab33d3..b0090ec8b2 100644 --- a/application/Espo/Repositories/Portal.php +++ b/application/Espo/Repositories/Portal.php @@ -49,17 +49,20 @@ class Portal extends Database implements $siteUrl = $this->config->get('siteUrl'); $siteUrl = rtrim($siteUrl , '/') . '/'; + $url = $siteUrl . 'portal/'; if ($entity->id === $this->config->get('defaultPortalId')) { $entity->set('isDefault', true); $entity->setFetched('isDefault', true); - } else { + } + else { if ($entity->get('customId')) { $url .= $entity->get('customId') . '/'; } else { $url .= $entity->id . '/'; } + $entity->set('isDefault', false); $entity->setFetched('isDefault', false); } diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index d4edb81fea..5ccb1f7d92 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -57,7 +57,7 @@ class Preferences extends Repository implements protected $entityType = 'Preferences'; - public function get(?string $id = null) : ?Entity + public function get(?string $id = null): ?Entity { if (!$id) { return $this->entityFactory->create('Preferences'); @@ -97,11 +97,13 @@ class Preferences extends Repository implements while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $data = Json::decode($row['data']); + break; } if ($data) { $this->data[$id] = get_object_vars($data); + return; } @@ -128,6 +130,7 @@ class Preferences extends Repository implements $defaults[$field] = $d['default']; } } + foreach ($this->defaultAttributeListFromSettings as $attr) { $defaults[$attr] = $this->config->get($attr); } @@ -141,7 +144,8 @@ class Preferences extends Repository implements $autoFollowEntityTypeList = []; - $autofollowList = $this->entityManager->getRepository('Autofollow') + $autofollowList = $this->entityManager + ->getRepository('Autofollow') ->select(['entityType']) ->where([ 'userId' => $id, diff --git a/application/Espo/Repositories/User.php b/application/Espo/Repositories/User.php index 1047413100..3c672ab6e1 100644 --- a/application/Espo/Repositories/User.php +++ b/application/Espo/Repositories/User.php @@ -144,7 +144,7 @@ class User extends Database } } - public function checkBelongsToAnyOfTeams(string $userId, array $teamIds) : bool + public function checkBelongsToAnyOfTeams(string $userId, array $teamIds): bool { if (empty($teamIds)) { return false; diff --git a/application/Espo/Repositories/UserData.php b/application/Espo/Repositories/UserData.php index 9ef8627b8c..6d455cd4b0 100644 --- a/application/Espo/Repositories/UserData.php +++ b/application/Espo/Repositories/UserData.php @@ -33,17 +33,26 @@ use Espo\ORM\Entity; class UserData extends \Espo\Core\Repositories\Database { - public function getByUserId(string $userId) : ?Entity + public function getByUserId(string $userId): ?Entity { - $userData = $this->where(['userId' => $userId])->findOne(); + $userData = $this + ->where(['userId' => $userId]) + ->findOne(); - if ($userData) return $userData; + if ($userData) { + return $userData; + } - $user = $this->getEntityManager()->getRepository('User')->getById($userId); + $user = $this->getEntityManager() + ->getRepository('User') + ->getById($userId); - if (!$user) return null; + if (!$user) { + return null; + } $userData = $this->getNew(); + $userData->set('userId', $userId); $this->save($userData, [ diff --git a/application/Espo/Repositories/Webhook.php b/application/Espo/Repositories/Webhook.php index 61c294d2a8..b6092808bb 100644 --- a/application/Espo/Repositories/Webhook.php +++ b/application/Espo/Repositories/Webhook.php @@ -58,6 +58,7 @@ class Webhook extends \Espo\Core\Repositories\Database protected function processSettingAdditionalFields(Entity $entity): void { $event = $entity->get('event'); + if (!$event) { return; }