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
This commit is contained in:
Jan Böhmer 2023-05-02 00:39:37 +02:00
parent 4a6a3b9269
commit 1c836918ca
2 changed files with 23 additions and 6 deletions

View file

@ -69,7 +69,10 @@ class MySQLDumpXMLConverter
//Iterate over all <table> nodes and convert them to arrays //Iterate over all <table> nodes and convert them to arrays
foreach ($tables as $table) { 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; return $table_data;

View file

@ -168,11 +168,21 @@ class PKPartImporter
$entity->setName($name); $entity->setName($name);
$entity->setValueText($partparameter['stringValue'] ?? ''); $entity->setValueText($partparameter['stringValue'] ?? '');
if ($partparameter['unit_id'] === null) {
$entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id'])); $entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id']));
} else {
$entity->setUnit("");
}
$entity->setValueMin($partparameter['normalizedMinValue'] ?? null); if ($partparameter['normalizedMinValue'] !== null) {
$entity->setValueTypical($partparameter['normalizedValue'] ?? null); $entity->setValueMin((float) $partparameter['normalizedMinValue']);
$entity->setValueMax($partparameter['normalizedMaxValue'] ?? null); }
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']); $part = $this->em->find(Part::class, (int) $partparameter['part_id']);
if (!$part) { if (!$part) {
@ -226,6 +236,7 @@ class PKPartImporter
$orderdetail->setSupplier($supplier); $orderdetail->setSupplier($supplier);
$orderdetail->setSupplierpartnr($spn); $orderdetail->setSupplierpartnr($spn);
$part->addOrderdetail($orderdetail); $part->addOrderdetail($orderdetail);
$this->em->persist($orderdetail);
} }
//Add the price information to the orderdetail //Add the price information to the orderdetail
@ -236,10 +247,13 @@ class PKPartImporter
$price_per_item = BigDecimal::of($partdistributor['price']); $price_per_item = BigDecimal::of($partdistributor['price']);
$pricedetail->setPrice($price_per_item->multipliedBy($partdistributor['packagingUnit'])); $pricedetail->setPrice($price_per_item->multipliedBy($partdistributor['packagingUnit']));
$pricedetail->setPriceRelatedQuantity($partdistributor['packagingUnit'] ?? 1); $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(); $this->em->flush();
//Clear the entity manager to improve performance
$this->em->clear();
} }
} }