Commit 02dfcbbd authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Troc de Listener pour opération en dure ?

parent 27dfd4e2
......@@ -2,7 +2,6 @@
namespace UnicaenRenderer\Service\Contenu;
use Application\Service\GestionEntiteHistorisationTrait;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
......@@ -10,11 +9,13 @@ use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenRenderer\Entity\Db\Content;
use UnicaenRenderer\Service\Macro\MacroServiceAwareTrait;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
class ContenuService {
use EntityManagerAwareTrait;
use MacroServiceAwareTrait;
use UserServiceAwareTrait;
/** GESTION DES ENTITES *******************************************************************************************/
......
......@@ -17,14 +17,17 @@ class ContenuServiceFactory {
{
/**
* @var EntityManager $entityManager
* @var UserService $userService
* @var MacroService $macroService
*/
$entityManager = $container->get('doctrine.entitymanager.orm_default');
$macroService = $container->get(MacroService::class);
$userService = $container->get(UserService::class);
$service = new ContenuService();
$service->setEntityManager($entityManager);
$service->setMacroService($macroService);
$service->setUserService($userService);
return $service;
}
}
\ No newline at end of file
......@@ -2,17 +2,18 @@
namespace UnicaenRenderer\Service\Macro;
use Application\Service\GestionEntiteHistorisationTrait;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\ORMException;
use Doctrine\ORM\QueryBuilder;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\EntityManagerAwareTrait;
use UnicaenRenderer\Entity\Db\Macro;
use UnicaenUtilisateur\Service\User\UserServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
class MacroService {
use EntityManagerAwareTrait;
use UserServiceAwareTrait;
/** GESTION DES ENTITES *******************************************************************************************/
......@@ -22,6 +23,14 @@ class MacroService {
*/
public function create(Macro $macro) : Macro
{
$user = $this->getUserService()->getConnectedUser();
if ($user === null) $user = $this->getUserService()->getUtilisateur(0);
$date = $this->getDateTime();
$macro->setHistoCreation($date);
$macro->setHistoCreateur($user);
$macro->setHistoModification($date);
$macro->setHistoModificateur($user);
try {
$this->getEntityManager()->persist($macro);
$this->getEntityManager()->flush($macro);
......@@ -37,6 +46,12 @@ class MacroService {
*/
public function update(Macro $macro) : Macro
{
$user = $this->getUserService()->getConnectedUser();
if ($user === null) $user = $this->getUserService()->getUtilisateur(0);
$date = $this->getDateTime();
$macro->setHistoModification($date);
$macro->setHistoModificateur($user);
try {
$this->getEntityManager()->flush($macro);
} catch (ORMException $e) {
......@@ -52,7 +67,12 @@ class MacroService {
public function historise(Macro $macro) : Macro
{
try {
$macro->historiser();
$user = $this->getUserService()->getConnectedUser();
if ($user === null) $user = $this->getUserService()->getUtilisateur(0);
$date = $this->getDateTime();
$macro->setHistoDestruction($date);
$macro->setHistoDestructeur($user);
$this->getEntityManager()->flush($macro);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en BD.", $e);
......@@ -67,7 +87,9 @@ class MacroService {
public function restore(Macro $macro) : Macro
{
try {
$macro->dehistoriser();
$macro->setHistoDestruction(null);
$macro->setHistoDestructeur(null);
$this->getEntityManager()->flush($macro);
} catch (ORMException $e) {
throw new RuntimeException("Un problème est survenue lors de l'enregistrement en BD.", $e);
......
......@@ -16,11 +16,14 @@ class MacroServiceFactory {
{
/**
* @var EntityManager $entityManager
* @var UserService $userService
*/
$entityManager = $container->get('doctrine.entitymanager.orm_default');
$userService = $container->get(UserService::class);
$service = new MacroService();
$service->setEntityManager($entityManager);
$service->setUserService($userService);
return $service;
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment