From aa3d09a55c41e107ae0facd07783187b97d809e4 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Tue, 8 Jun 2021 17:20:09 +0300 Subject: [PATCH] deprecate createCollection --- application/Espo/Modules/Crm/Services/Document.php | 12 ++++++++++-- application/Espo/Modules/Crm/Services/TargetList.php | 4 +++- application/Espo/ORM/EntityManager.php | 2 +- application/Espo/Services/Notification.php | 7 +++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/application/Espo/Modules/Crm/Services/Document.php b/application/Espo/Modules/Crm/Services/Document.php index bb13b0cfee..75851cf081 100644 --- a/application/Espo/Modules/Crm/Services/Document.php +++ b/application/Espo/Modules/Crm/Services/Document.php @@ -33,6 +33,9 @@ use Espo\Core\Exceptions\NotFound; class Document extends \Espo\Services\Record { + /** + * @return iterable + */ public function getAttachmentList(string $id) { $entity = $this->getEntity($id); @@ -51,9 +54,14 @@ class Document extends \Espo\Services\Record throw new NotFound(); } - $attachment = $this->getEntityManager()->getRepository('Attachment')->getCopiedAttachment($file, 'Attachment'); + $attachment = $this->entityManager + ->getRepository('Attachment') + ->getCopiedAttachment($file, 'Attachment'); + + $attachmentList = $this->entityManager + ->getCollectionFactory() + ->create('Attachment'); - $attachmentList = $this->getEntityManager()->createCollection('Attachment'); $attachmentList[] = $attachment; return $attachmentList; diff --git a/application/Espo/Modules/Crm/Services/TargetList.php b/application/Espo/Modules/Crm/Services/TargetList.php index 49e0ce52f1..6af9cb6b87 100644 --- a/application/Espo/Modules/Crm/Services/TargetList.php +++ b/application/Espo/Modules/Crm/Services/TargetList.php @@ -308,7 +308,9 @@ class TargetList extends \Espo\Services\Record implements $sth = $em->getQueryExecutor()->execute($unionQuery); - $collection = $this->getEntityManager()->createCollection(); + $collection = $this->entityManager + ->getCollectionFactory() + ->create(); while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { $itemEntity = $this->getEntityManager()->getEntity($row['entityType']); diff --git a/application/Espo/ORM/EntityManager.php b/application/Espo/ORM/EntityManager.php index 3324578afa..8a8869dadb 100644 --- a/application/Espo/ORM/EntityManager.php +++ b/application/Espo/ORM/EntityManager.php @@ -476,7 +476,7 @@ class EntityManager } /** - * Create a collection. An entity type can be omitted. + * @deprecated Use `getCollectionFactory`. */ public function createCollection(?string $entityType = null, array $data = []): EntityCollection { diff --git a/application/Espo/Services/Notification.php b/application/Espo/Services/Notification.php index 0e3ddf4542..c3a064e9b0 100644 --- a/application/Espo/Services/Notification.php +++ b/application/Espo/Services/Notification.php @@ -79,7 +79,9 @@ class Notification extends \Espo\Services\Record implements $now = date('Y-m-d H:i:s'); - $collection = $this->entityManager->createCollection(); + $collection = $this->entityManager + ->getCollectionFactory() + ->create(); $userList = $this->entityManager ->getRepository('User') @@ -87,7 +89,8 @@ class Notification extends \Espo\Services\Record implements ->where([ 'isActive' => true, 'id' => $userIdList, - ])->find(); + ]) + ->find(); foreach ($userList as $user) { $userId = $user->id;