Skip to content
Snippets Groups Projects
Select Git revision
  • 50b3c817b1ecdd7b7bc6d0efed87c132485dbf79
  • master default protected
  • detached4
  • detached3
  • detached2
  • bsv-next
  • detached
  • php82
  • 6.x
  • 6.4.0
  • 6.3.3
  • 6.3.2
  • 6.3.1
  • 6.3.0
  • 6.2.7
  • 6.2.6
  • 6.2.5
  • 6.2.4
  • 6.2.3
  • 6.2.2
  • 6.2.1
  • 6.2.0
  • 6.1.3
  • 6.1.2
  • 6.1.1
  • 6.1.0
  • 6.0.0
27 results

UTableAjax.vue

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ConsoleController.php 2.98 KiB
    <?php
    
    namespace UnicaenDbAnonym\Controller;
    
    use Exception;
    use RuntimeException;
    use Unicaen\Console\Controller\AbstractConsoleController;
    use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
    
    class ConsoleController extends AbstractConsoleController
    {
        use AnonymServiceAwareTrait;
    
        public function genererAction(): void
        {
            $start = microtime(true);
    
            $this->console->writeLine("Generation des scripts SQL...");
    
            $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
            $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
            try {
                $gen = $this->anonymService->genererScripts();
                foreach ($gen as ['entity' => $entity, 'fields' => $fields, 'count' => $count]) {
                    $this->console->writeLine(
                        sprintf("- Entite %s (%s) : %d lignes traitees", $entity, implode(', ', $fields), $count)
                    );
                }
            } catch (Exception $e) {
                throw new RuntimeException("Une erreur est survenue pendant la génération des scripts SQL.", null, $e);
            }
    
            $end = microtime(true);
    
            $this->console->writeLine(sprintf("> Script d'anonymisation cree : %s", realpath($anonymisationScriptPath)));
            $this->console->writeLine(sprintf("> Script de restauration cree : %s", realpath($restaurationScriptPath)));
            $this->console->writeLine(sprintf("Duree : %.2f s", $end - $start));
        }
    
        public function anonymiserAction(): void
        {
            $scriptPath = $this->anonymService->getAnonymisationScriptPath();
    
            $this->console->writeLine("Lancement du script d'anonymisation '$scriptPath'...");
    
            $start = microtime(true);
            try {
                $result = $this->anonymService->anonymiser();
            } catch (Exception $e) {
                throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
            }
            $end = microtime(true);
    
            $this->console->writeLine("> Résultat : " . ($result->isSuccess() ? 'Succès' : 'Échec'));
            $this->console->writeLine("> Log file : " . $result->getLogFilePath());
            $this->console->writeLine(sprintf("Duree : %.2f s", $end - $start));
        }
    
        public function restaurerAction(): void
        {
            $scriptPath = $this->anonymService->getRestaurationScriptPath();
    
            $this->console->writeLine("Lancement du script de restauration '$scriptPath'...");
    
            $start = microtime(true);
            try {
                $result = $this->anonymService->restaurer();
            } catch (Exception $e) {
                throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
            }
            $end = microtime(true);
    
            $this->console->writeLine("> Résultat : " . ($result->isSuccess() ? 'Succès' : 'Échec'));
            $this->console->writeLine("> Log file : " . $result->getLogFilePath());
            $this->console->writeLine(sprintf("Duree : %.2f s", $end - $start));
        }
    }