Skip to content
Snippets Groups Projects
Select Git revision
  • c06e4686c2fb1ce1940b669ba659e64aef068de2
  • master default protected
  • release/8.0-perimetres
  • php84
  • detached3
  • 6.x
  • 7.x
  • detached2
  • detached
  • php82
  • 5.x
  • cherry-pick-bf3b5271
  • v5.x-test
  • laminas_migration
  • 7.2.9
  • 7.2.8
  • 7.2.7
  • 7.2.6
  • 7.2.5
  • 7.2.4
  • 7.2.3
  • 7.2.2
  • 7.2.1
  • 7.2.0
  • 7.1.3
  • 7.1.2
  • 7.1.1
  • 7.1.0
  • 7.0.1
  • 7.0.0
  • 6.1.11
  • 6.1.10
  • 6.1.9
  • 6.1.8
34 results

MailController.php

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    UpdateBddCommand.php 2.44 KiB
    <?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 UpdateBddCommand
     *
     * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
     */
    class UpdateBddCommand extends Command
    {
        use BddAwareTrait;
    
        protected function execute(InputInterface $input, OutputInterface $output): int
        {
            $io  = new SymfonyStyle($input, $output);
            $bdd = $this->getBdd()->setLogger($io);
    
            $io->title('Mise à jour de la base de données');
    
            $ref = $bdd->getRefDdl();
    
            // Construction de la config de DDL pour filtrer
            $filters = [];
            foreach ($ref as $ddlClass => $objects) {
                foreach ($objects as $object => $objectDdl) {
                    $filters[$ddlClass]['includes'][] = $object;
                }
            }
    
            $tablesDep = [
                Ddl::INDEX,
                Ddl::PRIMARY_CONSTRAINT,
                Ddl::REF_CONSTRAINT,
                Ddl::UNIQUE_CONSTRAINT,
            ];
    
            foreach ($tablesDep as $tableDep) {
                $objects = $bdd->manager($tableDep)->get();
                foreach ($objects as $obj) {
                    if (in_array($obj['table'], $filters['table']['includes'])) {
                        $filters[$tableDep]['includes'][] = $obj['name'];
                    }
                }
            }
    
            // Initialisation et lancement de la pré-migration
            //$mm = new MigrationManager($oa, $ref, $filters);
            //$mm->migration('before');
    
    
            try {
                $bdd->alter($ref, $filters, true);
                $io->success('Objets à jour');
            } catch (\Throwable $e) {
                $io->error($e->getMessage());
            }
    
    
            // Mise à jour des séquences
            $bdd->majSequences($ref);
    
    
            // Mise à jour des données
            if (!empty($bdd->data()->getSources())) {
                $io->title('Contrôle et mise à jour des données');
                try {
                    $bdd->data()->run(DataManager::ACTION_UPDATE);
                    $io->success('Données à jour');
                } catch (\Throwable $e) {
                    $io->error($e->getMessage());
                }
            }
    
    
            // Post-migration
            //$mm->migration('after');
    
            return Command::SUCCESS;
        }
    }