Loading config/module.config.php +16 −5 Changes for config/module.config.php: 16 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -20,16 +20,20 @@ return [ 'ddl' => [ 'dir' => 'data/ddl', 'columns_positions_file' => 'data/ddl_columns_pos.php', 'filters' => [], ], 'data' => [ 'sources' => [], 'actions' => [], 'actions' => [ 'install' => 'Insertion des données', 'update' => 'Contrôle et mise à jour des données', ], 'config' => [], // configuration par tables 'sources' => [], ], 'migration' => [ 'dir' => 'Application/src/Migration', 'dir' => null, ], 'id_column' => 'id', Loading @@ -55,16 +59,23 @@ return [ 'service_manager' => [ 'factories' => [ Bdd::class => BddFactory::class, Command\UpdateBddCommand::class => Command\UpdateBddCommandFactory::class, Command\UpdateDdlCommand::class => Command\UpdateDdlCommandFactory::class, Command\InstallBddCommand::class => Command\CommandFactory::class, Command\UpdateBddCommand::class => Command\CommandFactory::class, Command\UpdateDdlCommand::class => Command\CommandFactory::class, Command\UpdateDataCommand::class => Command\CommandFactory::class, Command\ClearBddCommand::class => Command\CommandFactory::class, ], ], 'laminas-cli' => [ 'commands' => [ 'bddadmin:install-bdd' => Command\InstallBddCommand::class, 'bddadmin:update-bdd' => Command\UpdateBddCommand::class, 'bddadmin:clear-bdd' => Command\ClearBddCommand::class, 'bddadmin:update-ddl' => Command\UpdateDdlCommand::class, 'bddadmin:update-data' => Command\UpdateDataCommand::class, ], ], ]; No newline at end of file src/Bdd.php +17 −12 Changes for src/Bdd.php: 17 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -599,7 +599,6 @@ class Bdd public function create(Bdd|Ddl|array $ddl, DdlFilters|array $filters = []): void { $this->logBegin('Mise en place de la base de données'); $filters = DdlFilters::normalize($filters); if ($ddl instanceof self) { $ddl = $ddl->getDdl($filters); Loading Loading @@ -632,14 +631,12 @@ class Bdd } } $this->compilerTout(); $this->logEnd("Base de données créée"); } public function alter(Bdd|Ddl|array $ddl, DdlFilters|array $filters = []): void { $this->logBegin('Application des changements sur la BDD'); $filters = DdlFilters::normalize($filters); if ($ddl instanceof self) { Loading Loading @@ -680,20 +677,18 @@ class Bdd $this->logEnd(); } } } } $this->logEnd(); $this->compilerTout(); $this->migration()->migration('after'); $this->logEnd('Changements appliqués'); $this->majSequences($ddl); } public function drop(DdlFilters|array $filters = []): void { $this->logBegin('Suppression de la base de données'); $filters = DdlFilters::normalize($filters); foreach ($this->changements as $changement => $label) { Loading Loading @@ -721,7 +716,7 @@ class Bdd } } } $this->logEnd("Base de données vide"); $this->logEnd(); } Loading Loading @@ -848,13 +843,22 @@ class Bdd public function compilerTout(): array { $this->logBegin("Compilation de tous les objets de la BDD"); $errors = []; $compileTypes = [Ddl::PACKAGE, Ddl::VIEW, Ddl::TRIGGER]; $managers = []; foreach ($compileTypes as $compileType) { $manager = $this->manager($compileType); if ($manager instanceof CompilableInterface) { $managers[] = $manager; } } $errors = []; if ($managers) { $this->logBegin("Compilation de tous les objets de la BDD"); foreach ($managers as $manager) { $list = $manager->getList(); foreach ($list as $name) { try { Loading @@ -866,9 +870,10 @@ class Bdd } } } } $this->logEnd("Fin de la compilation"); } return $errors; } Loading src/BddFactory.php +18 −1 Changes for src/BddFactory.php: 18 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Unicaen\BddAdmin; use Psr\Container\ContainerInterface; use Unicaen\BddAdmin\Data\DataManager; /** * Description of BddFactory Loading @@ -23,8 +24,24 @@ class BddFactory { $config = $container->get('config')['unicaen-bddadmin']; $bdd = new Bdd($config); $bdd = new Bdd($this->prepareConfig($config, $container)); return $bdd; } public function prepareConfig(array $config, ContainerInterface $container): array { if (isset($config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES])){ $sources = &$config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES]; foreach( $sources as $index => $source){ if ($container->has($source)){ $sources[$index] = $container->get($source); } } } return $config; } } No newline at end of file src/Command/ClearBddCommand.php 0 → 100644 +38 −0 Changes for src/Command/ClearBddCommand.php: 38 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Unicaen\BddAdmin\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Unicaen\BddAdmin\BddAwareTrait; use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of ClearBddCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class ClearBddCommand extends Command { use BddAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $io->title('Vidage complet de la base de données'); try { $bdd->drop(); $io->success('Base de données vidée complètement'); } catch (\Throwable $e) { $io->error($e->getMessage()); } return Command::SUCCESS; } } No newline at end of file src/Command/UpdateBddCommandFactory.php→src/Command/CommandFactory.php +5 −5 Changes for src/Command/CommandFactory.php: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -7,11 +7,11 @@ use Unicaen\BddAdmin\Bdd; /** * Description of UpdateBddCommandFactory * Description of CommandFactory * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class UpdateBddCommandFactory class CommandFactory { /** Loading @@ -19,11 +19,11 @@ class UpdateBddCommandFactory * @param string $requestedName * @param array|null $options * * @return UpdateBddCommand * @return InstallBddCommand */ public function __invoke(ContainerInterface $container, $requestedName, $options = null): UpdateBddCommand public function __invoke(ContainerInterface $container, $requestedName, $options = null) { $command = new UpdateBddCommand; $command = new $requestedName; $command->setBdd($container->get(Bdd::class)); return $command; Loading Loading
config/module.config.php +16 −5 Changes for config/module.config.php: 16 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -20,16 +20,20 @@ return [ 'ddl' => [ 'dir' => 'data/ddl', 'columns_positions_file' => 'data/ddl_columns_pos.php', 'filters' => [], ], 'data' => [ 'sources' => [], 'actions' => [], 'actions' => [ 'install' => 'Insertion des données', 'update' => 'Contrôle et mise à jour des données', ], 'config' => [], // configuration par tables 'sources' => [], ], 'migration' => [ 'dir' => 'Application/src/Migration', 'dir' => null, ], 'id_column' => 'id', Loading @@ -55,16 +59,23 @@ return [ 'service_manager' => [ 'factories' => [ Bdd::class => BddFactory::class, Command\UpdateBddCommand::class => Command\UpdateBddCommandFactory::class, Command\UpdateDdlCommand::class => Command\UpdateDdlCommandFactory::class, Command\InstallBddCommand::class => Command\CommandFactory::class, Command\UpdateBddCommand::class => Command\CommandFactory::class, Command\UpdateDdlCommand::class => Command\CommandFactory::class, Command\UpdateDataCommand::class => Command\CommandFactory::class, Command\ClearBddCommand::class => Command\CommandFactory::class, ], ], 'laminas-cli' => [ 'commands' => [ 'bddadmin:install-bdd' => Command\InstallBddCommand::class, 'bddadmin:update-bdd' => Command\UpdateBddCommand::class, 'bddadmin:clear-bdd' => Command\ClearBddCommand::class, 'bddadmin:update-ddl' => Command\UpdateDdlCommand::class, 'bddadmin:update-data' => Command\UpdateDataCommand::class, ], ], ]; No newline at end of file
src/Bdd.php +17 −12 Changes for src/Bdd.php: 17 added lines, 12 removed lines. Original line number Diff line number Diff line Loading @@ -599,7 +599,6 @@ class Bdd public function create(Bdd|Ddl|array $ddl, DdlFilters|array $filters = []): void { $this->logBegin('Mise en place de la base de données'); $filters = DdlFilters::normalize($filters); if ($ddl instanceof self) { $ddl = $ddl->getDdl($filters); Loading Loading @@ -632,14 +631,12 @@ class Bdd } } $this->compilerTout(); $this->logEnd("Base de données créée"); } public function alter(Bdd|Ddl|array $ddl, DdlFilters|array $filters = []): void { $this->logBegin('Application des changements sur la BDD'); $filters = DdlFilters::normalize($filters); if ($ddl instanceof self) { Loading Loading @@ -680,20 +677,18 @@ class Bdd $this->logEnd(); } } } } $this->logEnd(); $this->compilerTout(); $this->migration()->migration('after'); $this->logEnd('Changements appliqués'); $this->majSequences($ddl); } public function drop(DdlFilters|array $filters = []): void { $this->logBegin('Suppression de la base de données'); $filters = DdlFilters::normalize($filters); foreach ($this->changements as $changement => $label) { Loading Loading @@ -721,7 +716,7 @@ class Bdd } } } $this->logEnd("Base de données vide"); $this->logEnd(); } Loading Loading @@ -848,13 +843,22 @@ class Bdd public function compilerTout(): array { $this->logBegin("Compilation de tous les objets de la BDD"); $errors = []; $compileTypes = [Ddl::PACKAGE, Ddl::VIEW, Ddl::TRIGGER]; $managers = []; foreach ($compileTypes as $compileType) { $manager = $this->manager($compileType); if ($manager instanceof CompilableInterface) { $managers[] = $manager; } } $errors = []; if ($managers) { $this->logBegin("Compilation de tous les objets de la BDD"); foreach ($managers as $manager) { $list = $manager->getList(); foreach ($list as $name) { try { Loading @@ -866,9 +870,10 @@ class Bdd } } } } $this->logEnd("Fin de la compilation"); } return $errors; } Loading
src/BddFactory.php +18 −1 Changes for src/BddFactory.php: 18 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -3,6 +3,7 @@ namespace Unicaen\BddAdmin; use Psr\Container\ContainerInterface; use Unicaen\BddAdmin\Data\DataManager; /** * Description of BddFactory Loading @@ -23,8 +24,24 @@ class BddFactory { $config = $container->get('config')['unicaen-bddadmin']; $bdd = new Bdd($config); $bdd = new Bdd($this->prepareConfig($config, $container)); return $bdd; } public function prepareConfig(array $config, ContainerInterface $container): array { if (isset($config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES])){ $sources = &$config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES]; foreach( $sources as $index => $source){ if ($container->has($source)){ $sources[$index] = $container->get($source); } } } return $config; } } No newline at end of file
src/Command/ClearBddCommand.php 0 → 100644 +38 −0 Changes for src/Command/ClearBddCommand.php: 38 added lines, 0 removed lines. Original line number Diff line number Diff line <?php namespace Unicaen\BddAdmin\Command; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Unicaen\BddAdmin\BddAwareTrait; use Unicaen\BddAdmin\Data\DataManager; use Unicaen\BddAdmin\Ddl\Ddl; /** * Description of ClearBddCommand * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class ClearBddCommand extends Command { use BddAwareTrait; protected function execute(InputInterface $input, OutputInterface $output): int { $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $io->title('Vidage complet de la base de données'); try { $bdd->drop(); $io->success('Base de données vidée complètement'); } catch (\Throwable $e) { $io->error($e->getMessage()); } return Command::SUCCESS; } } No newline at end of file
src/Command/UpdateBddCommandFactory.php→src/Command/CommandFactory.php +5 −5 Changes for src/Command/CommandFactory.php: 5 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -7,11 +7,11 @@ use Unicaen\BddAdmin\Bdd; /** * Description of UpdateBddCommandFactory * Description of CommandFactory * * @author Laurent Lécluse <laurent.lecluse at unicaen.fr> */ class UpdateBddCommandFactory class CommandFactory { /** Loading @@ -19,11 +19,11 @@ class UpdateBddCommandFactory * @param string $requestedName * @param array|null $options * * @return UpdateBddCommand * @return InstallBddCommand */ public function __invoke(ContainerInterface $container, $requestedName, $options = null): UpdateBddCommand public function __invoke(ContainerInterface $container, $requestedName, $options = null) { $command = new UpdateBddCommand; $command = new $requestedName; $command->setBdd($container->get(Bdd::class)); return $command; Loading