mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-21 01:25:55 +02:00
Fixed some issues when importing parameters from partkeepr
Before values were not properly imported, if there was not a normalized version yet and units were not correctly imported
This commit is contained in:
parent
301ecf6c95
commit
d9f58b935a
2 changed files with 30 additions and 7 deletions
|
@ -235,4 +235,27 @@ trait PKImportHelperTrait
|
||||||
$property->setAccessible(true);
|
$property->setAccessible(true);
|
||||||
$property->setValue($entity, $date);
|
$property->setValue($entity, $date);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the SI prefix factor for the given prefix ID.
|
||||||
|
* Used to convert a value from the PartKeepr database to the PartDB database.
|
||||||
|
* @param array $data
|
||||||
|
* @param int $prefix_id
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
protected function getSIPrefixFactor(array $data, int $prefix_id): float
|
||||||
|
{
|
||||||
|
if ($prefix_id === 0) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
$prefixes = $data['siprefix'];
|
||||||
|
foreach ($prefixes as $prefix) {
|
||||||
|
if ((int) $prefix['id'] === $prefix_id) {
|
||||||
|
return pow((int) $prefix['base'], (int) $prefix['exponent']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \RuntimeException(sprintf('Could not find SI prefix with ID %s', $prefix_id));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,20 +173,20 @@ class PKPartImporter
|
||||||
$entity->setName($name);
|
$entity->setName($name);
|
||||||
|
|
||||||
$entity->setValueText($partparameter['stringValue'] ?? '');
|
$entity->setValueText($partparameter['stringValue'] ?? '');
|
||||||
if ($partparameter['unit_id'] === null) {
|
if ($partparameter['unit_id'] !== null && (int) $partparameter['unit_id'] !== 0) {
|
||||||
$entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id']));
|
$entity->setUnit($this->getUnitSymbol($data, (int)$partparameter['unit_id']));
|
||||||
} else {
|
} else {
|
||||||
$entity->setUnit("");
|
$entity->setUnit("");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($partparameter['normalizedMinValue'] !== null) {
|
if ($partparameter['value'] !== null) {
|
||||||
$entity->setValueMin((float) $partparameter['normalizedMinValue']);
|
$entity->setValueTypical((float) $partparameter['value'] * $this->getSIPrefixFactor($data, (int) $partparameter['siPrefix_id']));
|
||||||
}
|
}
|
||||||
if ($partparameter['normalizedValue'] !== null) {
|
if ($partparameter['minimumValue'] !== null) {
|
||||||
$entity->setValueTypical((float) $partparameter['normalizedValue']);
|
$entity->setValueMin((float) $partparameter['minimumValue'] * $this->getSIPrefixFactor($data, (int) $partparameter['minSiPrefix_id']));
|
||||||
}
|
}
|
||||||
if ($partparameter['normalizedMaxValue'] !== null) {
|
if ($partparameter['maximumValue'] !== null) {
|
||||||
$entity->setValueMax((float) $partparameter['normalizedMaxValue']);
|
$entity->setValueMax((float) $partparameter['maximumValue'] * $this->getSIPrefixFactor($data, (int) $partparameter['maxSiPrefix_id']));
|
||||||
}
|
}
|
||||||
|
|
||||||
$part = $this->em->find(Part::class, (int) $partparameter['part_id']);
|
$part = $this->em->find(Part::class, (int) $partparameter['part_id']);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue