service refactoring
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\HookManager;
|
||||
|
||||
interface HookManagerAware
|
||||
{
|
||||
public function setHookManager(HookManager $hookManager);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\HookManager;
|
||||
|
||||
trait HookManagerSetter
|
||||
{
|
||||
protected $hookManager;
|
||||
|
||||
public function setHookManager(HookManager $hookManager)
|
||||
{
|
||||
$this->hookManager = $hookManager;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Htmlizer\Factory as HtmlizerFactory;
|
||||
|
||||
interface HtmlizerFactoryAware
|
||||
{
|
||||
public function setHtmlizerFactory(HtmlizerFactory $htmlizerFactory);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Htmlizer\Factory as HtmlizerFactory;
|
||||
|
||||
trait HtmlizerFactorySetter
|
||||
{
|
||||
protected $htmlizerFactory;
|
||||
|
||||
public function setHtmlizerFactory(HtmlizerFactory $htmlizerFactory)
|
||||
{
|
||||
$this->htmlizerFactory = $htmlizerFactory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Utils\Language;
|
||||
|
||||
interface LanguageAware
|
||||
{
|
||||
public function setLanguage(Language $language);
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
/************************************************************************
|
||||
* This file is part of EspoCRM.
|
||||
*
|
||||
* EspoCRM - Open Source CRM application.
|
||||
* Copyright (C) 2014-2020 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
|
||||
* Website: https://www.espocrm.com
|
||||
*
|
||||
* EspoCRM is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* EspoCRM is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with EspoCRM. If not, see http://www.gnu.org/licenses/.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Di;
|
||||
|
||||
use Espo\Core\Utils\Language;
|
||||
|
||||
trait LanguageSetter
|
||||
{
|
||||
protected $language;
|
||||
|
||||
public function setLanguage(Language $language)
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
}
|
||||
@@ -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'];
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -34,6 +34,7 @@ use Espo\Core\Exceptions\{
|
||||
BadRequest,
|
||||
Conflict,
|
||||
NotFound,
|
||||
Forbidden,
|
||||
NotFoundSilent,
|
||||
ForbiddenSilent,
|
||||
ConflictSilent,
|
||||
|
||||
Reference in New Issue
Block a user