mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
services refactoring
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace Espo\Controllers;
|
||||
|
||||
use \Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Notification extends \Espo\Core\Controllers\Record
|
||||
{
|
||||
@@ -47,18 +47,18 @@ class Notification extends \Espo\Core\Controllers\Record
|
||||
$maxSize = self::MAX_SIZE_LIMIT;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
$params = [
|
||||
'offset' => $offset,
|
||||
'maxSize' => $maxSize,
|
||||
'after' => $after
|
||||
);
|
||||
'after' => $after,
|
||||
];
|
||||
|
||||
$result = $this->getService('Notification')->getList($userId, $params);
|
||||
$recordCollection = $this->getService('Notification')->getList($userId, $params);
|
||||
|
||||
return array(
|
||||
'total' => $result['total'],
|
||||
'list' => $result['collection']->toArray()
|
||||
);
|
||||
return (object) [
|
||||
'total' => $recordCollection->getTotal(),
|
||||
'list' => $recordCollection->getValueMapList(),
|
||||
];
|
||||
}
|
||||
|
||||
public function actionNotReadCount()
|
||||
|
||||
37
application/Espo/Core/Di/DataManagerAware.php
Normal file
37
application/Espo/Core/Di/DataManagerAware.php
Normal file
@@ -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\DataManager;
|
||||
|
||||
interface DataManagerAware
|
||||
{
|
||||
public function setDataManager(DataManager $dataManager);
|
||||
}
|
||||
42
application/Espo/Core/Di/DataManagerSetter.php
Normal file
42
application/Espo/Core/Di/DataManagerSetter.php
Normal file
@@ -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\DataManager;
|
||||
|
||||
trait DataManagerSetter
|
||||
{
|
||||
protected $dataManager;
|
||||
|
||||
public function setDataManager(DataManager $dataManager)
|
||||
{
|
||||
$this->dataManager = $dataManager;
|
||||
}
|
||||
}
|
||||
37
application/Espo/Core/Di/DefaultLanguageAware.php
Normal file
37
application/Espo/Core/Di/DefaultLanguageAware.php
Normal file
@@ -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 DefaultLanguageAware
|
||||
{
|
||||
public function setDefaultLanguage(Language $defaultLanguage);
|
||||
}
|
||||
42
application/Espo/Core/Di/DefaultLanguageSetter.php
Normal file
42
application/Espo/Core/Di/DefaultLanguageSetter.php
Normal file
@@ -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 DefaultLanguageSetter
|
||||
{
|
||||
protected $defaultLanguage;
|
||||
|
||||
public function setDefaultLanguage(Language $defaultLanguage)
|
||||
{
|
||||
$this->defaultLanguage = $defaultLanguage;
|
||||
}
|
||||
}
|
||||
37
application/Espo/Core/Di/UserAware - Copy.php
Normal file
37
application/Espo/Core/Di/UserAware - Copy.php
Normal file
@@ -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\Entities\User;
|
||||
|
||||
interface UserAware
|
||||
{
|
||||
public function setUser(User $user);
|
||||
}
|
||||
37
application/Espo/Core/Di/WebSocketSubmissionAware.php
Normal file
37
application/Espo/Core/Di/WebSocketSubmissionAware.php
Normal file
@@ -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\WebSocket\Submission;
|
||||
|
||||
interface WebSocketSubmissionAware
|
||||
{
|
||||
public function setWebSocketSubmission(Submission $webSocketSubmission);
|
||||
}
|
||||
42
application/Espo/Core/Di/WebSocketSubmissionSetter.php
Normal file
42
application/Espo/Core/Di/WebSocketSubmissionSetter.php
Normal file
@@ -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\WebSocket\Submission;
|
||||
|
||||
trait WebSocketSubmissionSetter
|
||||
{
|
||||
protected $webSocketSubmission;
|
||||
|
||||
public function setWebSocketSubmission(Submission $webSocketSubmission)
|
||||
{
|
||||
$this->webSocketSubmission = $webSocketSubmission;
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ use Espo\ORM\{
|
||||
ICollection,
|
||||
};
|
||||
|
||||
use StdClass;
|
||||
|
||||
/**
|
||||
* Contains an ORM collection and total number of records.
|
||||
*/
|
||||
|
||||
@@ -32,26 +32,39 @@ namespace Espo\Services;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class Layout extends \Espo\Core\Services\Base
|
||||
use Espo\Core\{
|
||||
Acl,
|
||||
Utils\Layout as LayoutUtil,
|
||||
ORM\EntityManager,
|
||||
Utils\Metadata,
|
||||
DataManager,
|
||||
};
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class Layout
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
$this->addDependency('acl');
|
||||
$this->addDependency('layout');
|
||||
$this->addDependency('entityManager');
|
||||
$this->addDependency('metadata');
|
||||
$this->addDependency('dataManager');
|
||||
$this->addDependency('user');
|
||||
}
|
||||
protected $acl;
|
||||
protected $layout;
|
||||
protected $entityManager;
|
||||
protected $metadata;
|
||||
protected $dataManager;
|
||||
protected $user;
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->getInjection('acl');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
public function __construct(
|
||||
Acl $acl,
|
||||
LayoutUtil $layout,
|
||||
EntityManager $entityManager,
|
||||
Metadata $metadata,
|
||||
DataManager $dataManager,
|
||||
User $user
|
||||
) {
|
||||
$this->acl = $acl;
|
||||
$this->layout = $layout;
|
||||
$this->entityManager = $entityManager;
|
||||
$this->metadata = $metadata;
|
||||
$this->dataManager = $dataManager;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getOriginal(string $scope, string $name, ?string $setId = null)
|
||||
@@ -66,7 +79,7 @@ class Layout extends \Espo\Core\Services\Base
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
$result = $this->getInjection('layout')->get($scope, $name);
|
||||
$result = $this->layout->get($scope, $name);
|
||||
$result = json_decode($result);
|
||||
}
|
||||
|
||||
@@ -85,8 +98,8 @@ class Layout extends \Espo\Core\Services\Base
|
||||
$layoutSetId = null;
|
||||
$data = null;
|
||||
|
||||
$em = $this->getInjection('entityManager');
|
||||
$user = $this->getInjection('user');
|
||||
$em = $this->entityManager;
|
||||
$user = $this->user;
|
||||
|
||||
if ($user->isPortal()) {
|
||||
$portalId = $user->get('portalId');
|
||||
@@ -122,7 +135,7 @@ class Layout extends \Espo\Core\Services\Base
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$dataString = $this->getInjection('layout')->get($scope, $name);
|
||||
$dataString = $this->layout->get($scope, $name);
|
||||
$data = json_decode($dataString);
|
||||
} else {
|
||||
$dataString = json_encode($data);
|
||||
@@ -132,15 +145,15 @@ class Layout extends \Espo\Core\Services\Base
|
||||
throw new NotFound("Layout {$scope}:{$name} is not found.");
|
||||
}
|
||||
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
if (!$this->user->isAdmin()) {
|
||||
if ($name === 'relationships') {
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $i => $item) {
|
||||
$link = $item;
|
||||
if (is_object($item)) $link = $item->name ?? null;
|
||||
$foreignEntityType = $this->getMetadata()->get(['entityDefs', $scope, 'links', $link, 'entity']);
|
||||
$foreignEntityType = $this->metadata->get(['entityDefs', $scope, 'links', $link, 'entity']);
|
||||
if ($foreignEntityType) {
|
||||
if (!$this->getAcl()->check($foreignEntityType)) {
|
||||
if (!$this->acl->check($foreignEntityType)) {
|
||||
unset($data[$i]);
|
||||
}
|
||||
}
|
||||
@@ -162,7 +175,7 @@ class Layout extends \Espo\Core\Services\Base
|
||||
|
||||
protected function getRecordFromSet(string $scope, string $name, string $setId, bool $skipCheck = false)
|
||||
{
|
||||
$em = $this->getInjection('entityManager');
|
||||
$em = $this->entityManager;
|
||||
$layoutSet = $em->getEntity('LayoutSet', $setId);
|
||||
if (!$layoutSet) throw new NotFound("LayoutSet {$setId} not found.");
|
||||
|
||||
@@ -188,7 +201,7 @@ class Layout extends \Espo\Core\Services\Base
|
||||
if ($setId) {
|
||||
$layout = $this->getRecordFromSet($scope, $name, $setId);
|
||||
|
||||
$em = $this->getInjection('entityManager');
|
||||
$em = $this->entityManager;
|
||||
|
||||
if (!$layout) {
|
||||
$layout = $em->getEntity('LayoutRecord');
|
||||
@@ -205,32 +218,32 @@ class Layout extends \Espo\Core\Services\Base
|
||||
return $layout->get('data');
|
||||
}
|
||||
|
||||
$layoutManager = $this->getInjection('layout');
|
||||
$layoutManager = $this->layout;
|
||||
|
||||
$layoutManager->set($data, $scope, $name);
|
||||
$result = $layoutManager->save();
|
||||
|
||||
if ($result === false) throw new Error("Error while saving layout.");
|
||||
|
||||
$this->getInjection('dataManager')->updateCacheTimestamp();
|
||||
$this->dataManager->updateCacheTimestamp();
|
||||
|
||||
return $layoutManager->get($scope, $name);
|
||||
}
|
||||
|
||||
public function resetToDefault(string $scope, string $name, ?string $setId = null)
|
||||
{
|
||||
$this->getInjection('dataManager')->updateCacheTimestamp();
|
||||
$this->dataManager->updateCacheTimestamp();
|
||||
|
||||
if ($setId) {
|
||||
$layout = $this->getRecordFromSet($scope, $name, $setId);
|
||||
if ($layout) {
|
||||
$em = $this->getInjection('entityManager');
|
||||
$em = $this->entityManager;
|
||||
$em->removeEntity($layout);
|
||||
}
|
||||
return $this->getOriginal($scope, $name);
|
||||
}
|
||||
|
||||
$this->getInjection('layout')->resetToDefault($scope, $name);
|
||||
$this->layout->resetToDefault($scope, $name);
|
||||
|
||||
$methodName = 'resetToDefault' . ucfirst($name);
|
||||
if (method_exists($this, $methodName)) {
|
||||
@@ -272,6 +285,6 @@ class Layout extends \Espo\Core\Services\Base
|
||||
|
||||
protected function resetToDefaultBottomPanelsDetail(string $scope)
|
||||
{
|
||||
$this->getInjection('layout')->resetToDefault($scope, 'relationships');
|
||||
$this->layout->resetToDefault($scope, 'relationships');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,24 +37,24 @@ use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
|
||||
class LeadCapture extends Record
|
||||
use Espo\Core\Di;
|
||||
|
||||
class LeadCapture extends Record implements
|
||||
|
||||
Di\MailSenderAware,
|
||||
Di\DateTimeAware,
|
||||
Di\DefaultLanguageAware,
|
||||
Di\FieldManagerUtilAware,
|
||||
Di\HookManagerAware
|
||||
{
|
||||
use Di\MailSenderSetter;
|
||||
use Di\DateTimeSetter;
|
||||
use Di\DefaultLanguageSetter;
|
||||
use Di\FieldManagerUtilSetter;
|
||||
use Di\HookManagerSetter;
|
||||
|
||||
protected $readOnlyAttributeList = ['apiKey'];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
$this->addDependency('fieldManagerUtil');
|
||||
$this->addDependency('mailSender');
|
||||
$this->addDependency('defaultLanguage');
|
||||
$this->addDependency('hookManager');
|
||||
$this->addDependency('dateTime');
|
||||
}
|
||||
|
||||
protected function getMailSender()
|
||||
{
|
||||
return $this->getInjection('mailSender');
|
||||
}
|
||||
|
||||
public function prepareEntityForOutput(Entity $entity)
|
||||
{
|
||||
parent::prepareEntityForOutput($entity);
|
||||
@@ -64,7 +64,7 @@ class LeadCapture extends Record
|
||||
$requestUrl = $this->getConfig()->getSiteUrl() . '/api/v1/LeadCapture/' . $entity->get('apiKey');
|
||||
$entity->set('exampleRequestUrl', $requestUrl);
|
||||
|
||||
$fieldManagerUtil = $this->getInjection('fieldManagerUtil');
|
||||
$fieldManagerUtil = $this->fieldManagerUtil;
|
||||
|
||||
$requestPayload = "```{\n";
|
||||
|
||||
@@ -238,7 +238,7 @@ class LeadCapture extends Record
|
||||
}
|
||||
continue;
|
||||
}
|
||||
$attributeList = $this->getInjection('fieldManagerUtil')->getActualAttributeList('Lead', $field);
|
||||
$attributeList = $this->fieldManagerUtil->getActualAttributeList('Lead', $field);
|
||||
if (empty($attributeList)) continue;
|
||||
foreach ($attributeList as $attribute) {
|
||||
if (property_exists($data, $attribute)) {
|
||||
@@ -348,7 +348,7 @@ class LeadCapture extends Record
|
||||
|
||||
$targetList = $this->getEntityManager()->getEntity('TargetList', $leadCapture->get('targetListId'));
|
||||
if ($targetList) {
|
||||
$this->getInjection('hookManager')->process('TargetList', 'afterOptIn', $targetList, [], [
|
||||
$this->hookManager->process('TargetList', 'afterOptIn', $targetList, [], [
|
||||
'link' => 'contacts',
|
||||
'targetId' => $contact->id,
|
||||
'targetType' => 'Contact',
|
||||
@@ -372,11 +372,11 @@ class LeadCapture extends Record
|
||||
}
|
||||
|
||||
if ($contact && (!$isContactOptedIn || !$leadCapture->get('subscribeToTargetList'))) {
|
||||
$this->getInjection('hookManager')->process('LeadCapture', 'afterLeadCapture', $leadCapture, [], [
|
||||
$this->hookManager->process('LeadCapture', 'afterLeadCapture', $leadCapture, [], [
|
||||
'targetId' => $contact->id,
|
||||
'targetType' => 'Contact',
|
||||
]);
|
||||
$this->getInjection('hookManager')->process('Contact', 'afterLeadCapture', $contact, [], [
|
||||
$this->hookManager->process('Contact', 'afterLeadCapture', $contact, [], [
|
||||
'leadCaptureId' => $leadCapture->id,
|
||||
]);
|
||||
}
|
||||
@@ -406,7 +406,7 @@ class LeadCapture extends Record
|
||||
|
||||
$targetList = $this->getEntityManager()->getEntity('TargetList', $leadCapture->get('targetListId'));
|
||||
if ($targetList) {
|
||||
$this->getInjection('hookManager')->process('TargetList', 'afterOptIn', $targetList, [], [
|
||||
$this->hookManager->process('TargetList', 'afterOptIn', $targetList, [], [
|
||||
'link' => 'leads',
|
||||
'targetId' => $targetLead->id,
|
||||
'targetType' => 'Lead',
|
||||
@@ -416,11 +416,11 @@ class LeadCapture extends Record
|
||||
}
|
||||
|
||||
if ($toRelateLead || !$leadCapture->get('subscribeToTargetList')) {
|
||||
$this->getInjection('hookManager')->process('LeadCapture', 'afterLeadCapture', $leadCapture, [], [
|
||||
$this->hookManager->process('LeadCapture', 'afterLeadCapture', $leadCapture, [], [
|
||||
'targetId' => $targetLead->id,
|
||||
'targetType' => 'Lead',
|
||||
]);
|
||||
$this->getInjection('hookManager')->process('Lead', 'afterLeadCapture', $targetLead, [], [
|
||||
$this->hookManager->process('Lead', 'afterLeadCapture', $targetLead, [], [
|
||||
'leadCaptureId' => $leadCapture->id,
|
||||
]);
|
||||
}
|
||||
@@ -541,16 +541,16 @@ class LeadCapture extends Record
|
||||
}
|
||||
|
||||
$url = $this->getConfig()->getSiteUrl() . '/?entryPoint=confirmOptIn&id=' . $uniqueId->get('name');
|
||||
$linkHtml = '<a href='.$url.'>'.$this->getInjection('defaultLanguage')->translate('Confirm Opt-In', 'labels', 'LeadCapture').'</a>';
|
||||
$linkHtml = '<a href='.$url.'>'.$this->defaultLanguage->translate('Confirm Opt-In', 'labels', 'LeadCapture').'</a>';
|
||||
|
||||
$body = str_replace('{optInUrl}', $url, $body);
|
||||
$body = str_replace('{optInLink}', $linkHtml, $body);
|
||||
|
||||
$createdAt = $uniqueId->get('createdAt');
|
||||
if ($createdAt) {
|
||||
$dateString = $this->getInjection('dateTime')->convertSystemDateTime($createdAt, null, $this->getConfig()->get('dateFormat'));
|
||||
$timeString = $this->getInjection('dateTime')->convertSystemDateTime($createdAt, null, $this->getConfig()->get('timeFormat'));
|
||||
$dateTimeString = $this->getInjection('dateTime')->convertSystemDateTime($createdAt);
|
||||
$dateString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->getConfig()->get('dateFormat'));
|
||||
$timeString = $this->dateTime->convertSystemDateTime($createdAt, null, $this->getConfig()->get('timeFormat'));
|
||||
$dateTimeString = $this->dateTime->convertSystemDateTime($createdAt);
|
||||
|
||||
$body = str_replace('{optInDate}', $dateString, $body);
|
||||
$body = str_replace('{optInTime}', $timeString, $body);
|
||||
@@ -590,7 +590,7 @@ class LeadCapture extends Record
|
||||
}
|
||||
}
|
||||
|
||||
$sender = $this->getMailSender();
|
||||
$sender = $this->mailSender;
|
||||
|
||||
if ($smtpParams) {
|
||||
$sender->useSmtp($smtpParams);
|
||||
@@ -621,7 +621,7 @@ class LeadCapture extends Record
|
||||
if (time() > strtotime($terminateAt)) {
|
||||
return (object) [
|
||||
'status' => 'expired',
|
||||
'message' => $this->getInjection('defaultLanguage')->translate('optInConfirmationExpired', 'messages', 'LeadCapture')
|
||||
'message' => $this->defaultLanguage->translate('optInConfirmationExpired', 'messages', 'LeadCapture')
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -29,44 +29,35 @@
|
||||
|
||||
namespace Espo\Services;
|
||||
|
||||
class Metadata extends \Espo\Core\Services\Base
|
||||
use Espo\Core\{
|
||||
Acl,
|
||||
Utils\Metadata as MetadataUtil,
|
||||
};
|
||||
|
||||
use Espo\Entities\User;
|
||||
|
||||
class Metadata
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
$this->addDependency('metadata');
|
||||
$this->addDependency('acl');
|
||||
}
|
||||
protected $acl;
|
||||
protected $metadata;
|
||||
protected $user;
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->getInjection('acl');
|
||||
}
|
||||
|
||||
protected function getDefaultLanguage()
|
||||
{
|
||||
return $this->getInjection('container')->get('defaultLanguage');
|
||||
}
|
||||
|
||||
protected function getLanguage()
|
||||
{
|
||||
return $this->getInjection('container')->get('language');
|
||||
public function __construct(Acl $acl, MetadataUtil $metadata, User $user) {
|
||||
$this->acl = $acl;
|
||||
$this->metadata = $metadata;
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getDataForFrontend()
|
||||
{
|
||||
$data = $this->getMetadata()->getAllForFrontend();
|
||||
$data = $this->metadata->getAllForFrontend();
|
||||
|
||||
if (!$this->getUser()->isAdmin()) {
|
||||
$scopeList = array_keys($this->getMetadata()->get(['scopes'], []));
|
||||
if (!$this->user->isAdmin()) {
|
||||
$scopeList = array_keys($this->metadata->get(['scopes'], []));
|
||||
foreach ($scopeList as $scope) {
|
||||
if (!$this->getMetadata()->get(['scopes', $scope, 'entity'])) continue;
|
||||
if (!$this->metadata->get(['scopes', $scope, 'entity'])) continue;
|
||||
if (in_array($scope, ['Reminder'])) continue;
|
||||
if (!$this->getAcl()->check($scope)) {
|
||||
if (!$this->acl->check($scope)) {
|
||||
unset($data->entityDefs->$scope);
|
||||
unset($data->clientDefs->$scope);
|
||||
unset($data->entityAcl->$scope);
|
||||
@@ -76,21 +67,21 @@ class Metadata extends \Espo\Core\Services\Base
|
||||
|
||||
$entityTypeList = array_keys(get_object_vars($data->entityDefs));
|
||||
foreach ($entityTypeList as $entityType) {
|
||||
$linksDefs = $this->getMetadata()->get(['entityDefs', $entityType, 'links'], []);
|
||||
$linksDefs = $this->metadata->get(['entityDefs', $entityType, 'links'], []);
|
||||
|
||||
$fobiddenFieldList = $this->getAcl()->getScopeForbiddenFieldList($entityType);
|
||||
$fobiddenFieldList = $this->acl->getScopeForbiddenFieldList($entityType);
|
||||
|
||||
foreach ($linksDefs as $link => $defs) {
|
||||
$type = $defs['type'] ?? null;
|
||||
|
||||
$hasField = !!$this->getMetadata()->get(['entityDefs', $entityType, 'fields', $link]);
|
||||
$hasField = !!$this->metadata->get(['entityDefs', $entityType, 'fields', $link]);
|
||||
|
||||
if ($type === 'belongsToParent') {
|
||||
if ($hasField) {
|
||||
$parentEntityList = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $link, 'entityList']);
|
||||
$parentEntityList = $this->metadata->get(['entityDefs', $entityType, 'fields', $link, 'entityList']);
|
||||
if (is_array($parentEntityList)) {
|
||||
foreach ($parentEntityList as $i => $e) {
|
||||
if (!$this->getAcl()->check($e)) {
|
||||
if (!$this->acl->check($e)) {
|
||||
unset($parentEntityList[$i]);
|
||||
}
|
||||
}
|
||||
@@ -104,9 +95,9 @@ class Metadata extends \Espo\Core\Services\Base
|
||||
$foreignEntityType = $defs['entity'] ?? null;
|
||||
|
||||
if ($foreignEntityType) {
|
||||
if ($this->getAcl()->check($foreignEntityType)) continue;
|
||||
if ($this->acl->check($foreignEntityType)) continue;
|
||||
|
||||
if ($this->getUser()->isPortal()) {
|
||||
if ($this->user->isPortal()) {
|
||||
if ($foreignEntityType === 'Account' || $foreignEntityType === 'Contact') {
|
||||
continue;
|
||||
}
|
||||
@@ -136,11 +127,11 @@ class Metadata extends \Espo\Core\Services\Base
|
||||
|
||||
unset($data->entityDefs->Settings);
|
||||
|
||||
$dashletList = array_keys($this->getMetadata()->get(['dashlets'], []));
|
||||
$dashletList = array_keys($this->metadata->get(['dashlets'], []));
|
||||
|
||||
foreach ($dashletList as $item) {
|
||||
$aclScope = $this->getMetadata()->get(['dashlets', $item, 'aclScope']);
|
||||
if ($aclScope && !$this->getAcl()->check($aclScope)) {
|
||||
$aclScope = $this->metadata->get(['dashlets', $item, 'aclScope']);
|
||||
if ($aclScope && !$this->acl->check($aclScope)) {
|
||||
unset($data->dashlets->$item);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +139,7 @@ class Metadata extends \Espo\Core\Services\Base
|
||||
unset($data->authenticationMethods);
|
||||
unset($data->formula);
|
||||
|
||||
foreach (($this->getMetadata()->get(['app', 'metadata', 'aclDependencies']) ?? []) as $target => $item) {
|
||||
foreach (($this->metadata->get(['app', 'metadata', 'aclDependencies']) ?? []) as $target => $item) {
|
||||
$targetArr = explode('.', $target);
|
||||
|
||||
if (is_string($item)) {
|
||||
@@ -164,14 +155,14 @@ class Metadata extends \Espo\Core\Services\Base
|
||||
$aclScope = $item['scope'] ?? null;;
|
||||
$aclField = $item['field'] ?? null;
|
||||
if (!$aclScope) continue;
|
||||
if (!$this->getAcl()->check($aclScope)) continue;
|
||||
if ($aclField && in_array($aclField, $this->getAcl()->getScopeForbiddenFieldList($aclScope))) continue;
|
||||
if (!$this->acl->check($aclScope)) continue;
|
||||
if ($aclField && in_array($aclField, $this->acl->getScopeForbiddenFieldList($aclScope))) continue;
|
||||
}
|
||||
|
||||
$pointer = $data;
|
||||
foreach ($targetArr as $i => $k) {
|
||||
if ($i === count($targetArr) - 1) {
|
||||
$pointer->$k = $this->getMetadata()->get($targetArr);
|
||||
$pointer->$k = $this->metadata->get($targetArr);
|
||||
break;
|
||||
}
|
||||
if (!isset($pointer->$k)) {
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace Espo\Services;
|
||||
|
||||
use Espo\Core\Utils\Database\Schema\Utils as SchemaUtils;
|
||||
|
||||
|
||||
// TODO remove
|
||||
class MysqlCharacter extends \Espo\Core\Services\Base
|
||||
{
|
||||
protected function init()
|
||||
@@ -142,4 +144,4 @@ class MysqlCharacter extends \Espo\Core\Services\Base
|
||||
|
||||
$this->getContainer()->get('dataManager')->rebuild();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,17 +36,22 @@ use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\Utils\Json;
|
||||
|
||||
class Notification extends \Espo\Services\Record
|
||||
use Espo\Core\Record\Collection as RecordCollection;
|
||||
|
||||
use Espo\Entities\Note;
|
||||
use Espo\Entities\User;
|
||||
|
||||
use Espo\Core\Di;
|
||||
|
||||
class Notification extends \Espo\Services\Record implements
|
||||
|
||||
Di\WebSocketSubmissionAware
|
||||
{
|
||||
use Di\WebSocketSubmissionSetter;
|
||||
|
||||
protected $actionHistoryDisabled = true;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->addDependency('webSocketSubmission');
|
||||
}
|
||||
|
||||
public function notifyAboutMentionInPost($userId, $noteId)
|
||||
public function notifyAboutMentionInPost(string $userId, string $noteId)
|
||||
{
|
||||
$notification = $this->getEntityManager()->getEntity('Notification');
|
||||
$notification->set(array(
|
||||
@@ -59,7 +64,7 @@ class Notification extends \Espo\Services\Record
|
||||
$this->getEntityManager()->saveEntity($notification);
|
||||
}
|
||||
|
||||
public function notifyAboutNote(array $userIdList, \Espo\Entities\Note $note)
|
||||
public function notifyAboutNote(array $userIdList, Note $note)
|
||||
{
|
||||
$data = ['noteId' => $note->id];
|
||||
$encodedData = Json::encode($data);
|
||||
@@ -101,12 +106,12 @@ class Notification extends \Espo\Services\Record
|
||||
|
||||
if ($this->getConfig()->get('useWebSocket')) {
|
||||
foreach ($userIdList as $userId) {
|
||||
$this->getInjection('webSocketSubmission')->submit('newNotification', $userId);
|
||||
$this->webSocketSubmission->submit('newNotification', $userId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function checkUserNoteAccess(\Espo\Entities\User $user, \Espo\Entities\Note $note)
|
||||
public function checkUserNoteAccess(User $user, Note $note) : bool
|
||||
{
|
||||
if ($user->isPortal()) {
|
||||
if ($note->get('relatedType')) {
|
||||
@@ -133,7 +138,7 @@ class Notification extends \Espo\Services\Record
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getNotReadCount($userId)
|
||||
public function getNotReadCount(string $userId) : int
|
||||
{
|
||||
$whereClause = array(
|
||||
'userId' => $userId,
|
||||
@@ -155,7 +160,7 @@ class Notification extends \Espo\Services\Record
|
||||
return $this->getEntityManager()->getRepository('Notification')->where($whereClause)->count();
|
||||
}
|
||||
|
||||
public function markAllRead($userId)
|
||||
public function markAllRead(string $userId)
|
||||
{
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$sql = "UPDATE notification SET `read` = 1 WHERE user_id = ".$pdo->quote($userId)." AND `read` = 0";
|
||||
@@ -163,13 +168,13 @@ class Notification extends \Espo\Services\Record
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getList($userId, array $params = array())
|
||||
public function getList(string $userId, array $params = []) : RecordCollection
|
||||
{
|
||||
$searchParams = array();
|
||||
$searchParams = [];
|
||||
|
||||
$whereClause = array(
|
||||
$whereClause = [
|
||||
'userId' => $userId
|
||||
);
|
||||
];
|
||||
if (!empty($params['after'])) {
|
||||
$whereClause['createdAt>'] = $params['after'];
|
||||
}
|
||||
@@ -177,12 +182,12 @@ class Notification extends \Espo\Services\Record
|
||||
$ignoreScopeList = $this->getIgnoreScopeList();
|
||||
if (!empty($ignoreScopeList)) {
|
||||
$where = [];
|
||||
$where[] = array(
|
||||
'OR' => array(
|
||||
$where[] = [
|
||||
'OR' => [
|
||||
'relatedParentType' => null,
|
||||
'relatedParentType!=' => $ignoreScopeList
|
||||
)
|
||||
);
|
||||
]
|
||||
];
|
||||
$whereClause[] = $where;
|
||||
}
|
||||
|
||||
@@ -200,7 +205,7 @@ class Notification extends \Espo\Services\Record
|
||||
$collection = $this->getEntityManager()->getRepository('Notification')->find($searchParams);
|
||||
$count = $this->getEntityManager()->getRepository('Notification')->count($searchParams);
|
||||
|
||||
$ids = array();
|
||||
$ids = [];
|
||||
foreach ($collection as $k => $entity) {
|
||||
$ids[] = $entity->id;
|
||||
$data = $entity->get('data');
|
||||
@@ -262,17 +267,13 @@ class Notification extends \Espo\Services\Record
|
||||
$s->execute();
|
||||
}
|
||||
|
||||
|
||||
return array(
|
||||
'total' => $count,
|
||||
'collection' => $collection
|
||||
);
|
||||
return new RecordCollection($collection, $count);
|
||||
}
|
||||
|
||||
protected function getIgnoreScopeList()
|
||||
protected function getIgnoreScopeList() : array
|
||||
{
|
||||
$ignoreScopeList = [];
|
||||
$scopes = $this->getMetadata()->get('scopes', array());
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
foreach ($scopes as $scope => $d) {
|
||||
if (empty($d['entity']) || !$d['entity']) continue;
|
||||
if (empty($d['object']) || !$d['object']) continue;
|
||||
@@ -283,4 +284,3 @@ class Notification extends \Espo\Services\Record
|
||||
return $ignoreScopeList;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -31,16 +31,17 @@ namespace Espo\Services;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Portal extends Record
|
||||
{
|
||||
protected $getEntityBeforeUpdate = true;
|
||||
use Espo\Core\Di;
|
||||
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->addDependency('fileManager');
|
||||
$this->addDependency('dataManager');
|
||||
}
|
||||
class Portal extends Record implements
|
||||
|
||||
Di\FileManagerAware,
|
||||
Di\DataManagerAware
|
||||
{
|
||||
use Di\FileManagerSetter;
|
||||
use Di\DataManagerSetter;
|
||||
|
||||
protected $getEntityBeforeUpdate = true;
|
||||
|
||||
public function loadAdditionalFields(Entity $entity)
|
||||
{
|
||||
@@ -70,7 +71,7 @@ class Portal extends Record
|
||||
|
||||
protected function clearRolesCache()
|
||||
{
|
||||
$this->getInjection('fileManager')->removeInDir('data/cache/application/acl-portal');
|
||||
$this->getInjection('dataManager')->updateCacheTimestamp();
|
||||
$this->fileManager->removeInDir('data/cache/application/acl-portal');
|
||||
$this->dataManager->updateCacheTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,15 @@ namespace Espo\Services;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class PortalRole extends Record
|
||||
use Espo\Core\Di;
|
||||
|
||||
class PortalRole extends Record implements
|
||||
|
||||
Di\FileManagerAware,
|
||||
Di\DataManagerAware
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->addDependency('fileManager');
|
||||
$this->addDependency('dataManager');
|
||||
}
|
||||
use Di\FileManagerSetter;
|
||||
use Di\DataManagerSetter;
|
||||
|
||||
protected $forceSelectAllAttributes = true;
|
||||
|
||||
@@ -56,7 +57,7 @@ class PortalRole extends Record
|
||||
|
||||
protected function clearRolesCache()
|
||||
{
|
||||
$this->getInjection('fileManager')->removeInDir('data/cache/application/acl-portal');
|
||||
$this->getInjection('dataManager')->updateCacheTimestamp();
|
||||
$this->fileManager->removeInDir('data/cache/application/acl-portal');
|
||||
$this->dataManager->updateCacheTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,14 +31,15 @@ namespace Espo\Services;
|
||||
|
||||
use Espo\ORM\Entity;
|
||||
|
||||
class Role extends Record
|
||||
use Espo\Core\Di;
|
||||
|
||||
class Role extends Record implements
|
||||
|
||||
Di\FileManagerAware,
|
||||
Di\DataManagerAware
|
||||
{
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->addDependency('fileManager');
|
||||
$this->addDependency('dataManager');
|
||||
}
|
||||
use Di\FileManagerSetter;
|
||||
use Di\DataManagerSetter;
|
||||
|
||||
protected $forceSelectAllAttributes = true;
|
||||
|
||||
@@ -56,7 +57,7 @@ class Role extends Record
|
||||
|
||||
protected function clearRolesCache()
|
||||
{
|
||||
$this->getInjection('fileManager')->removeInDir('data/cache/application/acl');
|
||||
$this->getInjection('dataManager')->updateCacheTimestamp();
|
||||
$this->fileManager->removeInDir('data/cache/application/acl');
|
||||
$this->dataManager->updateCacheTimestamp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,8 @@ use Espo\ORM\Entity;
|
||||
|
||||
use Espo\Core\Exceptions\BadRequest;
|
||||
|
||||
use Cron\CronExpression;
|
||||
|
||||
class ScheduledJob extends Record
|
||||
{
|
||||
protected $findLinkedLogCountQueryDisabled = true;
|
||||
@@ -44,7 +46,7 @@ class ScheduledJob extends Record
|
||||
$scheduling = $entity->get('scheduling');
|
||||
|
||||
try {
|
||||
$cronExpression = \Cron\CronExpression::factory($scheduling);
|
||||
$cronExpression = CronExpression::factory($scheduling);
|
||||
$nextDate = $cronExpression->getNextRunDate()->format('Y-m-d H:i:s');
|
||||
} catch (\Exception $e) {
|
||||
throw new BadRequest("Not valid scheduling expression.");
|
||||
|
||||
Reference in New Issue
Block a user