diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a34952..11d7ac1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ CHANGELOG for 1.x =================== -## v1.x - (2021-XX-XX) +## v1.0.0 - (2021-07-06) ### Added +* [[#1](https://github.com/smartbooster/parameter-bundle/issues/1)] Init bundle * [[#2](https://github.com/smartbooster/parameter-bundle/issues/2)] Add bundle Configuration * [[#2](https://github.com/smartbooster/parameter-bundle/issues/2)] Add Parameter Entity * [[#2](https://github.com/smartbooster/parameter-bundle/issues/2)] Add ParameterProvider diff --git a/src/Admin/ParameterAdmin.php b/src/Admin/ParameterAdmin.php index 3a8f0b0..9a6c72f 100644 --- a/src/Admin/ParameterAdmin.php +++ b/src/Admin/ParameterAdmin.php @@ -71,4 +71,18 @@ protected function configureFormFields(FormMapper $form): void ->end() ; } + + public function getExportFormats(): array + { + return ['csv']; + } + + public function getExportFields(): array + { + return [ + $this->trans('field.label_code') => 'code', + $this->trans('field.label_value') => 'value', + $this->trans('field.label_help') => 'help', + ]; + } } diff --git a/src/Loader/ParameterLoader.php b/src/Loader/ParameterLoader.php index b661842..432fcb7 100644 --- a/src/Loader/ParameterLoader.php +++ b/src/Loader/ParameterLoader.php @@ -20,7 +20,7 @@ class ParameterLoader "nb_deleted" => 0, "nb_inserted" => 0, ]; - private bool $dryRun; + private bool $dryRun = false; public function __construct(EntityManagerInterface $entityManager) { @@ -37,12 +37,14 @@ public function addParameter(string $code, array $data): void */ public function load(bool $dryRun = false): array { - $this->entityManager->getConnection()->beginTransaction(); $this->dryRun = $dryRun; + if (false === $this->dryRun) { + $this->entityManager->getConnection()->beginTransaction(); + } try { // @phpstan-ignore-next-line - $existingParameters = $this->entityManager->getRepository(Parameter::class)->findExisting(); + $existingParameters = $this->entityManager->getRepository(Parameter::class)->findAllByCode(); $i = 1; foreach ($existingParameters as $code => $parameter) { $this->handleExistingParameters($code, $parameter, $i); @@ -55,16 +57,16 @@ public function load(bool $dryRun = false): array ++$i; } - if (!$this->dryRun) { + if (false === $this->dryRun) { $this->entityManager->flush(); $this->entityManager->clear(); $this->entityManager->getConnection()->commit(); } - // @codeCoverageIgnoreStart } catch (\Exception $e) { - $this->entityManager->getConnection()->rollBack(); + if (false === $this->dryRun) { + $this->entityManager->getConnection()->rollBack(); + } } - // @codeCoverageIgnoreEnd return $this->logs; } @@ -85,7 +87,7 @@ protected function handleExistingParameters(string $code, Parameter $parameter, $this->logs["nb_deleted"]++; } - if (($i % self::BATCH_SIZE) === 0 && !$this->dryRun) { + if (($i % self::BATCH_SIZE) === 0 && false === $this->dryRun) { $this->entityManager->flush(); $this->entityManager->clear(); } @@ -103,7 +105,7 @@ protected function handleParametersToInsert(string $code, array $data, int $i): $this->entityManager->persist($parameter); $this->logs["nb_inserted"]++; - if (($i % self::BATCH_SIZE) === 0 && !$this->dryRun) { + if (($i % self::BATCH_SIZE) === 0 && false === $this->dryRun) { $this->entityManager->flush(); $this->entityManager->clear(); } diff --git a/src/Repository/ParameterRepository.php b/src/Repository/ParameterRepository.php index 1b33fb6..bcbff6d 100644 --- a/src/Repository/ParameterRepository.php +++ b/src/Repository/ParameterRepository.php @@ -15,7 +15,7 @@ class ParameterRepository extends EntityRepository /** * @return Parameter[] */ - public function findExisting(): array + public function findAllByCode(): array { return $this->createQueryBuilder('p', 'p.code') ->getQuery()