Skip to content
Snippets Groups Projects
Select Git revision
  • 270ed768d6d784280bbdb2e0657f67ac32ee24af
  • 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

UModal.vue

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    IndexController.php 2.91 KiB
    <?php
    
    namespace UnicaenDbAnonym\Controller;
    
    use Application\Controller\AbstractController;
    use Exception;
    use Laminas\View\Model\ViewModel;
    use RuntimeException;
    use UnicaenSql\Service\SQL\RunSQLResult;
    use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
    
    class IndexController extends AbstractController
    {
        use AnonymServiceAwareTrait;
    
        public function indexAction(): array
        {
            $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
            $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
    
            $data = [];
            if (file_exists($anonymisationScriptPath) && file_exists($restaurationScriptPath)) {
                $data['anonymisationScriptPath'] = $anonymisationScriptPath;
                $data['restaurationScriptPath'] = $restaurationScriptPath;
            } else {
                $data['anonymisationScriptPath'] = null;
                $data['restaurationScriptPath'] = null;
            }
    
            return $data;
        }
    
        public function genererAction(): array
        {
            $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
            $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
            $messages = [];
    
            try {
                $gen = $this->anonymService->genererScripts();
                foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) {
                    $messages[] = sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count);
                }
            } catch (Exception $e) {
                throw new RuntimeException("Une erreur est survenue pendant la génération des scripts SQL.", null, $e);
            }
    
            return [
                'messages' => $messages,
                'anonymisationScriptPath' => $anonymisationScriptPath,
                'restaurationScriptPath' => $restaurationScriptPath,
            ];
        }
    
        public function anonymiserAction(): ViewModel
        {
            $scriptPath = $this->anonymService->getAnonymisationScriptPath();
    
            try {
                $result = $this->anonymService->anonymiser();
            } catch (Exception $e) {
                throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
            }
    
            return $this->resultViewModel($result);
        }
    
        public function restaurerAction(): ViewModel
        {
            $scriptPath = $this->anonymService->getRestaurationScriptPath();