From 6d2c6fb6e13d860cc288a1becc6149a8fb9e39f6 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 10 Feb 2023 10:51:16 +0100 Subject: [PATCH 01/14] FIX [renaming][translation] changing a translation for concerned groups in activities --- src/Bundle/ChillActivityBundle/translations/messages.fr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml index 461137454..4dd67ceb8 100644 --- a/src/Bundle/ChillActivityBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillActivityBundle/translations/messages.fr.yml @@ -77,7 +77,7 @@ Choose a type: Choisir un type 4 hours: 4 heures 4 hours 30: 4 heures 30 5 hours: 5 heures -Concerned groups: Parties concernées +Concerned groups: Parties concernées par l'échange Persons in accompanying course: Usagers du parcours Third persons: Tiers non-pro. Others persons: Usagers From f653f8fd7a3472942f0facd5b72cc488068b972f Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 10 Feb 2023 11:30:26 +0100 Subject: [PATCH 02/14] FIX [translations][wording] make distinction between parties concernees for an activity and an appointment in the translations --- .../ChillCalendarBundle/Resources/views/Calendar/edit.html.twig | 2 +- .../ChillCalendarBundle/Resources/views/Calendar/new.html.twig | 2 +- .../ChillCalendarBundle/Resources/views/Calendar/show.html.twig | 2 +- src/Bundle/ChillCalendarBundle/translations/messages.fr.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig index df814282a..8978739ea 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/edit.html.twig @@ -7,7 +7,7 @@
{# <=== vue component: mainUser #} -

{{ 'Concerned groups'|trans }}

+

{{ 'Concerned groups calendar'|trans }}

{%- if form.persons is defined -%} {{ form_widget(form.persons) }} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig index 84eca97a0..9fff55d63 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/new.html.twig @@ -7,7 +7,7 @@
{# <=== vue component: mainUser #} -

{{ 'Concerned groups'|trans }}

+

{{ 'Concerned groups calendar'|trans }}

{%- if form.mainUser is defined -%} {{ form_row(form.mainUser) }} diff --git a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig index bff4baa53..d48844f67 100644 --- a/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig +++ b/src/Bundle/ChillCalendarBundle/Resources/views/Calendar/show.html.twig @@ -14,7 +14,7 @@
{{ entity.mainUser }}
-

{{ 'Concerned groups'|trans }}

+

{{ 'Concerned groups calendar'|trans }}

{% include 'ChillActivityBundle:Activity:concernedGroups.html.twig' with {'context': 'calendar_' ~ context, 'render': 'bloc' } %} diff --git a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml index 623eb02cb..aa933bb63 100644 --- a/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillCalendarBundle/translations/messages.fr.yml @@ -4,7 +4,7 @@ My calendar list: Mes rendez-vous There is no calendar items.: Il n'y a pas de rendez-vous Remove calendar item: Supprimer le rendez-vous Are you sure you want to remove the calendar item?: Êtes-vous sûr de vouloir supprimer le rendez-vous? -Concerned groups: Parties concernées +Concerned groups calendar: Parties concernées Calendar data: Données du rendez-vous Update calendar: Modifier le rendez-vous main user concerned: Utilisateur concerné From eac3471cbb0b59c5e7dd7bebcd716ac1c5618a9c Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 10 Feb 2023 11:37:32 +0100 Subject: [PATCH 03/14] FIX [person][contactinfo] place the contactinfo fields underneath birthdate for easier access --- .../Resources/views/Person/edit.html.twig | 70 +++++++++---------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig index 6ffbe8430..872dc4eab 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Person/edit.html.twig @@ -63,6 +63,41 @@ {%- endif -%} + {%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contactInfo is defined-%} +
+

{{ 'Contact information'|trans }}

+ {%- if form.email is defined -%} +
+ {{ form_row(form.email, {'label': 'Email'}) }} +
+ {% endif %} + {%- if form.acceptEmail is defined -%} +
+ {{ form_row(form.acceptEmail, {'label' : 'Accept emails ?'}) }} +
+ {%- endif -%} + + {%- if form.phonenumber is defined -%} + {{ form_row(form.phonenumber, {'label': 'Phonenumber'}) }} + {%- endif -%} + {%- if form.mobilenumber is defined -%} +
+ {{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }} +
+
+ {{ form_row(form.acceptSMS, {'label' : 'Accept short text message ?'}) }} +
+ {%- endif -%} + {%- if form.otherPhoneNumbers is defined -%} + {{ form_widget(form.otherPhoneNumbers) }} + {{ form_errors(form.otherPhoneNumbers) }} + {%- endif -%} + {%- if form.contactInfo is defined -%} + {{ form_row(form.contactInfo, {'label': 'Notes on contact information'}) }} + {%- endif -%} +
+ {%- endif -%} + {%- if form.nationality is defined or form.spokenLanguages is defined -%}

{{ 'Administrative information'|trans }}

@@ -93,41 +128,6 @@
{%- endif -%} - {%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contactInfo is defined-%} -
-

{{ 'Contact information'|trans }}

- {%- if form.email is defined -%} -
- {{ form_row(form.email, {'label': 'Email'}) }} -
- {% endif %} - {%- if form.acceptEmail is defined -%} -
- {{ form_row(form.acceptEmail, {'label' : 'Accept emails ?'}) }} -
- {%- endif -%} - - {%- if form.phonenumber is defined -%} - {{ form_row(form.phonenumber, {'label': 'Phonenumber'}) }} - {%- endif -%} - {%- if form.mobilenumber is defined -%} -
- {{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }} -
-
- {{ form_row(form.acceptSMS, {'label' : 'Accept short text message ?'}) }} -
- {%- endif -%} - {%- if form.otherPhoneNumbers is defined -%} - {{ form_widget(form.otherPhoneNumbers) }} - {{ form_errors(form.otherPhoneNumbers) }} - {%- endif -%} - {%- if form.contactInfo is defined -%} - {{ form_row(form.contactInfo, {'label': 'Notes on contact information'}) }} - {%- endif -%} -
- {%- endif -%} - {{ form_rest(form) }}
    From bb05ba0f170bb2f3a872c6d4a9c209ec00d0ba48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 14 Feb 2023 19:35:28 +0100 Subject: [PATCH 04/14] Feature: [docgen] create a service to generate a document from a template --- .../GeneratorDriver/RelatorioDriver.php | 1 + .../Service/Generator/Generator.php | 132 +++++++++++++++++ .../Service/Generator/GeneratorException.php | 18 +++ .../Generator/ObjectReadyException.php | 11 ++ .../RelatedEntityNotFoundException.php | 14 ++ .../Messenger/RequestGenerationMessage.php | 45 ++++++ .../Context/Generator/GeneratorTest.php | 134 ++++++++++++++++++ .../Entity/StoredObject.php | 77 +++++++--- 8 files changed, 415 insertions(+), 17 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorException.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/ObjectReadyException.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/RelatedEntityNotFoundException.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/tests/Service/Context/Generator/GeneratorTest.php diff --git a/src/Bundle/ChillDocGeneratorBundle/GeneratorDriver/RelatorioDriver.php b/src/Bundle/ChillDocGeneratorBundle/GeneratorDriver/RelatorioDriver.php index 9f879f7ff..0f62931b4 100644 --- a/src/Bundle/ChillDocGeneratorBundle/GeneratorDriver/RelatorioDriver.php +++ b/src/Bundle/ChillDocGeneratorBundle/GeneratorDriver/RelatorioDriver.php @@ -53,6 +53,7 @@ final class RelatorioDriver implements DriverInterface $response = $this->client->request('POST', $this->url, [ 'headers' => $form->getPreparedHeaders()->toArray(), 'body' => $form->bodyToIterable(), + 'timeout' => '300', ]); return $response->getContent(); diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php new file mode 100644 index 000000000..755e608ba --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php @@ -0,0 +1,132 @@ +contextManager = $contextManager; + $this->driver = $driver; + $this->entityManager = $entityManager; + $this->logger = $logger; + $this->storedObjectManager = $storedObjectManager; + } + + /** + * @template T of File|null + * @template B of bool + * @param B $isTest + * @param (B is true ? T : null) $testFile + * @psalm-return (B is true ? string : null) + * @throws \Symfony\Component\Serializer\Exception\ExceptionInterface|\Throwable + */ + public function generateDocFromTemplate( + DocGeneratorTemplate $template, + string $entityClassName, + int $entityId, + ?StoredObject $destinationStoredObject = null, + bool $isTest = false, + ?File $testFile = null + ): ?string { + if ($destinationStoredObject instanceof StoredObject && StoredObject::STATUS_PENDING !== $destinationStoredObject->getStatus()) { + throw new ObjectReadyException(); + } + + $context = $this->contextManager->getContextByDocGeneratorTemplate($template); + $contextGenerationData = ['test_file' => $testFile]; + + $entity = $this + ->entityManager + ->find($context->getEntityClass(), $entityId) + ; + + if (null === $entity) { + throw new RelatedEntityNotFoundException($entityClassName, $entityId); + } + + if ($isTest && ($testFile instanceof File)) { + $dataDecrypted = file_get_contents($testFile->getPathname()); + } else { + $dataDecrypted = $this->storedObjectManager->read($template->getFile()); + } + + try { + $generatedResource = $this + ->driver + ->generateFromString( + $dataDecrypted, + $template->getFile()->getType(), + $context->getData($template, $entity, $contextGenerationData), + $template->getFile()->getFilename() + ); + } catch (TemplateException $e) { + throw new GeneratorException($e->getErrors(), $e); + } + + if ($isTest) { + return $generatedResource; + } + + /** @var StoredObject $storedObject */ + $destinationStoredObject + ->setType($template->getFile()->getType()) + ->setFilename(sprintf('%s_odt', uniqid('doc_', true))) + ->setStatus(StoredObject::STATUS_READY) + ; + + $this->storedObjectManager->write($destinationStoredObject, $generatedResource); + + try { + $context + ->storeGenerated( + $template, + $destinationStoredObject, + $entity, + $contextGenerationData + ); + } catch (\Exception $e) { + $this + ->logger + ->error( + 'Unable to store the associated document to entity', + [ + 'entityClassName' => $entityClassName, + 'entityId' => $entityId, + 'contextKey' => $context->getName(), + ] + ); + + throw $e; + } + + $this->entityManager->flush(); + + return null; + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorException.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorException.php new file mode 100644 index 000000000..423d59dd4 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorException.php @@ -0,0 +1,18 @@ + + */ + private array $errors; + + public function __construct(array $errors = [], \Throwable $previous = null) + { + $this->errors = $errors; + parent::__construct("Could not generate the document", 15252, + $previous); + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/ObjectReadyException.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/ObjectReadyException.php new file mode 100644 index 000000000..85c82cf95 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/ObjectReadyException.php @@ -0,0 +1,11 @@ +creatorId = $creator->getId(); + $this->templateId = $template->getId(); + $this->entityId = $entityId; + $this->entityClassName = $entityClassName; + } + + public function getCreatorId(): int + { + return $this->creatorId; + } + + public function getTemplateId(): int + { + return $this->templateId; + } + + public function getEntityId(): int + { + return $this->entityId; + } + + public function getEntityClassName(): string + { + return $this->entityClassName; + } +} diff --git a/src/Bundle/ChillDocGeneratorBundle/tests/Service/Context/Generator/GeneratorTest.php b/src/Bundle/ChillDocGeneratorBundle/tests/Service/Context/Generator/GeneratorTest.php new file mode 100644 index 000000000..2e68b443c --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/tests/Service/Context/Generator/GeneratorTest.php @@ -0,0 +1,134 @@ +setFile($templateStoredObject = (new StoredObject()) + ->setType('application/test')); + $destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING); + $entity = new class {}; + $data = []; + + $context = $this->prophesize(DocGeneratorContextInterface::class); + $context->getData($template, $entity, Argument::type('array'))->willReturn($data); + $context->storeGenerated($template, $destinationStoredObject, $entity, Argument::type('array')) + ->shouldBeCalled(); + $context->getName()->willReturn('dummy_context'); + $context->getEntityClass()->willReturn('DummyClass'); + $context = $context->reveal(); + + $contextManagerInterface = $this->prophesize(ContextManagerInterface::class); + $contextManagerInterface->getContextByDocGeneratorTemplate($template) + ->willReturn($context); + + $driver = $this->prophesize(DriverInterface::class); + $driver->generateFromString('template', 'application/test', $data, Argument::any()) + ->willReturn('generated'); + + $entityManager = $this->prophesize(EntityManagerInterface::class); + $entityManager->find(Argument::type('string'), Argument::type('int')) + ->willReturn($entity); + $entityManager->flush()->shouldBeCalled(); + + $storedObjectManager = $this->prophesize(StoredObjectManagerInterface::class); + $storedObjectManager->read($templateStoredObject)->willReturn('template'); + $storedObjectManager->write($destinationStoredObject, 'generated')->shouldBeCalled(); + + + $generator = new Generator( + $contextManagerInterface->reveal(), + $driver->reveal(), + $entityManager->reveal(), + new NullLogger(), + $storedObjectManager->reveal() + ); + + $generator->generateDocFromTemplate( + $template, + 'DummyEntity', + 1, + $destinationStoredObject + ); + } + + public function testPreventRegenerateDocument(): void + { + $this->expectException(ObjectReadyException::class); + + $generator = new Generator( + $this->prophesize(ContextManagerInterface::class)->reveal(), + $this->prophesize(DriverInterface::class)->reveal(), + $this->prophesize(EntityManagerInterface::class)->reveal(), + new NullLogger(), + $this->prophesize(StoredObjectManagerInterface::class)->reveal() + ); + + $template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject()) + ->setType('application/test')); + $destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_READY); + + $generator->generateDocFromTemplate( + $template, + 'DummyEntity', + 1, + $destinationStoredObject + ); + } + + public function testRelatedEntityNotFound(): void + { + $this->expectException(RelatedEntityNotFoundException::class); + + $template = (new DocGeneratorTemplate())->setFile($templateStoredObject = (new StoredObject()) + ->setType('application/test')); + $destinationStoredObject = (new StoredObject())->setStatus(StoredObject::STATUS_PENDING); + + $context = $this->prophesize(DocGeneratorContextInterface::class); + $context->getName()->willReturn('dummy_context'); + $context->getEntityClass()->willReturn('DummyClass'); + $context = $context->reveal(); + + $contextManagerInterface = $this->prophesize(ContextManagerInterface::class); + $contextManagerInterface->getContextByDocGeneratorTemplate($template) + ->willReturn($context); + + $entityManager = $this->prophesize(EntityManagerInterface::class); + $entityManager->find(Argument::type('string'), Argument::type('int')) + ->willReturn(null); + + $generator = new Generator( + $contextManagerInterface->reveal(), + $this->prophesize(DriverInterface::class)->reveal(), + $entityManager->reveal(), + new NullLogger(), + $this->prophesize(StoredObjectManagerInterface::class)->reveal() + ); + + $generator->generateDocFromTemplate( + $template, + 'DummyEntity', + 1, + $destinationStoredObject + ); + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php index ec2b67cf2..21abc1f56 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php @@ -14,6 +14,9 @@ namespace Chill\DocStoreBundle\Entity; use ChampsLibres\AsyncUploaderBundle\Model\AsyncFileInterface; use ChampsLibres\AsyncUploaderBundle\Validator\Constraints\AsyncFileExists; use ChampsLibres\WopiLib\Contract\Entity\Document; +use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; +use Chill\MainBundle\Doctrine\Model\TrackCreationInterface; +use Chill\MainBundle\Doctrine\Model\TrackCreationTrait; use DateTime; use DateTimeInterface; use Doctrine\ORM\Mapping as ORM; @@ -30,8 +33,14 @@ use Symfony\Component\Serializer\Annotation as Serializer; * message="The file is not stored properly" * ) */ -class StoredObject implements AsyncFileInterface, Document +class StoredObject implements AsyncFileInterface, Document, TrackCreationInterface { + public const STATUS_READY = "ready"; + public const STATUS_PENDING = "pending"; + public const STATUS_FAILURE = "failure"; + + use TrackCreationTrait; + /** * @ORM\Column(type="datetime", name="creation_date") * @Serializer\Groups({"read", "write"}) @@ -48,7 +57,7 @@ class StoredObject implements AsyncFileInterface, Document * @ORM\Column(type="text") * @Serializer\Groups({"read", "write"}) */ - private $filename; + private string $filename = ''; /** * @ORM\Id @@ -56,7 +65,7 @@ class StoredObject implements AsyncFileInterface, Document * @ORM\Column(type="integer") * @Serializer\Groups({"read", "write"}) */ - private $id; + private ?int $id; /** * @var int[] @@ -89,28 +98,44 @@ class StoredObject implements AsyncFileInterface, Document */ private UuidInterface $uuid; - public function __construct() + /** + * @ORM\ManyToOne(targetEntity=DocGeneratorTemplate::class) + */ + private ?DocGeneratorTemplate $template; + + /** + * @ORM\Column(type="text", options={"default": "ready"}) + */ + private string $status; + + /** + * @param StoredObject::STATUS_* $status + */ + public function __construct(string $status = "ready") { - $this->creationDate = new DateTime(); $this->uuid = Uuid::uuid4(); + $this->status = $status; } + /** + * @Serializer\Groups({"read", "write"}) + */ public function getCreationDate(): DateTime { - return $this->creationDate; + return DateTime::createFromImmutable($this->createdAt); } - public function getDatas() + public function getDatas(): array { return $this->datas; } - public function getFilename() + public function getFilename(): string { return $this->filename; } - public function getId() + public function getId(): ?int { return $this->id; } @@ -133,6 +158,11 @@ class StoredObject implements AsyncFileInterface, Document return $this->getFilename(); } + public function getStatus(): string + { + return $this->status; + } + public function getTitle() { return $this->title; @@ -153,49 +183,62 @@ class StoredObject implements AsyncFileInterface, Document return (string) $this->uuid; } - public function setCreationDate(DateTime $creationDate) + /** + * @Serializer\Groups({"write"}) + */ + public function setCreationDate(DateTime $creationDate): self { - $this->creationDate = $creationDate; + $this->createdAt = \DateTimeImmutable::createFromMutable($creationDate); return $this; } - public function setDatas(?array $datas) + public function setDatas(?array $datas): self { $this->datas = (array) $datas; return $this; } - public function setFilename(?string $filename) + public function setFilename(?string $filename): self { $this->filename = (string) $filename; return $this; } - public function setIv(?array $iv) + public function setIv(?array $iv): self { $this->iv = (array) $iv; return $this; } - public function setKeyInfos(?array $keyInfos) + public function setKeyInfos(?array $keyInfos): self { $this->keyInfos = (array) $keyInfos; return $this; } - public function setTitle(?string $title) + /** + * @param StoredObject::STATUS_* $status + */ + public function setStatus(string $status): self + { + $this->status = $status; + + return $this; + } + + public function setTitle(?string $title): self { $this->title = (string) $title; return $this; } - public function setType(?string $type) + public function setType(?string $type): self { $this->type = (string) $type; From 55918bcafb9b958e83696a9eaa4f6f17e90a9602 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 14 Feb 2023 20:57:34 +0100 Subject: [PATCH 05/14] Feature: [docgen][stored object] update model to store status, template_id and fix defaults --- .../migrations/Version20230214192558.php | 47 +++++++++++++++++++ .../Entity/StoredObject.php | 10 ++-- 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php diff --git a/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php new file mode 100644 index 000000000..de536ca84 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php @@ -0,0 +1,47 @@ +addSql('ALTER TABLE chill_doc.stored_object ADD template_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD status TEXT DEFAULT \'ready\' NOT NULL'); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); + $this->addSql('UPDATE chill_doc.stored_object SET createdAt = creation_date'); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD createdBy_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP creation_date;'); + $this->addSql('ALTER TABLE chill_doc.stored_object ALTER type SET DEFAULT \'\''); + $this->addSql('ALTER TABLE chill_doc.stored_object ALTER title DROP DEFAULT'); + $this->addSql('COMMENT ON COLUMN chill_doc.stored_object.createdAt IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD CONSTRAINT FK_49604E365DA0FB8 FOREIGN KEY (template_id) REFERENCES chill_docgen_template (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD CONSTRAINT FK_49604E363174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_49604E365DA0FB8 ON chill_doc.stored_object (template_id)'); + $this->addSql('CREATE INDEX IDX_49604E363174800F ON chill_doc.stored_object (createdBy_id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_doc.stored_object DROP CONSTRAINT FK_49604E365DA0FB8'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP CONSTRAINT FK_49604E363174800F'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP template_id'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP status'); + $this->addSql('ALTER TABLE chill_doc.stored_object ADD creation_date TIMESTAMP(0) DEFAULT NOW()'); + $this->addSql('UPDATE chill_doc.stored_object SET creation_date = createdAt'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP createdAt'); + $this->addSql('ALTER TABLE chill_doc.stored_object DROP createdBy_id'); + $this->addSql('ALTER TABLE chill_doc.stored_object ALTER title SET DEFAULT \'\''); + $this->addSql('ALTER TABLE chill_doc.stored_object ALTER type DROP DEFAULT'); + } +} diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php index 21abc1f56..ab09f870f 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php @@ -41,12 +41,6 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa use TrackCreationTrait; - /** - * @ORM\Column(type="datetime", name="creation_date") - * @Serializer\Groups({"read", "write"}) - */ - private DateTimeInterface $creationDate; - /** * @ORM\Column(type="json", name="datas") * @Serializer\Groups({"read", "write"}) @@ -87,7 +81,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa private string $title = ''; /** - * @ORM\Column(type="text", name="type") + * @ORM\Column(type="text", name="type", options={"default": ""}) * @Serializer\Groups({"read", "write"}) */ private string $type = ''; @@ -119,6 +113,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa /** * @Serializer\Groups({"read", "write"}) + * @deprecated */ public function getCreationDate(): DateTime { @@ -185,6 +180,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa /** * @Serializer\Groups({"write"}) + * @deprecated */ public function setCreationDate(DateTime $creationDate): self { From 91d21ba939e39af504888be3cced98d0b95a92bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 14 Feb 2023 23:26:00 +0100 Subject: [PATCH 06/14] Feature: [docgen][stored object] handler for request generator and required fixes --- .../Service/DocGenerator/ActivityContext.php | 10 ++ ...tActivitiesByAccompanyingPeriodContext.php | 10 ++ .../Service/DocGenerator/CalendarContext.php | 10 ++ .../DocGenerator/CalendarContextInterface.php | 4 + ...eneratorContextWithPublicFormInterface.php | 13 ++ .../DocGeneratorTemplateController.php | 130 ++++++++---------- .../Service/Generator/Generator.php | 35 ++--- .../Service/Generator/GeneratorInterface.php | 28 ++++ .../Messenger/RequestGenerationHandler.php | 50 +++++++ .../Messenger/RequestGenerationMessage.php | 27 +++- .../config/services.yaml | 16 ++- .../Phonenumber/PhonenumberHelper.php | 10 +- .../AccompanyingPeriodContext.php | 10 ++ .../AccompanyingPeriodWorkContext.php | 2 + ...ccompanyingPeriodWorkEvaluationContext.php | 10 ++ .../Service/DocGenerator/PersonContext.php | 38 +++++ .../DocGenerator/PersonContextInterface.php | 4 + .../PersonContextWithThirdParty.php | 10 ++ 18 files changed, 307 insertions(+), 110 deletions(-) create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php create mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationHandler.php diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php index 4e2970138..f7f30713b 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php @@ -206,6 +206,16 @@ class ActivityContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + /** * @param Activity $entity */ diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php index 3189307f9..3621ed80b 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php @@ -146,6 +146,16 @@ class ListActivitiesByAccompanyingPeriodContext implements return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php index 9ba9e36b4..e7be965a5 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php @@ -226,6 +226,16 @@ final class CalendarContext implements CalendarContextInterface return true; } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + /** * @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData */ diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php index d02cdc2c2..692d6991e 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php @@ -56,6 +56,10 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; + /** * @param Calendar $entity */ diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php index f013c8435..1ad3dfa51 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php @@ -23,6 +23,9 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void; + /** + * Fill the form with initial data + */ public function getFormData(DocGeneratorTemplate $template, $entity): array; /** @@ -31,4 +34,14 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext * @param mixed $entity */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; + + /** + * Transform the data from the form into serializable data, storable into messenger's message + */ + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; + + /** + * Reverse the data from the messenger's message into data usable for doc's generation + */ + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index d618f758a..ecb27c455 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -16,30 +16,28 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; -use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; +use Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface; +use Chill\DocGeneratorBundle\Service\Messenger\RequestGenerationMessage; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Serializer\Model\Collection; use Doctrine\ORM\EntityManagerInterface; -use Exception; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\FileType; -use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; // TODO à mettre dans services use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; +use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; -use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Contracts\HttpClient\HttpClientInterface; -use Throwable; use function strlen; final class DocGeneratorTemplateController extends AbstractController @@ -54,17 +52,24 @@ final class DocGeneratorTemplateController extends AbstractController private EntityManagerInterface $entityManager; + private GeneratorInterface $generator; + private LoggerInterface $logger; + private MessageBusInterface $messageBus; + private PaginatorFactory $paginatorFactory; private StoredObjectManagerInterface $storedObjectManager; + public function __construct( ContextManager $contextManager, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, DriverInterface $driver, + GeneratorInterface $generator, LoggerInterface $logger, + MessageBusInterface $messageBus, PaginatorFactory $paginatorFactory, HttpClientInterface $client, StoredObjectManagerInterface $storedObjectManager, @@ -73,7 +78,9 @@ final class DocGeneratorTemplateController extends AbstractController $this->contextManager = $contextManager; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->driver = $driver; + $this->generator = $generator; $this->logger = $logger; + $this->messageBus = $messageBus; $this->paginatorFactory = $paginatorFactory; $this->client = $client; $this->storedObjectManager = $storedObjectManager; @@ -259,99 +266,72 @@ final class DocGeneratorTemplateController extends AbstractController } } - $document = $template->getFile(); - - if ($isTest && ($contextGenerationData['test_file'] instanceof File)) { - $dataDecrypted = file_get_contents($contextGenerationData['test_file']->getPathname()); - } else { - try { - $dataDecrypted = $this->storedObjectManager->read($document); - } catch (Throwable $exception) { - throw $exception; - } - } + // transform context generation data + $contextGenerationDataSanitized = array_merge( + $contextGenerationData, + $context instanceof DocGeneratorContextWithPublicFormInterface ? + $context->publicFormTransform($template, $entity, $contextGenerationData) + : [] + ); + // if is test, render the data or generate the doc if ($isTest && isset($form) && $form['show_data']->getData()) { return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [ 'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT) ]); - } - - try { - $generatedResource = $this - ->driver - ->generateFromString( - $dataDecrypted, - $template->getFile()->getType(), - $context->getData($template, $entity, $contextGenerationData), - $template->getFile()->getFilename() - ); - } catch (TemplateException $e) { - return new Response( - implode("\n", $e->getErrors()), - 400, - [ - 'Content-Type' => 'text/plain', - ] + } elseif ($isTest) { + $generated = $this->generator->generateDocFromTemplate( + $template, + $entityClassName, + $entityId, + $contextGenerationDataSanitized, + null, + true, + isset($form) ? $form['test_file']->getData() : null ); - } - if ($isTest) { return new Response( - $generatedResource, + $generated, Response::HTTP_OK, [ 'Content-Transfer-Encoding', 'binary', 'Content-Type' => 'application/vnd.oasis.opendocument.text', 'Content-Disposition' => 'attachment; filename="generated.odt"', - 'Content-Length' => strlen($generatedResource), + 'Content-Length' => strlen($generated), ], ); } - /** @var StoredObject $storedObject */ - $storedObject = (new ObjectNormalizer()) - ->denormalize( - [ - 'type' => $template->getFile()->getType(), - 'filename' => sprintf('%s_odt', uniqid('doc_', true)), - ], - StoredObject::class - ); - - try { - $this->storedObjectManager->write($storedObject, $generatedResource); - } catch (Throwable $exception) { - throw $exception; - } + // this is not a test + // we prepare the object to store the document + $storedObject = (new StoredObject()) + ->setStatus(StoredObject::STATUS_PENDING) + ; $this->entityManager->persist($storedObject); - try { - $context - ->storeGenerated( - $template, - $storedObject, - $entity, - $contextGenerationData - ); - } catch (Exception $e) { - $this - ->logger - ->error( - 'Unable to store the associated document to entity', - [ - 'entityClassName' => $entityClassName, - 'entityId' => $entityId, - 'contextKey' => $context->getName(), - ] - ); - - throw $e; - } + // we store the generated document + $context + ->storeGenerated( + $template, + $storedObject, + $entity, + $contextGenerationData + ); $this->entityManager->flush(); + $this->messageBus->dispatch( + new RequestGenerationMessage( + $this->getUser(), + $template, + $entityId, + $entityClassName, + $storedObject, + $contextGenerationDataSanitized, + ) + ); + return $this ->redirectToRoute( 'chill_wopi_file_edit', diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php index 755e608ba..376cfc268 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php @@ -3,6 +3,7 @@ namespace Chill\DocGeneratorBundle\Service\Generator; use Chill\DocGeneratorBundle\Context\ContextManagerInterface; +use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; @@ -12,7 +13,7 @@ use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\File\File; -class Generator +class Generator implements GeneratorInterface { private ContextManagerInterface $contextManager; @@ -50,6 +51,7 @@ class Generator DocGeneratorTemplate $template, string $entityClassName, int $entityId, + array $contextGenerationData, ?StoredObject $destinationStoredObject = null, bool $isTest = false, ?File $testFile = null @@ -59,7 +61,6 @@ class Generator } $context = $this->contextManager->getContextByDocGeneratorTemplate($template); - $contextGenerationData = ['test_file' => $testFile]; $entity = $this ->entityManager @@ -70,6 +71,13 @@ class Generator throw new RelatedEntityNotFoundException($entityClassName, $entityId); } + $contextGenerationData = array_merge( + $contextGenerationData, + $context instanceof DocGeneratorContextWithPublicFormInterface ? + $context->publicFormReverseTransform($template, $entity, $contextGenerationData) + : [] + ); + if ($isTest && ($testFile instanceof File)) { $dataDecrypted = file_get_contents($testFile->getPathname()); } else { @@ -102,29 +110,6 @@ class Generator $this->storedObjectManager->write($destinationStoredObject, $generatedResource); - try { - $context - ->storeGenerated( - $template, - $destinationStoredObject, - $entity, - $contextGenerationData - ); - } catch (\Exception $e) { - $this - ->logger - ->error( - 'Unable to store the associated document to entity', - [ - 'entityClassName' => $entityClassName, - 'entityId' => $entityId, - 'contextKey' => $context->getName(), - ] - ); - - throw $e; - } - $this->entityManager->flush(); return null; diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php new file mode 100644 index 000000000..c18dc3bc2 --- /dev/null +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php @@ -0,0 +1,28 @@ +storedObjectRepository = $storedObjectRepository; + $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; + $this->generator = $generator; + } + + public function __invoke(RequestGenerationMessage $message) + { + if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) { + throw new \RuntimeException('template not found: ' . $message->getTemplateId()); + } + + if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) { + throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId()); + } + + $this->generator->generateDocFromTemplate( + $template, + $message->getEntityClassName(), + $message->getEntityId(), + $message->getContextGenerationData(), + $destinationStoredObject + ); + } + +} diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php index 1489e2686..535e569d7 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php @@ -3,6 +3,7 @@ namespace Chill\DocGeneratorBundle\Service\Messenger; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; +use Chill\DocStoreBundle\Entity\StoredObject; use Chill\MainBundle\Entity\User; class RequestGenerationMessage @@ -15,12 +16,24 @@ class RequestGenerationMessage private string $entityClassName; - public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName) - { + private int $destinationStoredObjectId; + + private array $contextGenerationData; + + public function __construct( + User $creator, + DocGeneratorTemplate $template, + int $entityId, + string $entityClassName, + StoredObject $destinationStoredObject, + array $contextGenerationData + ) { $this->creatorId = $creator->getId(); $this->templateId = $template->getId(); $this->entityId = $entityId; $this->entityClassName = $entityClassName; + $this->destinationStoredObjectId = $destinationStoredObject->getId(); + $this->contextGenerationData = $contextGenerationData; } public function getCreatorId(): int @@ -28,6 +41,11 @@ class RequestGenerationMessage return $this->creatorId; } + public function getDestinationStoredObjectId(): int + { + return $this->destinationStoredObjectId; + } + public function getTemplateId(): int { return $this->templateId; @@ -42,4 +60,9 @@ class RequestGenerationMessage { return $this->entityClassName; } + + public function getContextGenerationData(): array + { + return $this->contextGenerationData; + } } diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml index 5bdfe2a11..5fef6fb22 100644 --- a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml +++ b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml @@ -20,10 +20,14 @@ services: resource: '../Serializer/Normalizer/' tags: - { name: 'serializer.normalizer', priority: -152 } + Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer: tags: - { name: 'serializer.normalizer', priority: -126 } + Chill\DocGeneratorBundle\Service\Context\: + resource: "../Service/Context" + Chill\DocGeneratorBundle\Controller\: resource: "../Controller" autowire: true @@ -34,18 +38,20 @@ services: autowire: true autoconfigure: true - Chill\DocGeneratorBundle\Service\Context\: - resource: "../Service/Context/" - autowire: true - autoconfigure: true - Chill\DocGeneratorBundle\GeneratorDriver\: resource: "../GeneratorDriver/" autowire: true autoconfigure: true + Chill\DocGeneratorBundle\Service\Messenger\: + resource: "../Service/Messenger/" + + Chill\DocGeneratorBundle\Service\Generator\Generator: ~ + Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface: '@Chill\DocGeneratorBundle\Service\Generator\Generator' + Chill\DocGeneratorBundle\Driver\RelatorioDriver: '@Chill\DocGeneratorBundle\Driver\DriverInterface' Chill\DocGeneratorBundle\Context\ContextManager: arguments: $contexts: !tagged_iterator { tag: chill_docgen.context, default_index_method: getKey } + Chill\DocGeneratorBundle\Context\ContextManagerInterface: '@Chill\DocGeneratorBundle\Context\ContextManager' diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php index 5b52f6819..94a09cafb 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php @@ -118,7 +118,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string $phonenumber + * @param string|PhoneNumber $phonenumber */ public function isValidPhonenumberAny($phonenumber): bool { @@ -138,7 +138,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string $phonenumber + * @param string|PhoneNumber $phonenumber */ public function isValidPhonenumberLandOrVoip($phonenumber): bool { @@ -159,7 +159,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * REturn true if the phonenumber is a mobile phone. Return always true * if the validation is not configured. * - * @param string $phonenumber + * @param string|PhoneNumber $phonenumber */ public function isValidPhonenumberMobile($phonenumber): bool { @@ -182,6 +182,10 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface return null; } + if ($phonenumber instanceof PhoneNumber) { + $phonenumber = (string) $phonenumber; + } + // filter only number $filtered = preg_replace('/[^0-9]/', '', $phonenumber); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index 23bfac56f..dac850446 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -256,6 +256,16 @@ class AccompanyingPeriodContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + /** * @param AccompanyingPeriod $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index 7e9280e5d..d73d1aa7b 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -109,6 +109,8 @@ class AccompanyingPeriodWorkContext return $this->periodContext->hasPublicForm($template, $entity); } + + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { // TODO: Implement storeGenerated() method. diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 4dd14faab..3b9d958cb 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -174,6 +174,16 @@ class AccompanyingPeriodWorkEvaluationContext implements ->hasPublicForm($template, $entity->getAccompanyingPeriodWork()); } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $doc = new AccompanyingPeriodWorkEvaluationDocument(); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index af6c6e114..5f98f7798 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -21,11 +21,13 @@ use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Form\Type\ScopePickerType; +use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Person; +use Chill\PersonBundle\Repository\PersonRepository; use DateTime; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; @@ -55,6 +57,8 @@ final class PersonContext implements PersonContextInterface private NormalizerInterface $normalizer; + private ScopeRepositoryInterface $scopeRepository; + private Security $security; private bool $showScopes; @@ -71,6 +75,7 @@ final class PersonContext implements PersonContextInterface EntityManagerInterface $em, NormalizerInterface $normalizer, ParameterBagInterface $parameterBag, + ScopeRepositoryInterface $scopeRepository, Security $security, TranslatorInterface $translator, TranslatableStringHelperInterface $translatableStringHelper @@ -81,6 +86,7 @@ final class PersonContext implements PersonContextInterface $this->documentCategoryRepository = $documentCategoryRepository; $this->em = $em; $this->normalizer = $normalizer; + $this->scopeRepository = $scopeRepository; $this->security = $security; $this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes']; $this->translator = $translator; @@ -211,6 +217,38 @@ final class PersonContext implements PersonContextInterface return true; } + /** + * @param Person $entity + */ + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + $scope = $data['scope'] ?? null; + + return [ + 'title' => $data['title'] ?? '', + 'scope_id' => $scope instanceof Scope ? $scope->getId() : null, + ]; + } + + /** + * @param Person $entity + */ + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + if (!isset($data['scope'])) { + $scope = null; + } else { + if (null === $scope = $this->scopeRepository->find($data['scope'])) { + throw new \UnexpectedValueException('scope not found'); + } + } + + return [ + 'title' => $data['title'] ?? '', + 'scope' => $scope, + ]; + } + /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php index 58a6b5863..782ed13db 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php @@ -48,6 +48,10 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; + /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php index 23d57c431..b4fa6fb26 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php @@ -123,6 +123,16 @@ class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInt return true; } + public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormTransform() method. + } + + public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array + { + // TODO: Implement publicFormReverseTransform() method. + } + public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); From 55a845fcd63f2fe45f0bf84da79ee75d7207db64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 14 Feb 2023 23:34:21 +0100 Subject: [PATCH 07/14] Sanitize DocGeneratorTemplateController constructor --- .../DocGeneratorTemplateController.php | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index ecb27c455..934933286 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -42,48 +42,31 @@ use function strlen; final class DocGeneratorTemplateController extends AbstractController { - private HttpClientInterface $client; - private ContextManager $contextManager; private DocGeneratorTemplateRepository $docGeneratorTemplateRepository; - private DriverInterface $driver; - private EntityManagerInterface $entityManager; private GeneratorInterface $generator; - private LoggerInterface $logger; - private MessageBusInterface $messageBus; private PaginatorFactory $paginatorFactory; - private StoredObjectManagerInterface $storedObjectManager; - - public function __construct( ContextManager $contextManager, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, - DriverInterface $driver, GeneratorInterface $generator, - LoggerInterface $logger, MessageBusInterface $messageBus, PaginatorFactory $paginatorFactory, - HttpClientInterface $client, - StoredObjectManagerInterface $storedObjectManager, EntityManagerInterface $entityManager ) { $this->contextManager = $contextManager; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; - $this->driver = $driver; $this->generator = $generator; - $this->logger = $logger; $this->messageBus = $messageBus; $this->paginatorFactory = $paginatorFactory; - $this->client = $client; - $this->storedObjectManager = $storedObjectManager; $this->entityManager = $entityManager; } From 7c4bc8f46a9f29a0124bab32b4cf3aaa6305eebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Feb 2023 14:07:47 +0100 Subject: [PATCH 08/14] Revert commits linked to decoupling of docgen (changes not reviewed) This reverts commit 55a845fcd63f2fe45f0bf84da79ee75d7207db64. --- .../DocGeneratorTemplateController.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index 934933286..ecb27c455 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -42,31 +42,48 @@ use function strlen; final class DocGeneratorTemplateController extends AbstractController { + private HttpClientInterface $client; + private ContextManager $contextManager; private DocGeneratorTemplateRepository $docGeneratorTemplateRepository; + private DriverInterface $driver; + private EntityManagerInterface $entityManager; private GeneratorInterface $generator; + private LoggerInterface $logger; + private MessageBusInterface $messageBus; private PaginatorFactory $paginatorFactory; + private StoredObjectManagerInterface $storedObjectManager; + + public function __construct( ContextManager $contextManager, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, + DriverInterface $driver, GeneratorInterface $generator, + LoggerInterface $logger, MessageBusInterface $messageBus, PaginatorFactory $paginatorFactory, + HttpClientInterface $client, + StoredObjectManagerInterface $storedObjectManager, EntityManagerInterface $entityManager ) { $this->contextManager = $contextManager; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; + $this->driver = $driver; $this->generator = $generator; + $this->logger = $logger; $this->messageBus = $messageBus; $this->paginatorFactory = $paginatorFactory; + $this->client = $client; + $this->storedObjectManager = $storedObjectManager; $this->entityManager = $entityManager; } From 9676975cd8e5b5c4a948c3c24f4fbd52dc9c5235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Feb 2023 14:08:11 +0100 Subject: [PATCH 09/14] Revert "Feature: [docgen][stored object] handler for request generator and required fixes" This reverts commit 91d21ba939e39af504888be3cced98d0b95a92bb. --- .../Service/DocGenerator/ActivityContext.php | 10 -- ...tActivitiesByAccompanyingPeriodContext.php | 10 -- .../Service/DocGenerator/CalendarContext.php | 10 -- .../DocGenerator/CalendarContextInterface.php | 4 - ...eneratorContextWithPublicFormInterface.php | 13 -- .../DocGeneratorTemplateController.php | 132 ++++++++++-------- .../Service/Generator/Generator.php | 35 +++-- .../Service/Generator/GeneratorInterface.php | 28 ---- .../Messenger/RequestGenerationHandler.php | 50 ------- .../Messenger/RequestGenerationMessage.php | 27 +--- .../config/services.yaml | 16 +-- .../Phonenumber/PhonenumberHelper.php | 10 +- .../AccompanyingPeriodContext.php | 10 -- .../AccompanyingPeriodWorkContext.php | 2 - ...ccompanyingPeriodWorkEvaluationContext.php | 10 -- .../Service/DocGenerator/PersonContext.php | 38 ----- .../DocGenerator/PersonContextInterface.php | 4 - .../PersonContextWithThirdParty.php | 10 -- 18 files changed, 111 insertions(+), 308 deletions(-) delete mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php delete mode 100644 src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationHandler.php diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php index f7f30713b..4e2970138 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ActivityContext.php @@ -206,16 +206,6 @@ class ActivityContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param Activity $entity */ diff --git a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php index 3621ed80b..3189307f9 100644 --- a/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php +++ b/src/Bundle/ChillActivityBundle/Service/DocGenerator/ListActivitiesByAccompanyingPeriodContext.php @@ -146,16 +146,6 @@ class ListActivitiesByAccompanyingPeriodContext implements return $this->accompanyingPeriodContext->hasPublicForm($template, $entity); } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->accompanyingPeriodContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php index e7be965a5..9ba9e36b4 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContext.php @@ -226,16 +226,6 @@ final class CalendarContext implements CalendarContextInterface return true; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param array{mainPerson?: Person, thirdParty?: ThirdParty, title: string} $contextGenerationData */ diff --git a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php index 692d6991e..d02cdc2c2 100644 --- a/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php +++ b/src/Bundle/ChillCalendarBundle/Service/DocGenerator/CalendarContextInterface.php @@ -56,10 +56,6 @@ interface CalendarContextInterface extends DocGeneratorContextWithPublicFormInte */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; - /** * @param Calendar $entity */ diff --git a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php index 1ad3dfa51..f013c8435 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php +++ b/src/Bundle/ChillDocGeneratorBundle/Context/DocGeneratorContextWithPublicFormInterface.php @@ -23,9 +23,6 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext */ public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, $entity): void; - /** - * Fill the form with initial data - */ public function getFormData(DocGeneratorTemplate $template, $entity): array; /** @@ -34,14 +31,4 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext * @param mixed $entity */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - - /** - * Transform the data from the form into serializable data, storable into messenger's message - */ - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - /** - * Reverse the data from the messenger's message into data usable for doc's generation - */ - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; } diff --git a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php index ecb27c455..d618f758a 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php +++ b/src/Bundle/ChillDocGeneratorBundle/Controller/DocGeneratorTemplateController.php @@ -16,28 +16,30 @@ use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Context\Exception\ContextNotFoundException; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; +use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository; -use Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface; -use Chill\DocGeneratorBundle\Service\Messenger\RequestGenerationMessage; use Chill\DocStoreBundle\Entity\StoredObject; use Chill\DocStoreBundle\Service\StoredObjectManagerInterface; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Serializer\Model\Collection; use Doctrine\ORM\EntityManagerInterface; +use Exception; use Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\Extension\Core\Type\FileType; +use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; // TODO à mettre dans services use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; -use Symfony\Component\Messenger\MessageBusInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Serializer\Normalizer\AbstractNormalizer; +use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Contracts\HttpClient\HttpClientInterface; +use Throwable; use function strlen; final class DocGeneratorTemplateController extends AbstractController @@ -52,24 +54,17 @@ final class DocGeneratorTemplateController extends AbstractController private EntityManagerInterface $entityManager; - private GeneratorInterface $generator; - private LoggerInterface $logger; - private MessageBusInterface $messageBus; - private PaginatorFactory $paginatorFactory; private StoredObjectManagerInterface $storedObjectManager; - public function __construct( ContextManager $contextManager, DocGeneratorTemplateRepository $docGeneratorTemplateRepository, DriverInterface $driver, - GeneratorInterface $generator, LoggerInterface $logger, - MessageBusInterface $messageBus, PaginatorFactory $paginatorFactory, HttpClientInterface $client, StoredObjectManagerInterface $storedObjectManager, @@ -78,9 +73,7 @@ final class DocGeneratorTemplateController extends AbstractController $this->contextManager = $contextManager; $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; $this->driver = $driver; - $this->generator = $generator; $this->logger = $logger; - $this->messageBus = $messageBus; $this->paginatorFactory = $paginatorFactory; $this->client = $client; $this->storedObjectManager = $storedObjectManager; @@ -266,72 +259,99 @@ final class DocGeneratorTemplateController extends AbstractController } } - // transform context generation data - $contextGenerationDataSanitized = array_merge( - $contextGenerationData, - $context instanceof DocGeneratorContextWithPublicFormInterface ? - $context->publicFormTransform($template, $entity, $contextGenerationData) - : [] - ); + $document = $template->getFile(); + + if ($isTest && ($contextGenerationData['test_file'] instanceof File)) { + $dataDecrypted = file_get_contents($contextGenerationData['test_file']->getPathname()); + } else { + try { + $dataDecrypted = $this->storedObjectManager->read($document); + } catch (Throwable $exception) { + throw $exception; + } + } - // if is test, render the data or generate the doc if ($isTest && isset($form) && $form['show_data']->getData()) { return $this->render('@ChillDocGenerator/Generator/debug_value.html.twig', [ 'datas' => json_encode($context->getData($template, $entity, $contextGenerationData), JSON_PRETTY_PRINT) ]); - } elseif ($isTest) { - $generated = $this->generator->generateDocFromTemplate( - $template, - $entityClassName, - $entityId, - $contextGenerationDataSanitized, - null, - true, - isset($form) ? $form['test_file']->getData() : null - ); + } + try { + $generatedResource = $this + ->driver + ->generateFromString( + $dataDecrypted, + $template->getFile()->getType(), + $context->getData($template, $entity, $contextGenerationData), + $template->getFile()->getFilename() + ); + } catch (TemplateException $e) { return new Response( - $generated, + implode("\n", $e->getErrors()), + 400, + [ + 'Content-Type' => 'text/plain', + ] + ); + } + + if ($isTest) { + return new Response( + $generatedResource, Response::HTTP_OK, [ 'Content-Transfer-Encoding', 'binary', 'Content-Type' => 'application/vnd.oasis.opendocument.text', 'Content-Disposition' => 'attachment; filename="generated.odt"', - 'Content-Length' => strlen($generated), + 'Content-Length' => strlen($generatedResource), ], ); } - // this is not a test - // we prepare the object to store the document - $storedObject = (new StoredObject()) - ->setStatus(StoredObject::STATUS_PENDING) - ; + /** @var StoredObject $storedObject */ + $storedObject = (new ObjectNormalizer()) + ->denormalize( + [ + 'type' => $template->getFile()->getType(), + 'filename' => sprintf('%s_odt', uniqid('doc_', true)), + ], + StoredObject::class + ); + + try { + $this->storedObjectManager->write($storedObject, $generatedResource); + } catch (Throwable $exception) { + throw $exception; + } $this->entityManager->persist($storedObject); - // we store the generated document - $context - ->storeGenerated( - $template, - $storedObject, - $entity, - $contextGenerationData - ); + try { + $context + ->storeGenerated( + $template, + $storedObject, + $entity, + $contextGenerationData + ); + } catch (Exception $e) { + $this + ->logger + ->error( + 'Unable to store the associated document to entity', + [ + 'entityClassName' => $entityClassName, + 'entityId' => $entityId, + 'contextKey' => $context->getName(), + ] + ); + + throw $e; + } $this->entityManager->flush(); - $this->messageBus->dispatch( - new RequestGenerationMessage( - $this->getUser(), - $template, - $entityId, - $entityClassName, - $storedObject, - $contextGenerationDataSanitized, - ) - ); - return $this ->redirectToRoute( 'chill_wopi_file_edit', diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php index 376cfc268..755e608ba 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/Generator.php @@ -3,7 +3,6 @@ namespace Chill\DocGeneratorBundle\Service\Generator; use Chill\DocGeneratorBundle\Context\ContextManagerInterface; -use Chill\DocGeneratorBundle\Context\DocGeneratorContextWithPublicFormInterface; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; use Chill\DocGeneratorBundle\GeneratorDriver\DriverInterface; use Chill\DocGeneratorBundle\GeneratorDriver\Exception\TemplateException; @@ -13,7 +12,7 @@ use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\HttpFoundation\File\File; -class Generator implements GeneratorInterface +class Generator { private ContextManagerInterface $contextManager; @@ -51,7 +50,6 @@ class Generator implements GeneratorInterface DocGeneratorTemplate $template, string $entityClassName, int $entityId, - array $contextGenerationData, ?StoredObject $destinationStoredObject = null, bool $isTest = false, ?File $testFile = null @@ -61,6 +59,7 @@ class Generator implements GeneratorInterface } $context = $this->contextManager->getContextByDocGeneratorTemplate($template); + $contextGenerationData = ['test_file' => $testFile]; $entity = $this ->entityManager @@ -71,13 +70,6 @@ class Generator implements GeneratorInterface throw new RelatedEntityNotFoundException($entityClassName, $entityId); } - $contextGenerationData = array_merge( - $contextGenerationData, - $context instanceof DocGeneratorContextWithPublicFormInterface ? - $context->publicFormReverseTransform($template, $entity, $contextGenerationData) - : [] - ); - if ($isTest && ($testFile instanceof File)) { $dataDecrypted = file_get_contents($testFile->getPathname()); } else { @@ -110,6 +102,29 @@ class Generator implements GeneratorInterface $this->storedObjectManager->write($destinationStoredObject, $generatedResource); + try { + $context + ->storeGenerated( + $template, + $destinationStoredObject, + $entity, + $contextGenerationData + ); + } catch (\Exception $e) { + $this + ->logger + ->error( + 'Unable to store the associated document to entity', + [ + 'entityClassName' => $entityClassName, + 'entityId' => $entityId, + 'contextKey' => $context->getName(), + ] + ); + + throw $e; + } + $this->entityManager->flush(); return null; diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php b/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php deleted file mode 100644 index c18dc3bc2..000000000 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Generator/GeneratorInterface.php +++ /dev/null @@ -1,28 +0,0 @@ -storedObjectRepository = $storedObjectRepository; - $this->docGeneratorTemplateRepository = $docGeneratorTemplateRepository; - $this->generator = $generator; - } - - public function __invoke(RequestGenerationMessage $message) - { - if (null === $template = $this->docGeneratorTemplateRepository->find($message->getTemplateId())) { - throw new \RuntimeException('template not found: ' . $message->getTemplateId()); - } - - if (null === $destinationStoredObject = $this->storedObjectRepository->find($message->getDestinationStoredObjectId())) { - throw new \RuntimeException('destination stored object not found : ' . $message->getDestinationStoredObjectId()); - } - - $this->generator->generateDocFromTemplate( - $template, - $message->getEntityClassName(), - $message->getEntityId(), - $message->getContextGenerationData(), - $destinationStoredObject - ); - } - -} diff --git a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php index 535e569d7..1489e2686 100644 --- a/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php +++ b/src/Bundle/ChillDocGeneratorBundle/Service/Messenger/RequestGenerationMessage.php @@ -3,7 +3,6 @@ namespace Chill\DocGeneratorBundle\Service\Messenger; use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate; -use Chill\DocStoreBundle\Entity\StoredObject; use Chill\MainBundle\Entity\User; class RequestGenerationMessage @@ -16,24 +15,12 @@ class RequestGenerationMessage private string $entityClassName; - private int $destinationStoredObjectId; - - private array $contextGenerationData; - - public function __construct( - User $creator, - DocGeneratorTemplate $template, - int $entityId, - string $entityClassName, - StoredObject $destinationStoredObject, - array $contextGenerationData - ) { + public function __construct(User $creator, DocGeneratorTemplate $template, int $entityId, string $entityClassName) + { $this->creatorId = $creator->getId(); $this->templateId = $template->getId(); $this->entityId = $entityId; $this->entityClassName = $entityClassName; - $this->destinationStoredObjectId = $destinationStoredObject->getId(); - $this->contextGenerationData = $contextGenerationData; } public function getCreatorId(): int @@ -41,11 +28,6 @@ class RequestGenerationMessage return $this->creatorId; } - public function getDestinationStoredObjectId(): int - { - return $this->destinationStoredObjectId; - } - public function getTemplateId(): int { return $this->templateId; @@ -60,9 +42,4 @@ class RequestGenerationMessage { return $this->entityClassName; } - - public function getContextGenerationData(): array - { - return $this->contextGenerationData; - } } diff --git a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml index 5fef6fb22..5bdfe2a11 100644 --- a/src/Bundle/ChillDocGeneratorBundle/config/services.yaml +++ b/src/Bundle/ChillDocGeneratorBundle/config/services.yaml @@ -20,14 +20,10 @@ services: resource: '../Serializer/Normalizer/' tags: - { name: 'serializer.normalizer', priority: -152 } - Chill\DocGeneratorBundle\Serializer\Normalizer\CollectionDocGenNormalizer: tags: - { name: 'serializer.normalizer', priority: -126 } - Chill\DocGeneratorBundle\Service\Context\: - resource: "../Service/Context" - Chill\DocGeneratorBundle\Controller\: resource: "../Controller" autowire: true @@ -38,20 +34,18 @@ services: autowire: true autoconfigure: true + Chill\DocGeneratorBundle\Service\Context\: + resource: "../Service/Context/" + autowire: true + autoconfigure: true + Chill\DocGeneratorBundle\GeneratorDriver\: resource: "../GeneratorDriver/" autowire: true autoconfigure: true - Chill\DocGeneratorBundle\Service\Messenger\: - resource: "../Service/Messenger/" - - Chill\DocGeneratorBundle\Service\Generator\Generator: ~ - Chill\DocGeneratorBundle\Service\Generator\GeneratorInterface: '@Chill\DocGeneratorBundle\Service\Generator\Generator' - Chill\DocGeneratorBundle\Driver\RelatorioDriver: '@Chill\DocGeneratorBundle\Driver\DriverInterface' Chill\DocGeneratorBundle\Context\ContextManager: arguments: $contexts: !tagged_iterator { tag: chill_docgen.context, default_index_method: getKey } - Chill\DocGeneratorBundle\Context\ContextManagerInterface: '@Chill\DocGeneratorBundle\Context\ContextManager' diff --git a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php index 94a09cafb..5b52f6819 100644 --- a/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php +++ b/src/Bundle/ChillMainBundle/Phonenumber/PhonenumberHelper.php @@ -118,7 +118,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberAny($phonenumber): bool { @@ -138,7 +138,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * Return true if the phonenumber is a landline or voip phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberLandOrVoip($phonenumber): bool { @@ -159,7 +159,7 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface * REturn true if the phonenumber is a mobile phone. Return always true * if the validation is not configured. * - * @param string|PhoneNumber $phonenumber + * @param string $phonenumber */ public function isValidPhonenumberMobile($phonenumber): bool { @@ -182,10 +182,6 @@ final class PhonenumberHelper implements PhoneNumberHelperInterface return null; } - if ($phonenumber instanceof PhoneNumber) { - $phonenumber = (string) $phonenumber; - } - // filter only number $filtered = preg_replace('/[^0-9]/', '', $phonenumber); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php index dac850446..23bfac56f 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodContext.php @@ -256,16 +256,6 @@ class AccompanyingPeriodContext implements return $options['mainPerson'] || $options['person1'] || $options['person2']; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - /** * @param AccompanyingPeriod $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php index d73d1aa7b..7e9280e5d 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkContext.php @@ -109,8 +109,6 @@ class AccompanyingPeriodWorkContext return $this->periodContext->hasPublicForm($template, $entity); } - - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { // TODO: Implement storeGenerated() method. diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php index 3b9d958cb..4dd14faab 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/AccompanyingPeriodWorkEvaluationContext.php @@ -174,16 +174,6 @@ class AccompanyingPeriodWorkEvaluationContext implements ->hasPublicForm($template, $entity->getAccompanyingPeriodWork()); } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $doc = new AccompanyingPeriodWorkEvaluationDocument(); diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php index 5f98f7798..af6c6e114 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContext.php @@ -21,13 +21,11 @@ use Chill\DocStoreBundle\Repository\DocumentCategoryRepository; use Chill\DocStoreBundle\Security\Authorization\PersonDocumentVoter; use Chill\MainBundle\Entity\Scope; use Chill\MainBundle\Form\Type\ScopePickerType; -use Chill\MainBundle\Repository\ScopeRepositoryInterface; use Chill\MainBundle\Security\Authorization\AuthorizationHelper; use Chill\MainBundle\Security\Authorization\AuthorizationHelperInterface; use Chill\MainBundle\Security\Resolver\CenterResolverManagerInterface; use Chill\MainBundle\Templating\TranslatableStringHelperInterface; use Chill\PersonBundle\Entity\Person; -use Chill\PersonBundle\Repository\PersonRepository; use DateTime; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityRepository; @@ -57,8 +55,6 @@ final class PersonContext implements PersonContextInterface private NormalizerInterface $normalizer; - private ScopeRepositoryInterface $scopeRepository; - private Security $security; private bool $showScopes; @@ -75,7 +71,6 @@ final class PersonContext implements PersonContextInterface EntityManagerInterface $em, NormalizerInterface $normalizer, ParameterBagInterface $parameterBag, - ScopeRepositoryInterface $scopeRepository, Security $security, TranslatorInterface $translator, TranslatableStringHelperInterface $translatableStringHelper @@ -86,7 +81,6 @@ final class PersonContext implements PersonContextInterface $this->documentCategoryRepository = $documentCategoryRepository; $this->em = $em; $this->normalizer = $normalizer; - $this->scopeRepository = $scopeRepository; $this->security = $security; $this->showScopes = $parameterBag->get('chill_main')['acl']['form_show_scopes']; $this->translator = $translator; @@ -217,38 +211,6 @@ final class PersonContext implements PersonContextInterface return true; } - /** - * @param Person $entity - */ - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - $scope = $data['scope'] ?? null; - - return [ - 'title' => $data['title'] ?? '', - 'scope_id' => $scope instanceof Scope ? $scope->getId() : null, - ]; - } - - /** - * @param Person $entity - */ - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - if (!isset($data['scope'])) { - $scope = null; - } else { - if (null === $scope = $this->scopeRepository->find($data['scope'])) { - throw new \UnexpectedValueException('scope not found'); - } - } - - return [ - 'title' => $data['title'] ?? '', - 'scope' => $scope, - ]; - } - /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php index 782ed13db..58a6b5863 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextInterface.php @@ -48,10 +48,6 @@ interface PersonContextInterface extends DocGeneratorContextWithAdminFormInterfa */ public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool; - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array; - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array; - /** * @param Person $entity */ diff --git a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php index b4fa6fb26..23d57c431 100644 --- a/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php +++ b/src/Bundle/ChillPersonBundle/Service/DocGenerator/PersonContextWithThirdParty.php @@ -123,16 +123,6 @@ class PersonContextWithThirdParty implements DocGeneratorContextWithAdminFormInt return true; } - public function publicFormTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormTransform() method. - } - - public function publicFormReverseTransform(DocGeneratorTemplate $template, $entity, array $data): array - { - // TODO: Implement publicFormReverseTransform() method. - } - public function storeGenerated(DocGeneratorTemplate $template, StoredObject $storedObject, object $entity, array $contextGenerationData): void { $this->personContext->storeGenerated($template, $storedObject, $entity, $contextGenerationData); From 6254303392b7d023c4e9c87eeae882197e5e8b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Thu, 16 Feb 2023 14:08:16 +0100 Subject: [PATCH 10/14] Revert "Feature: [docgen][stored object] update model to store status, template_id and fix defaults" This reverts commit 55918bcafb9b958e83696a9eaa4f6f17e90a9602. --- .../migrations/Version20230214192558.php | 47 ------------------- .../Entity/StoredObject.php | 10 ++-- 2 files changed, 7 insertions(+), 50 deletions(-) delete mode 100644 src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php diff --git a/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php b/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php deleted file mode 100644 index de536ca84..000000000 --- a/src/Bundle/ChillDocGeneratorBundle/migrations/Version20230214192558.php +++ /dev/null @@ -1,47 +0,0 @@ -addSql('ALTER TABLE chill_doc.stored_object ADD template_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD status TEXT DEFAULT \'ready\' NOT NULL'); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD createdAt TIMESTAMP(0) WITHOUT TIME ZONE DEFAULT NULL'); - $this->addSql('UPDATE chill_doc.stored_object SET createdAt = creation_date'); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD createdBy_id INT DEFAULT NULL'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP creation_date;'); - $this->addSql('ALTER TABLE chill_doc.stored_object ALTER type SET DEFAULT \'\''); - $this->addSql('ALTER TABLE chill_doc.stored_object ALTER title DROP DEFAULT'); - $this->addSql('COMMENT ON COLUMN chill_doc.stored_object.createdAt IS \'(DC2Type:datetime_immutable)\''); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD CONSTRAINT FK_49604E365DA0FB8 FOREIGN KEY (template_id) REFERENCES chill_docgen_template (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD CONSTRAINT FK_49604E363174800F FOREIGN KEY (createdBy_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); - $this->addSql('CREATE INDEX IDX_49604E365DA0FB8 ON chill_doc.stored_object (template_id)'); - $this->addSql('CREATE INDEX IDX_49604E363174800F ON chill_doc.stored_object (createdBy_id)'); - } - - public function down(Schema $schema): void - { - $this->addSql('ALTER TABLE chill_doc.stored_object DROP CONSTRAINT FK_49604E365DA0FB8'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP CONSTRAINT FK_49604E363174800F'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP template_id'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP status'); - $this->addSql('ALTER TABLE chill_doc.stored_object ADD creation_date TIMESTAMP(0) DEFAULT NOW()'); - $this->addSql('UPDATE chill_doc.stored_object SET creation_date = createdAt'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP createdAt'); - $this->addSql('ALTER TABLE chill_doc.stored_object DROP createdBy_id'); - $this->addSql('ALTER TABLE chill_doc.stored_object ALTER title SET DEFAULT \'\''); - $this->addSql('ALTER TABLE chill_doc.stored_object ALTER type DROP DEFAULT'); - } -} diff --git a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php index ab09f870f..21abc1f56 100644 --- a/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php +++ b/src/Bundle/ChillDocStoreBundle/Entity/StoredObject.php @@ -41,6 +41,12 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa use TrackCreationTrait; + /** + * @ORM\Column(type="datetime", name="creation_date") + * @Serializer\Groups({"read", "write"}) + */ + private DateTimeInterface $creationDate; + /** * @ORM\Column(type="json", name="datas") * @Serializer\Groups({"read", "write"}) @@ -81,7 +87,7 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa private string $title = ''; /** - * @ORM\Column(type="text", name="type", options={"default": ""}) + * @ORM\Column(type="text", name="type") * @Serializer\Groups({"read", "write"}) */ private string $type = ''; @@ -113,7 +119,6 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa /** * @Serializer\Groups({"read", "write"}) - * @deprecated */ public function getCreationDate(): DateTime { @@ -180,7 +185,6 @@ class StoredObject implements AsyncFileInterface, Document, TrackCreationInterfa /** * @Serializer\Groups({"write"}) - * @deprecated */ public function setCreationDate(DateTime $creationDate): self { From 27f13e0dd175aafe7ec0708e899276f23f5c3968 Mon Sep 17 00:00:00 2001 From: Julie Lenaerts Date: Fri, 24 Feb 2023 13:54:44 +0100 Subject: [PATCH 11/14] FEATURE [menu][counters] show counter icon for person resources and residential address if there are any --- .../ChillPersonBundle/Menu/PersonMenuBuilder.php | 11 ++++++++++- .../ChillPersonBundle/Resources/views/menu.html.twig | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillPersonBundle/Menu/PersonMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/PersonMenuBuilder.php index 9185e372f..bf11a6c01 100644 --- a/src/Bundle/ChillPersonBundle/Menu/PersonMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/PersonMenuBuilder.php @@ -12,11 +12,13 @@ declare(strict_types=1); namespace Chill\PersonBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; +use Chill\PersonBundle\Repository\ResidentialAddressRepository; use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter; use Knp\Menu\MenuItem; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Security; use Symfony\Contracts\Translation\TranslatorInterface; +use function count; /** * Add menu entrie to person menu. @@ -35,16 +37,20 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface protected TranslatorInterface $translator; + private ResidentialAddressRepository $residentialAddressRepo; + private Security $security; public function __construct( ParameterBagInterface $parameterBag, Security $security, - TranslatorInterface $translator + TranslatorInterface $translator, + ResidentialAddressRepository $residentialAddressRepo ) { $this->showAccompanyingPeriod = $parameterBag->get('chill_person.accompanying_period'); $this->security = $security; $this->translator = $translator; + $this->residentialAddressRepo = $residentialAddressRepo; } public function buildMenu($menuId, MenuItem $menu, array $parameters) @@ -67,6 +73,8 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface ]) ->setExtras([ 'order' => 60, + 'counter' => count($this->residentialAddressRepo->findBy(['person' => $parameters['person']])) > 0 ? + count($this->residentialAddressRepo->findBy(['person' => $parameters['person']])) : null, ]); $menu->addChild($this->translator->trans('person_resources_menu'), [ @@ -77,6 +85,7 @@ class PersonMenuBuilder implements LocalMenuBuilderInterface ]) ->setExtras([ 'order' => 70, + 'counter' => count($parameters['person']->getResources()) > 0 ? count($parameters['person']->getResources()) : null, ]); $menu->addChild($this->translator->trans('household.person history'), [ diff --git a/src/Bundle/ChillPersonBundle/Resources/views/menu.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/menu.html.twig index 23dda065e..cf60e31b7 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/menu.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/menu.html.twig @@ -17,8 +17,12 @@