mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
stream service refactoring
This commit is contained in:
@@ -35,7 +35,19 @@ use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\ORM\Entity;
|
||||
use Espo\Entities\User;
|
||||
|
||||
class Stream extends \Espo\Core\Services\Base
|
||||
use Espo\Core\{
|
||||
ORM\EntityManager,
|
||||
Utils\Config,
|
||||
Utils\Metadata,
|
||||
Acl,
|
||||
AclManager,
|
||||
ServiceFactory,
|
||||
Portal\AclManagerContainer as PortalAclManagerContainer,
|
||||
SelectManagerFactory,
|
||||
Utils\FieldManagerUtil,
|
||||
};
|
||||
|
||||
class Stream
|
||||
{
|
||||
protected $statusStyles = null;
|
||||
|
||||
@@ -45,59 +57,49 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
protected $dangerDefaultStyleList = ['Not Held', 'Closed Lost', 'Dead'];
|
||||
|
||||
protected function init()
|
||||
{
|
||||
parent::init();
|
||||
$this->addDependencyList([
|
||||
'entityManager',
|
||||
'config',
|
||||
'user',
|
||||
'metadata',
|
||||
'acl',
|
||||
'aclManager',
|
||||
'container',
|
||||
'portalAclManagerContainer',
|
||||
]);
|
||||
protected $entityManager;
|
||||
protected $config;
|
||||
protected $user;
|
||||
protected $metadata;
|
||||
protected $acl;
|
||||
protected $aclManager;
|
||||
protected $serviceFactory;
|
||||
protected $portalAclManagerContainer;
|
||||
protected $selectManagerFactory;
|
||||
protected $fieldManagerUtil;
|
||||
|
||||
public function __construct(
|
||||
EntityManager $entityManager,
|
||||
Config $config,
|
||||
User $user,
|
||||
Metadata $metadata,
|
||||
Acl $acl,
|
||||
AclManager $aclManager,
|
||||
ServiceFactory $serviceFactory,
|
||||
PortalAclManagerContainer $portalAclManagerContainer,
|
||||
SelectManagerFactory $selectManagerFactory,
|
||||
FieldManagerUtil $fieldManagerUtil
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
$this->config = $config;
|
||||
$this->user = $user;
|
||||
$this->metadata = $metadata;
|
||||
$this->acl = $acl;
|
||||
$this->aclManager = $aclManager;
|
||||
$this->serviceFactory = $serviceFactory;
|
||||
$this->portalAclManagerContainer = $portalAclManagerContainer;
|
||||
$this->selectManagerFactory = $selectManagerFactory;
|
||||
$this->fieldManagerUtil = $fieldManagerUtil;
|
||||
}
|
||||
|
||||
protected $auditedFieldsCache = [];
|
||||
|
||||
private $notificationService = null;
|
||||
|
||||
protected function getServiceFactory()
|
||||
{
|
||||
return $this->getInjection('container')->get('serviceFactory');
|
||||
}
|
||||
|
||||
protected function getAcl()
|
||||
{
|
||||
return $this->getInjection('acl');
|
||||
}
|
||||
|
||||
protected function getAclManager()
|
||||
{
|
||||
return $this->getInjection('aclManager');
|
||||
}
|
||||
|
||||
protected function getMetadata()
|
||||
{
|
||||
return $this->getInjection('metadata');
|
||||
}
|
||||
|
||||
protected function getFieldManager()
|
||||
{
|
||||
return $this->getInjection('container')->get('fieldManager');
|
||||
}
|
||||
|
||||
protected function getSelectMangerFactory()
|
||||
{
|
||||
return $this->getInjection('container')->get('selectManagerFactory');
|
||||
}
|
||||
|
||||
protected function getNotificationService()
|
||||
{
|
||||
if (empty($this->notificationService)) {
|
||||
$this->notificationService = $this->getServiceFactory()->create('Notification');
|
||||
$this->notificationService = $this->serviceFactory->create('Notification');
|
||||
}
|
||||
return $this->notificationService;
|
||||
}
|
||||
@@ -105,7 +107,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
protected function getStatusStyles()
|
||||
{
|
||||
if (empty($this->statusStyles)) {
|
||||
$this->statusStyles = $this->getMetadata()->get('entityDefs.Note.statusStyles', []);
|
||||
$this->statusStyles = $this->metadata->get('entityDefs.Note.statusStyles', []);
|
||||
}
|
||||
return $this->statusStyles;
|
||||
}
|
||||
@@ -114,7 +116,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
{
|
||||
if (is_null($this->statusFields)) {
|
||||
$this->statusFields = array();
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
foreach ($scopes as $scope => $data) {
|
||||
if (empty($data['statusField'])) continue;
|
||||
$this->statusFields[$scope] = $data['statusField'];
|
||||
@@ -135,18 +137,18 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$entityType = $data->entityType;
|
||||
$entityId = $data->entityId;
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($entityType, $entityId);
|
||||
$entity = $this->entityManager->getEntity($entityType, $entityId);
|
||||
if (!$entity) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($userIdList as $i => $userId) {
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
$user = $this->entityManager->getEntity('User', $userId);
|
||||
if (!$user) {
|
||||
unset($userIdList[$i]);
|
||||
continue;
|
||||
}
|
||||
if (!$this->getAclManager()->check($user, $entity, 'stream')) {
|
||||
if (!$this->aclManager->check($user, $entity, 'stream')) {
|
||||
unset($userIdList[$i]);
|
||||
}
|
||||
}
|
||||
@@ -165,7 +167,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$this->followEntityMass($entity, $userIdList);
|
||||
|
||||
$noteList = $this->getEntityManager()->getRepository('Note')->where([
|
||||
$noteList = $this->entityManager->getRepository('Note')->where([
|
||||
'parentType' => $entityType,
|
||||
'parentId' => $entityId
|
||||
])->order('number', 'ASC')->find();
|
||||
@@ -178,10 +180,10 @@ class Stream extends \Espo\Core\Services\Base
|
||||
public function checkIsFollowed(Entity $entity, $userId = null)
|
||||
{
|
||||
if (empty($userId)) {
|
||||
$userId = $this->getUser()->id;
|
||||
$userId = $this->user->id;
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
$sql = "
|
||||
SELECT id FROM subscription
|
||||
WHERE
|
||||
@@ -199,7 +201,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
public function followEntityMass(Entity $entity, array $sourceUserIdList, bool $skipAclCheck = false)
|
||||
{
|
||||
if (!$this->getMetadata()->get(['scopes', $entity->getEntityType(), 'stream'])) {
|
||||
if (!$this->metadata->get(['scopes', $entity->getEntityType(), 'stream'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -215,7 +217,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
if (!$skipAclCheck) {
|
||||
foreach ($userIdList as $i => $userId) {
|
||||
$user = $this->getEntityManager()->getRepository('User')
|
||||
$user = $this->entityManager->getRepository('User')
|
||||
->select(['id', 'type', 'isActive'])
|
||||
->where([
|
||||
'id' => $userId,
|
||||
@@ -227,7 +229,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$this->getAclManager()->check($user, $entity, 'stream')) {
|
||||
if (!$this->aclManager->check($user, $entity, 'stream')) {
|
||||
unset($userIdList[$i]);
|
||||
}
|
||||
}
|
||||
@@ -238,7 +240,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
return;
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
|
||||
$userIdQuotedList = [];
|
||||
foreach ($userIdList as $userId) {
|
||||
@@ -271,12 +273,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
if ($userId == 'system') {
|
||||
return;
|
||||
}
|
||||
if (!$this->getMetadata()->get('scopes.' . $entity->getEntityType() . '.stream')) {
|
||||
if (!$this->metadata->get('scopes.' . $entity->getEntityType() . '.stream')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$skipAclCheck) {
|
||||
$user = $this->getEntityManager()->getRepository('User')
|
||||
$user = $this->entityManager->getRepository('User')
|
||||
->select(['id', 'type', 'isActive'])
|
||||
->where([
|
||||
'id' => $userId,
|
||||
@@ -284,10 +286,10 @@ class Stream extends \Espo\Core\Services\Base
|
||||
])->findOne();
|
||||
|
||||
if (!$user) return false;
|
||||
if (!$this->getAclManager()->check($user, $entity, 'stream')) return false;
|
||||
if (!$this->aclManager->check($user, $entity, 'stream')) return false;
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
|
||||
if (!$this->checkIsFollowed($entity, $userId)) {
|
||||
$sql = "
|
||||
@@ -303,11 +305,11 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
public function unfollowEntity(Entity $entity, $userId)
|
||||
{
|
||||
if (!$this->getMetadata()->get('scopes.' . $entity->getEntityType() . '.stream')) {
|
||||
if (!$this->metadata->get('scopes.' . $entity->getEntityType() . '.stream')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
|
||||
$sql = "
|
||||
DELETE FROM subscription
|
||||
@@ -327,7 +329,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
return;
|
||||
}
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
$sql = "
|
||||
DELETE FROM subscription
|
||||
WHERE
|
||||
@@ -343,14 +345,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$sqLimit = $offset + $maxSize + 1;
|
||||
|
||||
if ($userId === $this->getUser()->id) {
|
||||
$user = $this->getUser();
|
||||
if ($userId === $this->user->id) {
|
||||
$user = $this->user;
|
||||
} else {
|
||||
$user = $this->getEntityManager()->getEntity('User', $userId);
|
||||
$user = $this->entityManager->getEntity('User', $userId);
|
||||
if (!$user) {
|
||||
throw new NotFound();
|
||||
}
|
||||
if (!$this->getAcl()->checkUser('userPermission', $user)) {
|
||||
if (!$this->acl->checkUser('userPermission', $user)) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
}
|
||||
@@ -359,7 +361,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$teamIdList = $user->getTeamIdList();
|
||||
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
|
||||
$select = [
|
||||
'id', 'number', 'type', 'post', 'data', 'parentType', 'parentId', 'relatedType', 'relatedId',
|
||||
@@ -371,7 +373,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$additionalSelectParams = null;
|
||||
if (!empty($params['where'])) {
|
||||
$selectManager = $this->getSelectMangerFactory()->create('Note');
|
||||
$selectManager = $this->selectManagerFactory->create('Note');
|
||||
$additionalSelectParams = $selectManager->getSelectParams([
|
||||
'where' => $params['where']
|
||||
], false, true, true);
|
||||
@@ -719,21 +721,21 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$itemName = $selectParams['_name'] ?? null;
|
||||
if ($itemName !== 'selfPost' && $itemName !== 'globalPost') {
|
||||
$selectParams['whereClause'][] = [
|
||||
'createdById!=' => $this->getUser()->id,
|
||||
'createdById!=' => $this->user->id,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
$sqlPartList[] = "(\n" . $this->getEntityManager()->getQuery()->createSelectQuery('Note', $selectParams) . "\n)";
|
||||
$sqlPartList[] = "(\n" . $this->entityManager->getQuery()->createSelectQuery('Note', $selectParams) . "\n)";
|
||||
}
|
||||
|
||||
$sql = implode("\n UNION ALL \n", $sqlPartList) . "
|
||||
ORDER BY number DESC
|
||||
";
|
||||
|
||||
$sql = $this->getEntityManager()->getQuery()->limit($sql, $offset, $maxSize + 1);
|
||||
$sql = $this->entityManager->getQuery()->limit($sql, $offset, $maxSize + 1);
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('Note')->findByQuery($sql);
|
||||
$collection = $this->entityManager->getRepository('Note')->findByQuery($sql);
|
||||
|
||||
foreach ($collection as $e) {
|
||||
$this->loadNoteAdditionalFields($e);
|
||||
@@ -782,20 +784,20 @@ class Stream extends \Espo\Core\Services\Base
|
||||
{
|
||||
if ($scope === 'User') {
|
||||
if (empty($id)) {
|
||||
$id = $this->getUser()->id;
|
||||
$id = $this->user->id;
|
||||
}
|
||||
return $this->findUserStream($id, $params);
|
||||
}
|
||||
$entity = $this->getEntityManager()->getEntity($scope, $id);
|
||||
$entity = $this->entityManager->getEntity($scope, $id);
|
||||
|
||||
$onlyTeamEntityTypeList = $this->getOnlyTeamEntityTypeList($this->getUser());
|
||||
$onlyOwnEntityTypeList = $this->getOnlyOwnEntityTypeList($this->getUser());
|
||||
$onlyTeamEntityTypeList = $this->getOnlyTeamEntityTypeList($this->user);
|
||||
$onlyOwnEntityTypeList = $this->getOnlyOwnEntityTypeList($this->user);
|
||||
|
||||
if (empty($entity)) {
|
||||
throw new NotFound();
|
||||
}
|
||||
|
||||
if (!$this->getAcl()->checkEntity($entity, 'stream')) {
|
||||
if (!$this->acl->checkEntity($entity, 'stream')) {
|
||||
throw new Forbidden();
|
||||
}
|
||||
|
||||
@@ -820,13 +822,13 @@ class Stream extends \Espo\Core\Services\Base
|
||||
]
|
||||
];
|
||||
|
||||
if ($this->getUser()->isPortal()) {
|
||||
if ($this->user->isPortal()) {
|
||||
$where = [
|
||||
'parentType' => $scope,
|
||||
'parentId' => $id,
|
||||
];
|
||||
|
||||
$notAllEntityTypeList = $this->getNotAllEntityTypeList($this->getUser());
|
||||
$notAllEntityTypeList = $this->getNotAllEntityTypeList($this->user);
|
||||
|
||||
$orGroup = [
|
||||
[
|
||||
@@ -838,7 +840,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
],
|
||||
];
|
||||
|
||||
if ($this->getAcl()->check('Email', 'read')) {
|
||||
if ($this->acl->check('Email', 'read')) {
|
||||
$selectParams['leftJoins'][] = [
|
||||
'noteUser', 'noteUser', [
|
||||
'noteUser.noteId=:' => 'id',
|
||||
@@ -849,7 +851,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$orGroup[] = [
|
||||
'relatedId!=' => null,
|
||||
'relatedType' => 'Email',
|
||||
'noteUser.userId' => $this->getUser()->id,
|
||||
'noteUser.userId' => $this->user->id,
|
||||
];
|
||||
}
|
||||
$where[] = [
|
||||
@@ -893,8 +895,8 @@ class Stream extends \Espo\Core\Services\Base
|
||||
],
|
||||
[
|
||||
'OR' => [
|
||||
'teamsMiddle.teamId' => $this->getUser()->getTeamIdList(),
|
||||
'usersMiddle.userId' => $this->getUser()->id
|
||||
'teamsMiddle.teamId' => $this->user->getTeamIdList(),
|
||||
'usersMiddle.userId' => $this->user->id
|
||||
]
|
||||
]
|
||||
],
|
||||
@@ -909,7 +911,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
'parentType=' => $onlyOwnEntityTypeList
|
||||
]
|
||||
],
|
||||
'usersMiddle.userId' => $this->getUser()->id
|
||||
'usersMiddle.userId' => $this->user->id
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -931,7 +933,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
}
|
||||
}
|
||||
|
||||
$ignoreScopeList = $this->getIgnoreScopeList($this->getUser());
|
||||
$ignoreScopeList = $this->getIgnoreScopeList($this->user);
|
||||
if (!empty($ignoreScopeList)) {
|
||||
$where[] = [
|
||||
'OR' => [
|
||||
@@ -952,7 +954,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getUser()->isPortal()) {
|
||||
if ($this->user->isPortal()) {
|
||||
$where[] = [
|
||||
'isInternal' => false
|
||||
];
|
||||
@@ -961,7 +963,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$selectParams['whereClause'] = $where;
|
||||
|
||||
if (!empty($params['where'])) {
|
||||
$selectManager = $this->getSelectMangerFactory()->create('Note');
|
||||
$selectManager = $this->selectManagerFactory->create('Note');
|
||||
$additionalSelectParams = $selectManager->getSelectParams([
|
||||
'where' => $params['where']
|
||||
], false, true);
|
||||
@@ -970,7 +972,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$where = $selectParams['whereClause'];
|
||||
}
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('Note')->find($selectParams);
|
||||
$collection = $this->entityManager->getRepository('Note')->find($selectParams);
|
||||
|
||||
foreach ($collection as $e) {
|
||||
if ($e->get('type') == 'Post' || $e->get('type') == 'EmailReceived') {
|
||||
@@ -996,7 +998,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
unset($selectParams['limit']);
|
||||
|
||||
$selectParams['where'] = $where;
|
||||
$count = $this->getEntityManager()->getRepository('Note')->count($selectParams);
|
||||
$count = $this->entityManager->getRepository('Note')->count($selectParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $count,
|
||||
@@ -1012,7 +1014,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$after = $params['after'] ?? null;
|
||||
$filter = $params['filter'] ?? null;
|
||||
|
||||
$selectManager = $this->getSelectMangerFactory()->create('Note');
|
||||
$selectManager = $this->selectManagerFactory->create('Note');
|
||||
$selectParams = $selectManager->getEmptySelectParams();
|
||||
|
||||
if ($where) {
|
||||
@@ -1084,9 +1086,9 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$selectManager->applyLimit($offset, $maxSize + 1, $selectParams);
|
||||
|
||||
$sql = $this->getEntityManager()->getQuery()->createSelectQuery('Note', $selectParams);
|
||||
$sql = $this->entityManager->getQuery()->createSelectQuery('Note', $selectParams);
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('Note')->findByQuery($sql);
|
||||
$collection = $this->entityManager->getRepository('Note')->findByQuery($sql);
|
||||
|
||||
foreach ($collection as $e) {
|
||||
$this->loadNoteAdditionalFields($e);
|
||||
@@ -1106,7 +1108,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
protected function loadAssignedUserName(Entity $entity)
|
||||
{
|
||||
$user = $this->getEntityManager()->getRepository('User')->select(['name'])->where([
|
||||
$user = $this->entityManager->getRepository('User')->select(['name'])->where([
|
||||
'id' => $entity->get('assignedUserId'),
|
||||
])->findOne();
|
||||
if ($user) {
|
||||
@@ -1127,7 +1129,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
}
|
||||
}
|
||||
|
||||
$ownerUserIdAttribute = $this->getAclManager()->getImplementation($entity->getEntityType())->getOwnerUserIdAttribute($entity);
|
||||
$ownerUserIdAttribute = $this->aclManager->getImplementation($entity->getEntityType())->getOwnerUserIdAttribute($entity);
|
||||
if ($ownerUserIdAttribute && $entity->get($ownerUserIdAttribute)) {
|
||||
if ($entity->getAttributeParam($ownerUserIdAttribute, 'isLinkMultipleIdList')) {
|
||||
$userIdList = $entity->get($ownerUserIdAttribute);
|
||||
@@ -1143,7 +1145,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
{
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
if ($this->getEntityManager()->getRepository('Note')->where([
|
||||
if ($this->entityManager->getRepository('Note')->where([
|
||||
'type' => 'EmailReceived',
|
||||
'parentId' => $entity->id,
|
||||
'parentType' => $entityType,
|
||||
@@ -1153,7 +1155,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
return;
|
||||
}
|
||||
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'EmailReceived');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1168,7 +1170,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$note->set('superParentType', 'Account');
|
||||
}
|
||||
|
||||
$withContent = in_array($entityType, $this->getConfig()->get('streamEmailWithContentEntityTypeList', []));
|
||||
$withContent = in_array($entityType, $this->config->get('streamEmailWithContentEntityTypeList', []));
|
||||
|
||||
if ($withContent) {
|
||||
$note->set('post', $email->getBodyPlain());
|
||||
@@ -1186,7 +1188,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$from = $email->get('from');
|
||||
if ($from) {
|
||||
$person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from);
|
||||
$person = $this->entityManager->getRepository('EmailAddress')->getEntityByAddress($from);
|
||||
if ($person) {
|
||||
$data['personEntityType'] = $person->getEntityType();
|
||||
$data['personEntityName'] = $person->get('name');
|
||||
@@ -1197,14 +1199,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$note->set('data', (object) $data);
|
||||
|
||||
|
||||
$this->getEntityManager()->saveEntity($note);
|
||||
$this->entityManager->saveEntity($note);
|
||||
}
|
||||
|
||||
public function noteEmailSent(Entity $entity, Entity $email)
|
||||
{
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'EmailSent');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1219,7 +1221,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$note->set('superParentType', 'Account');
|
||||
}
|
||||
|
||||
$withContent = in_array($entityType, $this->getConfig()->get('streamEmailWithContentEntityTypeList', []));
|
||||
$withContent = in_array($entityType, $this->config->get('streamEmailWithContentEntityTypeList', []));
|
||||
|
||||
if ($withContent) {
|
||||
$note->set('post', $email->getBodyPlain());
|
||||
@@ -1233,14 +1235,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$data['attachmentsIds'] = $email->get('attachmentsIds');
|
||||
}
|
||||
|
||||
$user = $this->getUser();
|
||||
$user = $this->user;
|
||||
|
||||
if ($user->id != 'system') {
|
||||
$person = $user;
|
||||
} else {
|
||||
$from = $email->get('from');
|
||||
if ($from) {
|
||||
$person = $this->getEntityManager()->getRepository('EmailAddress')->getEntityByAddress($from);
|
||||
$person = $this->entityManager->getRepository('EmailAddress')->getEntityByAddress($from);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1252,14 +1254,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
$note->set('data', (object) $data);
|
||||
|
||||
$this->getEntityManager()->saveEntity($note);
|
||||
$this->entityManager->saveEntity($note);
|
||||
}
|
||||
|
||||
public function noteCreate(Entity $entity, array $options = [])
|
||||
{
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'Create');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1300,12 +1302,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['createdById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
|
||||
protected function getStatusStyle($entityType, $field, $value)
|
||||
{
|
||||
$style = $this->getMetadata()->get(['entityDefs', $entityType, 'fields', $field, 'style', $value]);
|
||||
$style = $this->metadata->get(['entityDefs', $entityType, 'fields', $field, 'style', $value]);
|
||||
if ($style) {
|
||||
return $style;
|
||||
}
|
||||
@@ -1327,7 +1329,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
public function noteCreateRelated(Entity $entity, $parentType, $parentId, array $options = [])
|
||||
{
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
@@ -1351,14 +1353,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['createdById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
|
||||
public function noteRelate(Entity $entity, $parentType, $parentId, array $options = [])
|
||||
{
|
||||
$entityType = $entity->getEntityType();
|
||||
|
||||
$existing = $this->getEntityManager()->getRepository('Note')->select(['id'])->where([
|
||||
$existing = $this->entityManager->getRepository('Note')->select(['id'])->where([
|
||||
'type' => 'Relate',
|
||||
'parentId' => $parentId,
|
||||
'parentType' => $parentType,
|
||||
@@ -1367,7 +1369,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
])->findOne();
|
||||
if ($existing) return false;
|
||||
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set([
|
||||
'type' => 'Relate',
|
||||
@@ -1384,12 +1386,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['createdById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
|
||||
public function noteAssign(Entity $entity, array $options = [])
|
||||
{
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'Assign');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1424,12 +1426,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['modifiedById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
|
||||
public function noteStatus(Entity $entity, $field, array $options = [])
|
||||
{
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'Status');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1463,7 +1465,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['modifiedById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
|
||||
protected function getAuditedFieldsData(Entity $entity)
|
||||
@@ -1473,7 +1475,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$statusFields = $this->getStatusFields();
|
||||
|
||||
if (!array_key_exists($entityType, $this->auditedFieldsCache)) {
|
||||
$fields = $this->getMetadata()->get('entityDefs.' . $entityType . '.fields');
|
||||
$fields = $this->metadata->get('entityDefs.' . $entityType . '.fields');
|
||||
$auditedFields = array();
|
||||
foreach ($fields as $field => $d) {
|
||||
if (!empty($d['audited'])) {
|
||||
@@ -1481,8 +1483,8 @@ class Stream extends \Espo\Core\Services\Base
|
||||
continue;
|
||||
}
|
||||
$auditedFields[$field] = array();
|
||||
$auditedFields[$field]['actualList'] = $this->getFieldManager()->getActualAttributeList($entityType, $field);
|
||||
$auditedFields[$field]['notActualList'] = $this->getFieldManager()->getNotActualAttributeList($entityType, $field);
|
||||
$auditedFields[$field]['actualList'] = $this->fieldManagerUtil->getActualAttributeList($entityType, $field);
|
||||
$auditedFields[$field]['notActualList'] = $this->fieldManagerUtil->getNotActualAttributeList($entityType, $field);
|
||||
$auditedFields[$field]['fieldType'] = $d['type'];
|
||||
}
|
||||
}
|
||||
@@ -1522,8 +1524,8 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$wasParentType = $was[$field . 'Type'];
|
||||
$wasParentId = $was[$field . 'Id'];
|
||||
if ($wasParentType && $wasParentId) {
|
||||
if ($this->getEntityManager()->hasRepository($wasParentType)) {
|
||||
$wasParent = $this->getEntityManager()->getEntity($wasParentType, $wasParentId);
|
||||
if ($this->entityManager->hasRepository($wasParentType)) {
|
||||
$wasParent = $this->entityManager->getEntity($wasParentType, $wasParentId);
|
||||
if ($wasParent) {
|
||||
$was[$field . 'Name'] = $wasParent->get('name');
|
||||
}
|
||||
@@ -1534,7 +1536,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
}
|
||||
|
||||
if (!empty($updatedFieldList)) {
|
||||
$note = $this->getEntityManager()->getEntity('Note');
|
||||
$note = $this->entityManager->getEntity('Note');
|
||||
|
||||
$note->set('type', 'Update');
|
||||
$note->set('parentId', $entity->id);
|
||||
@@ -1553,14 +1555,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$o['createdById'] = $options['modifiedById'];
|
||||
}
|
||||
|
||||
$this->getEntityManager()->saveEntity($note, $o);
|
||||
$this->entityManager->saveEntity($note, $o);
|
||||
}
|
||||
}
|
||||
|
||||
public function getEntityFolowerIdList(Entity $entity)
|
||||
{
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$query = $this->entityManager->getQuery();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
$sql = $query->createSelectQuery('User', [
|
||||
'select' => ['id'],
|
||||
'joins' => [
|
||||
@@ -1592,15 +1594,15 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
public function findEntityFollowers(Entity $entity, $params)
|
||||
{
|
||||
$selectAttributeList = $this->getServiceFactory()->create('User')->getSelectAttributeList($params);
|
||||
$selectAttributeList = $this->serviceFactory->create('User')->getSelectAttributeList($params);
|
||||
|
||||
$selectManager = $this->getSelectMangerFactory()->create('User');
|
||||
$selectManager = $this->selectManagerFactory->create('User');
|
||||
|
||||
$selectParams = $selectManager->getSelectParams($params, true, true);
|
||||
|
||||
if (empty($params['orderBy'])) {
|
||||
$selectParams['orderBy'] = [
|
||||
['LIST:id:' . $this->getUser()->id, 'DESC'],
|
||||
['LIST:id:' . $this->user->id, 'DESC'],
|
||||
['name']
|
||||
];
|
||||
}
|
||||
@@ -1619,12 +1621,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$selectParams['select'] = $selectAttributeList;
|
||||
}
|
||||
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
$query = $this->entityManager->getQuery();
|
||||
$selectParams['t'] = true;
|
||||
$sql = $query->createSelectQuery('User', $selectParams);
|
||||
|
||||
$collection = $this->getEntityManager()->getRepository('User')->find($selectParams);
|
||||
$total = $this->getEntityManager()->getRepository('User')->count($selectParams);
|
||||
$collection = $this->entityManager->getRepository('User')->find($selectParams);
|
||||
$total = $this->entityManager->getRepository('User')->count($selectParams);
|
||||
|
||||
return (object) [
|
||||
'total' => $total,
|
||||
@@ -1634,8 +1636,8 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
public function getEntityFollowers(Entity $entity, $offset = 0, $limit = false)
|
||||
{
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
$query = $this->entityManager->getQuery();
|
||||
$pdo = $this->entityManager->getPDO();
|
||||
|
||||
if (!$limit) {
|
||||
$limit = 200;
|
||||
@@ -1660,7 +1662,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
'isActive' => true
|
||||
],
|
||||
'orderBy' => [
|
||||
['LIST:id:' . $this->getUser()->id, 'DESC'],
|
||||
['LIST:id:' . $this->user->id, 'DESC'],
|
||||
['name']
|
||||
]
|
||||
]);
|
||||
@@ -1687,13 +1689,13 @@ class Stream extends \Espo\Core\Services\Base
|
||||
if ($user->isPortal()) return [];
|
||||
|
||||
$list = [];
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
foreach ($scopes as $scope => $item) {
|
||||
if ($scope === 'User') continue;
|
||||
if (empty($item['entity'])) continue;
|
||||
if (empty($item['object'])) continue;
|
||||
if (
|
||||
$this->getAclManager()->getLevel($user, $scope, 'read') === 'team'
|
||||
$this->aclManager->getLevel($user, $scope, 'read') === 'team'
|
||||
) {
|
||||
$list[] = $scope;
|
||||
}
|
||||
@@ -1707,13 +1709,13 @@ class Stream extends \Espo\Core\Services\Base
|
||||
if ($user->isPortal()) return [];
|
||||
|
||||
$list = [];
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
foreach ($scopes as $scope => $item) {
|
||||
if ($scope === 'User') continue;
|
||||
if (empty($item['entity'])) continue;
|
||||
if (empty($item['object'])) continue;
|
||||
if (
|
||||
$this->getAclManager()->getLevel($user, $scope, 'read') === 'own'
|
||||
$this->aclManager->getLevel($user, $scope, 'read') === 'own'
|
||||
) {
|
||||
$list[] = $scope;
|
||||
}
|
||||
@@ -1723,12 +1725,12 @@ class Stream extends \Espo\Core\Services\Base
|
||||
|
||||
protected function getUserAclManager(\Espo\Entities\User $user)
|
||||
{
|
||||
$aclManager = $this->getAclManager();
|
||||
$aclManager = $this->aclManager;
|
||||
|
||||
if ($user->isPortal() && !$this->getUser()->isPortal()) {
|
||||
if ($user->isPortal() && !$this->user->isPortal()) {
|
||||
$portals = $user->get('portals');
|
||||
if (count($portals)) {
|
||||
$aclManager = $this->getInjection('portalAclManagerContainer')->get($portals[0]);
|
||||
$aclManager = $this->portalAclManagerContainer->get($portals[0]);
|
||||
} else {
|
||||
$aclManager = null;
|
||||
}
|
||||
@@ -1744,7 +1746,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$aclManager = $this->getUserAclManager($user);
|
||||
|
||||
$list = [];
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
foreach ($scopes as $scope => $item) {
|
||||
if ($scope === 'User') continue;
|
||||
if (empty($item['entity'])) continue;
|
||||
@@ -1761,7 +1763,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
protected function getIgnoreScopeList(\Espo\Entities\User $user)
|
||||
{
|
||||
$ignoreScopeList = [];
|
||||
$scopes = $this->getMetadata()->get('scopes', []);
|
||||
$scopes = $this->metadata->get('scopes', []);
|
||||
|
||||
$aclManager = $this->getUserAclManager($user);
|
||||
|
||||
@@ -1791,14 +1793,14 @@ class Stream extends \Espo\Core\Services\Base
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->getEntityManager()->hasRepository($data->entityType)) return;
|
||||
if (!$this->entityManager->hasRepository($data->entityType)) return;
|
||||
|
||||
$entity = $this->getEntityManager()->getEntity($data->entityType, $data->entityId);
|
||||
$entity = $this->entityManager->getEntity($data->entityType, $data->entityId);
|
||||
if (!$entity) return;
|
||||
|
||||
$idList = $this->getEntityFolowerIdList($entity);
|
||||
|
||||
$userList = $this->getEntityManager()->getRepository('User')->where(array(
|
||||
$userList = $this->entityManager->getRepository('User')->where(array(
|
||||
'id' => $idList
|
||||
))->find();
|
||||
|
||||
@@ -1809,7 +1811,7 @@ class Stream extends \Espo\Core\Services\Base
|
||||
}
|
||||
|
||||
if (!$user->isPortal()) {
|
||||
if (!$this->getAclManager()->check($user, $entity, 'stream')) {
|
||||
if (!$this->aclManager->check($user, $entity, 'stream')) {
|
||||
$this->unfollowEntity($entity, $user->id);
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user