Specify order in which the data fixtures should be loaded

This commit is contained in:
Jan Böhmer 2023-06-18 22:06:42 +02:00
parent 4977f6c270
commit cce3e1cfb8
5 changed files with 36 additions and 41 deletions

View file

@ -1,37 +0,0 @@
<?php
/**
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
declare(strict_types=1);
namespace App\DataFixtures;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Persistence\ObjectManager;
class AppFixtures extends Fixture
{
public function load(ObjectManager $manager): void
{
// $product = new Product();
// $manager->persist($product);
$manager->flush();
}
}

View file

@ -31,12 +31,14 @@ use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use InvalidArgumentException;
class DataStructureFixtures extends Fixture
class DataStructureFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(protected EntityManagerInterface $em)
{
@ -106,4 +108,11 @@ class DataStructureFixtures extends Fixture
$manager->persist($node2_1);
$manager->persist($node1_1_1);
}
public function getDependencies(): array
{
return [
UserFixtures::class
];
}
}

View file

@ -110,4 +110,11 @@ class LabelProfileFixtures extends Fixture
$manager->flush();
}
public function getDependencies(): array
{
return [
PartFixtures::class,
];
}
}

View file

@ -55,10 +55,11 @@ use App\Entity\PriceInformations\Pricedetail;
use Brick\Math\BigDecimal;
use DateTime;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
class PartFixtures extends Fixture
class PartFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(protected EntityManagerInterface $em)
{
@ -132,4 +133,11 @@ class PartFixtures extends Fixture
$manager->persist($part);
$manager->flush();
}
public function getDependencies(): array
{
return [
DataStructureFixtures::class
];
}
}

View file

@ -24,11 +24,12 @@ namespace App\DataFixtures;
use App\Entity\UserSystem\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
class UserFixtures extends Fixture
class UserFixtures extends Fixture implements DependentFixtureInterface
{
public function __construct(protected UserPasswordHasherInterface $encoder, protected EntityManagerInterface $em)
{
@ -66,4 +67,11 @@ class UserFixtures extends Fixture
$manager->flush();
}
public function getDependencies(): array
{
return [
GroupFixtures::class,
];
}
}