fix: customer seeder
This commit is contained in:
@@ -8,7 +8,7 @@ sleep $SLEEP_TIME
|
|||||||
|
|
||||||
# Provision database
|
# Provision database
|
||||||
php /var/www/bin/console doctrine:migrations:migrate --no-interaction
|
php /var/www/bin/console doctrine:migrations:migrate --no-interaction
|
||||||
php /var/www/bin/console doctrine:fixtures:load --no-interaction
|
php /var/www/bin/console db:seed
|
||||||
|
|
||||||
# Start Apache in the foreground
|
# Start Apache in the foreground
|
||||||
echo "Starting Apache..."
|
echo "Starting Apache..."
|
||||||
|
|||||||
159
src/Command/SeedDatabaseCommand.php
Normal file
159
src/Command/SeedDatabaseCommand.php
Normal file
@@ -0,0 +1,159 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use App\User\Framework\Repository\PreferenceOptionRepository;
|
||||||
|
use App\User\Framework\Repository\PreferencesRepository;
|
||||||
|
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;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'db:seed',
|
||||||
|
description: 'Seed the database with required data.',
|
||||||
|
)]
|
||||||
|
class SeedDatabaseCommand extends Command
|
||||||
|
{
|
||||||
|
private PreferencesRepository $preferenceRepository;
|
||||||
|
private PreferenceOptionRepository $preferenceOptionRepository;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
PreferencesRepository $preferenceRepository,
|
||||||
|
PreferenceOptionRepository $preferenceOptionRepository,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
$this->preferenceRepository = $preferenceRepository;
|
||||||
|
$this->preferenceOptionRepository = $preferenceOptionRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
$this->seedPreferences($io);
|
||||||
|
$this->seedPreferenceOptions($io);
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function seedPreferences(SymfonyStyle $io)
|
||||||
|
{
|
||||||
|
$io->info('[SeedDatabaseCommand] > Seeding preferences...');
|
||||||
|
$preferences = $this->getPreferences();
|
||||||
|
|
||||||
|
foreach ($preferences as $preference) {
|
||||||
|
if ($this->preferenceRepository->find($preference['id'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preferenceRepository->getEntityManager()->persist((new \App\User\Framework\Entity\Preference())
|
||||||
|
->setId($preference['id'])
|
||||||
|
->setName($preference['name'])
|
||||||
|
->setDescription($preference['description'])
|
||||||
|
->setEnabled($preference['enabled'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preferenceRepository->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPreferences(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'id' => 'codec',
|
||||||
|
'name' => 'Codec',
|
||||||
|
'description' => null,
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'resolution',
|
||||||
|
'name' => 'Resolution',
|
||||||
|
'description' => null,
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'language',
|
||||||
|
'name' => 'Language',
|
||||||
|
'description' => null,
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'id' => 'provider',
|
||||||
|
'name' => 'Provider',
|
||||||
|
'description' => null,
|
||||||
|
'enabled' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function seedPreferenceOptions(SymfonyStyle $io)
|
||||||
|
{
|
||||||
|
$io->info('[SeedDatabaseCommand] > Seeding preference options...');
|
||||||
|
$options = $this->getPreferenceOptions();
|
||||||
|
|
||||||
|
foreach ($options as $option) {
|
||||||
|
if ($this->preferenceOptionRepository->findBy([
|
||||||
|
'preference' => $option['preference_id'],
|
||||||
|
'name' => $option['name'],
|
||||||
|
'value' => $option['value'],
|
||||||
|
'enabled' => $option['enabled'],
|
||||||
|
])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$this->preferenceOptionRepository->getEntityManager()->persist(
|
||||||
|
(new \App\User\Framework\Entity\PreferenceOption())
|
||||||
|
->setPreference($this->preferenceRepository->find($option['preference_id']))
|
||||||
|
->setName($option['name'])
|
||||||
|
->setValue($option['value'])
|
||||||
|
->setEnabled($option['enabled'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->preferenceOptionRepository->getEntityManager()->flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function getPreferenceOptions(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
[
|
||||||
|
'preference_id' => 'resolution',
|
||||||
|
'name' => '720p',
|
||||||
|
'value' => '720p',
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'preference_id' => 'resolution',
|
||||||
|
'name' => '1080p',
|
||||||
|
'value' => '1080p',
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'preference_id' => 'resolution',
|
||||||
|
'name' => '2160p',
|
||||||
|
'value' => '2160p',
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'preference_id' => 'codec',
|
||||||
|
'name' => '-',
|
||||||
|
'value' => '-',
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'preference_id' => 'codec',
|
||||||
|
'name' => 'h264',
|
||||||
|
'value' => 'h264',
|
||||||
|
'enabled' => true
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'preference_id' => 'codec',
|
||||||
|
'name' => 'h265/HEVC',
|
||||||
|
'value' => 'h265',
|
||||||
|
'enabled' => true
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\User\Framework\DataFixtures;
|
|
||||||
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
|
|
||||||
class PreferenceFixtures extends Fixture
|
|
||||||
{
|
|
||||||
public function load(ObjectManager $manager): void
|
|
||||||
{
|
|
||||||
$preferences = [
|
|
||||||
[
|
|
||||||
'id' => 'codec',
|
|
||||||
'name' => 'Codec',
|
|
||||||
'description' => null,
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'resolution',
|
|
||||||
'name' => 'Resolution',
|
|
||||||
'description' => null,
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'language',
|
|
||||||
'name' => 'Language',
|
|
||||||
'description' => null,
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'id' => 'provider',
|
|
||||||
'name' => 'Provider',
|
|
||||||
'description' => null,
|
|
||||||
'enabled' => true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($preferences as $preference) {
|
|
||||||
$manager->persist((new \App\User\Framework\Entity\Preference())
|
|
||||||
->setId($preference['id'])
|
|
||||||
->setName($preference['name'])
|
|
||||||
->setDescription($preference['description'])
|
|
||||||
->setEnabled($preference['enabled'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
|
|
||||||
$options = [
|
|
||||||
[
|
|
||||||
'preference_id' => 'resolution',
|
|
||||||
'name' => '720p',
|
|
||||||
'value' => '720p',
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'preference_id' => 'resolution',
|
|
||||||
'name' => '1080p',
|
|
||||||
'value' => '1080p',
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'preference_id' => 'resolution',
|
|
||||||
'name' => '2160p',
|
|
||||||
'value' => '2160p',
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'preference_id' => 'codec',
|
|
||||||
'name' => '-',
|
|
||||||
'value' => '-',
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'preference_id' => 'codec',
|
|
||||||
'name' => 'h264',
|
|
||||||
'value' => 'h264',
|
|
||||||
'enabled' => true
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'preference_id' => 'codec',
|
|
||||||
'name' => 'h265/HEVC',
|
|
||||||
'value' => 'h265',
|
|
||||||
'enabled' => true
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$preferenceRepository = $manager->getRepository(\App\User\Framework\Entity\Preference::class);
|
|
||||||
foreach ($options as $option) {
|
|
||||||
$manager->persist(
|
|
||||||
(new \App\User\Framework\Entity\PreferenceOption())
|
|
||||||
->setPreference($preferenceRepository->find($option['preference_id']))
|
|
||||||
->setName($option['name'])
|
|
||||||
->setValue($option['value'])
|
|
||||||
->setEnabled($option['enabled'])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user