diff --git a/CHANGELOG.md b/CHANGELOG.md index 07cf76ff..be4d363b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ * Adjust Admin List Order * Add __toString methods to Entities +* Improve fixture loading while increasing the number of fixtures # 3.3.1 (2023.11.12) @@ -60,7 +61,7 @@ # 2.7.17 (2021.12.30) -* Set creationTime and updatedTime in all entity constructors (Fixes #207) +* Set creationTime and updatedTime in all entity constructors (Fixes #207) * Update to symfony 4.3.36 * Update dependencies @@ -145,8 +146,8 @@ # 2.7.3 (2020.10.21) * Improve OpenPGP key import filter: - - Keep UIDs with valid email address but without realname - - Drop UIDs with invalid email address that have the valid email + * Keep UIDs with valid email address but without realname + * Drop UIDs with invalid email address that have the valid email address in realname # 2.7.2 (2020.10.21) diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 00000000..e900aaee --- /dev/null +++ b/codecov.yml @@ -0,0 +1,9 @@ +--- +ignore: + - "config" + - "features" + - "hugo" + - "public" + - "src/DataFixtures" + - "templates" + - "tests" diff --git a/src/DataFixtures/LoadAliasData.php b/src/DataFixtures/LoadAliasData.php index 76ac0877..dd8ca804 100644 --- a/src/DataFixtures/LoadAliasData.php +++ b/src/DataFixtures/LoadAliasData.php @@ -2,28 +2,14 @@ namespace App\DataFixtures; -use App\Entity\Domain; use App\Entity\User; use App\Factory\AliasFactory; -use App\Repository\DomainRepository; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Persistence\ObjectManager; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -class LoadAliasData extends Fixture implements OrderedFixtureInterface, ContainerAwareInterface +class LoadAliasData extends Fixture implements OrderedFixtureInterface { - private ContainerInterface $container; - - /** - * {@inheritdoc} - */ - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } - /** * {@inheritdoc} */ @@ -32,23 +18,25 @@ public function load(ObjectManager $manager): void $user = $manager->getRepository(User::class)->findByEmail('admin@example.org'); for ($i = 1; $i < 5; ++$i) { - $alias = AliasFactory::create($user, 'alias'.$i); + $alias = AliasFactory::create($user, null); $manager->persist($alias); - $manager->flush(); } - for ($i = 1; $i < 5; ++$i) { - $alias = AliasFactory::create($user, null); + $users = $manager->getRepository(User::class)->findAll(); + + for ($i = 1; $i < 500; ++$i) { + $alias = AliasFactory::create($users[random_int(0, count($users) - 1)], 'alias' . $i); $manager->persist($alias); - $manager->flush(); + + if (($i % 100) === 0) { + $manager->flush(); + } } - } - private function getRepository(): DomainRepository - { - return $this->container->get('doctrine')->getRepository(Domain::class); + $manager->flush(); + $manager->clear(); } /** diff --git a/src/DataFixtures/LoadDomainData.php b/src/DataFixtures/LoadDomainData.php index 149682d4..650832f0 100644 --- a/src/DataFixtures/LoadDomainData.php +++ b/src/DataFixtures/LoadDomainData.php @@ -24,8 +24,10 @@ public function load(ObjectManager $manager): void $domain->setName($name); $manager->persist($domain); - $manager->flush(); } + + $manager->flush(); + $manager->clear(); } /** diff --git a/src/DataFixtures/LoadUserData.php b/src/DataFixtures/LoadUserData.php index e8d850f9..28d12bb0 100644 --- a/src/DataFixtures/LoadUserData.php +++ b/src/DataFixtures/LoadUserData.php @@ -16,6 +16,8 @@ class LoadUserData extends Fixture implements OrderedFixtureInterface, Container { private const PASSWORD = 'password'; + private string $passwordHash; + private array $users = [ ['email' => 'admin@example.org', 'roles' => [Roles::ADMIN]], ['email' => 'user@example.org', 'roles' => [Roles::USER]], @@ -41,6 +43,11 @@ public function setContainer(ContainerInterface $container = null): void */ public function load(ObjectManager $manager): void { + $user = new User(); + $user->setPlainPassword(self::PASSWORD); + $this->getPasswordUpdater()->updatePassword($user); + $this->passwordHash = $user->getPassword(); + $this->loadStaticUsers($manager); $this->loadRandomUsers($manager); } @@ -58,20 +65,13 @@ private function getPasswordUpdater(): PasswordUpdater return $this->container->get(PasswordUpdater::class); } - /** - * @param $domain - * @param $email - * @param $roles - */ - private function buildUser($domain, $email, $roles): User + private function buildUser(Domain $domain, string $email, array $roles): User { $user = new User(); $user->setDomain($domain); $user->setEmail($email); $user->setRoles($roles); - $user->setPlainPassword(self::PASSWORD); - - $this->getPasswordUpdater()->updatePassword($user); + $user->setPassword($this->passwordHash); return $user; } @@ -89,8 +89,10 @@ private function loadStaticUsers(ObjectManager $manager): void $user = $this->buildUser($domain, $email, $roles); $manager->persist($user); - $manager->flush(); } + + $manager->flush(); + $manager->clear(); } /** @@ -99,12 +101,11 @@ private function loadStaticUsers(ObjectManager $manager): void private function loadRandomUsers(ObjectManager $manager): void { $domainRepository = $manager->getRepository(Domain::class); + $domain = $domainRepository->findOneBy(['name' => 'example.org']); + $roles = [Roles::USER]; - for ($i = 0; $i < 500; ++$i) { - $email = sprintf('%s@example.org', uniqid('', true)); - $splitted = explode('@', $email); - $roles = [Roles::USER]; - $domain = $domainRepository->findOneBy(['name' => $splitted[1]]); + for ($i = 0; $i < 15000; ++$i) { + $email = sprintf('user-%d@%s', $i, $domain->getName()); $user = $this->buildUser($domain, $email, $roles); $user->setCreationTime(new \DateTime(sprintf('-%s days', random_int(1, 25)))); @@ -118,7 +119,13 @@ private function loadRandomUsers(ObjectManager $manager): void } $manager->persist($user); - $manager->flush(); + + if (($i % 100) === 0) { + $manager->flush(); + } } + + $manager->flush(); + $manager->clear(); } } diff --git a/src/DataFixtures/LoadVoucherData.php b/src/DataFixtures/LoadVoucherData.php index 92fccac9..b3264e50 100644 --- a/src/DataFixtures/LoadVoucherData.php +++ b/src/DataFixtures/LoadVoucherData.php @@ -3,26 +3,13 @@ namespace App\DataFixtures; use App\Entity\User; -use App\Entity\Voucher; use App\Factory\VoucherFactory; use Doctrine\Bundle\FixturesBundle\Fixture; use Doctrine\Common\DataFixtures\OrderedFixtureInterface; use Doctrine\Persistence\ObjectManager; -use Symfony\Component\DependencyInjection\ContainerAwareInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; -class LoadVoucherData extends Fixture implements OrderedFixtureInterface, ContainerAwareInterface +class LoadVoucherData extends Fixture implements OrderedFixtureInterface { - private ContainerInterface $container; - - /** - * {@inheritdoc} - */ - public function setContainer(ContainerInterface $container = null): void - { - $this->container = $container; - } - /** * {@inheritdoc} * @@ -46,6 +33,10 @@ public function load(ObjectManager $manager): void } $manager->persist($voucher); + + if (($i % 100) === 0) { + $manager->flush(); + } } // add redeemed voucher to a suspicious parent @@ -58,6 +49,7 @@ public function load(ObjectManager $manager): void $manager->persist($voucher); $manager->flush(); + $manager->clear(); } /**