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

Appel des fonctions d'update du createur/modificateur lors de la création et...

Appel des fonctions d'update du createur/modificateur lors de la création et la modification des entités
parent 19620b1b
Pipeline #10842 passed with stage
in 22 seconds
...@@ -9,11 +9,13 @@ use UnicaenApp\Exception\RuntimeException; ...@@ -9,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 *******************************************************************************************/
...@@ -24,6 +26,7 @@ class ContenuService { ...@@ -24,6 +26,7 @@ class ContenuService {
public function create(Content $content) : Content public function create(Content $content) : Content
{ {
try { try {
$content->updateCreation($this->getUserService());
$this->getEntityManager()->persist($content); $this->getEntityManager()->persist($content);
$this->getEntityManager()->flush($content); $this->getEntityManager()->flush($content);
} catch (ORMException $e) { } catch (ORMException $e) {
...@@ -39,6 +42,7 @@ class ContenuService { ...@@ -39,6 +42,7 @@ class ContenuService {
public function update(Content $content) : Content public function update(Content $content) : Content
{ {
try { try {
$content->updateModification($this->getUserService());
$this->getEntityManager()->flush($content); $this->getEntityManager()->flush($content);
} 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);
......
...@@ -5,6 +5,7 @@ namespace UnicaenRenderer\Service\Contenu; ...@@ -5,6 +5,7 @@ namespace UnicaenRenderer\Service\Contenu;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use UnicaenRenderer\Service\Macro\MacroService; use UnicaenRenderer\Service\Macro\MacroService;
use UnicaenUtilisateur\Service\User\UserService;
class ContenuServiceFactory { class ContenuServiceFactory {
...@@ -24,6 +25,11 @@ class ContenuServiceFactory { ...@@ -24,6 +25,11 @@ class ContenuServiceFactory {
$service = new ContenuService(); $service = new ContenuService();
$service->setEntityManager($entityManager); $service->setEntityManager($entityManager);
$service->setMacroService($macroService); $service->setMacroService($macroService);
/** @var UserService $userService */
$userService = $container->get(UserService::class);
$service->setUserService($userService);
return $service; return $service;
} }
} }
\ No newline at end of file
...@@ -8,10 +8,12 @@ use Doctrine\ORM\QueryBuilder; ...@@ -8,10 +8,12 @@ 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 +24,7 @@ class MacroService { ...@@ -22,6 +24,7 @@ class MacroService {
public function create(Macro $macro) : Macro public function create(Macro $macro) : Macro
{ {
try { try {
$macro->updateCreation($this->getUserService());
$this->getEntityManager()->persist($macro); $this->getEntityManager()->persist($macro);
$this->getEntityManager()->flush($macro); $this->getEntityManager()->flush($macro);
} catch (ORMException $e) { } catch (ORMException $e) {
...@@ -37,6 +40,7 @@ class MacroService { ...@@ -37,6 +40,7 @@ class MacroService {
public function update(Macro $macro) : Macro public function update(Macro $macro) : Macro
{ {
try { try {
$macro->updateModification($this->getUserService());
$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);
......
...@@ -4,6 +4,7 @@ namespace UnicaenRenderer\Service\Macro; ...@@ -4,6 +4,7 @@ namespace UnicaenRenderer\Service\Macro;
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Interop\Container\ContainerInterface; use Interop\Container\ContainerInterface;
use UnicaenUtilisateur\Service\User\UserService;
class MacroServiceFactory { class MacroServiceFactory {
...@@ -20,6 +21,10 @@ class MacroServiceFactory { ...@@ -20,6 +21,10 @@ class MacroServiceFactory {
$service = new MacroService(); $service = new MacroService();
$service->setEntityManager($entityManager); $service->setEntityManager($entityManager);
/** @var UserService $userService */
$userService = $container->get(UserService::class);
$service->setUserService($userService);
return $service; return $service;
} }
} }
\ No newline at end of file
Supports Markdown
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