Skip to content

Commit

Permalink
feat(prettyblocks): installer will now use doctrine without sql with …
Browse files Browse the repository at this point in the history
…prefix
  • Loading branch information
Dreimus committed Sep 16, 2024
1 parent 3b90bbc commit 6dec589
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
33 changes: 33 additions & 0 deletions src/Doctrine/CustomTablePrefixNamingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
declare(strict_types=1);

namespace Evolutive\Library\Doctrine;

use Doctrine\ORM\Mapping\DefaultNamingStrategy;

class CustomTablePrefixNamingStrategy extends DefaultNamingStrategy
{
private string $prefix;

public function __construct(string $prefix)
{
$this->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);
}

}
2 changes: 1 addition & 1 deletion src/Doctrine/DynamicDiscriminatorMapService.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
declare(strict_types=1);

namespace PrestaSafe\PrettyBlocks\Service;
namespace PrestaSafe\PrettyBlocks\Doctrine;

use Doctrine\ORM\EntityManagerInterface;
use PrestaSafe\PrettyBlocks\Entity\Element;
Expand Down
11 changes: 7 additions & 4 deletions src/Install/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@
use Evolutive\Library\Tab\TabCollection;
use Exception;
use Module;
use PrestaSafe\PrettyBlocks\Doctrine\DynamicDiscriminatorMapService;
use PrestaSafe\PrettyBlocks\Entity\Block\TextBlock;
use PrestaSafe\PrettyBlocks\Entity\Component\TextComponent;
use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\NumberField;
use PrestaSafe\PrettyBlocks\Entity\PrimitiveField\TextField;
use PrestaSafe\PrettyBlocks\Entity\Zone;
use PrestaSafe\PrettyBlocks\Registry\ElementRegistry;
use PrestaSafe\PrettyBlocks\Service\DynamicDiscriminatorMapService;
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
use PrestaShop\PrestaShop\Core\Module\ModuleInterface;
use PrestaShopBundle\Translation\TranslatorInterface;

class Installer extends AbstractInstaller
Expand Down Expand Up @@ -86,6 +85,7 @@ public function install(Module $module): bool
$this->registerDoctrineNamespace();
$this->registerInitialElements();
$this->dynamicDiscriminatorMapService->updateDiscriminatorMap();

return $this->installSchema($module) && parent::install($module);
}

Expand All @@ -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);

Expand All @@ -115,6 +117,7 @@ protected function installSchema(Module $module): bool
$tool->createSchema($filteredMetadata);
} catch (Exception $e) {
$module->displayError($e->getMessage());

return false;
}

Expand All @@ -132,7 +135,6 @@ protected function registerDoctrineNamespace(): void
);

($config->getMetadataDriverImpl())->addDriver($annotationDriver, 'PrestaSafe\PrettyBlocks\Entity');

}

public function getClasses(EntityManager $entityManager): array
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 6dec589

Please sign in to comment.