Commit de62fd5a authored by Thibaut Vallee's avatar Thibaut Vallee
Browse files

Restaurer manquants

parent 240b714f
Loading
Loading
Loading
Loading
+4 −0
Changes for CHANGELOG.md: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
CHANGELOG
=========
0.2.1 (17/10/2025)
------------------
- Ajout de RestaurerProcessor

0.2.0 (17/10/2025)
------------------
- Commande console `utilisateur:create-user`
+42 −0
Changes for api/src/State/RestaurerProcessor.php: 42 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Unicaen\Utilisateur\State;

use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use Unicaen\Utilisateur\Model\HistoriqueAwareInterface;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ContainerBagInterface;

class RestaurerProcessor implements ProcessorInterface
{
    use HistoUserTrait;

    public function __construct(
        private Security $security,
        private EntityManagerInterface $em,
        private ClockInterface $clock,
        private ContainerBagInterface $param
    ) {
    }

    /**
     * @throws \Exception
     */
    public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
    {
        if(!$data instanceof HistoriqueAwareInterface){
            throw new Exception("L'entité doit implémenter HistoriqueAwareInterface pour permettre l'historisation");
        }
        $user = $this->getHistoUser();
        $data->setHistoModificateur($user);
        $data->setHistoModification($this->clock->now());
        $data->dehistoriser();
        $this->em->persist($data);
        $this->em->flush();
        return $data;
    }
}
+2 −1
Changes for documentation/Historique.md: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -92,7 +92,8 @@ parameters:

### HistoriserProcessor

L'historisation et la restauration des entités passe par un autre processor `Unicaen\Utilisateur\State\HistoriserProcessor` qui est a associer aux routes `/historiser` `/restaurer`
L'historisation et la restauration des entités passe par deux autres processor `Unicaen\Utilisateur\State\HistoriserProcessor` `Unicaen\Utilisateur\State\RestaurerProcessor`
qui sont a associer aux routes `/historiser` `/restaurer`

```php