diff --git a/application/Espo/Core/Repositories/CategoryTree.php b/application/Espo/Core/Repositories/CategoryTree.php index 03cd7327de..72502384f0 100644 --- a/application/Espo/Core/Repositories/CategoryTree.php +++ b/application/Espo/Core/Repositories/CategoryTree.php @@ -39,7 +39,7 @@ class CategoryTree extends Database $parentId = $entity->get('parentId'); - $em = $this->getEntityManager(); + $em = $this->entityManager; $pathEntityType = $entity->getEntityType() . 'Path'; @@ -152,7 +152,7 @@ class CategoryTree extends Database $pathEntityType = $entity->getEntityType() . 'Path'; - $em = $this->getEntityManager(); + $em = $this->entityManager; $delete = $em->getQueryBuilder() ->delete() diff --git a/application/Espo/Core/Repositories/Database.php b/application/Espo/Core/Repositories/Database.php index 9fd252c56b..8585f168e9 100644 --- a/application/Espo/Core/Repositories/Database.php +++ b/application/Espo/Core/Repositories/Database.php @@ -48,6 +48,9 @@ use Espo\Core\{ Utils\Id\RecordIdGenerator, }; +/** + * The default repository used for all entities. + */ class Database extends RDBRepository { protected $hooksDisabled = false; @@ -195,7 +198,7 @@ class Database extends RDBRepository $foreignEntityType = $entity->getRelationParam($relationName, 'entity'); if ($foreignEntityType) { - $foreign = $this->getEntityManager()->getEntity($foreignEntityType); + $foreign = $this->entityManager->getEntity($foreignEntityType); $foreign->set('id', $foreignId); @@ -226,7 +229,7 @@ class Database extends RDBRepository $foreignEntityType = $entity->getRelationParam($relationName, 'entity'); if ($foreignEntityType) { - $foreign = $this->getEntityManager()->getEntity($foreignEntityType); + $foreign = $this->entityManager->getEntity($foreignEntityType); $foreign->id = $foreignId; $foreign->setAsFetched(); } diff --git a/application/Espo/Core/Repositories/Event.php b/application/Espo/Core/Repositories/Event.php index 133f79448b..dab70fddf5 100644 --- a/application/Espo/Core/Repositories/Event.php +++ b/application/Espo/Core/Repositories/Event.php @@ -132,7 +132,7 @@ class Event extends Database implements { parent::afterRemove($entity, $options); - $delete = $this->getEntityManager()->getQueryBuilder() + $delete = $this->entityManager->getQueryBuilder() ->delete() ->from('Reminder') ->where([ @@ -141,7 +141,7 @@ class Event extends Database implements ]) ->build(); - $this->getEntityManager()->getQueryExecutor()->execute($delete); + $this->entityManager->getQueryExecutor()->execute($delete); } protected function convertDateTimeToDefaultTimezone($string) diff --git a/application/Espo/Modules/Crm/Repositories/CaseObj.php b/application/Espo/Modules/Crm/Repositories/CaseObj.php index ca159695e7..e1185d11d4 100644 --- a/application/Espo/Modules/Crm/Repositories/CaseObj.php +++ b/application/Espo/Modules/Crm/Repositories/CaseObj.php @@ -67,7 +67,7 @@ class CaseObj extends \Espo\Core\Repositories\Database implements $fetchedContactId = $entity->getFetched('contactId'); if ($fetchedContactId) { - $previousPortalUser = $this->getEntityManager() + $previousPortalUser = $this->entityManager ->getRepository('User') ->select(['id']) ->where([ @@ -89,7 +89,7 @@ class CaseObj extends \Espo\Core\Repositories\Database implements return; } - $portalUser = $this->getEntityManager() + $portalUser = $this->entityManager ->getRepository('User') ->select(['id']) ->where([ diff --git a/application/Espo/Modules/Crm/Repositories/Contact.php b/application/Espo/Modules/Crm/Repositories/Contact.php index a295bafd07..5ea2135ee9 100644 --- a/application/Espo/Modules/Crm/Repositories/Contact.php +++ b/application/Espo/Modules/Crm/Repositories/Contact.php @@ -47,13 +47,17 @@ class Contact extends \Espo\Core\Repositories\Database protected function handleAfterSaveAccounts(Entity $entity, array $options = []) { - $accountIdChanged = $entity->has('accountId') && $entity->get('accountId') != $entity->getFetched('accountId'); + $accountIdChanged = $entity->has('accountId') && + $entity->get('accountId') != $entity->getFetched('accountId'); + $titleChanged = $entity->has('title') && $entity->get('title') != $entity->getFetched('title'); if ($accountIdChanged) { $accountId = $entity->get('accountId'); + if (empty($accountId)) { $this->unrelate($entity, 'accounts', $entity->getFetched('accountId')); + return; } } @@ -61,6 +65,7 @@ class Contact extends \Espo\Core\Repositories\Database if ($titleChanged) { if (empty($accountId)) { $accountId = $entity->getFetched('accountId'); + if (empty($accountId)) { return; } @@ -68,7 +73,7 @@ class Contact extends \Espo\Core\Repositories\Database } if ($accountIdChanged || $titleChanged) { - $accountContact = $this->getEntityManager()->getRepository('AccountContact') + $accountContact = $this->entityManager->getRepository('AccountContact') ->select(['role']) ->where([ 'accountId' => $accountId, @@ -83,6 +88,7 @@ class Contact extends \Espo\Core\Repositories\Database 'role' => $entity->get('title') ]); } + return; } diff --git a/application/Espo/Modules/Crm/Repositories/Task.php b/application/Espo/Modules/Crm/Repositories/Task.php index cce3648e38..8c8015c9da 100644 --- a/application/Espo/Modules/Crm/Repositories/Task.php +++ b/application/Espo/Modules/Crm/Repositories/Task.php @@ -69,7 +69,7 @@ class Task extends EventRepository $parentId = $entity->get('parentId'); $parentType = $entity->get('parentType'); - if ($parentId && $parentType && $this->getEntityManager()->hasRepository($parentType)) { + if ($parentId && $parentType && $this->entityManager->hasRepository($parentType)) { $columnList = ['id', 'name']; $defs = $this->entityManager->getMetadata()->getDefs(); diff --git a/application/Espo/ORM/Repository/RDBRepository.php b/application/Espo/ORM/Repository/RDBRepository.php index 8c2586c1a7..dd2ab70239 100644 --- a/application/Espo/ORM/Repository/RDBRepository.php +++ b/application/Espo/ORM/Repository/RDBRepository.php @@ -29,25 +29,29 @@ namespace Espo\ORM\Repository; -use Espo\ORM\{ - EntityManager, - EntityFactory, - Collection, - SthCollection, - Entity, - Mapper\RDBMapper, - Query\Select, - Query\Part\WhereItem, - Query\Part\Selection, - Query\Part\Join, -}; +use Espo\ORM\EntityManager; +use Espo\ORM\EntityFactory; +use Espo\ORM\Collection; +use Espo\ORM\SthCollection; +use Espo\ORM\Entity; +use Espo\ORM\Mapper\RDBMapper; +use Espo\ORM\Query\Select; +use Espo\ORM\Query\Part\WhereItem; +use Espo\ORM\Query\Part\Selection; +use Espo\ORM\Query\Part\Join; -use StdClass; +use stdClass; use RuntimeException; use PDO; -class RDBRepository extends Repository +class RDBRepository implements Repository { + protected $entityType; + + protected $entityManager; + + protected $entityFactory; + protected $mapper; protected $hookMediator; @@ -60,16 +64,18 @@ class RDBRepository extends Repository EntityFactory $entityFactory, ?HookMediator $hookMediator = null ) { - parent::__construct($entityType, $entityManager, $entityFactory); + $this->entityType = $entityType; + $this->entityFactory = $entityFactory; + $this->entityManager = $entityManager; $this->hookMediator = $hookMediator ?? (new EmptyHookMediator()); $this->transactionManager = new RDBTransactionManager($entityManager->getTransactionManager()); } - protected function getMapper(): RDBMapper + public function getEntityType(): string { - return $this->entityManager->getMapper(); + return $this->entityType; } /** @@ -456,7 +462,7 @@ class RDBRepository extends Repository else { $data = $columnData; - if ($columnData instanceof StdClass) { + if ($columnData instanceof stdClass) { $data = get_object_vars($columnData); } @@ -582,7 +588,7 @@ class RDBRepository extends Repository throw new RuntimeException("Bad foreign value."); } - if ($columnData instanceof StdClass) { + if ($columnData instanceof stdClass) { $columnData = get_object_vars($columnData); } @@ -860,4 +866,17 @@ class RDBRepository extends Repository { $this->hookMediator->afterRemove($entity, $options); } + + protected function getMapper(): RDBMapper + { + return $this->entityManager->getMapper(); + } + + /** + * @deprecated Use `$this->entityManager`. + */ + protected function getEntityManager(): EntityManager + { + return $this->entityManager; + } } diff --git a/application/Espo/ORM/Repository/Repository.php b/application/Espo/ORM/Repository/Repository.php index 73a4c5e7fd..c91244558e 100644 --- a/application/Espo/ORM/Repository/Repository.php +++ b/application/Espo/ORM/Repository/Repository.php @@ -29,66 +29,25 @@ namespace Espo\ORM\Repository; -use Espo\ORM\{ - Entity, - EntityManager, - EntityFactory, -}; +use Espo\ORM\Entity; /** * An access point for fetching and storing records. */ -abstract class Repository +interface Repository { - /** - * @var EntityFactory - */ - protected $entityFactory; - - /** - * @var EntityManager - */ - protected $entityManager; - - /** - * @var string - */ - protected $entityType; - - public function __construct(string $entityType, EntityManager $entityManager, EntityFactory $entityFactory) - { - $this->entityType = $entityType; - $this->entityFactory = $entityFactory; - $this->entityManager = $entityManager; - } - - protected function getEntityFactory(): EntityFactory - { - return $this->entityFactory; - } - - protected function getEntityManager(): EntityManager - { - return $this->entityManager; - } - - public function getEntityType(): string - { - return $this->entityType; - } - /** * Get a new entity. */ - abstract public function getNew(): Entity; + public function getNew(): Entity; /** * Fetch an entity by ID. */ - abstract public function getById(string $id): ?Entity; + public function getById(string $id): ?Entity; /** * Store an entity. */ - abstract public function save(Entity $entity): void; + public function save(Entity $entity): void; } diff --git a/application/Espo/Repositories/Email.php b/application/Espo/Repositories/Email.php index 1d3cc3a9d1..71c2bcf946 100644 --- a/application/Espo/Repositories/Email.php +++ b/application/Espo/Repositories/Email.php @@ -44,7 +44,7 @@ class Email extends \Espo\Core\Repositories\Database implements return; } - $eaRepository = $this->getEntityManager()->getRepository('EmailAddress'); + $eaRepository = $this->entityManager->getRepository('EmailAddress'); $addressValue = $entity->get($type); $idList = []; @@ -75,7 +75,7 @@ class Email extends \Espo\Core\Repositories\Database implements protected function addUserByEmailAddressId(Entity $entity, $emailAddressId, $addAssignedUser = false) { - $userList = $this->getEntityManager() + $userList = $this->entityManager ->getRepository('EmailAddress') ->getEntityListByAddressId($emailAddressId, null, 'User', true); @@ -97,7 +97,7 @@ class Email extends \Espo\Core\Repositories\Database implements } if ($entity->get('fromEmailAddressId')) { - $ea = $this->getEntityManager() + $ea = $this->entityManager ->getRepository('EmailAddress') ->get($entity->get('fromEmailAddressId')); @@ -230,12 +230,12 @@ class Email extends \Espo\Core\Repositories\Database implements $idHash = (object) []; foreach ($addressList as $address) { - $p = $this->getEntityManager() + $p = $this->entityManager ->getRepository('EmailAddress') ->getEntityByAddress($address); if (!$p) { - $p = $this->getEntityManager() + $p = $this->entityManager ->getRepository('InboundEmail') ->where(array('emailAddress' => $address)) ->findOne(); @@ -292,7 +292,7 @@ class Email extends \Espo\Core\Repositories\Database implements $from = trim($entity->get('from')); if (!empty($from)) { - $ids = $this->getEntityManager() + $ids = $this->entityManager ->getRepository('EmailAddress') ->getIds([$from]); @@ -303,7 +303,7 @@ class Email extends \Espo\Core\Repositories\Database implements $this->addUserByEmailAddressId($entity, $ids[0], true); if (!$entity->get('sentById')) { - $user = $this->getEntityManager() + $user = $this->entityManager ->getRepository('EmailAddress') ->getEntityByAddressId( $entity->get('fromEmailAddressId'), @@ -373,7 +373,7 @@ class Email extends \Espo\Core\Repositories\Database implements $parentType = $entity->get('parentType'); if ($parentId && $parentType) { - $parent = $this->getEntityManager()->getEntity($parentType, $parentId); + $parent = $this->entityManager->getEntity($parentType, $parentId); if ($parent) { $accountId = null; @@ -391,7 +391,7 @@ class Email extends \Espo\Core\Repositories\Database implements } if ($accountId) { - $account = $this->getEntityManager()->getEntity('Account', $accountId); + $account = $this->entityManager->getEntity('Account', $accountId); if ($account) { $entity->set('accountId', $accountId); @@ -453,7 +453,7 @@ class Email extends \Espo\Core\Repositories\Database implements 'parentType' => $entity->get('parentType') ]); - $this->getEntityManager()->saveEntity($reply); + $this->entityManager->saveEntity($reply); } } } @@ -465,10 +465,10 @@ class Email extends \Espo\Core\Repositories\Database implements ($entity->isAttributeChanged('status') || $entity->isNew()) ) { if ($entity->get('repliedId')) { - $replied = $this->getEntityManager()->getEntity('Email', $entity->get('repliedId')); + $replied = $this->entityManager->getEntity('Email', $entity->get('repliedId')); if ($replied && $replied->id !== $entity->id && !$replied->get('isReplied')) { $replied->set('isReplied', true); - $this->getEntityManager()->saveEntity($replied, ['silent' => true]); + $this->entityManager->saveEntity($replied, ['silent' => true]); } } } diff --git a/application/Espo/Repositories/EmailAddress.php b/application/Espo/Repositories/EmailAddress.php index af626e7689..1c5bd8be0c 100644 --- a/application/Espo/Repositories/EmailAddress.php +++ b/application/Espo/Repositories/EmailAddress.php @@ -170,7 +170,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements ]; } - $itemList = $this->getEntityManager()->getRepository('EntityEmailAddress') + $itemList = $this->entityManager->getRepository('EntityEmailAddress') ->sth() ->select(['entityType', 'entityId']) ->where($where) @@ -184,7 +184,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements continue; } - if (!$this->getEntityManager()->hasRepository($itemEntityType)) { + if (!$this->entityManager->hasRepository($itemEntityType)) { continue; } @@ -195,13 +195,13 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements $select[] = 'isActive'; } - $entity = $this->getEntityManager()->getRepository($itemEntityType) + $entity = $this->entityManager->getRepository($itemEntityType) ->select($select) ->where(['id' => $itemEntityId]) ->findOne(); } else { - $entity = $this->getEntityManager()->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); } if (!$entity) { @@ -232,7 +232,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements $where[] = ['entityType' => $entityType]; } - $itemList = $this->getEntityManager()->getRepository('EntityEmailAddress') + $itemList = $this->entityManager->getRepository('EntityEmailAddress') ->sth() ->select(['entityType', 'entityId']) ->where($where) @@ -251,7 +251,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements continue; } - if (!$this->getEntityManager()->hasRepository($itemEntityType)) { + if (!$this->entityManager->hasRepository($itemEntityType)) { continue; } @@ -262,13 +262,13 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements $select[] = 'isActive'; } - $entity = $this->getEntityManager()->getRepository($itemEntityType) + $entity = $this->entityManager->getRepository($itemEntityType) ->select($select) ->where(['id' => $itemEntityId]) ->findOne(); } else { - $entity = $this->getEntityManager()->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); } if ($entity) { @@ -291,7 +291,7 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements array $order = ['User', 'Contact', 'Lead', 'Account'] ): ?Entity { - $selectBuilder = $this->getEntityManager() + $selectBuilder = $this->entityManager ->getRepository('EntityEmailAddress') ->select(); @@ -317,11 +317,11 @@ class EmailAddress extends \Espo\Core\Repositories\Database implements continue; } - if (!$this->getEntityManager()->hasRepository($itemEntityType)) { + if (!$this->entityManager->hasRepository($itemEntityType)) { continue; } - $entity = $this->getEntityManager()->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); if ($entity) { if ($entity->getEntityType() === 'User') { diff --git a/application/Espo/Repositories/Import.php b/application/Espo/Repositories/Import.php index 4ff1152f64..dfa592e937 100644 --- a/application/Espo/Repositories/Import.php +++ b/application/Espo/Repositories/Import.php @@ -48,7 +48,7 @@ class Import extends Database $modifiedQuery = $this->addImportEntityJoin($entity, $relationName, $query); - return $this->getEntityManager() + return $this->entityManager ->getRepository($entityType) ->clone($modifiedQuery) ->find(); @@ -109,7 +109,7 @@ class Import extends Database $modifiedQuery = $this->addImportEntityJoin($entity, $relationName, $query); - return $this->getEntityManager() + return $this->entityManager ->getRepository($entityType) ->clone($modifiedQuery) ->count(); @@ -118,13 +118,13 @@ class Import extends Database protected function afterRemove(Entity $entity, array $options = []) { if ($entity->get('fileId')) { - $attachment = $this->getEntityManager()->getEntity('Attachment', $entity->get('fileId')); + $attachment = $this->entityManager->getEntity('Attachment', $entity->get('fileId')); if ($attachment) { - $this->getEntityManager()->removeEntity($attachment); + $this->entityManager->removeEntity($attachment); } } - $delete = $this->getEntityManager() + $delete = $this->entityManager ->getQueryBuilder() ->delete() ->from('ImportEntity') @@ -133,7 +133,7 @@ class Import extends Database ]) ->build(); - $this->getEntityManager()->getQueryExecutor()->execute($delete); + $this->entityManager->getQueryExecutor()->execute($delete); parent::afterRemove($entity, $options); } diff --git a/application/Espo/Repositories/LayoutSet.php b/application/Espo/Repositories/LayoutSet.php index cac4ca0800..d893067c34 100644 --- a/application/Espo/Repositories/LayoutSet.php +++ b/application/Espo/Repositories/LayoutSet.php @@ -43,7 +43,7 @@ class LayoutSet extends \Espo\Core\Repositories\Database foreach ($listBefore as $name) { if (!in_array($name, $listNow)) { - $layout = $this->getEntityManager() + $layout = $this->entityManager ->getRepository('LayoutRecord') ->where([ 'layoutSetId' => $entity->id, @@ -52,7 +52,7 @@ class LayoutSet extends \Espo\Core\Repositories\Database ->findOne(); if ($layout) { - $this->getEntityManager()->removeEntity($layout); + $this->entityManager->removeEntity($layout); } } } @@ -61,7 +61,7 @@ class LayoutSet extends \Espo\Core\Repositories\Database protected function afterRemove(Entity $entity, array $options = []) { - $layoutList = $this->getEntityManager() + $layoutList = $this->entityManager ->getRepository('LayoutRecord') ->where([ 'layoutSetId' => $entity->id, @@ -69,7 +69,7 @@ class LayoutSet extends \Espo\Core\Repositories\Database ->find(); foreach ($layoutList as $layout) { - $this->getEntityManager()->removeEntity($layout); + $this->entityManager->removeEntity($layout); } } } diff --git a/application/Espo/Repositories/PhoneNumber.php b/application/Espo/Repositories/PhoneNumber.php index 7d5913c061..6960b80cb0 100644 --- a/application/Espo/Repositories/PhoneNumber.php +++ b/application/Espo/Repositories/PhoneNumber.php @@ -151,7 +151,7 @@ class PhoneNumber extends Database implements ]; } - $itemList = $this->getEntityManager() + $itemList = $this->entityManager ->getRepository('EntityPhoneNumber') ->sth() ->select(['entityType', 'entityId']) @@ -166,11 +166,11 @@ class PhoneNumber extends Database implements continue; } - if (!$this->getEntityManager()->hasRepository($itemEntityType)) { + if (!$this->entityManager->hasRepository($itemEntityType)) { continue; } - $entity = $this->getEntityManager()->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); if (!$entity) { continue; @@ -192,7 +192,7 @@ class PhoneNumber extends Database implements $where[] = ['entityType' => $entityType]; } - $itemList = $this->getEntityManager()->getRepository('EntityPhoneNumber') + $itemList = $this->entityManager->getRepository('EntityPhoneNumber') ->sth() ->select(['entityType', 'entityId']) ->where($where) @@ -211,11 +211,11 @@ class PhoneNumber extends Database implements continue; } - if (!$this->getEntityManager()->hasRepository($itemEntityType)) { + if (!$this->entityManager->hasRepository($itemEntityType)) { continue; } - $entity = $this->getEntityManager()->getEntity($itemEntityType, $itemEntityId); + $entity = $this->entityManager->getEntity($itemEntityType, $itemEntityId); if ($entity) { if ($entity->getEntityType() === 'User') { diff --git a/application/Espo/Repositories/Preferences.php b/application/Espo/Repositories/Preferences.php index 568156efc0..c94e6d889a 100644 --- a/application/Espo/Repositories/Preferences.php +++ b/application/Espo/Repositories/Preferences.php @@ -30,15 +30,17 @@ namespace Espo\Repositories; use Espo\ORM\Entity; +use Espo\ORM\EntityManager; +use Espo\ORM\EntityFactory; use Espo\ORM\Repository\Repository; use Espo\Core\Utils\Json; -use PDO; -use StdClass; +use stdClass; use Espo\Core\Di; -class Preferences extends Repository implements +class Preferences implements Repository, + Di\MetadataAware, Di\ConfigAware, Di\EntityManagerAware @@ -47,6 +49,14 @@ class Preferences extends Repository implements use Di\ConfigSetter; use Di\EntityManagerSetter; + public function __construct( + EntityManager $entityManager, + EntityFactory $entityFactory + ) { + $this->entityFactory = $entityFactory; + $this->entityManager = $entityManager; + } + protected $defaultAttributeListFromSettings = [ 'decimalMark', 'thousandSeparator', @@ -54,9 +64,7 @@ class Preferences extends Repository implements 'followCreatedEntities', ]; - protected $data = []; - - protected $entityType = 'Preferences'; + private $data = []; public function getNew(): Entity { @@ -95,7 +103,7 @@ class Preferences extends Repository implements { $data = null; - $select = $this->getEntityManager()->getQueryBuilder() + $select = $this->entityManager->getQueryBuilder() ->select() ->from('Preferences') ->select(['id', 'data']) @@ -105,9 +113,9 @@ class Preferences extends Repository implements ->limit(0, 1) ->build(); - $sth = $this->getEntityManager()->getQueryExecutor()->execute($select); + $sth = $this->entityManager->getQueryExecutor()->execute($select); - while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { + while ($row = $sth->fetch()) { $data = Json::decode($row['data']); break; @@ -157,7 +165,7 @@ class Preferences extends Repository implements $autoFollowEntityTypeList = []; $autofollowList = $this->entityManager - ->getRepository('Autofollow') + ->getRDBRepository('Autofollow') ->select(['entityType']) ->where([ 'userId' => $id, @@ -224,7 +232,7 @@ class Preferences extends Repository implements $dataString = Json::encode($data, \JSON_PRETTY_PRINT); - $insert = $this->getEntityManager()->getQueryBuilder() + $insert = $this->entityManager->getQueryBuilder() ->insert() ->into('Preferences') ->columns(['id', 'data']) @@ -237,9 +245,10 @@ class Preferences extends Repository implements ]) ->build(); - $this->getEntityManager()->getQueryExecutor()->execute($insert); + $this->entityManager->getQueryExecutor()->execute($insert); $user = $this->entityManager->getEntity('User', $entity->id); + if ($user && !$user->isPortal()) { $this->storeAutoFollowEntityTypeList($entity); } @@ -247,7 +256,7 @@ class Preferences extends Repository implements public function deleteFromDb(string $id): void { - $delete = $this->getEntityManager()->getQueryBuilder() + $delete = $this->entityManager->getQueryBuilder() ->delete() ->from('Preferences') ->where([ @@ -255,7 +264,7 @@ class Preferences extends Repository implements ]) ->build(); - $this->getEntityManager()->getQueryExecutor()->execute($delete); + $this->entityManager->getQueryExecutor()->execute($delete); } public function remove(Entity $entity, array $options = []): void @@ -271,7 +280,7 @@ class Preferences extends Repository implements } } - public function resetToDefaults(string $userId): ?StdClass + public function resetToDefaults(string $userId): ?stdClass { $this->deleteFromDb($userId); diff --git a/application/Espo/Repositories/ScheduledJob.php b/application/Espo/Repositories/ScheduledJob.php index eef007c64c..8a266f5adc 100644 --- a/application/Espo/Repositories/ScheduledJob.php +++ b/application/Espo/Repositories/ScheduledJob.php @@ -42,7 +42,7 @@ class ScheduledJob extends \Espo\Core\Repositories\Database parent::afterSave($entity, $options); if ($entity->isAttributeChanged('scheduling')) { - $jobList = $this->getEntityManager() + $jobList = $this->entityManager ->getRepository('Job') ->where([ 'scheduledJobId' => $entity->id, @@ -51,7 +51,7 @@ class ScheduledJob extends \Espo\Core\Repositories\Database ->find(); foreach ($jobList as $job) { - $this->getEntityManager()->removeEntity($job); + $this->entityManager->removeEntity($job); } } } diff --git a/application/Espo/Repositories/User.php b/application/Espo/Repositories/User.php index 3c672ab6e1..5f6f0e048e 100644 --- a/application/Espo/Repositories/User.php +++ b/application/Espo/Repositories/User.php @@ -83,7 +83,7 @@ class User extends Database throw new Error("Username can't be empty."); } - $this->getEntityManager()->getLocker()->lockExclusive($this->entityType); + $this->entityManager->getLocker()->lockExclusive($this->entityType); $user = $this ->select(['id']) @@ -93,7 +93,7 @@ class User extends Database ->findOne(); if ($user) { - $this->getEntityManager()->getLocker()->rollback(); + $this->entityManager->getLocker()->rollback(); throw new Conflict(json_encode(['reason' => 'userNameExists'])); } @@ -105,7 +105,7 @@ class User extends Database throw new Error("Username can't be empty."); } - $this->getEntityManager()->getLocker()->lockExclusive($this->entityType); + $this->entityManager->getLocker()->lockExclusive($this->entityType); $user = $this ->select(['id']) @@ -116,7 +116,7 @@ class User extends Database ->findOne(); if ($user) { - $this->getEntityManager()->getLocker()->rollback(); + $this->entityManager->getLocker()->rollback(); throw new Conflict(json_encode(['reason' => 'userNameExists'])); } @@ -126,8 +126,8 @@ class User extends Database protected function afterSave(Entity $entity, array $options = []) { - if ($this->getEntityManager()->getLocker()->isLocked()) { - $this->getEntityManager()->getLocker()->commit(); + if ($this->entityManager->getLocker()->isLocked()) { + $this->entityManager->getLocker()->commit(); } parent::afterSave($entity, $options); @@ -137,10 +137,10 @@ class User extends Database { parent::afterRemove($entity, $options); - $userData = $this->getEntityManager()->getRepository('UserData')->getByUserId($entity->id); + $userData = $this->entityManager->getRepository('UserData')->getByUserId($entity->id); if ($userData) { - $this->getEntityManager()->removeEntity($userData); + $this->entityManager->removeEntity($userData); } } @@ -150,7 +150,7 @@ class User extends Database return false; } - return (bool) $this->getEntityManager() + return (bool) $this->entityManager ->getRepository('TeamUser') ->where([ 'deleted' => false, diff --git a/application/Espo/Repositories/UserData.php b/application/Espo/Repositories/UserData.php index 6d455cd4b0..298f332b33 100644 --- a/application/Espo/Repositories/UserData.php +++ b/application/Espo/Repositories/UserData.php @@ -43,7 +43,7 @@ class UserData extends \Espo\Core\Repositories\Database return $userData; } - $user = $this->getEntityManager() + $user = $this->entityManager ->getRepository('User') ->getById($userId);