Skip to content
Snippets Groups Projects
Commit 02dfcbbd authored by Jean-Philippe Metivier's avatar Jean-Philippe Metivier
Browse files

Troc de Listener pour opération en dure ?

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