From 5882c1ee00a0ad0088378e5b13ce647c398efe59 Mon Sep 17 00:00:00 2001 From: PululuK Date: Fri, 1 Mar 2024 20:36:50 +0100 Subject: [PATCH] Add entity schema manager DatabaseException --- src/Core/Util/Database/EntitySchemaManager.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Core/Util/Database/EntitySchemaManager.php b/src/Core/Util/Database/EntitySchemaManager.php index dc50e3c15dede..8cdeeaed0f7be 100644 --- a/src/Core/Util/Database/EntitySchemaManager.php +++ b/src/Core/Util/Database/EntitySchemaManager.php @@ -29,6 +29,8 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Tools\SchemaTool; +use Doctrine\ORM\Tools\ToolsException; +use PrestaShop\PrestaShop\Core\Exception\DatabaseException; /** * Class EntitySchemaManager help to manage an entity schema: update, create, drop. @@ -61,6 +63,8 @@ public function __construct(EntityManagerInterface $entityManager) * @param bool $dropIfExist * * @return bool + * + * @throws DatabaseException */ public function create(string $entityClassName, bool $dropIfExist = true): bool { @@ -72,8 +76,8 @@ public function create(string $entityClassName, bool $dropIfExist = true): bool try { $this->schemaTool->createSchema([$entityMetaData]); - } catch (\Exception $exception) { - return false; + } catch (ToolsException $exception) { + throw new DatabaseException($exception->getMessage()); } return true; @@ -116,6 +120,8 @@ public function drop(string $entityClassName): bool * @param bool $dropIfExist * * @return bool + * + * @throws DatabaseException */ public function createMultiple(array $entitiesClassesName, bool $dropIfExist = true): bool {