Loading module/Import/src/Import/Model/Mapping/Import.Model.SynchroLog.dcm.xml 0 → 100644 +16 −0 Changes for module/Import/src/Import/Model/Mapping/Import.Model.SynchroLog.dcm.xml: 16 added lines, 0 removed lines. Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Import\Model\SynchroLog" table="SYNCHRO_LOG"> <id name="id" type="integer" column="ID"> <generator strategy="SEQUENCE"/> </id> <field name="logDate" column="LOG_DATE" type="datetime"/> <field name="startDate" column="START_DATE" type="datetime"/> <field name="finishDate" column="FINISH_DATE" type="datetime"/> <field name="status" column="STATUS"/> <field name="sql" column="SQL"/> <field name="message" column="MESSAGE"/> </entity> </doctrine-mapping> No newline at end of file module/Import/src/Import/Model/SynchroLog.php 0 → 100644 +147 −0 Changes for module/Import/src/Import/Model/SynchroLog.php: 147 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Import\Model; /** * SynchroLog */ class SynchroLog { private $id; private $logDate; private $startDate; private $finishDate; private $status; private $sql; private $message; /** * @return string */ public function getId() { return $this->id; } /** * @return \DateTime */ public function getLogDate() { return $this->logDate; } /** * @param \DateTime $logDate * @return self */ public function setLogDate(\DateTime $logDate) { $this->logDate = $logDate; return $this; } /** * @return \DateTime */ public function getStartDate() { return $this->startDate; } /** * @param \DateTime $startDate * @return self */ public function setStartDate(\DateTime $startDate) { $this->startDate = $startDate; return $this; } /** * @return \DateTime */ public function getFinishDate() { return $this->finishDate; } /** * @param \DateTime $finishDate * @return self */ public function setFinishDate(\DateTime $finishDate) { $this->finishDate = $finishDate; return $this; } /** * @return mixed */ public function getStatus() { return $this->status; } /** * @param mixed $status * @return self */ public function setStatus($status) { $this->status = $status; return $this; } /** * @return string */ public function getSql() { return $this->sql; } /** * @param string $sql * @return self */ public function setSql($sql) { $this->sql = $sql; return $this; } /** * @return string */ public function getMessage() { return $this->message; } /** * @param string $message * @return self */ public function setMessage($message) { $this->message = $message; return $this; } } module/Import/src/Import/Service/SynchroService.php +48 −2 Changes for module/Import/src/Import/Service/SynchroService.php: 48 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2,7 +2,11 @@ namespace Import\Service; use DateTime; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DBALException; use Doctrine\ORM\OptimisticLockException; use Import\Model\SynchroLog; use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; Loading Loading @@ -68,11 +72,28 @@ class SynchroService { $plsql = implode(PHP_EOL, array_merge(['BEGIN'], $calls, ['END;'])); $startDate = new DateTime(); $connection = $this->entityManager->getConnection(); $connection->beginTransaction(); try { $this->entityManager->getConnection()->executeQuery($plsql); $connection->executeQuery($plsql); $connection->commit(); $status = 'SUCCESS'; $message = null; } catch (DBALException $e) { throw new RuntimeException("Erreur rrencontrée lors de l'exécution des procédures de synchro (import)", null, $e); $status = 'FAILURE'; $message = "Erreur rencontrée lors de l'exécution des procédures de synchro (import) : " . PHP_EOL . $e->getTraceAsString(); try { $connection->rollBack(); } catch (ConnectionException $e) { $message .= PHP_EOL . "Et en plus le rollback a échoué!"; } } $finishDate = new DateTime(); $this->log($startDate, $finishDate, $plsql, $status, $message); } /** Loading Loading @@ -161,4 +182,29 @@ EOS; return sprintf($template, str_replace("'", "''", $plsql)); } /** * @param DateTime $startDate * @param DateTime $finishDate * @param string $sql * @param string $status * @param string $message */ private function log(DateTime $startDate, DateTime $finishDate, $sql, $status, $message = null) { $log = (new SynchroLog()) ->setLogDate(new DateTime()) ->setStartDate($startDate) ->setFinishDate($finishDate) ->setSql($sql) ->setStatus($status) ->setMessage($message); $this->entityManager->persist($log); try { $this->entityManager->flush($log); } catch (OptimisticLockException $e) { throw new RuntimeException("Erreur rencontrée lors de l'enregistrement du SynchroLog.", null, $e); } } } No newline at end of file Loading
module/Import/src/Import/Model/Mapping/Import.Model.SynchroLog.dcm.xml 0 → 100644 +16 −0 Changes for module/Import/src/Import/Model/Mapping/Import.Model.SynchroLog.dcm.xml: 16 added lines, 0 removed lines. Original line number Diff line number Diff line <?xml version="1.0" encoding="utf-8"?> <doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="Import\Model\SynchroLog" table="SYNCHRO_LOG"> <id name="id" type="integer" column="ID"> <generator strategy="SEQUENCE"/> </id> <field name="logDate" column="LOG_DATE" type="datetime"/> <field name="startDate" column="START_DATE" type="datetime"/> <field name="finishDate" column="FINISH_DATE" type="datetime"/> <field name="status" column="STATUS"/> <field name="sql" column="SQL"/> <field name="message" column="MESSAGE"/> </entity> </doctrine-mapping> No newline at end of file
module/Import/src/Import/Model/SynchroLog.php 0 → 100644 +147 −0 Changes for module/Import/src/Import/Model/SynchroLog.php: 147 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Import\Model; /** * SynchroLog */ class SynchroLog { private $id; private $logDate; private $startDate; private $finishDate; private $status; private $sql; private $message; /** * @return string */ public function getId() { return $this->id; } /** * @return \DateTime */ public function getLogDate() { return $this->logDate; } /** * @param \DateTime $logDate * @return self */ public function setLogDate(\DateTime $logDate) { $this->logDate = $logDate; return $this; } /** * @return \DateTime */ public function getStartDate() { return $this->startDate; } /** * @param \DateTime $startDate * @return self */ public function setStartDate(\DateTime $startDate) { $this->startDate = $startDate; return $this; } /** * @return \DateTime */ public function getFinishDate() { return $this->finishDate; } /** * @param \DateTime $finishDate * @return self */ public function setFinishDate(\DateTime $finishDate) { $this->finishDate = $finishDate; return $this; } /** * @return mixed */ public function getStatus() { return $this->status; } /** * @param mixed $status * @return self */ public function setStatus($status) { $this->status = $status; return $this; } /** * @return string */ public function getSql() { return $this->sql; } /** * @param string $sql * @return self */ public function setSql($sql) { $this->sql = $sql; return $this; } /** * @return string */ public function getMessage() { return $this->message; } /** * @param string $message * @return self */ public function setMessage($message) { $this->message = $message; return $this; } }
module/Import/src/Import/Service/SynchroService.php +48 −2 Changes for module/Import/src/Import/Service/SynchroService.php: 48 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -2,7 +2,11 @@ namespace Import\Service; use DateTime; use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DBALException; use Doctrine\ORM\OptimisticLockException; use Import\Model\SynchroLog; use UnicaenApp\Exception\LogicException; use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Service\EntityManagerAwareTrait; Loading Loading @@ -68,11 +72,28 @@ class SynchroService { $plsql = implode(PHP_EOL, array_merge(['BEGIN'], $calls, ['END;'])); $startDate = new DateTime(); $connection = $this->entityManager->getConnection(); $connection->beginTransaction(); try { $this->entityManager->getConnection()->executeQuery($plsql); $connection->executeQuery($plsql); $connection->commit(); $status = 'SUCCESS'; $message = null; } catch (DBALException $e) { throw new RuntimeException("Erreur rrencontrée lors de l'exécution des procédures de synchro (import)", null, $e); $status = 'FAILURE'; $message = "Erreur rencontrée lors de l'exécution des procédures de synchro (import) : " . PHP_EOL . $e->getTraceAsString(); try { $connection->rollBack(); } catch (ConnectionException $e) { $message .= PHP_EOL . "Et en plus le rollback a échoué!"; } } $finishDate = new DateTime(); $this->log($startDate, $finishDate, $plsql, $status, $message); } /** Loading Loading @@ -161,4 +182,29 @@ EOS; return sprintf($template, str_replace("'", "''", $plsql)); } /** * @param DateTime $startDate * @param DateTime $finishDate * @param string $sql * @param string $status * @param string $message */ private function log(DateTime $startDate, DateTime $finishDate, $sql, $status, $message = null) { $log = (new SynchroLog()) ->setLogDate(new DateTime()) ->setStartDate($startDate) ->setFinishDate($finishDate) ->setSql($sql) ->setStatus($status) ->setMessage($message); $this->entityManager->persist($log); try { $this->entityManager->flush($log); } catch (OptimisticLockException $e) { throw new RuntimeException("Erreur rencontrée lors de l'enregistrement du SynchroLog.", null, $e); } } } No newline at end of file