Loading config/module.config.php +1 −1 Changes for config/module.config.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ return [ ], 'migration' => [ 'dir' => null, // array des classes ou services utilisés pour la migration [index => classe ou service, ...] ], 'id_column' => 'id', Loading src/Bdd.php +138 −10 Changes for src/Bdd.php: 138 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -398,7 +398,8 @@ class Bdd public function migration(): MigrationManager { if (!isset($this->migration)) { $this->migration = new MigrationManager($this); $this->migration = new MigrationManager(); $this->migration->setBdd($this); $this->migration->setOptions($this->getOption(self::OPTION_MIGRATION, [])); } Loading Loading @@ -667,7 +668,6 @@ class Bdd } } } $this->compilerTout(); } Loading @@ -685,9 +685,6 @@ class Bdd $ddl = Ddl::normalize($ddl)->filter($filters); } $this->migration()->init($ddl, $filters); $this->migration()->migration('before'); foreach ($this->changements as $changement => $label) { [$ddlName, $action] = explode('.', $changement); Loading Loading @@ -718,13 +715,11 @@ class Bdd } } $this->logEnd(); $this->compilerTout(); $this->migration()->migration('after'); } public function drop(DdlFilters|array $filters = []): void public function drop(DdlFilters|array $filters = []): self { $filters = DdlFilters::normalize($filters); Loading Loading @@ -753,7 +748,125 @@ class Bdd } } } $this->logEnd(); return $this; } public function clear(): self { $this->logTitle('Vidage complet de la base de données'); try { $this->drop(); } catch (\Throwable $e) { $this->logError($e); } $this->logSuccess('Base de données vidée complètement'); return $this; } public function install(): self { $this->logTitle('Installation de la base de données'); // Mise en place des objets try { $ddl = $this->getRefDdl(); $this->create($ddl); $this->logSuccess('Objets en place'); } catch (\Throwable $e) { $this->logError($e); } if (!empty($this->data()->getSources())) { // Installation des données $this->logTitle('Insertion du jeu de données données'); try { $this->data()->run(DataManager::ACTION_INSTALL); $this->logSuccess('Données écrites'); } catch (\Throwable $e) { $this->logError($e); } } return $this; } public function update(): self { $this->logTitle('Mise à jour de la base de données'); $ddl = $this->getRefDdl(); $filters = $this->getFiltersForUpdateBdd($ddl); // Initialisation et lancement de la pré-migration $migrationManager = $this->migration(); $migrationManager->init($ddl, $filters); $migrationManager->run(MigrationManager::ACTION_BEFORE); try { $this->alter($ddl, $filters, true); $this->logSuccess('Objets à jour'); } catch (\Throwable $e) { $this->logError($e); } // On compile tout $this->compilerTout(); // Mise à jour des séquences $this->majSequences($ddl); // Mise à jour des données $this->updateData(); // Post-migration $migrationManager->run(MigrationManager::ACTION_AFTER); return $this; } public function updateData(): self { if (!empty($this->data()->getSources())) { $this->logTitle('Contrôle et mise à jour des données'); try { $this->data()->run(DataManager::ACTION_UPDATE); $this->logSuccess('Données à jour'); } catch (\Throwable $e) { $this->logError($e); } } return $this; } public function updateDdl(): self { $this->logTitle('Génération de la DDL à partir de la base de données'); try { $filters = $bdd->getFiltersForUpdateDdl(); $ddl = $bdd->getDdl($filters); $ddl->saveToDir(); $this->logSuccess('DDL mise à jour'); } catch (\Throwable $e) { $this->logError($e); } return $this; } Loading Loading @@ -923,8 +1036,11 @@ class Bdd public function copy(Bdd $source, DdlFilters|array $filters = [], array $fncs = []): self public function copy(Bdd|string $source, DdlFilters|array $filters = [], array $fncs = []): self { if (is_string($source)) { $source = $this->getBdd($source); } if ($this->getLogger() && !$source->getLogger()) { $source->setLogger($this->getLogger()); } Loading Loading @@ -978,6 +1094,18 @@ class Bdd public function copyTo(string|Bdd $destination, DdlFilters|array $filters = [], array $fncs = []): self { if (is_string($destination)) { $destination = $this->getBdd($destination); } $destination->copy($this, $filters, $fncs); return $this; } public function save(string $filename, DdlFilters|array $filters = [], array $fncs = []): void { $this->logBegin("Sauvegarde de la base de données"); Loading src/BddFactory.php +17 −1 Changes for src/BddFactory.php: 17 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -22,6 +22,11 @@ class BddFactory */ public function __invoke(ContainerInterface $container, $requestedName, $options = null): Bdd { if (Bdd::class == $requestedName){ $configKey = 'unicaen-bddadmin'; }else{ $configKey = $requestedName; } $config = $container->get('config')['unicaen-bddadmin']; $bdd = new Bdd($this->prepareConfig($config, $container)); Loading @@ -31,8 +36,9 @@ class BddFactory public function prepareConfig(array $config, ContainerInterface $container): array protected function prepareConfig(array $config, ContainerInterface $container): array { // Chargement des sources de données depuis le ServiceManager si nécessaire if (isset($config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES])){ $sources = &$config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES]; foreach( $sources as $index => $source){ Loading @@ -42,6 +48,16 @@ class BddFactory } } // Chargement des scripts de migration depuis le ServiceManager si nécessaire if (isset($config[Bdd::OPTION_MIGRATION])){ $sources = &$config[Bdd::OPTION_MIGRATION]; 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 −7 Changes for src/Command/ClearBddCommand.php: 0 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -24,14 +24,7 @@ class ClearBddCommand extends Command $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; } Loading src/Command/InstallBddCommand.php +1 −21 Changes for src/Command/InstallBddCommand.php: 1 added line, 21 removed lines. Original line number Diff line number Diff line Loading @@ -24,27 +24,7 @@ class InstallBddCommand extends Command $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $io->title('Installation de la base de données'); // Mise en place des objets try { $ddl = $bdd->getRefDdl(); $bdd->create($ddl); $io->success('Objets en place'); } catch (\Throwable $e) { $io->error($e->getMessage()); } if (!empty($bdd->data()->getSources())) { // Installation des données $io->title('Insertion du jeu de données données'); try { $bdd->data()->run(DataManager::ACTION_INSTALL); $io->success('Données écrites'); } catch (\Throwable $e) { $io->error($e->getMessage()); } } $bdd->install(); return Command::SUCCESS; } Loading Loading
config/module.config.php +1 −1 Changes for config/module.config.php: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -35,7 +35,7 @@ return [ ], 'migration' => [ 'dir' => null, // array des classes ou services utilisés pour la migration [index => classe ou service, ...] ], 'id_column' => 'id', Loading
src/Bdd.php +138 −10 Changes for src/Bdd.php: 138 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -398,7 +398,8 @@ class Bdd public function migration(): MigrationManager { if (!isset($this->migration)) { $this->migration = new MigrationManager($this); $this->migration = new MigrationManager(); $this->migration->setBdd($this); $this->migration->setOptions($this->getOption(self::OPTION_MIGRATION, [])); } Loading Loading @@ -667,7 +668,6 @@ class Bdd } } } $this->compilerTout(); } Loading @@ -685,9 +685,6 @@ class Bdd $ddl = Ddl::normalize($ddl)->filter($filters); } $this->migration()->init($ddl, $filters); $this->migration()->migration('before'); foreach ($this->changements as $changement => $label) { [$ddlName, $action] = explode('.', $changement); Loading Loading @@ -718,13 +715,11 @@ class Bdd } } $this->logEnd(); $this->compilerTout(); $this->migration()->migration('after'); } public function drop(DdlFilters|array $filters = []): void public function drop(DdlFilters|array $filters = []): self { $filters = DdlFilters::normalize($filters); Loading Loading @@ -753,7 +748,125 @@ class Bdd } } } $this->logEnd(); return $this; } public function clear(): self { $this->logTitle('Vidage complet de la base de données'); try { $this->drop(); } catch (\Throwable $e) { $this->logError($e); } $this->logSuccess('Base de données vidée complètement'); return $this; } public function install(): self { $this->logTitle('Installation de la base de données'); // Mise en place des objets try { $ddl = $this->getRefDdl(); $this->create($ddl); $this->logSuccess('Objets en place'); } catch (\Throwable $e) { $this->logError($e); } if (!empty($this->data()->getSources())) { // Installation des données $this->logTitle('Insertion du jeu de données données'); try { $this->data()->run(DataManager::ACTION_INSTALL); $this->logSuccess('Données écrites'); } catch (\Throwable $e) { $this->logError($e); } } return $this; } public function update(): self { $this->logTitle('Mise à jour de la base de données'); $ddl = $this->getRefDdl(); $filters = $this->getFiltersForUpdateBdd($ddl); // Initialisation et lancement de la pré-migration $migrationManager = $this->migration(); $migrationManager->init($ddl, $filters); $migrationManager->run(MigrationManager::ACTION_BEFORE); try { $this->alter($ddl, $filters, true); $this->logSuccess('Objets à jour'); } catch (\Throwable $e) { $this->logError($e); } // On compile tout $this->compilerTout(); // Mise à jour des séquences $this->majSequences($ddl); // Mise à jour des données $this->updateData(); // Post-migration $migrationManager->run(MigrationManager::ACTION_AFTER); return $this; } public function updateData(): self { if (!empty($this->data()->getSources())) { $this->logTitle('Contrôle et mise à jour des données'); try { $this->data()->run(DataManager::ACTION_UPDATE); $this->logSuccess('Données à jour'); } catch (\Throwable $e) { $this->logError($e); } } return $this; } public function updateDdl(): self { $this->logTitle('Génération de la DDL à partir de la base de données'); try { $filters = $bdd->getFiltersForUpdateDdl(); $ddl = $bdd->getDdl($filters); $ddl->saveToDir(); $this->logSuccess('DDL mise à jour'); } catch (\Throwable $e) { $this->logError($e); } return $this; } Loading Loading @@ -923,8 +1036,11 @@ class Bdd public function copy(Bdd $source, DdlFilters|array $filters = [], array $fncs = []): self public function copy(Bdd|string $source, DdlFilters|array $filters = [], array $fncs = []): self { if (is_string($source)) { $source = $this->getBdd($source); } if ($this->getLogger() && !$source->getLogger()) { $source->setLogger($this->getLogger()); } Loading Loading @@ -978,6 +1094,18 @@ class Bdd public function copyTo(string|Bdd $destination, DdlFilters|array $filters = [], array $fncs = []): self { if (is_string($destination)) { $destination = $this->getBdd($destination); } $destination->copy($this, $filters, $fncs); return $this; } public function save(string $filename, DdlFilters|array $filters = [], array $fncs = []): void { $this->logBegin("Sauvegarde de la base de données"); Loading
src/BddFactory.php +17 −1 Changes for src/BddFactory.php: 17 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -22,6 +22,11 @@ class BddFactory */ public function __invoke(ContainerInterface $container, $requestedName, $options = null): Bdd { if (Bdd::class == $requestedName){ $configKey = 'unicaen-bddadmin'; }else{ $configKey = $requestedName; } $config = $container->get('config')['unicaen-bddadmin']; $bdd = new Bdd($this->prepareConfig($config, $container)); Loading @@ -31,8 +36,9 @@ class BddFactory public function prepareConfig(array $config, ContainerInterface $container): array protected function prepareConfig(array $config, ContainerInterface $container): array { // Chargement des sources de données depuis le ServiceManager si nécessaire if (isset($config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES])){ $sources = &$config[Bdd::OPTION_DATA][DataManager::OPTION_SOURCES]; foreach( $sources as $index => $source){ Loading @@ -42,6 +48,16 @@ class BddFactory } } // Chargement des scripts de migration depuis le ServiceManager si nécessaire if (isset($config[Bdd::OPTION_MIGRATION])){ $sources = &$config[Bdd::OPTION_MIGRATION]; 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 −7 Changes for src/Command/ClearBddCommand.php: 0 added lines, 7 removed lines. Original line number Diff line number Diff line Loading @@ -24,14 +24,7 @@ class ClearBddCommand extends Command $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; } Loading
src/Command/InstallBddCommand.php +1 −21 Changes for src/Command/InstallBddCommand.php: 1 added line, 21 removed lines. Original line number Diff line number Diff line Loading @@ -24,27 +24,7 @@ class InstallBddCommand extends Command $io = new SymfonyStyle($input, $output); $bdd = $this->getBdd()->setLogger($io); $io->title('Installation de la base de données'); // Mise en place des objets try { $ddl = $bdd->getRefDdl(); $bdd->create($ddl); $io->success('Objets en place'); } catch (\Throwable $e) { $io->error($e->getMessage()); } if (!empty($bdd->data()->getSources())) { // Installation des données $io->title('Insertion du jeu de données données'); try { $bdd->data()->run(DataManager::ACTION_INSTALL); $io->success('Données écrites'); } catch (\Throwable $e) { $io->error($e->getMessage()); } } $bdd->install(); return Command::SUCCESS; } Loading