From c4d37a26edf585ea83af98dbf8c9ea556df46568 Mon Sep 17 00:00:00 2001 From: Mikel Date: Thu, 11 Aug 2022 08:55:46 +0200 Subject: [PATCH] handle exceptions on LoggableMigrations --- .../Persistence/Doctrine/LoggableMigration.php | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Infrastructure/Persistence/Doctrine/LoggableMigration.php b/Infrastructure/Persistence/Doctrine/LoggableMigration.php index ae7006f..682b832 100644 --- a/Infrastructure/Persistence/Doctrine/LoggableMigration.php +++ b/Infrastructure/Persistence/Doctrine/LoggableMigration.php @@ -15,16 +15,28 @@ abstract class LoggableMigration extends AbstractMigration public function postUp(Schema $schema) { - $this->logChanges('up'); + $this->logChangesAndHandleErrors('up'); parent::postUp(...func_get_args()); } public function postDown(Schema $schema) { - $this->logChanges('down'); + $this->logChangesAndHandleErrors('down'); parent::postDown(...func_get_args()); } + private function logChangesAndHandleErrors(string $direction) + { + try { + $this->logChanges($direction); + } catch (\Exception $e) { + $this->warnIf( + true, + $e->getMessage() + ); + } + } + private function logChanges(string $direction) { $event = new CommandWasExecuted( @@ -76,7 +88,6 @@ private function logChanges(string $direction) } } - /** * @param string $entity * @param array $commandData