mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-07-18 09:54:35 +02:00
Use imports instead of FQNs
This commit is contained in:
parent
f63b6d7207
commit
5629215ce4
179 changed files with 792 additions and 597 deletions
|
@ -64,7 +64,7 @@ class EntityExporter
|
|||
* @param array $options The options to use for exporting
|
||||
* @return string The serialized data
|
||||
*/
|
||||
public function exportEntities(\App\Entity\Base\AbstractNamedDBElement|array $entities, array $options): string
|
||||
public function exportEntities(AbstractNamedDBElement|array $entities, array $options): string
|
||||
{
|
||||
if (!is_array($entities)) {
|
||||
$entities = [$entities];
|
||||
|
@ -108,7 +108,7 @@ class EntityExporter
|
|||
*
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function exportEntityFromRequest(\App\Entity\Base\AbstractNamedDBElement|array $entities, Request $request): Response
|
||||
public function exportEntityFromRequest(AbstractNamedDBElement|array $entities, Request $request): Response
|
||||
{
|
||||
$options = [
|
||||
'format' => $request->get('format') ?? 'json',
|
||||
|
|
|
@ -61,7 +61,7 @@ class EntityImporter
|
|||
if (!is_a($class_name, AbstractNamedDBElement::class, true)) {
|
||||
throw new InvalidArgumentException('$class_name must be a StructuralDBElement type!');
|
||||
}
|
||||
if ($parent instanceof \App\Entity\Base\AbstractStructuralDBElement && !$parent instanceof $class_name) {
|
||||
if ($parent instanceof AbstractStructuralDBElement && !$parent instanceof $class_name) {
|
||||
throw new InvalidArgumentException('$parent must have the same type as specified in $class_name!');
|
||||
}
|
||||
|
||||
|
@ -85,11 +85,7 @@ class EntityImporter
|
|||
}
|
||||
while ($identSize < end($indentations)) {
|
||||
//If the line is intendet less than the last line, we have to go up in the tree
|
||||
if ($current_parent instanceof AbstractStructuralDBElement) {
|
||||
$current_parent = $current_parent->getParent();
|
||||
} else {
|
||||
$current_parent = null;
|
||||
}
|
||||
$current_parent = $current_parent instanceof AbstractStructuralDBElement ? $current_parent->getParent() : null;
|
||||
array_pop($indentations);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
namespace App\Services\ImportExportSystem\PartKeeprImporter;
|
||||
|
||||
use Doctrine\ORM\Id\AssignedGenerator;
|
||||
use App\Entity\Attachments\Attachment;
|
||||
use App\Entity\Attachments\AttachmentContainingDBElement;
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
|
@ -210,7 +211,7 @@ trait PKImportHelperTrait
|
|||
|
||||
$metadata = $this->em->getClassMetadata($element::class);
|
||||
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_NONE);
|
||||
$metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
|
||||
$metadata->setIdGenerator(new AssignedGenerator());
|
||||
$metadata->setIdentifierValues($element, ['id' => $id]);
|
||||
}
|
||||
|
||||
|
|
|
@ -143,7 +143,7 @@ class PKPartImporter
|
|||
throw new \RuntimeException(sprintf('Could not find part with ID %s', $partmanufacturer['part_id']));
|
||||
}
|
||||
$manufacturer = $this->em->find(Manufacturer::class, (int) $partmanufacturer['manufacturer_id']);
|
||||
if (!$manufacturer instanceof \App\Entity\Parts\Manufacturer) {
|
||||
if (!$manufacturer instanceof Manufacturer) {
|
||||
throw new \RuntimeException(sprintf('Could not find manufacturer with ID %s', $partmanufacturer['manufacturer_id']));
|
||||
}
|
||||
$part->setManufacturer($manufacturer);
|
||||
|
@ -187,7 +187,7 @@ class PKPartImporter
|
|||
}
|
||||
|
||||
$part = $this->em->find(Part::class, (int) $partparameter['part_id']);
|
||||
if (!$part instanceof \App\Entity\Parts\Part) {
|
||||
if (!$part instanceof Part) {
|
||||
throw new \RuntimeException(sprintf('Could not find part with ID %s', $partparameter['part_id']));
|
||||
}
|
||||
|
||||
|
@ -235,12 +235,12 @@ class PKPartImporter
|
|||
foreach ($data['partdistributor'] as $partdistributor) {
|
||||
//Retrieve the part
|
||||
$part = $this->em->find(Part::class, (int) $partdistributor['part_id']);
|
||||
if (!$part instanceof \App\Entity\Parts\Part) {
|
||||
if (!$part instanceof Part) {
|
||||
throw new \RuntimeException(sprintf('Could not find part with ID %s', $partdistributor['part_id']));
|
||||
}
|
||||
//Retrieve the distributor
|
||||
$supplier = $this->em->find(Supplier::class, (int) $partdistributor['distributor_id']);
|
||||
if (!$supplier instanceof \App\Entity\Parts\Supplier) {
|
||||
if (!$supplier instanceof Supplier) {
|
||||
throw new \RuntimeException(sprintf('Could not find supplier with ID %s', $partdistributor['distributor_id']));
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue