From 1f982031ca9e4faaa2c42b47d650337be0e0c02e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 21 Mar 2022 12:43:12 +0200 Subject: [PATCH] type fixes --- .../Espo/Tools/FieldManager/FieldManager.php | 4 ++++ .../Espo/Tools/FieldManager/Hooks/NumberType.php | 2 +- application/Espo/Tools/Import/Import.php | 14 +++++++++----- application/Espo/Tools/Import/Service.php | 14 +++++++++++++- application/Espo/Tools/Kanban/OrdererProcessor.php | 2 +- .../Espo/Tools/LayoutManager/LayoutManager.php | 1 + 6 files changed, 29 insertions(+), 8 deletions(-) diff --git a/application/Espo/Tools/FieldManager/FieldManager.php b/application/Espo/Tools/FieldManager/FieldManager.php index 0e25673648..0971312490 100644 --- a/application/Espo/Tools/FieldManager/FieldManager.php +++ b/application/Espo/Tools/FieldManager/FieldManager.php @@ -718,6 +718,10 @@ class FieldManager $actualCustomFieldDefs = $this->getCustomFieldDefs($scope, $name, []); $actualFieldDefs = $this->getFieldDefs($scope, $name, (object) []); + + assert($actualFieldDefs !== null); + assert($actualCustomFieldDefs !== null); + $permittedParamList = array_keys($params); $filteredFieldDefs = !empty($actualCustomFieldDefs) ? $actualCustomFieldDefs : []; diff --git a/application/Espo/Tools/FieldManager/Hooks/NumberType.php b/application/Espo/Tools/FieldManager/Hooks/NumberType.php index 0ec656cd88..ccd5947ed4 100644 --- a/application/Espo/Tools/FieldManager/Hooks/NumberType.php +++ b/application/Espo/Tools/FieldManager/Hooks/NumberType.php @@ -85,7 +85,7 @@ class NumberType implements Di\EntityManagerAware ->findOne(); if (!$number) { - $number = $this->entityManager->getEntity('NextNumber'); + $number = $this->entityManager->getNewEntity('NextNumber'); $number->set('entityType', $scope); $number->set('fieldName', $name); diff --git a/application/Espo/Tools/Import/Import.php b/application/Espo/Tools/Import/Import.php index 302bc0d860..a8aecf7a33 100644 --- a/application/Espo/Tools/Import/Import.php +++ b/application/Espo/Tools/Import/Import.php @@ -218,6 +218,8 @@ class Import $enclosure = $params->getTextQualifier() ?? self::DEFAULT_TEXT_QUALIFIER; + assert(is_string($this->entityType)); + if (!$this->user->isAdmin()) { $forbiddenAttributeList = $this->aclManager->getScopeForbiddenAttributeList($this->user, $this->entityType, 'edit'); @@ -248,7 +250,7 @@ class Import $startFromIndex = null; if ($this->id) { - $import = $this->entityManager->getEntity('Import', $this->id); + $import = $this->entityManager->getEntityById('Import', $this->id); if (!$import) { throw new Error('Import: Could not find import record.'); @@ -261,7 +263,7 @@ class Import $import->set('status', ImportEntity::STATUS_IN_PROCESS); } else { - $import = $this->entityManager->getEntity(ImportEntity::ENTITY_TYPE); + $import = $this->entityManager->getNewEntity(ImportEntity::ENTITY_TYPE); $import->set([ 'entityType' => $this->entityType, @@ -423,6 +425,8 @@ class Import } } + assert(is_string($this->entityType)); + $recordService = $this->recordServiceContainer->get($this->entityType); if (in_array($action, [Params::ACTION_CREATE_AND_UPDATE, Params::ACTION_UPDATE])) { @@ -445,7 +449,7 @@ class Import if (!$entity) { if ($action === Params::ACTION_CREATE_AND_UPDATE) { - $entity = $this->entityManager->getEntity($this->entityType); + $entity = $this->entityManager->getNewEntity($this->entityType); if (array_key_exists('id', $whereClause)) { $entity->set('id', $whereClause['id']); @@ -611,7 +615,7 @@ class Import $nameValue = $entity->get($attribute); if ($isPerson) { - $where = $this->parsePersonName($nameValue, $this->params->getPersonNameFormat()); + $where = $this->parsePersonName($nameValue, $this->params->getPersonNameFormat() ?? ''); } else { $where = [ @@ -698,7 +702,7 @@ class Import $lastNameAttribute = 'last' . ucfirst($attribute); $middleNameAttribute = 'middle' . ucfirst($attribute); - $personNameData = $this->parsePersonName($value, $params->getPersonNameFormat()); + $personNameData = $this->parsePersonName($value, $params->getPersonNameFormat() ?? ''); if (!$entity->get($firstNameAttribute) && isset($personNameData['firstName'])) { $personNameData['firstName'] = $this->prepareAttributeValue( diff --git a/application/Espo/Tools/Import/Service.php b/application/Espo/Tools/Import/Service.php index 4def79a605..1b1b062b11 100644 --- a/application/Espo/Tools/Import/Service.php +++ b/application/Espo/Tools/Import/Service.php @@ -123,6 +123,10 @@ class Service $entityType = $source->getTargetEntityType(); $attributeList = $source->getTargetAttributeList() ?? []; + if (!$entityType) { + throw new Error("No entity-type."); + } + $params = Params::fromRaw($source->getParams()) ->withIdleMode(false) ->withManualMode(false); @@ -156,11 +160,19 @@ class Service $entityType = $import->getTargetEntityType(); $attributeList = $import->getTargetAttributeList() ?? []; + if (!$entityType) { + throw new Error("No entity-type."); + } + $params = Params::fromRaw($import->getParams()) ->withStartFromLastIndex($startFromLastIndex); $attachmentId = $import->getFileId(); + if (!$attachmentId) { + throw new Error("No file-id."); + } + return $this->factory ->create() ->setEntityType($entityType) @@ -255,7 +267,7 @@ class Service */ public function uploadFile(string $contents): string { - $attachment = $this->entityManager->getEntity(Attachment::ENTITY_TYPE); + $attachment = $this->entityManager->getNewEntity(Attachment::ENTITY_TYPE); $attachment->set('type', 'text/csv'); $attachment->set('role', 'Import File'); diff --git a/application/Espo/Tools/Kanban/OrdererProcessor.php b/application/Espo/Tools/Kanban/OrdererProcessor.php index 1cbc1e3e9a..4ca4c5ad3f 100644 --- a/application/Espo/Tools/Kanban/OrdererProcessor.php +++ b/application/Espo/Tools/Kanban/OrdererProcessor.php @@ -167,7 +167,7 @@ class OrdererProcessor ->create('KanbanOrder'); foreach ($ids as $i => $id) { - $item = $this->entityManager->getEntity('KanbanOrder'); + $item = $this->entityManager->getNewEntity('KanbanOrder'); $item->set([ 'id' => Util::generateId(), diff --git a/application/Espo/Tools/LayoutManager/LayoutManager.php b/application/Espo/Tools/LayoutManager/LayoutManager.php index b7a7e6f264..4dc7cb1bd3 100644 --- a/application/Espo/Tools/LayoutManager/LayoutManager.php +++ b/application/Espo/Tools/LayoutManager/LayoutManager.php @@ -145,6 +145,7 @@ class LayoutManager protected function sanitizeInput(string $name): string { + /** @var string */ return preg_replace("([\.]{2,})", '', $name); } }