diff --git a/composer.json b/composer.json index 46f6bac..67bc6af 100644 --- a/composer.json +++ b/composer.json @@ -96,6 +96,7 @@ } }, "require-dev": { + "doctrine/doctrine-fixtures-bundle": "^3.4", "friendsofphp/php-cs-fixer": "^3.21", "phpstan/phpstan": "^1.10", "phpunit/phpunit": "^9.5", diff --git a/composer.lock b/composer.lock index 9538f7d..c4f3f96 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "e0d0272d134103b1c3eb7b8dd6218014", + "content-hash": "3f7c88a7058a622c9199a3974b60a59b", "packages": [ { "name": "components/font-awesome", @@ -7818,6 +7818,171 @@ ], "time": "2022-02-25T21:32:43+00:00" }, + { + "name": "doctrine/data-fixtures", + "version": "1.6.7", + "source": { + "type": "git", + "url": "https://github.com/doctrine/data-fixtures.git", + "reference": "ae4e845decbe177348fdbecd04331f4fb96aa301" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/data-fixtures/zipball/ae4e845decbe177348fdbecd04331f4fb96aa301", + "reference": "ae4e845decbe177348fdbecd04331f4fb96aa301", + "shasum": "" + }, + "require": { + "doctrine/deprecations": "^0.5.3 || ^1.0", + "doctrine/persistence": "^1.3.3 || ^2.0 || ^3.0", + "php": "^7.2 || ^8.0" + }, + "conflict": { + "doctrine/dbal": "<2.13", + "doctrine/orm": "<2.14", + "doctrine/phpcr-odm": "<1.3.0" + }, + "require-dev": { + "doctrine/coding-standard": "^11.0", + "doctrine/dbal": "^2.13 || ^3.0", + "doctrine/mongodb-odm": "^1.3.0 || ^2.0.0", + "doctrine/orm": "^2.14", + "ext-sqlite3": "*", + "phpstan/phpstan": "^1.5", + "phpunit/phpunit": "^8.5 || ^9.5 || ^10.0", + "symfony/cache": "^5.0 || ^6.0", + "vimeo/psalm": "^4.10 || ^5.9" + }, + "suggest": { + "alcaeus/mongo-php-adapter": "For using MongoDB ODM 1.3 with PHP 7 (deprecated)", + "doctrine/mongodb-odm": "For loading MongoDB ODM fixtures", + "doctrine/orm": "For loading ORM fixtures", + "doctrine/phpcr-odm": "For loading PHPCR ODM fixtures" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Common\\DataFixtures\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + } + ], + "description": "Data Fixtures for all Doctrine Object Managers", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "database" + ], + "support": { + "issues": "https://github.com/doctrine/data-fixtures/issues", + "source": "https://github.com/doctrine/data-fixtures/tree/1.6.7" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdata-fixtures", + "type": "tidelift" + } + ], + "time": "2023-08-17T21:15:33+00:00" + }, + { + "name": "doctrine/doctrine-fixtures-bundle", + "version": "3.4.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/DoctrineFixturesBundle.git", + "reference": "9ec3139c52a42e94c9fd1e95f8d2bca94326edfb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/DoctrineFixturesBundle/zipball/9ec3139c52a42e94c9fd1e95f8d2bca94326edfb", + "reference": "9ec3139c52a42e94c9fd1e95f8d2bca94326edfb", + "shasum": "" + }, + "require": { + "doctrine/data-fixtures": "^1.3", + "doctrine/doctrine-bundle": "^1.11|^2.0", + "doctrine/orm": "^2.6.0", + "doctrine/persistence": "^1.3.7|^2.0|^3.0", + "php": "^7.1 || ^8.0", + "symfony/config": "^3.4|^4.3|^5.0|^6.0", + "symfony/console": "^3.4|^4.3|^5.0|^6.0", + "symfony/dependency-injection": "^3.4.47|^4.3|^5.0|^6.0", + "symfony/doctrine-bridge": "^3.4|^4.1|^5.0|^6.0", + "symfony/http-kernel": "^3.4|^4.3|^5.0|^6.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpstan/phpstan": "^1.4.10", + "phpunit/phpunit": "^7.5.20 || ^8.5.26 || ^9.5.20", + "symfony/phpunit-bridge": "^6.0.8", + "vimeo/psalm": "^4.22" + }, + "type": "symfony-bundle", + "autoload": { + "psr-4": { + "Doctrine\\Bundle\\FixturesBundle\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Doctrine Project", + "homepage": "https://www.doctrine-project.org" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony DoctrineFixturesBundle", + "homepage": "https://www.doctrine-project.org", + "keywords": [ + "Fixture", + "persistence" + ], + "support": { + "issues": "https://github.com/doctrine/DoctrineFixturesBundle/issues", + "source": "https://github.com/doctrine/DoctrineFixturesBundle/tree/3.4.4" + }, + "funding": [ + { + "url": "https://www.doctrine-project.org/sponsorship.html", + "type": "custom" + }, + { + "url": "https://www.patreon.com/phpdoctrine", + "type": "patreon" + }, + { + "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdoctrine-fixtures-bundle", + "type": "tidelift" + } + ], + "time": "2023-05-02T15:12:16+00:00" + }, { "name": "friendsofphp/php-cs-fixer", "version": "v3.38.2", @@ -10298,5 +10463,5 @@ "ext-iconv": "*" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/config/bundles.php b/config/bundles.php index 075b830..6cab317 100644 --- a/config/bundles.php +++ b/config/bundles.php @@ -1,7 +1,7 @@ ['all' => true], Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true], Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true], + Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true], ]; diff --git a/config/preload.php b/config/preload.php index e23eaf0..c14136e 100644 --- a/config/preload.php +++ b/config/preload.php @@ -1,7 +1,7 @@ parameterBag->get('kernel.project_dir') . '/src/DataFixtures'; + + $fixtures = Finder::create()->in($fixturesPath); + + $progressBar = new ProgressBar($output, count($fixtures)); + $progressBar->start(); + + foreach ($fixtures as $fixture) { + $class = str_replace('Fixtures.php', '', $fixture->getRelativePathname()); + + $io->info($class . ' successfully created'); + $progressBar->advance(); + } + + $progressBar->finish(); + $output->writeln(PHP_EOL); + + $process = new Process(['php', 'bin/console', 'doctrine:fixtures:load', '--no-interaction']); + $process->run(); + if (!$process->isSuccessful()) { + throw new ProcessFailedException($process); + } + + $output->writeln($process->getOutput()); + + $io->success('Preview Data was successfully loaded!'); + + return Command::SUCCESS; + } +} diff --git a/src/Command/Scheduler/RunSchedulerCommand.php b/src/Command/Scheduler/RunSchedulerCommand.php index 0d04be3..f68d5c9 100644 --- a/src/Command/Scheduler/RunSchedulerCommand.php +++ b/src/Command/Scheduler/RunSchedulerCommand.php @@ -1,7 +1,7 @@ setName('Fixture'); + $asset->setHostname('www.google.com'); + $asset->setIpv4Address('172.217.18.4'); + $asset->setIpv6Address('2a00:1450:4016:80a::2004'); + $asset->addAssetGroup($this->getReference(AssetGroupFixtures::REFERENCE_KEY_ASSET_GROUP)); + + $manager->persist($asset); + $manager->flush(); + } + + public function getDependencies() + { + return [ + UserFixtures::class, + AssetGroupFixtures::class, + ]; + } +} diff --git a/src/DataFixtures/AssetGroupFixtures.php b/src/DataFixtures/AssetGroupFixtures.php new file mode 100644 index 0000000..158c130 --- /dev/null +++ b/src/DataFixtures/AssetGroupFixtures.php @@ -0,0 +1,34 @@ +setName('Fixture'); + + $this->addReference(self::REFERENCE_KEY_ASSET_GROUP, $assetGroup); + $manager->persist($assetGroup); + $manager->flush(); + } + + public function getDependencies() + { + return [ + UserFixtures::class, + ]; + } +} diff --git a/src/DataFixtures/CheckScriptFixtures.php b/src/DataFixtures/CheckScriptFixtures.php new file mode 100644 index 0000000..60d4f00 --- /dev/null +++ b/src/DataFixtures/CheckScriptFixtures.php @@ -0,0 +1,44 @@ +setName('Fixture Script') + ->setFilename('Ping v4') + ->setDescription('Ping Connection') + ->setFilehash(md5(file_get_contents($this->kernel->getProjectDir() . self::SCRIPT_PATH . self::SCRIPT_FILE))) + ; + + $this->addReference(self::REFERENCE_KEY_CHECK_SCRIPT, $checkScript); + $manager->persist($checkScript); + $manager->flush(); + } + + public function getDependencies() + { + return [ + UserFixtures::class, + ]; + } +} diff --git a/src/DataFixtures/ServiceCheckFixtures.php b/src/DataFixtures/ServiceCheckFixtures.php new file mode 100644 index 0000000..ecea415 --- /dev/null +++ b/src/DataFixtures/ServiceCheckFixtures.php @@ -0,0 +1,39 @@ +setName('Fixture Service Check') + ->setCheckScript($this->getReference(CheckScriptFixtures::REFERENCE_KEY_CHECK_SCRIPT)) + ->setCheckIntervalSeconds(15) + ->setRetryIntervalSeconds(60) + ->setMaxRetries(3) + ->setNotificationsEnabled(false) + ->addAssetGroup($this->getReference(AssetGroupFixtures::REFERENCE_KEY_ASSET_GROUP)) + ; + $manager->persist($serviceCheck); + $manager->flush(); + } + + public function getDependencies() + { + return [ + UserFixtures::class, + AssetGroupFixtures::class, + CheckScriptFixtures::class, + ]; + } +} diff --git a/src/DataFixtures/UserFixtures.php b/src/DataFixtures/UserFixtures.php new file mode 100644 index 0000000..11d07e4 --- /dev/null +++ b/src/DataFixtures/UserFixtures.php @@ -0,0 +1,69 @@ +getUserData(); + + foreach ($users as $key => $data) { + ${$key} = new User(); + ${$key}->setEmail($data['email']); + ${$key}->setRoles($data['roles']); + + $password = $this->hasher->hashPassword(${$key}, $data['password']); + + ${$key}->setPassword($password); + ${$key}->setName($data['name']); + ${$key}->setTheme($data['theme']); + ${$key}->setRowLimit($data['rowLimit']); + ${$key}->setLanguage($data['language']); + + $this->addReference($key, ${$key}); + + $manager->persist(${$key}); + } + + $manager->flush(); + } + + /** + * @return array|int|string>> + */ + private function getUserData(): array + { + return [ + 'standard-user' => [ + 'email' => 'test@localhost.local', + 'roles' => ['ROLE_USER'], + 'password' => 'test', + 'name' => 'User', + 'theme' => 'dark', + 'rowLimit' => 25, + 'language' => 'auto', + ], + 'admin-user' => [ + 'email' => 'admin@localhost.local', + 'roles' => ['ROLE_ADMIN'], + 'password' => 'admin', + 'name' => 'Admin', + 'theme' => 'light', + 'rowLimit' => 25, + 'language' => 'auto', + ], + ]; + } +} diff --git a/src/DataObject/Api/ApiInfoMessageDataObject.php b/src/DataObject/Api/ApiInfoMessageDataObject.php index 04c0a24..bc20384 100644 --- a/src/DataObject/Api/ApiInfoMessageDataObject.php +++ b/src/DataObject/Api/ApiInfoMessageDataObject.php @@ -1,7 +1,7 @@