Revert "Feature: [docgen][stored object] handler for request generator and required fixes"

This reverts commit 91d21ba939.
This commit is contained in:
2023-02-16 14:08:11 +01:00
parent 7c4bc8f46a
commit 9676975cd8
18 changed files with 111 additions and 308 deletions

View File

@@ -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;

View File

@@ -1,28 +0,0 @@
<?php
namespace Chill\DocGeneratorBundle\Service\Generator;
use Chill\DocGeneratorBundle\Entity\DocGeneratorTemplate;
use Chill\DocStoreBundle\Entity\StoredObject;
use Symfony\Component\HttpFoundation\File\File;
interface GeneratorInterface
{
/**
* @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,
array $contextGenerationData,
?StoredObject $destinationStoredObject = null,
bool $isTest = false,
?File $testFile = null
): ?string;
}

View File

@@ -1,50 +0,0 @@
<?php
namespace Chill\DocGeneratorBundle\Service\Messenger;
use Chill\DocGeneratorBundle\Repository\DocGeneratorTemplateRepository;
use Chill\DocGeneratorBundle\Service\Generator\Generator;
use Chill\DocStoreBundle\Repository\StoredObjectRepository;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
/**
* Handle the request of document generation
*/
class RequestGenerationHandler implements MessageHandlerInterface
{
private StoredObjectRepository $storedObjectRepository;
private DocGeneratorTemplateRepository $docGeneratorTemplateRepository;
private Generator $generator;
public function __construct(
StoredObjectRepository $storedObjectRepository,
DocGeneratorTemplateRepository $docGeneratorTemplateRepository,
Generator $generator
) {
$this->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
);
}
}

View File

@@ -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;
}
}