diff --git a/application/Espo/Controllers/Notification.php b/application/Espo/Controllers/Notification.php
index 1f0ba6841e..55beca71da 100644
--- a/application/Espo/Controllers/Notification.php
+++ b/application/Espo/Controllers/Notification.php
@@ -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()
diff --git a/application/Espo/Core/Di/DataManagerAware.php b/application/Espo/Core/Di/DataManagerAware.php
new file mode 100644
index 0000000000..fcb1049405
--- /dev/null
+++ b/application/Espo/Core/Di/DataManagerAware.php
@@ -0,0 +1,37 @@
+dataManager = $dataManager;
+ }
+}
diff --git a/application/Espo/Core/Di/DefaultLanguageAware.php b/application/Espo/Core/Di/DefaultLanguageAware.php
new file mode 100644
index 0000000000..3ca78caebb
--- /dev/null
+++ b/application/Espo/Core/Di/DefaultLanguageAware.php
@@ -0,0 +1,37 @@
+defaultLanguage = $defaultLanguage;
+ }
+}
diff --git a/application/Espo/Core/Di/UserAware - Copy.php b/application/Espo/Core/Di/UserAware - Copy.php
new file mode 100644
index 0000000000..2b37a64ef4
--- /dev/null
+++ b/application/Espo/Core/Di/UserAware - Copy.php
@@ -0,0 +1,37 @@
+webSocketSubmission = $webSocketSubmission;
+ }
+}
diff --git a/application/Espo/Core/Record/Collection.php b/application/Espo/Core/Record/Collection.php
index bdb360303e..be73e72a55 100644
--- a/application/Espo/Core/Record/Collection.php
+++ b/application/Espo/Core/Record/Collection.php
@@ -33,6 +33,8 @@ use Espo\ORM\{
ICollection,
};
+use StdClass;
+
/**
* Contains an ORM collection and total number of records.
*/
diff --git a/application/Espo/Services/Layout.php b/application/Espo/Services/Layout.php
index c214d2e914..f04beea0fc 100644
--- a/application/Espo/Services/Layout.php
+++ b/application/Espo/Services/Layout.php
@@ -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');
}
}
diff --git a/application/Espo/Services/LeadCapture.php b/application/Espo/Services/LeadCapture.php
index 4292df528e..171653e79a 100644
--- a/application/Espo/Services/LeadCapture.php
+++ b/application/Espo/Services/LeadCapture.php
@@ -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 = ''.$this->getInjection('defaultLanguage')->translate('Confirm Opt-In', 'labels', 'LeadCapture').'';
+ $linkHtml = ''.$this->defaultLanguage->translate('Confirm Opt-In', 'labels', 'LeadCapture').'';
$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')
];
}
diff --git a/application/Espo/Services/Metadata.php b/application/Espo/Services/Metadata.php
index a375d03ecf..e20fa4a9ca 100644
--- a/application/Espo/Services/Metadata.php
+++ b/application/Espo/Services/Metadata.php
@@ -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)) {
diff --git a/application/Espo/Services/MysqlCharacter.php b/application/Espo/Services/MysqlCharacter.php
index 6168933b51..530453f12a 100644
--- a/application/Espo/Services/MysqlCharacter.php
+++ b/application/Espo/Services/MysqlCharacter.php
@@ -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();
}
-}
\ No newline at end of file
+}
diff --git a/application/Espo/Services/Notification.php b/application/Espo/Services/Notification.php
index 983352413b..3c3cf85815 100644
--- a/application/Espo/Services/Notification.php
+++ b/application/Espo/Services/Notification.php
@@ -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;
}
}
-
diff --git a/application/Espo/Services/Portal.php b/application/Espo/Services/Portal.php
index 141befd2f8..b58892d10b 100644
--- a/application/Espo/Services/Portal.php
+++ b/application/Espo/Services/Portal.php
@@ -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();
}
}
diff --git a/application/Espo/Services/PortalRole.php b/application/Espo/Services/PortalRole.php
index 9249ca22ea..35f45e4e50 100644
--- a/application/Espo/Services/PortalRole.php
+++ b/application/Espo/Services/PortalRole.php
@@ -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();
}
}
diff --git a/application/Espo/Services/Role.php b/application/Espo/Services/Role.php
index 763c9ec955..c55b5a5612 100644
--- a/application/Espo/Services/Role.php
+++ b/application/Espo/Services/Role.php
@@ -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();
}
}
diff --git a/application/Espo/Services/ScheduledJob.php b/application/Espo/Services/ScheduledJob.php
index 8fddfda57d..73554cbaa9 100644
--- a/application/Espo/Services/ScheduledJob.php
+++ b/application/Espo/Services/ScheduledJob.php
@@ -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.");