Skip to content
Snippets Groups Projects
Commit 26481e5c authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Renommage du module en unicaen/db-anonym

parent 5c1c3d57
No related branches found
No related tags found
No related merge requests found
Pipeline #12349 passed
Showing
with 99 additions and 99 deletions
<?php <?php
namespace UnicaenDbfakator; namespace UnicaenDbAnonym;
use Laminas\Config\Factory as ConfigFactory; use Laminas\Config\Factory as ConfigFactory;
use Laminas\Console\Adapter\AdapterInterface; use Laminas\Console\Adapter\AdapterInterface;
...@@ -45,7 +45,7 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte ...@@ -45,7 +45,7 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte
*/ */
public function getConsoleBanner(AdapterInterface $console): ?string public function getConsoleBanner(AdapterInterface $console): ?string
{ {
return "UnicaenDbfakator"; return "UnicaenDbAnonym";
} }
/** /**
...@@ -57,18 +57,18 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte ...@@ -57,18 +57,18 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte
/** /**
* @see ConsoleController::genererAction() * @see ConsoleController::genererAction()
*/ */
'unicaen-dbfakator generer' => "Génère le script d'anonymisation et le script de restauration.", 'unicaen-db-anonym generer' => "Génère le script d'anonymisation et le script de restauration.",
/** /**
* @see ConsoleController::anonymiserAction() * @see ConsoleController::anonymiserAction()
*/ */
'unicaen-dbfakator anonymiser' => "Lance le script SQL d'anonymisation généré précédemment.", 'unicaen-db-anonym anonymiser' => "Lance le script SQL d'anonymisation généré précédemment.",
[], [],
/** /**
* @see ConsoleController::restaurerAction() * @see ConsoleController::restaurerAction()
*/ */
'unicaen-dbfakator restaurer' => "Lance le script SQL de restauration généré précédemment.", 'unicaen-db-anonym restaurer' => "Lance le script SQL de restauration généré précédemment.",
[], [],
]; ];
} }
......
# unicaen/dbfakator # unicaen/db-anonym
Ce module permet d'anonymiser et de restaurer la base de données d'une appli, selon ce qui est spécifié Ce module permet d'anonymiser et de restaurer la base de données d'une appli, selon ce qui est spécifié
dans un fichier de configuration. dans un fichier de configuration.
......
{ {
"name": "unicaen/dbfakator", "name": "unicaen/db-anonym",
"description": "Module pour anonymiser une base de données", "description": "Module pour anonymiser les données d'une bdd",
"require": { "require": {
"php": ">=7.3", "php": ">=7.3",
"unicaen/app": "^4.0", "unicaen/app": "^4.0",
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
}, },
"autoload": { "autoload": {
"psr-0": { "psr-0": {
"UnicaenDbfakator": "src/" "UnicaenDbAnonym": "src/"
}, },
"classmap": [ "classmap": [
"./Module.php" "./Module.php"
......
<?php <?php
namespace UnicaenDbfakator; namespace UnicaenDbAnonym;
use Laminas\Mvc\Console\Router\Simple; use Laminas\Mvc\Console\Router\Simple;
use UnicaenAuth\Guard\PrivilegeController; use UnicaenAuth\Guard\PrivilegeController;
use UnicaenDbfakator\Controller\ConsoleController; use UnicaenDbAnonym\Controller\ConsoleController;
use UnicaenDbfakator\Controller\ConsoleControllerFactory; use UnicaenDbAnonym\Controller\ConsoleControllerFactory;
use UnicaenDbfakator\Controller\IndexController; use UnicaenDbAnonym\Controller\IndexController;
use UnicaenDbfakator\Controller\IndexControllerFactory; use UnicaenDbAnonym\Controller\IndexControllerFactory;
use UnicaenDbfakator\Service\DbfakatorService; use UnicaenDbAnonym\Service\AnonymService;
use UnicaenDbfakator\Service\DbfakatorServiceFactory; use UnicaenDbAnonym\Service\AnonymServiceFactory;
use UnicaenDbfakator\Service\DbService; use UnicaenDbAnonym\Service\DbService;
use UnicaenDbfakator\Service\DbServiceFactory; use UnicaenDbAnonym\Service\DbServiceFactory;
return [ return [
'router' => [ 'router' => [
'routes' => [ 'routes' => [
'unicaen-dbfakator' => [ 'unicaen-db-anonym' => [
'type' => 'Literal', 'type' => 'Literal',
'options' => [ 'options' => [
'route' => '/unicaen-dbfakator', 'route' => '/unicaen-db-anonym',
'defaults' => [ 'defaults' => [
'controller' => IndexController::class, 'controller' => IndexController::class,
'action' => 'index', 'action' => 'index',
...@@ -76,7 +76,7 @@ return [ ...@@ -76,7 +76,7 @@ return [
'generer' => [ 'generer' => [
'type' => Simple::class, 'type' => Simple::class,
'options' => [ 'options' => [
'route' => 'unicaen-dbfakator generer', 'route' => 'unicaen-db-anonym generer',
'defaults' => [ 'defaults' => [
/** /**
* @see ConsoleController::genererAction() * @see ConsoleController::genererAction()
...@@ -89,7 +89,7 @@ return [ ...@@ -89,7 +89,7 @@ return [
'anonymiser' => [ 'anonymiser' => [
'type' => Simple::class, 'type' => Simple::class,
'options' => [ 'options' => [
'route' => 'unicaen-dbfakator anonymiser', 'route' => 'unicaen-db-anonym anonymiser',
'defaults' => [ 'defaults' => [
/** /**
* @see ConsoleController::anonymiserAction() * @see ConsoleController::anonymiserAction()
...@@ -102,7 +102,7 @@ return [ ...@@ -102,7 +102,7 @@ return [
'restaurer' => [ 'restaurer' => [
'type' => Simple::class, 'type' => Simple::class,
'options' => [ 'options' => [
'route' => 'unicaen-dbfakator restaurer', 'route' => 'unicaen-db-anonym restaurer',
'defaults' => [ 'defaults' => [
/** /**
* @see ConsoleController::restaurerAction() * @see ConsoleController::restaurerAction()
...@@ -153,7 +153,7 @@ return [ ...@@ -153,7 +153,7 @@ return [
'service_manager' => [ 'service_manager' => [
'factories' => [ 'factories' => [
DbService::class => DbServiceFactory::class, DbService::class => DbServiceFactory::class,
DbfakatorService::class => DbfakatorServiceFactory::class, AnonymService::class => AnonymServiceFactory::class,
], ],
], ],
'controllers' => [ 'controllers' => [
......
<?php <?php
namespace UnicaenDbfakator\Controller; namespace UnicaenDbAnonym\Controller;
use Exception; use Exception;
use Laminas\Mvc\Console\Controller\AbstractConsoleController; use Laminas\Mvc\Console\Controller\AbstractConsoleController;
use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Exception\RuntimeException;
use UnicaenDbfakator\Service\DbfakatorServiceAwareTrait; use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
class ConsoleController extends AbstractConsoleController class ConsoleController extends AbstractConsoleController
{ {
use DbfakatorServiceAwareTrait; use AnonymServiceAwareTrait;
/** /**
* @var string * @var string
...@@ -22,10 +22,10 @@ class ConsoleController extends AbstractConsoleController ...@@ -22,10 +22,10 @@ class ConsoleController extends AbstractConsoleController
$this->console->writeLine("Generation des scripts SQL..."); $this->console->writeLine("Generation des scripts SQL...");
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath(); $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath(); $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
try { try {
$gen = $this->dbfakatorService->generer(); $gen = $this->anonymService->generer();
foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) { foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) {
$this->console->writeLine( $this->console->writeLine(
sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count) sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count)
...@@ -44,13 +44,13 @@ class ConsoleController extends AbstractConsoleController ...@@ -44,13 +44,13 @@ class ConsoleController extends AbstractConsoleController
public function anonymiserAction() public function anonymiserAction()
{ {
$scriptPath = $this->dbfakatorService->getAnonymisationScriptPath(); $scriptPath = $this->anonymService->getAnonymisationScriptPath();
$this->console->writeLine("Lancement du script d'anonymisation '$scriptPath'..."); $this->console->writeLine("Lancement du script d'anonymisation '$scriptPath'...");
$start = microtime(true); $start = microtime(true);
try { try {
$result = $this->dbfakatorService->anonymiser(); $result = $this->anonymService->anonymiser();
} catch (Exception $e) { } catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e); throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
} }
...@@ -63,13 +63,13 @@ class ConsoleController extends AbstractConsoleController ...@@ -63,13 +63,13 @@ class ConsoleController extends AbstractConsoleController
public function restaurerAction() public function restaurerAction()
{ {
$scriptPath = $this->dbfakatorService->getRestaurationScriptPath(); $scriptPath = $this->anonymService->getRestaurationScriptPath();
$this->console->writeLine("Lancement du script de restauration '$scriptPath'..."); $this->console->writeLine("Lancement du script de restauration '$scriptPath'...");
$start = microtime(true); $start = microtime(true);
try { try {
$result = $this->dbfakatorService->restaurer(); $result = $this->anonymService->restaurer();
} catch (Exception $e) { } catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e); throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
} }
......
<?php <?php
namespace UnicaenDbfakator\Controller; namespace UnicaenDbAnonym\Controller;
use UnicaenDbfakator\Service\DbfakatorService; use UnicaenDbAnonym\Service\AnonymService;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
class ConsoleControllerFactory class ConsoleControllerFactory
{ {
/** /**
* @param \Psr\Container\ContainerInterface $container * @param \Psr\Container\ContainerInterface $container
* @return \UnicaenDbfakator\Controller\ConsoleController * @return \UnicaenDbAnonym\Controller\ConsoleController
* @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface
*/ */
public function __invoke(ContainerInterface $container): ConsoleController public function __invoke(ContainerInterface $container): ConsoleController
{ {
/** @var \UnicaenDbfakator\Service\DbfakatorService $service */ /** @var \UnicaenDbAnonym\Service\AnonymService $service */
$dbFakeService = $container->get(DbfakatorService::class); $dbFakeService = $container->get(AnonymService::class);
$controller = new ConsoleController(); $controller = new ConsoleController();
$controller->setDbfakatorService($dbFakeService); $controller->setAnonymService($dbFakeService);
return $controller; return $controller;
} }
......
<?php <?php
namespace UnicaenDbfakator\Controller; namespace UnicaenDbAnonym\Controller;
use Application\Controller\AbstractController; use Application\Controller\AbstractController;
use Exception; use Exception;
use Laminas\View\Model\ViewModel; use Laminas\View\Model\ViewModel;
use UnicaenApp\Exception\RuntimeException; use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\SQL\RunSQLResult; use UnicaenApp\Service\SQL\RunSQLResult;
use UnicaenDbfakator\Service\DbfakatorServiceAwareTrait; use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
class IndexController extends AbstractController class IndexController extends AbstractController
{ {
use DbfakatorServiceAwareTrait; use AnonymServiceAwareTrait;
public function indexAction(): array public function indexAction(): array
{ {
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath(); $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath(); $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
$data = []; $data = [];
if (file_exists($anonymisationScriptPath) && file_exists($restaurationScriptPath)) { if (file_exists($anonymisationScriptPath) && file_exists($restaurationScriptPath)) {
...@@ -32,12 +32,12 @@ class IndexController extends AbstractController ...@@ -32,12 +32,12 @@ class IndexController extends AbstractController
public function genererAction(): array public function genererAction(): array
{ {
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath(); $anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath(); $restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
$messages = []; $messages = [];
try { try {
$gen = $this->dbfakatorService->generer(); $gen = $this->anonymService->generer();
foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) { foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) {
$messages[] = sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count); $messages[] = sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count);
} }
...@@ -54,10 +54,10 @@ class IndexController extends AbstractController ...@@ -54,10 +54,10 @@ class IndexController extends AbstractController
public function anonymiserAction(): ViewModel public function anonymiserAction(): ViewModel
{ {
$scriptPath = $this->dbfakatorService->getAnonymisationScriptPath(); $scriptPath = $this->anonymService->getAnonymisationScriptPath();
try { try {
$result = $this->dbfakatorService->anonymiser(); $result = $this->anonymService->anonymiser();
} catch (Exception $e) { } catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e); throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
} }
...@@ -67,10 +67,10 @@ class IndexController extends AbstractController ...@@ -67,10 +67,10 @@ class IndexController extends AbstractController
public function restaurerAction(): ViewModel public function restaurerAction(): ViewModel
{ {
$scriptPath = $this->dbfakatorService->getRestaurationScriptPath(); $scriptPath = $this->anonymService->getRestaurationScriptPath();
try { try {
$result = $this->dbfakatorService->restaurer(); $result = $this->anonymService->restaurer();
} catch (Exception $e) { } catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e); throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
} }
...@@ -83,7 +83,7 @@ class IndexController extends AbstractController ...@@ -83,7 +83,7 @@ class IndexController extends AbstractController
$vm = new ViewModel([ $vm = new ViewModel([
'result' => $result, 'result' => $result,
]); ]);
$vm ->setTemplate('unicaen-dbfakator/index/result'); $vm ->setTemplate('unicaen-db-anonym/index/result');
return $vm; return $vm;
} }
......
<?php <?php
namespace UnicaenDbfakator\Controller; namespace UnicaenDbAnonym\Controller;
use UnicaenDbfakator\Service\DbfakatorService; use UnicaenDbAnonym\Service\AnonymService;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
class IndexControllerFactory class IndexControllerFactory
...@@ -15,11 +15,11 @@ class IndexControllerFactory ...@@ -15,11 +15,11 @@ class IndexControllerFactory
*/ */
public function __invoke(ContainerInterface $container): IndexController public function __invoke(ContainerInterface $container): IndexController
{ {
/** @var \UnicaenDbfakator\Service\DbfakatorService $service */ /** @var \UnicaenDbAnonym\Service\AnonymService $service */
$service = $container->get(DbfakatorService::class); $service = $container->get(AnonymService::class);
$controller = new IndexController(); $controller = new IndexController();
$controller->setDbfakatorService($service); $controller->setAnonymService($service);
return $controller; return $controller;
} }
......
<?php <?php
namespace UnicaenDbfakator\Service; namespace UnicaenDbAnonym\Service;
use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception;
......
<?php <?php
namespace UnicaenDbfakator\Service; namespace UnicaenDbAnonym\Service;
trait DbServiceAwareTrait trait DbServiceAwareTrait
{ {
......
<?php <?php
namespace UnicaenDbfakator\Service; namespace UnicaenDbAnonym\Service;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
......
<?php <?php
namespace UnicaenDbfakator\Service; namespace UnicaenDbAnonym\Service;
use Generator; use Generator;
use UnicaenApp\Service\SQL\RunSQLResult; use UnicaenApp\Service\SQL\RunSQLResult;
...@@ -10,7 +10,7 @@ use Webmozart\Assert\InvalidArgumentException; ...@@ -10,7 +10,7 @@ use Webmozart\Assert\InvalidArgumentException;
/** /**
* @property \Psr\Log\LoggerInterface $logger * @property \Psr\Log\LoggerInterface $logger
*/ */
class DbfakatorService class AnonymService
{ {
use DbServiceAwareTrait; use DbServiceAwareTrait;
......
<?php
namespace UnicaenDbAnonym\Service;
trait AnonymServiceAwareTrait
{
/**
* @var AnonymService
*/
protected $anonymService;
/**
* @param AnonymService $anonymService
* @return self
*/
public function setAnonymService(AnonymService $anonymService): self
{
$this->anonymService = $anonymService;
return $this;
}
}
\ No newline at end of file
<?php <?php
namespace UnicaenDbfakator\Service; namespace UnicaenDbAnonym\Service;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Webmozart\Assert\Assert; use Webmozart\Assert\Assert;
class DbfakatorServiceFactory class AnonymServiceFactory
{ {
/** /**
* @param \Psr\Container\ContainerInterface $container * @param \Psr\Container\ContainerInterface $container
* @return \UnicaenDbfakator\Service\DbfakatorService * @return \UnicaenDbAnonym\Service\AnonymService
* @throws \Psr\Container\ContainerExceptionInterface * @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface * @throws \Psr\Container\NotFoundExceptionInterface
*/ */
public function __invoke(ContainerInterface $container): DbfakatorService public function __invoke(ContainerInterface $container): AnonymService
{ {
/** @var DbService $dbService */ /** @var DbService $dbService */
$dbService = $container->get(DbService::class); $dbService = $container->get(DbService::class);
$config = $this->getConfig($container); $config = $this->getConfig($container);
$service = new DbfakatorService(); $service = new AnonymService();
$service->setConfig($config); $service->setConfig($config);
$service->setDbService($dbService); $service->setDbService($dbService);
...@@ -36,7 +36,7 @@ class DbfakatorServiceFactory ...@@ -36,7 +36,7 @@ class DbfakatorServiceFactory
/** @var array $appConfig */ /** @var array $appConfig */
$appConfig = $container->get('Config'); $appConfig = $container->get('Config');
$config = $appConfig['unicaen-dbfakator'] ?? []; $config = $appConfig['unicaen-db-anonym'] ?? [];
if (!$config) { if (!$config) {
return []; return [];
} }
......
<?php
namespace UnicaenDbfakator\Service;
trait DbfakatorServiceAwareTrait
{
/**
* @var DbfakatorService
*/
protected $dbfakatorService;
/**
* @param DbfakatorService $dbfakatorService
* @return self
*/
public function setDbfakatorService(DbfakatorService $dbfakatorService): self
{
$this->dbfakatorService = $dbfakatorService;
return $this;
}
}
\ No newline at end of file
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
*/ */
$this->headTitle("Génération"); $this->headTitle("Génération");
$this->headTitle("UnicaenDbfakator"); $this->headTitle("UnicaenDbAnonym");
?> ?>
<h1>Résultat de la génération des scripts SQL</h1> <h1>Résultat de la génération des scripts SQL</h1>
......
...@@ -5,14 +5,14 @@ ...@@ -5,14 +5,14 @@
*/ */
$this->headTitle("Accueil"); $this->headTitle("Accueil");
$this->headTitle("UnicaenDbfakator"); $this->headTitle("UnicaenDbAnonym");
?> ?>
<h1>Module unicaen/dbfakator</h1> <h1>Module unicaen/db-anonym</h1>
<h2>Génération des scripts SQL</h2> <h2>Génération des scripts SQL</h2>
<p> <p>
<a href="<?php echo $this->url('unicaen-dbfakator/generer') ?>" class="btn bg-gradient bg-secondary">Lancer la génération</a> <a href="<?php echo $this->url('unicaen-db-anonym/generer') ?>" class="btn bg-gradient bg-secondary">Lancer la génération</a>
</p> </p>
...@@ -24,12 +24,12 @@ $this->headTitle("UnicaenDbfakator"); ...@@ -24,12 +24,12 @@ $this->headTitle("UnicaenDbfakator");
<dt>Anonymisation</dt> <dt>Anonymisation</dt>
<dd> <dd>
<?php echo $anonymisationScriptPath ?><br> <?php echo $anonymisationScriptPath ?><br>
<a href="<?php echo $this->url('unicaen-dbfakator/anonymiser') ?>" class="btn btn-sm bg-gradient bg-primary">Lancer le script d'anonymisation</a> <a href="<?php echo $this->url('unicaen-db-anonym/anonymiser') ?>" class="btn btn-sm bg-gradient bg-primary">Lancer le script d'anonymisation</a>
</dd> </dd>
<dt>Restauration</dt> <dt>Restauration</dt>
<dd> <dd>
<?php echo $restaurationScriptPath ?><br> <?php echo $restaurationScriptPath ?><br>
<a href="<?php echo $this->url('unicaen-dbfakator/restaurer') ?>" class="btn btn-sm bg-gradient bg-primary">Lancer le script de restauration</a> <a href="<?php echo $this->url('unicaen-db-anonym/restaurer') ?>" class="btn btn-sm bg-gradient bg-primary">Lancer le script de restauration</a>
</dd> </dd>
</dl> </dl>
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
*/ */
$this->headTitle("Lancement"); $this->headTitle("Lancement");
$this->headTitle("UnicaenDbfakator"); $this->headTitle("UnicaenDbAnonym");
?> ?>
<h1>Résultat du lancement du script</h1> <h1>Résultat du lancement du script</h1>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment