Commit d0918c9e authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Renommage du module en unicaen/db-anonym

parent 5c1c3d57
Pipeline #12352 passed with stage
in 15 seconds
<?php
namespace UnicaenDbfakator;
namespace UnicaenDbAnonym;
use Laminas\Config\Factory as ConfigFactory;
use Laminas\Console\Adapter\AdapterInterface;
......@@ -45,7 +45,7 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte
*/
public function getConsoleBanner(AdapterInterface $console): ?string
{
return "UnicaenDbfakator";
return "UnicaenDbAnonym";
}
/**
......@@ -57,18 +57,18 @@ class Module implements ConsoleBannerProviderInterface, ConsoleUsageProviderInte
/**
* @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()
*/
'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()
*/
'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é
dans un fichier de configuration.
......
{
"name": "unicaen/dbfakator",
"description": "Module pour anonymiser une base de données",
"name": "unicaen/db-anonym",
"description": "Module pour anonymiser les données d'une bdd",
"require": {
"php": ">=7.3",
"unicaen/app": "^4.0",
......@@ -13,7 +13,7 @@
},
"autoload": {
"psr-0": {
"UnicaenDbfakator": "src/"
"UnicaenDbAnonym": "src/"
},
"classmap": [
"./Module.php"
......
<?php
namespace UnicaenDbfakator;
namespace UnicaenDbAnonym;
use Laminas\Mvc\Console\Router\Simple;
use UnicaenAuth\Guard\PrivilegeController;
use UnicaenDbfakator\Controller\ConsoleController;
use UnicaenDbfakator\Controller\ConsoleControllerFactory;
use UnicaenDbfakator\Controller\IndexController;
use UnicaenDbfakator\Controller\IndexControllerFactory;
use UnicaenDbfakator\Service\DbfakatorService;
use UnicaenDbfakator\Service\DbfakatorServiceFactory;
use UnicaenDbfakator\Service\DbService;
use UnicaenDbfakator\Service\DbServiceFactory;
use UnicaenDbAnonym\Controller\ConsoleController;
use UnicaenDbAnonym\Controller\ConsoleControllerFactory;
use UnicaenDbAnonym\Controller\IndexController;
use UnicaenDbAnonym\Controller\IndexControllerFactory;
use UnicaenDbAnonym\Service\AnonymService;
use UnicaenDbAnonym\Service\AnonymServiceFactory;
use UnicaenDbAnonym\Service\DbService;
use UnicaenDbAnonym\Service\DbServiceFactory;
return [
'router' => [
'routes' => [
'unicaen-dbfakator' => [
'unicaen-db-anonym' => [
'type' => 'Literal',
'options' => [
'route' => '/unicaen-dbfakator',
'route' => '/unicaen-db-anonym',
'defaults' => [
'controller' => IndexController::class,
'action' => 'index',
......@@ -76,7 +76,7 @@ return [
'generer' => [
'type' => Simple::class,
'options' => [
'route' => 'unicaen-dbfakator generer',
'route' => 'unicaen-db-anonym generer',
'defaults' => [
/**
* @see ConsoleController::genererAction()
......@@ -89,7 +89,7 @@ return [
'anonymiser' => [
'type' => Simple::class,
'options' => [
'route' => 'unicaen-dbfakator anonymiser',
'route' => 'unicaen-db-anonym anonymiser',
'defaults' => [
/**
* @see ConsoleController::anonymiserAction()
......@@ -102,7 +102,7 @@ return [
'restaurer' => [
'type' => Simple::class,
'options' => [
'route' => 'unicaen-dbfakator restaurer',
'route' => 'unicaen-db-anonym restaurer',
'defaults' => [
/**
* @see ConsoleController::restaurerAction()
......@@ -153,7 +153,7 @@ return [
'service_manager' => [
'factories' => [
DbService::class => DbServiceFactory::class,
DbfakatorService::class => DbfakatorServiceFactory::class,
AnonymService::class => AnonymServiceFactory::class,
],
],
'controllers' => [
......
......@@ -6,18 +6,29 @@ use Application\Entity\Db\Individu;
use Application\Entity\Db\Utilisateur;
return [
'unicaen-db-fake' => [
'unicaen-db-anonym' => [
'output' => [
/**
* Chemin des scripts SQL à générer :
* - 'anonymisation' : mise à jour des données avec des données fictives spécifiées.
*/
'anonymisation' => '/tmp/unicaen_db_anonym_anonymisation.sql',
'restauration' => '/tmp/unicaen_db_anonym_restauration.sql',
],
'entities' => [
/**
* Config par classe d'entité Doctrine.
*/
Individu::class => [
/**
* Mapping des champs à modifier avec des données fictives générées avec FakerPHP
* (@see https://fakerphp.github.io/formatters)
*
* 'field' => 'xxxxx' : formatter FakerPHP sans arguments `$faker->xxxxx()`
* 'field' => ['xxxxx', 3, true] : formatter FakerPHP avec arguments `$faker->xxxxx(3, true)`
* 'field' => 'null' : mise à NULL.
*/
'mapping' => [
/**
* 'field' => 'xxxxx' : pour appeler le formatter sans arguments `$faker->xxxxx()` (@see https://fakerphp.github.io/formatters)
* 'field' => ['xxxxx', 3, true] : pour appeler le formatter avec arguments `$faker->xxxxx(3, true)`
* 'field' => 'null' : pour mettre le champ à NULL.
*/
'nomUsuel' => 'lastName',
'nomPatronymique' => 'null',
'prenom1' => 'firstName',
......
<?php
namespace UnicaenDbfakator\Controller;
namespace UnicaenDbAnonym\Controller;
use Exception;
use Laminas\Mvc\Console\Controller\AbstractConsoleController;
use UnicaenApp\Exception\RuntimeException;
use UnicaenDbfakator\Service\DbfakatorServiceAwareTrait;
use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
class ConsoleController extends AbstractConsoleController
{
use DbfakatorServiceAwareTrait;
use AnonymServiceAwareTrait;
/**
* @var string
......@@ -22,10 +22,10 @@ class ConsoleController extends AbstractConsoleController
$this->console->writeLine("Generation des scripts SQL...");
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath();
$anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
try {
$gen = $this->dbfakatorService->generer();
$gen = $this->anonymService->generer();
foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) {
$this->console->writeLine(
sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count)
......@@ -44,13 +44,13 @@ class ConsoleController extends AbstractConsoleController
public function anonymiserAction()
{
$scriptPath = $this->dbfakatorService->getAnonymisationScriptPath();
$scriptPath = $this->anonymService->getAnonymisationScriptPath();
$this->console->writeLine("Lancement du script d'anonymisation '$scriptPath'...");
$start = microtime(true);
try {
$result = $this->dbfakatorService->anonymiser();
$result = $this->anonymService->anonymiser();
} catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
}
......@@ -63,13 +63,13 @@ class ConsoleController extends AbstractConsoleController
public function restaurerAction()
{
$scriptPath = $this->dbfakatorService->getRestaurationScriptPath();
$scriptPath = $this->anonymService->getRestaurationScriptPath();
$this->console->writeLine("Lancement du script de restauration '$scriptPath'...");
$start = microtime(true);
try {
$result = $this->dbfakatorService->restaurer();
$result = $this->anonymService->restaurer();
} catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
}
......
<?php
namespace UnicaenDbfakator\Controller;
namespace UnicaenDbAnonym\Controller;
use UnicaenDbfakator\Service\DbfakatorService;
use UnicaenDbAnonym\Service\AnonymService;
use Psr\Container\ContainerInterface;
class ConsoleControllerFactory
{
/**
* @param \Psr\Container\ContainerInterface $container
* @return \UnicaenDbfakator\Controller\ConsoleController
* @return \UnicaenDbAnonym\Controller\ConsoleController
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): ConsoleController
{
/** @var \UnicaenDbfakator\Service\DbfakatorService $service */
$dbFakeService = $container->get(DbfakatorService::class);
/** @var \UnicaenDbAnonym\Service\AnonymService $service */
$dbFakeService = $container->get(AnonymService::class);
$controller = new ConsoleController();
$controller->setDbfakatorService($dbFakeService);
$controller->setAnonymService($dbFakeService);
return $controller;
}
......
<?php
namespace UnicaenDbfakator\Controller;
namespace UnicaenDbAnonym\Controller;
use Application\Controller\AbstractController;
use Exception;
use Laminas\View\Model\ViewModel;
use UnicaenApp\Exception\RuntimeException;
use UnicaenApp\Service\SQL\RunSQLResult;
use UnicaenDbfakator\Service\DbfakatorServiceAwareTrait;
use UnicaenDbAnonym\Service\AnonymServiceAwareTrait;
class IndexController extends AbstractController
{
use DbfakatorServiceAwareTrait;
use AnonymServiceAwareTrait;
public function indexAction(): array
{
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath();
$anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
$data = [];
if (file_exists($anonymisationScriptPath) && file_exists($restaurationScriptPath)) {
......@@ -32,12 +32,12 @@ class IndexController extends AbstractController
public function genererAction(): array
{
$anonymisationScriptPath = $this->dbfakatorService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->dbfakatorService->getRestaurationScriptPath();
$anonymisationScriptPath = $this->anonymService->getAnonymisationScriptPath();
$restaurationScriptPath = $this->anonymService->getRestaurationScriptPath();
$messages = [];
try {
$gen = $this->dbfakatorService->generer();
$gen = $this->anonymService->generer();
foreach ($gen as ['table' => $table, 'fields' => $fields, 'count' => $count]) {
$messages[] = sprintf("- Table %s (colonnes %s) : %d lignes", $table, implode(', ', $fields), $count);
}
......@@ -54,10 +54,10 @@ class IndexController extends AbstractController
public function anonymiserAction(): ViewModel
{
$scriptPath = $this->dbfakatorService->getAnonymisationScriptPath();
$scriptPath = $this->anonymService->getAnonymisationScriptPath();
try {
$result = $this->dbfakatorService->anonymiser();
$result = $this->anonymService->anonymiser();
} catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
}
......@@ -67,10 +67,10 @@ class IndexController extends AbstractController
public function restaurerAction(): ViewModel
{
$scriptPath = $this->dbfakatorService->getRestaurationScriptPath();
$scriptPath = $this->anonymService->getRestaurationScriptPath();
try {
$result = $this->dbfakatorService->restaurer();
$result = $this->anonymService->restaurer();
} catch (Exception $e) {
throw new RuntimeException("Une erreur est survenue lors du lancement du script '$scriptPath'.", null, $e);
}
......@@ -83,7 +83,7 @@ class IndexController extends AbstractController
$vm = new ViewModel([
'result' => $result,
]);
$vm ->setTemplate('unicaen-dbfakator/index/result');
$vm ->setTemplate('unicaen-db-anonym/index/result');
return $vm;
}
......
<?php
namespace UnicaenDbfakator\Controller;
namespace UnicaenDbAnonym\Controller;
use UnicaenDbfakator\Service\DbfakatorService;
use UnicaenDbAnonym\Service\AnonymService;
use Psr\Container\ContainerInterface;
class IndexControllerFactory
......@@ -15,11 +15,11 @@ class IndexControllerFactory
*/
public function __invoke(ContainerInterface $container): IndexController
{
/** @var \UnicaenDbfakator\Service\DbfakatorService $service */
$service = $container->get(DbfakatorService::class);
/** @var \UnicaenDbAnonym\Service\AnonymService $service */
$service = $container->get(AnonymService::class);
$controller = new IndexController();
$controller->setDbfakatorService($service);
$controller->setAnonymService($service);
return $controller;
}
......
<?php
namespace UnicaenDbfakator\Service;
namespace UnicaenDbAnonym\Service;
use Generator;
use UnicaenApp\Service\SQL\RunSQLResult;
......@@ -10,7 +10,7 @@ use Webmozart\Assert\InvalidArgumentException;
/**
* @property \Psr\Log\LoggerInterface $logger
*/
class DbfakatorService
class AnonymService
{
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
namespace UnicaenDbfakator\Service;
namespace UnicaenDbAnonym\Service;
use Psr\Container\ContainerInterface;
use Webmozart\Assert\Assert;
class DbfakatorServiceFactory
class AnonymServiceFactory
{
/**
* @param \Psr\Container\ContainerInterface $container
* @return \UnicaenDbfakator\Service\DbfakatorService
* @return \UnicaenDbAnonym\Service\AnonymService
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
public function __invoke(ContainerInterface $container): DbfakatorService
public function __invoke(ContainerInterface $container): AnonymService
{
/** @var DbService $dbService */
$dbService = $container->get(DbService::class);
$config = $this->getConfig($container);
$service = new DbfakatorService();
$service = new AnonymService();
$service->setConfig($config);
$service->setDbService($dbService);
......@@ -36,7 +36,7 @@ class DbfakatorServiceFactory
/** @var array $appConfig */
$appConfig = $container->get('Config');
$config = $appConfig['unicaen-dbfakator'] ?? [];
$config = $appConfig['unicaen-db-anonym'] ?? [];
if (!$config) {
return [];
}
......
<?php
namespace UnicaenDbfakator\Service;
namespace UnicaenDbAnonym\Service;
use Doctrine\DBAL\ConnectionException;
use Doctrine\DBAL\Exception;
......
<?php
namespace UnicaenDbfakator\Service;
namespace UnicaenDbAnonym\Service;
trait DbServiceAwareTrait
{
......
<?php
namespace UnicaenDbfakator\Service;
namespace UnicaenDbAnonym\Service;
use Psr\Container\ContainerInterface;
......
<?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 @@
*/
$this->headTitle("Génération");
$this->headTitle("UnicaenDbfakator");
$this->headTitle("UnicaenDbAnonym");
?>
<h1>Résultat de la génération des scripts SQL</h1>
......
......@@ -5,14 +5,14 @@
*/
$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>
<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>
......@@ -24,12 +24,12 @@ $this->headTitle("UnicaenDbfakator");
<dt>Anonymisation</dt>
<dd>
<?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>
<dt>Restauration</dt>
<dd>
<?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>
</dl>
......
......@@ -4,7 +4,7 @@
*/
$this->headTitle("Lancement");
$this->headTitle("UnicaenDbfakator");
$this->headTitle("UnicaenDbAnonym");
?>
<h1>Résultat du lancement du script</h1>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment