From 35a0f14d2835e1d69bc7e75317aaaf1161c24a11 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 13 Mar 2023 08:59:09 +0200 Subject: [PATCH] id generator usage --- application/Espo/Tools/Kanban/Orderer.php | 24 ++++++++---------- .../Espo/Tools/Kanban/OrdererProcessor.php | 17 ++++++------- .../Espo/Tools/Notification/Service.php | 25 ++++++------------- 3 files changed, 25 insertions(+), 41 deletions(-) diff --git a/application/Espo/Tools/Kanban/Orderer.php b/application/Espo/Tools/Kanban/Orderer.php index 7724c7b00f..f7eda80ea9 100644 --- a/application/Espo/Tools/Kanban/Orderer.php +++ b/application/Espo/Tools/Kanban/Orderer.php @@ -29,22 +29,17 @@ namespace Espo\Tools\Kanban; -use Espo\Core\{ - ORM\EntityManager, - Utils\Metadata, -}; +use Espo\Core\ORM\EntityManager; +use Espo\Core\Utils\Id\RecordIdGenerator; +use Espo\Core\Utils\Metadata; class Orderer { - private $entityManager; - - private $metadata; - - public function __construct(EntityManager $entityManager, Metadata $metadata) - { - $this->entityManager = $entityManager; - $this->metadata = $metadata; - } + public function __construct( + private EntityManager $entityManager, + private Metadata $metadata, + private RecordIdGenerator $idGenerator + ) {} public function setEntityType(string $entityType): OrdererProcessor { @@ -70,7 +65,8 @@ class Orderer { return new OrdererProcessor( $this->entityManager, - $this->metadata + $this->metadata, + $this->idGenerator ); } } diff --git a/application/Espo/Tools/Kanban/OrdererProcessor.php b/application/Espo/Tools/Kanban/OrdererProcessor.php index e3b1069a50..a26fc4f411 100644 --- a/application/Espo/Tools/Kanban/OrdererProcessor.php +++ b/application/Espo/Tools/Kanban/OrdererProcessor.php @@ -29,10 +29,10 @@ namespace Espo\Tools\Kanban; +use Espo\Core\Utils\Id\RecordIdGenerator; use Espo\Entities\KanbanOrder; use Espo\Core\ORM\EntityManager; use Espo\Core\Utils\Metadata; -use Espo\Core\Utils\Util; use LogicException; @@ -47,14 +47,11 @@ class OrdererProcessor private int $maxNumber = self::DEFAULT_MAX_NUMBER; - private EntityManager $entityManager; - private Metadata $metadata; - - public function __construct(EntityManager $entityManager, Metadata $metadata) - { - $this->entityManager = $entityManager; - $this->metadata = $metadata; - } + public function __construct( + private EntityManager $entityManager, + private Metadata $metadata, + private RecordIdGenerator $idGenerator + ) {} public function setEntityType(string $entityType): self { @@ -165,7 +162,7 @@ class OrdererProcessor $item = $this->entityManager->getNewEntity(KanbanOrder::ENTITY_TYPE); $item->set([ - 'id' => Util::generateId(), + 'id' => $this->idGenerator->generate(), 'entityId' => $id, 'entityType' => $this->entityType, 'group' => $this->group, diff --git a/application/Espo/Tools/Notification/Service.php b/application/Espo/Tools/Notification/Service.php index 8f55697510..e7d94a3c19 100644 --- a/application/Espo/Tools/Notification/Service.php +++ b/application/Espo/Tools/Notification/Service.php @@ -29,13 +29,13 @@ namespace Espo\Tools\Notification; +use Espo\Core\Utils\Id\RecordIdGenerator; use Espo\Entities\Note; use Espo\Entities\Notification; use Espo\Entities\User; use Espo\Entities\Email; use Espo\Core\Utils\Config; -use Espo\Core\Utils\Util; use Espo\Core\AclManager; use Espo\Core\WebSocket\Submission; use Espo\Core\Utils\DateTime as DateTimeUtil; @@ -45,22 +45,13 @@ use Espo\ORM\EntityManager; class Service { - private EntityManager $entityManager; - private Config $config; - private AclManager $aclManager; - private Submission $webSocketSubmission; - public function __construct( - EntityManager $entityManager, - Config $config, - AclManager $aclManager, - Submission $webSocketSubmission - ) { - $this->entityManager = $entityManager; - $this->config = $config; - $this->aclManager = $aclManager; - $this->webSocketSubmission = $webSocketSubmission; - } + private EntityManager $entityManager, + private Config $config, + private AclManager $aclManager, + private Submission $webSocketSubmission, + private RecordIdGenerator $idGenerator + ) {} public function notifyAboutMentionInPost(string $userId, Note $note): void { @@ -131,7 +122,7 @@ class Service $notification = $this->entityManager->getNewEntity(Notification::ENTITY_TYPE); $notification->set([ - 'id' => Util::generateId(), + 'id' => $this->idGenerator->generate(), 'data' => [ 'noteId' => $note->getId(), ],