diff --git a/application/Espo/Core/FieldProcessing/Stars/StarLoader.php b/application/Espo/Core/FieldProcessing/Stars/StarLoader.php index 9cbf418aed..9cfef36f58 100644 --- a/application/Espo/Core/FieldProcessing/Stars/StarLoader.php +++ b/application/Espo/Core/FieldProcessing/Stars/StarLoader.php @@ -31,6 +31,7 @@ namespace Espo\Core\FieldProcessing\Stars; use Espo\Core\FieldProcessing\Loader; use Espo\Core\FieldProcessing\Loader\Params; +use Espo\Core\Name\Field; use Espo\Entities\User; use Espo\ORM\Entity; use Espo\Tools\Stars\StarService; @@ -48,12 +49,12 @@ class StarLoader implements Loader public function process(Entity $entity, Params $params): void { if ( - !$entity->hasAttribute('isStarred') || + !$entity->hasAttribute(Field::IS_STARRED) || !$this->service->isEnabled($entity->getEntityType()) ) { return; } - $entity->set('isStarred', $this->service->isStarred($entity, $this->user)); + $entity->set(Field::IS_STARRED, $this->service->isStarred($entity, $this->user)); } } diff --git a/application/Espo/Core/FieldProcessing/Stream/FollowersLoader.php b/application/Espo/Core/FieldProcessing/Stream/FollowersLoader.php index 5e3bd9dba8..1437f1c092 100644 --- a/application/Espo/Core/FieldProcessing/Stream/FollowersLoader.php +++ b/application/Espo/Core/FieldProcessing/Stream/FollowersLoader.php @@ -29,6 +29,7 @@ namespace Espo\Core\FieldProcessing\Stream; +use Espo\Core\Name\Field; use Espo\ORM\Entity; use Espo\Core\Acl; use Espo\Core\FieldProcessing\Loader as LoaderInterface; @@ -61,13 +62,13 @@ class FollowersLoader implements LoaderInterface public function processIsFollowed(Entity $entity): void { - if (!$entity->hasAttribute('isFollowed')) { + if (!$entity->hasAttribute(Field::IS_FOLLOWED)) { return; } $isFollowed = $this->streamService->checkIsFollowed($entity); - $entity->set('isFollowed', $isFollowed); + $entity->set(Field::IS_FOLLOWED, $isFollowed); } public function processFollowers(Entity $entity): void @@ -88,7 +89,7 @@ class FollowersLoader implements LoaderInterface $data = $this->streamService->getEntityFollowers($entity, 0, $limit); - $entity->set('followersIds', $data['idList']); - $entity->set('followersNames', $data['nameMap']); + $entity->set(Field::FOLLOWERS . 'Ids', $data['idList']); + $entity->set(Field::FOLLOWERS . 'Names', $data['nameMap']); } } diff --git a/application/Espo/Core/Name/Field.php b/application/Espo/Core/Name/Field.php index d9ce53b9fc..40828b10a6 100644 --- a/application/Espo/Core/Name/Field.php +++ b/application/Espo/Core/Name/Field.php @@ -40,4 +40,7 @@ class Field public const COLLABORATORS = 'collaborators'; public const TEAMS = 'teams'; public const PARENT = 'parent'; + public const IS_FOLLOWED = 'isFollowed'; + public const FOLLOWERS = 'followers'; + public const IS_STARRED = 'isStarred'; } diff --git a/application/Espo/Core/Select/Applier/AdditionalAppliers/IsStarred.php b/application/Espo/Core/Select/Applier/AdditionalAppliers/IsStarred.php index 139fb1a933..a4d1ff872d 100644 --- a/application/Espo/Core/Select/Applier/AdditionalAppliers/IsStarred.php +++ b/application/Espo/Core/Select/Applier/AdditionalAppliers/IsStarred.php @@ -29,6 +29,7 @@ namespace Espo\Core\Select\Applier\AdditionalAppliers; +use Espo\Core\Name\Field; use Espo\Core\Select\Applier\AdditionalApplier; use Espo\Core\Select\SearchParams; use Espo\Core\Utils\Metadata; @@ -55,7 +56,7 @@ class IsStarred implements AdditionalApplier } $queryBuilder - ->select(Expr::isNotNull(Expr::column('starSubscription.id')), 'isStarred') + ->select(Expr::isNotNull(Expr::column('starSubscription.id')), Field::IS_STARRED) ->leftJoin(StarSubscription::ENTITY_TYPE, 'starSubscription', [ 'userId' => $this->user->getId(), 'entityType' => $this->entityType, diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 126cfb78a3..843c53ad3a 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -31,6 +31,7 @@ namespace Espo\Core\Utils\Database\Orm; use Doctrine\DBAL\Types\Types; use Espo\Core\InjectableFactory; +use Espo\Core\Name\Field; use Espo\Core\ORM\Defs\AttributeParam; use Espo\Core\ORM\Type\FieldType; use Espo\Core\Utils\Database\ConfigDataProvider; @@ -498,20 +499,20 @@ class Converter $scopeDefs = $this->metadata->get(['scopes', $entityType]) ?? []; if ($scopeDefs['stream'] ?? false) { - if (!isset($entityMetadata['fields']['isFollowed'])) { - $ormMetadata[$entityType]['attributes']['isFollowed'] = [ + if (!isset($entityMetadata['fields'][Field::IS_FOLLOWED])) { + $ormMetadata[$entityType]['attributes'][Field::IS_FOLLOWED] = [ 'type' => Entity::BOOL, 'notStorable' => true, AttributeParam::NOT_EXPORTABLE => true, ]; - $ormMetadata[$entityType]['attributes']['followersIds'] = [ + $ormMetadata[$entityType]['attributes'][Field::FOLLOWERS . 'Ids'] = [ 'type' => Entity::JSON_ARRAY, 'notStorable' => true, AttributeParam::NOT_EXPORTABLE => true, ]; - $ormMetadata[$entityType]['attributes']['followersNames'] = [ + $ormMetadata[$entityType]['attributes'][Field::FOLLOWERS . 'Names'] = [ 'type' => Entity::JSON_OBJECT, 'notStorable' => true, AttributeParam::NOT_EXPORTABLE => true, @@ -521,8 +522,8 @@ class Converter // @todo Refactor. if ($scopeDefs['stars'] ?? false) { - if (!isset($entityMetadata['fields']['isStarred'])) { - $ormMetadata[$entityType]['attributes']['isStarred'] = [ + if (!isset($entityMetadata['fields'][Field::IS_STARRED])) { + $ormMetadata[$entityType]['attributes'][Field::IS_STARRED] = [ 'type' => Entity::BOOL, 'notStorable' => true, AttributeParam::NOT_EXPORTABLE => true, diff --git a/application/Espo/Core/Webhook/Manager.php b/application/Espo/Core/Webhook/Manager.php index f37fe3bda8..08078c419a 100644 --- a/application/Espo/Core/Webhook/Manager.php +++ b/application/Espo/Core/Webhook/Manager.php @@ -50,7 +50,7 @@ class Manager /** @var string[] */ protected $skipAttributeList = [ - 'isFollowed', + Field::IS_FOLLOWED, Field::MODIFIED_AT, Field::MODIFIED_BY, ]; diff --git a/application/Espo/Tools/EntityManager/NameUtil.php b/application/Espo/Tools/EntityManager/NameUtil.php index 5e655282c3..7a30f97c8a 100644 --- a/application/Espo/Tools/EntityManager/NameUtil.php +++ b/application/Espo/Tools/EntityManager/NameUtil.php @@ -29,6 +29,7 @@ namespace Espo\Tools\EntityManager; +use Espo\Core\Name\Field; use Espo\Core\Utils\Config; use Espo\Core\Utils\Metadata; use Espo\Core\Utils\Route; @@ -136,16 +137,17 @@ class NameUtil 'deleted', 'deleteId', 'skipDuplicateCheck', - 'isFollowed', - 'isStarred', 'versionNumber', 'null', 'false', 'true', - 'teams', - 'assignedUser', - 'assignedUsers', - 'collaborators', + Field::IS_STARRED, + Field::IS_FOLLOWED, + Field::FOLLOWERS, + Field::TEAMS, + Field::ASSIGNED_USER, + Field::ASSIGNED_USERS, + Field::COLLABORATORS, ]; /** @@ -155,7 +157,6 @@ class NameUtil 'posts', 'stream', 'subscription', - 'followers', 'starSubscription', 'action', 'null', @@ -163,10 +164,11 @@ class NameUtil 'true', 'layout', 'system', - 'teams', - 'assignedUser', - 'assignedUsers', - 'collaborators', + Field::FOLLOWERS, + Field::TEAMS, + Field::ASSIGNED_USER, + Field::ASSIGNED_USERS, + Field::COLLABORATORS, ]; /** diff --git a/application/Espo/Tools/Stream/HookProcessor.php b/application/Espo/Tools/Stream/HookProcessor.php index a136f83bbe..7507f88486 100644 --- a/application/Espo/Tools/Stream/HookProcessor.php +++ b/application/Espo/Tools/Stream/HookProcessor.php @@ -389,7 +389,7 @@ class HookProcessor } if (in_array($this->user->getId(), $userIdList)) { - $entity->set('isFollowed', true); + $entity->set(Field::IS_FOLLOWED, true); } $autofollowUserIdList = $this->getAutofollowUserIdList($entity->getEntityType(), $userIdList); @@ -465,7 +465,7 @@ class HookProcessor $this->service->followEntity($entity, $userId); if ($this->user->getId() === $userId) { - $entity->set('isFollowed', true); + $entity->set(Field::IS_FOLLOWED, true); } } } @@ -487,7 +487,7 @@ class HookProcessor $this->service->noteAssign($entity, $options); if ($this->user->getId() === $assignedUserId) { - $entity->set('isFollowed', true); + $entity->set(Field::IS_FOLLOWED, true); } } @@ -508,7 +508,7 @@ class HookProcessor $this->service->noteAssign($entity, $options); if (in_array($this->user->getId(), $userIds)) { - $entity->set('isFollowed', true); + $entity->set(Field::IS_FOLLOWED, true); } }