From 6dec589801a9cf05692f3bb8381e22c94b8105f7 Mon Sep 17 00:00:00 2001 From: Paul Coudeville Date: Mon, 16 Sep 2024 14:44:24 +0200 Subject: [PATCH] feat(prettyblocks): installer will now use doctrine without sql with prefix --- .../CustomTablePrefixNamingStrategy.php | 33 +++++++++++++++++++ .../DynamicDiscriminatorMapService.php | 2 +- src/Install/Installer.php | 11 ++++--- 3 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 src/Doctrine/CustomTablePrefixNamingStrategy.php diff --git a/src/Doctrine/CustomTablePrefixNamingStrategy.php b/src/Doctrine/CustomTablePrefixNamingStrategy.php new file mode 100644 index 0000000..ae43e6e --- /dev/null +++ b/src/Doctrine/CustomTablePrefixNamingStrategy.php @@ -0,0 +1,33 @@ +prefix = $prefix; + } + + /** + * Applique le préfixe à toutes les tables + */ + public function classToTableName($className): string + { + return $this->prefix . parent::classToTableName($className); + } + + /** + * Applique le préfixe aux tables des associations (join tables) + */ + public function joinTableName($sourceEntity, $targetEntity, $propertyName = null): string + { + return $this->prefix . parent::joinTableName($sourceEntity, $targetEntity, $propertyName); + } + +} diff --git a/src/Doctrine/DynamicDiscriminatorMapService.php b/src/Doctrine/DynamicDiscriminatorMapService.php index c26762c..ea69554 100644 --- a/src/Doctrine/DynamicDiscriminatorMapService.php +++ b/src/Doctrine/DynamicDiscriminatorMapService.php @@ -1,7 +1,7 @@ registerDoctrineNamespace(); $this->registerInitialElements(); $this->dynamicDiscriminatorMapService->updateDiscriminatorMap(); + return $this->installSchema($module) && parent::install($module); } @@ -100,6 +100,8 @@ public function uninstall(Module $module): bool protected function installSchema(Module $module): bool { $entityManager = $this->getEntityManager(); + $eventManager = $entityManager->getEventManager(); + $listeners = $eventManager->getListeners(); $tool = new SchemaTool($entityManager); @@ -115,6 +117,7 @@ protected function installSchema(Module $module): bool $tool->createSchema($filteredMetadata); } catch (Exception $e) { $module->displayError($e->getMessage()); + return false; } @@ -132,7 +135,6 @@ protected function registerDoctrineNamespace(): void ); ($config->getMetadataDriverImpl())->addDriver($annotationDriver, 'PrestaSafe\PrettyBlocks\Entity'); - } public function getClasses(EntityManager $entityManager): array @@ -161,12 +163,13 @@ protected function uninstallSchema(Module $module): bool $tool->dropSchema($classes); } catch (Exception $e) { $module->displayError($e->getMessage()); + return false; } + return true; } - public function updateDoctrineSchemaWithNewBlocks(): void { $entityManager = $this->getEntityManager();