Commit 5e7648ba authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

nouvelles commandes et améliorations

parent 99b32c14
Loading
Loading
Loading
Loading
Loading
+10 −0
Changes for config/module.config.php: 10 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -55,6 +55,16 @@ return [
    'service_manager' => [
        'factories' => [
            Bdd::class                      => BddFactory::class,
            Command\UpdateBddCommand::class => Command\UpdateBddCommandFactory::class,
            Command\UpdateDdlCommand::class => Command\UpdateDdlCommandFactory::class,
        ],
    ],


    'laminas-cli' => [
        'commands' => [
            'bddadmin:update-bdd' => Command\UpdateBddCommand::class,
            'bddadmin:update-ddl' => Command\UpdateDdlCommand::class,
        ],
    ],
];
 No newline at end of file
+80 −0
Changes for src/Command/UpdateBddCommand.php: 80 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\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');
        $io->info('Mise à jour des définitions de la base de données. Merci de patienter ...');

        $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');


        // Mise à jour de la BDD (structures)
        $bdd->alter($ref, $filters, true);


        // Mise à jour des séquences
        $bdd->majSequences($ref);


        // Mise à jour des données
        //$bdd->logBegin('Contrôle et mise à jour des données');
        //$bdd->dataUpdater()->run('update');
        //$bdd->logEnd('Données à jour');



        // Post-migration
        //$mm->migration('after');

        return Command::SUCCESS;
    }
}
 No newline at end of file
+31 −0
Changes for src/Command/UpdateBddCommandFactory.php: 31 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Unicaen\BddAdmin\Command;

use Psr\Container\ContainerInterface;
use Unicaen\BddAdmin\Bdd;


/**
 * Description of UpdateBddCommandFactory
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class UpdateBddCommandFactory
{

    /**
     * @param ContainerInterface $container
     * @param string             $requestedName
     * @param array|null         $options
     *
     * @return UpdateBddCommand
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null): UpdateBddCommand
    {
        $command = new UpdateBddCommand;
        $command->setBdd($container->get(Bdd::class));

        return $command;
    }
}
 No newline at end of file
+36 −0
Changes for src/Command/UpdateDdlCommand.php: 36 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;

/**
 * Description of UpdateDdlCommand
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class UpdateDdlCommand extends Command
{
    use BddAwareTrait;

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $io = new SymfonyStyle($input, $output);
        $bdd = $this->getBdd()->setLogger($io);

        $filters = [
        ];

        $io->title('Génération de la DDL à partir de la base de données');

        $ddl = $bdd->getDdl($filters);

        $ddl->saveToDir();

        return Command::SUCCESS;
    }
}
 No newline at end of file
+32 −0
Changes for src/Command/UpdateDdlCommandFactory.php: 32 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Unicaen\BddAdmin\Command;

use Psr\Container\ContainerInterface;
use Unicaen\BddAdmin\Bdd;


/**
 * Description of UpdateDdlCommandFactory
 *
 * @author Laurent Lécluse <laurent.lecluse at unicaen.fr>
 */
class UpdateDdlCommandFactory
{
    
    
    /**
     * @param ContainerInterface $container
     * @param string             $requestedName
     * @param array|null         $options
     *
     * @return UpdateBddCommand
     */
    public function __invoke(ContainerInterface $container, $requestedName, $options = null): UpdateDdlCommand
    {
        $command = new UpdateDdlCommand;
        $command->setBdd($container->get(Bdd::class));

        return $command;
    }
}
 No newline at end of file
Loading