type fixes

This commit is contained in:
Yuri Kuznetsov
2022-03-21 13:51:54 +02:00
parent 5dd845327e
commit f70e1bd38e
4 changed files with 35 additions and 11 deletions

View File

@@ -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;
}

View File

@@ -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();
}

View File

@@ -137,7 +137,7 @@ class Settings
unset($data->$item);
}
$entity = $this->entityManager->getEntity('Settings');
$entity = $this->entityManager->getNewEntity('Settings');
$entity->set($data);
$entity->setAsNotNew();

View File

@@ -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());