diff --git a/src/Base/Framework/Command/SeedDatabaseCommand.php b/src/Base/Framework/Command/SeedDatabaseCommand.php index 385d594..3aa84f6 100644 --- a/src/Base/Framework/Command/SeedDatabaseCommand.php +++ b/src/Base/Framework/Command/SeedDatabaseCommand.php @@ -2,15 +2,20 @@ namespace App\Base\Framework\Command; +use App\User\Framework\Entity\Preference; use App\User\Framework\Entity\UserPreference; use App\User\Framework\Repository\PreferenceOptionRepository; use App\User\Framework\Repository\PreferencesRepository; use App\User\Framework\Repository\UserRepository; +use Doctrine\ORM\EntityManagerInterface; +use Symfony\Bridge\Doctrine\PropertyInfo\DoctrineExtractor; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; +use Symfony\Component\PropertyInfo\Extractor\ReflectionExtractor; +use Symfony\Component\PropertyInfo\PropertyInfoExtractor; #[AsCommand( name: 'db:seed', @@ -50,17 +55,23 @@ class SeedDatabaseCommand extends Command $preferences = $this->getPreferences(); foreach ($preferences as $preference) { - if ($this->preferenceRepository->find($preference['id'])) { - continue; + $isNewRecord = false; + $preferenceRecord = $this->preferenceRepository->findOneBy(['id' => $preference['id']]); + if (null === $preferenceRecord) { + $isNewRecord = true; + $preferenceRecord = new Preference(); } - $this->preferenceRepository->getEntityManager()->persist((new \App\User\Framework\Entity\Preference()) + $preferenceRecord ->setId($preference['id']) ->setName($preference['name']) ->setDescription($preference['description']) ->setEnabled($preference['enabled']) - ->setType($preference['type']) - ); + ->setType($preference['type']); + + if (true === $isNewRecord) { + $this->preferenceRepository->getEntityManager()->persist($preferenceRecord); + } } $this->preferenceRepository->getEntityManager()->flush();