mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-05 04:49:44 +00:00
Add attachments to workflow
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Workflow\Attachment;
|
||||
|
||||
use Chill\DocStoreBundle\GenericDoc\Exception\AssociatedStoredObjectNotFound;
|
||||
use Chill\DocStoreBundle\GenericDoc\ManagerInterface;
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflowAttachment;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
class AddAttachmentAction
|
||||
{
|
||||
public function __construct(private readonly EntityManagerInterface $em, private readonly ManagerInterface $manager) {}
|
||||
|
||||
/**
|
||||
* @throws AssociatedStoredObjectNotFound
|
||||
*/
|
||||
public function __invoke(AddAttachmentRequestDTO $dto): EntityWorkflowAttachment
|
||||
{
|
||||
$genericDoc = $this->manager->buildOneGenericDoc($dto->relatedGenericDocKey, $dto->relatedGenericDocIdentifiers);
|
||||
|
||||
if (null === $genericDoc) {
|
||||
throw new \RuntimeException(sprintf('could not build any generic doc, %s key and %s identifiers', $dto->relatedGenericDocKey, json_encode($dto->relatedGenericDocIdentifiers)));
|
||||
}
|
||||
|
||||
$storedObject = $this->manager->fetchStoredObject($genericDoc);
|
||||
|
||||
$attachement = new EntityWorkflowAttachment($dto->relatedGenericDocKey, $dto->relatedGenericDocIdentifiers, $dto->entityWorkflow, $storedObject);
|
||||
|
||||
$this->em->persist($attachement);
|
||||
|
||||
return $attachement;
|
||||
}
|
||||
}
|
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\MainBundle\Workflow\Attachment;
|
||||
|
||||
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
final class AddAttachmentRequestDTO
|
||||
{
|
||||
#[Serializer\Groups('write')]
|
||||
#[Assert\NotNull()]
|
||||
public ?string $relatedGenericDocKey = null;
|
||||
#[Serializer\Groups('write')]
|
||||
#[Assert\NotNull()]
|
||||
public ?array $relatedGenericDocIdentifiers = null;
|
||||
|
||||
public function __construct(
|
||||
public readonly EntityWorkflow $entityWorkflow,
|
||||
) {}
|
||||
}
|
Reference in New Issue
Block a user