diff --git a/application/Espo/Core/Di/HookManagerAware.php b/application/Espo/Core/Di/HookManagerAware.php new file mode 100644 index 0000000000..faeacce153 --- /dev/null +++ b/application/Espo/Core/Di/HookManagerAware.php @@ -0,0 +1,37 @@ +hookManager = $hookManager; + } +} diff --git a/application/Espo/Core/Di/HtmlizerFactoryAware.php b/application/Espo/Core/Di/HtmlizerFactoryAware.php new file mode 100644 index 0000000000..96e9b4c7cf --- /dev/null +++ b/application/Espo/Core/Di/HtmlizerFactoryAware.php @@ -0,0 +1,37 @@ +htmlizerFactory = $htmlizerFactory; + } +} diff --git a/application/Espo/Core/Di/LanguageAware.php b/application/Espo/Core/Di/LanguageAware.php new file mode 100644 index 0000000000..97fac35796 --- /dev/null +++ b/application/Espo/Core/Di/LanguageAware.php @@ -0,0 +1,37 @@ +language = $language; + } +} diff --git a/application/Espo/Services/EmailTemplate.php b/application/Espo/Services/EmailTemplate.php index 117e14d7af..2d28d7e6ef 100644 --- a/application/Espo/Services/EmailTemplate.php +++ b/application/Espo/Services/EmailTemplate.php @@ -35,38 +35,42 @@ use Espo\Core\Entities\Person; use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\NotFound; -class EmailTemplate extends Record -{ - protected function init() - { - parent::init(); +use Espo\Core\Di; - $this->addDependency('fileStorageManager'); - $this->addDependency('dateTime'); - $this->addDependency('language'); - $this->addDependency('number'); - $this->addDependency('htmlizerFactory'); - $this->addDependency('fieldManagerUtil'); - } +class EmailTemplate extends Record implements + + Di\FileStorageManagerAware, + Di\DateTimeAware, + Di\LanguageAware, + Di\NumberAware, + Di\HtmlizerFactoryAware, + Di\FieldManagerUtilAware +{ + use Di\FileStorageManagerSetter; + use Di\DateTimeSetter; + use Di\LanguageSetter; + use Di\NumberSetter; + use Di\HtmlizerFactorySetter; + use Di\FieldManagerUtilSetter; protected function getFileStorageManager() { - return $this->getInjection('fileStorageManager'); + return $this->fileStorageManager; } protected function getDateTime() { - return $this->getInjection('dateTime'); + return $this->dateTime; } protected function getLanguage() { - return $this->getInjection('language'); + return $this->language; } protected function getNumber() { - return $this->getInjection('number'); + return $this->number; } public function parseTemplate(Entity $emailTemplate, array $params = [], $copyAttachments = false, $skipAcl = false) @@ -138,7 +142,7 @@ class EmailTemplate extends Record $handlebarsInBody = strpos($body, '{{') !== false && strpos($body, '}}') !== false; if ($handlebarsInSubject || $handlebarsInBody) { - $htmlizer = $this->getInjection('htmlizerFactory')->create($skipAcl); + $htmlizer = $this->htmlizerFactory->create($skipAcl); if ($handlebarsInSubject) { $subject = $htmlizer->render($parent, $subject); @@ -369,7 +373,7 @@ class EmailTemplate extends Record } } - $fm = $this->getInjection('fieldManagerUtil'); + $fm = $this->fieldManagerUtil; foreach ($dataList as $item) { $type = $item['type']; diff --git a/application/Espo/Services/ExternalAccount.php b/application/Espo/Services/ExternalAccount.php index 61d7b2f01b..2636d2bed6 100644 --- a/application/Espo/Services/ExternalAccount.php +++ b/application/Espo/Services/ExternalAccount.php @@ -35,15 +35,13 @@ use Espo\Core\Exceptions\Error; use Espo\Core\Exceptions\NotFound; use Espo\Core\Exceptions\Forbidden; -class ExternalAccount extends Record -{ - protected function init() - { - parent::init(); - $this->addDependency('hookManager'); - } +use Espo\Core\Di; - protected function getClient($integration, $id) +class ExternalAccount extends Record implements Di\HookManagerAware +{ + use Di\HookManagerSetter; + + protected function getClient(string $integration, string $id) { $integrationEntity = $this->getEntityManager()->getEntity('Integration', $integration); @@ -62,12 +60,12 @@ class ExternalAccount extends Record return $factory->create($integration, $id); } - public function getExternalAccountEntity($integration, $userId) + public function getExternalAccountEntity(string $integration, string $userId) { return $this->getEntityManager()->getEntity('ExternalAccount', $integration . '__' . $userId); } - public function ping($integration, $userId) + public function ping(string $integration, string $userId) { $entity = $this->getExternalAccountEntity($integration, $userId); try { @@ -76,9 +74,11 @@ class ExternalAccount extends Record return $client->ping(); } } catch (\Exception $e) {} + + return false; } - public function authorizationCode($integration, $userId, $code) + public function authorizationCode(string $integration, string $userId, string $code) { $entity = $this->getExternalAccountEntity($integration, $userId); if (!$entity) { @@ -99,7 +99,7 @@ class ExternalAccount extends Record $entity->set($name, $value); } $this->getEntityManager()->saveEntity($entity); - $this->getInjection('hookManager')->process('ExternalAccount', 'afterConnect', $entity, [ + $this->hookManager->process('ExternalAccount', 'afterConnect', $entity, [ 'integration' => $integration, 'userId' => $userId, 'code' => $code, diff --git a/application/Espo/Services/Import.php b/application/Espo/Services/Import.php index 7595f38149..331ee24bb7 100644 --- a/application/Espo/Services/Import.php +++ b/application/Espo/Services/Import.php @@ -39,18 +39,20 @@ use Espo\Entities\User; use StdClass; -class Import extends \Espo\Services\Record +use Espo\Core\Di; + +use Espo\Core\Record\Collection as RecordCollection; + +class Import extends \Espo\Services\Record implements + + Di\FileManagerAware, + Di\FileStorageManagerAware { + use Di\FileManagerSetter; + use Di\FileStorageManagerSetter; + const REVERT_PERMANENTLY_REMOVE_PERIOD_DAYS = 2; - protected function init() - { - parent::init(); - - $this->addDependency('fileManager'); - $this->addDependency('fileStorageManager'); - } - protected $dateFormatsMap = [ 'YYYY-MM-DD' => 'Y-m-d', 'DD-MM-YYYY' => 'd-m-Y', @@ -73,12 +75,12 @@ class Import extends \Espo\Services\Record protected function getFileStorageManager() { - return $this->getInjection('fileStorageManager'); + return $this->fileStorageManager; } protected function getFileManager() { - return $this->getInjection('fileManager'); + return $this->fileManager; } protected function getAcl() @@ -110,7 +112,7 @@ class Import extends \Espo\Services\Record ]); } - public function findLinked(string $id, string $link, array $params) : StdClass + public function findLinked(string $id, string $link, array $params) : RecordCollection { $entity = $this->getRepository()->get($id); $foreignEntityType = $entity->get('entityType'); @@ -139,13 +141,10 @@ class Import extends \Espo\Services\Record $total = $this->getRepository()->countRelated($entity, $link, $selectParams); - return (object) [ - 'total' => $total, - 'collection' => $collection, - ]; + return new RecordCollection($collection, $total); } - public function uploadFile($contents) + public function uploadFile($contents) : string { $attachment = $this->getEntityManager()->getEntity('Attachment'); $attachment->set('type', 'text/csv'); diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index 37d31a7352..54c80d5d57 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -34,6 +34,7 @@ use Espo\Core\Exceptions\{ BadRequest, Conflict, NotFound, + Forbidden, NotFoundSilent, ForbiddenSilent, ConflictSilent,