diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index 7a0c0adb2a..10e4771b7d 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -113,6 +113,8 @@ class Record extends RecordService implements */ public function getEntityType(): string { + assert($this->entityType !== null); + return $this->entityType; } @@ -220,6 +222,8 @@ class Record extends RecordService implements */ protected function getSelectManager($entityType = null) { + assert($this->entityType !== null); + if (!$entityType) { $entityType = $this->entityType; } @@ -263,6 +267,8 @@ class Record extends RecordService implements */ public function exportCollection(array $params, Collection $collection): string { + assert($this->entityType !== null); + if ($this->acl->getPermissionLevel('exportPermission') !== AclTable::LEVEL_YES) { throw new ForbiddenSilent("No 'export' permission."); } @@ -336,6 +342,8 @@ class Record extends RecordService implements */ protected function getConvertCurrencyFieldList() { + assert($this->entityType !== null); + if (isset($this->convertCurrencyFieldList)) { return $this->convertCurrencyFieldList; } diff --git a/application/Espo/Services/RecordTree.php b/application/Espo/Services/RecordTree.php index 3d0eb84126..8b7a14fbdc 100644 --- a/application/Espo/Services/RecordTree.php +++ b/application/Espo/Services/RecordTree.php @@ -73,6 +73,8 @@ class RecordTree extends Record { parent::__construct(); + assert($this->entityType !== null); + if (!$this->subjectEntityType && $this->entityType !== 'RecordTree') { $this->subjectEntityType = substr($this->entityType, 0, strlen($this->entityType) - 8); } @@ -88,6 +90,8 @@ class RecordTree extends Record { parent::setEntityType($entityType); + assert($this->entityType !== null); + if (!$this->subjectEntityType) { $this->subjectEntityType = substr($this->entityType, 0, strlen($this->entityType) - 8); } @@ -122,6 +126,8 @@ class RecordTree extends Record int $level = 0 ): ?Collection { + assert($this->entityType !== null); + if (!$maxDepth) { $maxDepth = self::MAX_DEPTH; } @@ -182,6 +188,8 @@ class RecordTree extends Record protected function checkFilterOnlyNotEmpty(): bool { + assert($this->subjectEntityType !== null); + try { if (!$this->acl->checkScope($this->subjectEntityType, 'create')) { return true; @@ -200,6 +208,8 @@ class RecordTree extends Record return false; } + assert($this->subjectEntityType !== null); + $query = $this->selectBuilderFactory ->create() ->from($this->subjectEntityType) @@ -227,6 +237,8 @@ class RecordTree extends Record public function getCategoryData(?string $id): ?stdClass { + assert($this->entityType !== null); + if (!$this->acl->check($this->entityType, AclTable::ACTION_READ)) { throw new Forbidden(); } @@ -259,6 +271,8 @@ class RecordTree extends Record */ public function getTreeItemPath(?string $parentId = null): array { + assert($this->entityType !== null); + if (!$this->acl->check($this->entityType, AclTable::ACTION_READ)) { throw new Forbidden(); } @@ -288,7 +302,7 @@ class RecordTree extends Record protected function getSeed(): Entity { if (empty($this->seed)) { - $this->seed = $this->getEntityManager()->getEntity($this->getEntityType()); + $this->seed = $this->getEntityManager()->getNewEntity($this->getEntityType()); } return $this->seed; @@ -346,6 +360,8 @@ class RecordTree extends Record */ public function getLastChildrenIdList(?string $parentId = null): array { + assert($this->entityType !== null); + if (!$this->acl->check($this->getEntityType(), 'read')) { throw new Forbidden(); } diff --git a/application/Espo/Services/Settings.php b/application/Espo/Services/Settings.php index 889be0464c..f5f7f6ead5 100644 --- a/application/Espo/Services/Settings.php +++ b/application/Espo/Services/Settings.php @@ -137,7 +137,7 @@ class Settings unset($data->$item); } - $entity = $this->entityManager->getEntity('Settings'); + $entity = $this->entityManager->getNewEntity('Settings'); $entity->set($data); $entity->setAsNotNew(); diff --git a/application/Espo/Services/Stream.php b/application/Espo/Services/Stream.php index 144ba2c3db..1710589796 100644 --- a/application/Espo/Services/Stream.php +++ b/application/Espo/Services/Stream.php @@ -307,7 +307,7 @@ class Stream $collection = new EntityCollection(); foreach ($userIdList as $userId) { - $subscription = $this->entityManager->getEntity('Subscription'); + $subscription = $this->entityManager->getNewEntity('Subscription'); $subscription->set([ 'userId' => $userId, @@ -1351,7 +1351,7 @@ class Stream return; } - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'EmailReceived'); $note->set('parentId', $entity->getId()); @@ -1403,7 +1403,7 @@ class Stream { $entityType = $entity->getEntityType(); - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'EmailSent'); $note->set('parentId', $entity->getId()); @@ -1466,7 +1466,7 @@ class Stream { $entityType = $entity->getEntityType(); - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'Create'); $note->set('parentId', $entity->getId()); @@ -1553,7 +1553,7 @@ class Stream array $options = [] ): void { - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $entityType = $entity->getEntityType(); @@ -1604,7 +1604,7 @@ class Stream return; } - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set([ 'type' => 'Relate', @@ -1630,7 +1630,7 @@ class Stream */ public function noteAssign(Entity $entity, array $options = []): void { - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'Assign'); $note->set('parentId', $entity->getId()); @@ -1677,7 +1677,7 @@ class Stream */ public function noteStatus(Entity $entity, string $field, array $options = []): void { - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'Status'); $note->set('parentId', $entity->getId()); @@ -1827,7 +1827,7 @@ class Stream return; } - $note = $this->entityManager->getEntity('Note'); + $note = $this->entityManager->getNewEntity('Note'); $note->set('type', 'Update'); $note->set('parentId', $entity->getId());