From 1c836918caa895a9c36cd7c5fb18ac7212d61cc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 2 May 2023 00:39:37 +0200 Subject: [PATCH] Fixed various Partkeepr import issues On Linux mysql table names can contain uppercase characters, and we expect always lowercase character, so we now normalize the tablenames to lowercase. Also fixed some type errors on part parameters and improved performace for orderdetails import. This fixes issue #286 --- .../MySQLDumpXMLConverter.php | 5 +++- .../PartKeeprImporter/PKPartImporter.php | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/Services/ImportExportSystem/PartKeeprImporter/MySQLDumpXMLConverter.php b/src/Services/ImportExportSystem/PartKeeprImporter/MySQLDumpXMLConverter.php index 9d583d2a..4ff9c189 100644 --- a/src/Services/ImportExportSystem/PartKeeprImporter/MySQLDumpXMLConverter.php +++ b/src/Services/ImportExportSystem/PartKeeprImporter/MySQLDumpXMLConverter.php @@ -69,7 +69,10 @@ class MySQLDumpXMLConverter //Iterate over all nodes and convert them to arrays foreach ($tables as $table) { - $table_data[$table->getAttribute('name')] = $this->convertTableToArray($table); + //Normalize the table name to lowercase. On Linux filesystems the tables sometimes contain uppercase letters + //However we expect the table names to be lowercase in the further steps + $table_name = strtolower($table->getAttribute('name')); + $table_data[$table_name] = $this->convertTableToArray($table); } return $table_data; diff --git a/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php b/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php index 5065d04c..a0594899 100644 --- a/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php +++ b/src/Services/ImportExportSystem/PartKeeprImporter/PKPartImporter.php @@ -168,11 +168,21 @@ class PKPartImporter $entity->setName($name); $entity->setValueText($partparameter['stringValue'] ?? ''); - $entity->setUnit($this->getUnitSymbol($data, (int) $partparameter['unit_id'])); + if ($partparameter['unit_id'] === null) { + $entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id'])); + } else { + $entity->setUnit(""); + } - $entity->setValueMin($partparameter['normalizedMinValue'] ?? null); - $entity->setValueTypical($partparameter['normalizedValue'] ?? null); - $entity->setValueMax($partparameter['normalizedMaxValue'] ?? null); + if ($partparameter['normalizedMinValue'] !== null) { + $entity->setValueMin((float) $partparameter['normalizedMinValue']); + } + if ($partparameter['normalizedValue'] !== null) { + $entity->setValueTypical((float) $partparameter['normalizedValue']); + } + if ($partparameter['normalizedMaxValue'] !== null) { + $entity->setValueMax((float) $partparameter['normalizedMaxValue']); + } $part = $this->em->find(Part::class, (int) $partparameter['part_id']); if (!$part) { @@ -226,6 +236,7 @@ class PKPartImporter $orderdetail->setSupplier($supplier); $orderdetail->setSupplierpartnr($spn); $part->addOrderdetail($orderdetail); + $this->em->persist($orderdetail); } //Add the price information to the orderdetail @@ -236,10 +247,13 @@ class PKPartImporter $price_per_item = BigDecimal::of($partdistributor['price']); $pricedetail->setPrice($price_per_item->multipliedBy($partdistributor['packagingUnit'])); $pricedetail->setPriceRelatedQuantity($partdistributor['packagingUnit'] ?? 1); + + $this->em->persist($pricedetail); } - //We have to flush the changes in every loop, so the find function can find newly created entities $this->em->flush(); + //Clear the entity manager to improve performance + $this->em->clear(); } }