Commit 821add3b authored by Laurent Lécluse's avatar Laurent Lécluse
Browse files

Refonte de l'organisation du module.

Sission entre plusieurs contrôleurs.
Réorganisation complète des routes.
Préparation aux futures améliorations du module (configurabilité des vues sources, etc.
parent 4b0da34d
......@@ -10,14 +10,128 @@ return [
'router' => [
'routes' => [
'import' => [
'type' => 'Segment',
'options' => [
'route' => '/import[/:action][/:table]',
'type' => 'Literal',
'options' => [
'route' => '/import',
'defaults' => [
'__NAMESPACE__' => 'Import\Controller',
'controller' => 'Import',
'action' => 'index',
'table' => null,
],
],
'may_terminate' => true,
'child_routes' => [
'tableau-bord' => [
'type' => 'Literal',
'options' => [
'route' => '/tableau-bord',
'defaults' => [
'action' => 'tableau-bord',
],
],
],
'maj-vues-fonctions' => [
'type' => 'Literal',
'options' => [
'route' => '/maj-vues-fonctions',
'defaults' => [
'action' => 'maj-vues-fonctions',
],
],
],
'sources' => [
'type' => 'Literal',
'options' => [
'route' => '/sources',
'defaults' => [
'controller' => 'Source',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'edition' => [
'type' => 'Segment',
'options' => [
'route' => '/edition[/:source]',
'constraints' => [
'source' => '[0-9]*',
],
'defaults' => [
'action' => 'edition',
],
],
'may_terminate' => true,
],
'suppression' => [
'type' => 'Segment',
'options' => [
'route' => '/suppression/:source',
'constraints' => [
'source' => '[0-9]*',
],
'defaults' => [
'action' => 'suppression',
],
],
'may_terminate' => true,
],
],
],
'differentiel' => [
'type' => 'Literal',
'options' => [
'route' => '/differentiel',
'defaults' => [
'controller' => 'Differentiel',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'maj-vue-materialisee' => [
'type' => 'Segment',
'options' => [
'route' => '/maj-vue-materialisee[/:table]',
'defaults' => [
'action' => 'maj-vue-materialisee',
],
],
],
'synchronisation' => [
'type' => 'Segment',
'options' => [
'route' => '/synchronisation[/:table]',
'defaults' => [
'action' => 'synchronisation',
],
],
],
'details' => [
'type' => 'Segment',
'options' => [
'route' => '/details[/:table]',
'defaults' => [
'action' => 'details',
],
],
],
],
],
'tables' => [
'type' => 'Literal',
'options' => [
'route' => '/tables',
'defaults' => [
'controller' => 'Table',
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
//* Placez ici vos routes filles
],
],
],
],
......@@ -54,42 +168,35 @@ return [
'sources' => [
'label' => "Sources de données",
'description' => "Liste des sources de données",
'route' => 'import',
'resource' => PrivilegeController::getResourceId('Import\Controller\Import', 'sources'),
'params' => [
'action' => 'sources',
],
'route' => 'import/sources',
'resource' => PrivilegeController::getResourceId('Import\Controller\Source', 'index'),
],
'differentiel' => [
'label' => "Écarts entre les données de l'application et ses sources",
'description' => "Affiche, table par table, la liste des données différentes entre l'application et ses sources de données",
'route' => 'import',
'resource' => PrivilegeController::getResourceId('Import\Controller\Import', 'differentiel'),
'params' => [
'action' => 'index',
],
'tables' => [
'label' => 'Tables',
'route' => 'import/tables',
'resource' => PrivilegeController::getResourceId('Import\Controller\Table', 'index'),
],
'tableau-bord' => [
'label' => "Tableau de bord principal",
'description' => "Liste, table par table, les colonnes dont les données sont importables ou non, leur caractéristiques et l'état de l'import à leur niveau.",
'route' => 'import',
'route' => 'import/tableau-bord',
'resource' => PrivilegeController::getResourceId('Import\Controller\Import', 'tableau-bord'),
'params' => [
'action' => 'tableau-bord',
],
],
'update-views-and-packages' => [
'differentiel' => [
'label' => "Écarts entre les données de l'application et ses sources",
'description' => "Affiche, table par table, la liste des données différentes entre l'application et ses sources de données",
'route' => 'import/differentiel',
'resource' => PrivilegeController::getResourceId('Import\Controller\Differentiel', 'index'),
],
'maj-vues-fonctions' => [
'label' => "Mise à jour des vues différentielles et des procédures de mise à jour",
'description' => "Réactualise les vues différentielles d'import. Ces dernières servent à déterminer quelles données ont changé,
sont apparues ou ont disparues des sources de données.
Met également à jour les procédures de mise à jour qui actualisent les données de l'application à partir des informations
fournies par les vues différentielles.
Cette réactualisation n'est utile que si les vues sources ont été modifiées.",
'route' => 'import',
'route' => 'import/maj-vues-fonctions',
'resource' => PrivilegeController::getResourceId('Import\Controller\Import', 'update-views-and-packages'),
'params' => [
'action' => 'update-views-and-packages',
],
],
],
],
......@@ -101,35 +208,58 @@ return [
'bjyauthorize' => [
'guards' => [
PrivilegeController::class => [
/* Import */
[
'controller' => 'Import\Controller\Import',
'action' => ['sources'],
'privileges' => [Privileges::IMPORT_SOURCES_VISUALISATION],
'action' => ['index'],
'privileges' => [
Privileges::IMPORT_ECARTS,
Privileges::IMPORT_MAJ,
Privileges::IMPORT_TBL,
Privileges::IMPORT_VUES_PROCEDURES,
Privileges::IMPORT_TABLES_VISUALISATION,
],
],
[
'controller' => 'Import\Controller\Import',
'action' => ['source-edition', 'source-suppression'],
'privileges' => [Privileges::IMPORT_SOURCES_EDITION],
'action' => ['tableau-bord'],
'privileges' => [Privileges::IMPORT_TBL],
],
[
'controller' => 'Import\Controller\Import',
'action' => ['index', 'differentiel'],
'privileges' => [Privileges::IMPORT_ECARTS, Privileges::IMPORT_MAJ, Privileges::IMPORT_TBL, Privileges::IMPORT_VUES_PROCEDURES],
'action' => ['maj-vues-fonctions'],
'privileges' => [Privileges::IMPORT_VUES_PROCEDURES],
],
/* Gestion des sources */
[
'controller' => 'Import\Controller\Import',
'action' => ['tableau-bord'],
'privileges' => [Privileges::IMPORT_TBL],
'controller' => 'Import\Controller\Source',
'action' => ['index'],
'privileges' => [Privileges::IMPORT_SOURCES_VISUALISATION],
],
[
'controller' => 'Import\Controller\Import',
'action' => ['synchronisation'],
'privileges' => [Privileges::IMPORT_ECARTS, Privileges::IMPORT_MAJ],
'controller' => 'Import\Controller\Source',
'action' => ['edition', 'suppression'],
'privileges' => [Privileges::IMPORT_SOURCES_EDITION],
],
/* Tables */
[
'controller' => 'Import\Controller\Import',
'action' => ['update-views-and-packages'],
'privileges' => [Privileges::IMPORT_VUES_PROCEDURES],
'controller' => 'Import\Controller\Table',
'action' => ['index'],
'privileges' => [Privileges::IMPORT_TABLES_VISUALISATION],
],
/* Différentiel */
[
'controller' => 'Import\Controller\Differentiel',
'action' => ['index', 'synchronisation', 'details'],
'privileges' => [
Privileges::IMPORT_ECARTS,
Privileges::IMPORT_MAJ,
Privileges::IMPORT_TBL,
Privileges::IMPORT_VUES_PROCEDURES,
],
],
],
],
......@@ -169,7 +299,10 @@ return [
'controllers' => [
'factories' => [
'Import\Controller\Import' => Controller\Factory\ImportControllerFactory::class,
'Import\Controller\Import' => Controller\Factory\ImportControllerFactory::class,
'Import\Controller\Source' => Controller\Factory\SourceControllerFactory::class,
'Import\Controller\Table' => Controller\Factory\TableControllerFactory::class,
'Import\Controller\Differentiel' => Controller\Factory\DifferentielControllerFactory::class,
],
],
......
<?php
namespace UnicaenImport\Controller;
use UnicaenImport\Entity\Differentiel\Query;
use UnicaenImport\Provider\Privilege\Privileges;
use UnicaenImport\Service\Traits\DifferentielServiceAwareTrait;
use UnicaenImport\Service\Traits\QueryGeneratorServiceAwareTrait;
use UnicaenImport\Service\Traits\SchemaServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\JsonModel;
/**
* Description of DifferentielController
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class DifferentielController extends AbstractActionController
{
use SchemaServiceAwareTrait;
use QueryGeneratorServiceAwareTrait;
use DifferentielServiceAwareTrait;
public function indexAction()
{
$sc = $this->getServiceSchema();
$tables = $sc->getImportTables();
$mviews = $sc->getImportMviews();
return compact('tables', 'mviews');
}
public function synchronisationAction()
{
$errors = [];
$success = [];
$table = $this->params()->fromRoute('table');
$action = $this->params()->fromPost('action');
/* Mise à jour */
if ($this->isAllowed(Privileges::getResourceId(Privileges::IMPORT_MAJ))) {
if ('vue-materialisee' === $action) {
try {
$sq = $this->getServiceQueryGenerator();
$sq->execMajVM($table);
$success[] = 'Vue matérialisée mise à jour avec succès';
} catch (\Exception $e) {
$errors = [$e->getMessage()];
}
} elseif ($action) {
$sq = $this->getServiceQueryGenerator();
$query = new Query($table);
$query->addDefaultSyncFiltre($sq);
if ($action != 'all') $query->setAction($action);
/* Mise à jour des données et récupération des éventuelles erreurs */
try {
$errors = $sq->syncTable($query);
if (!$errors) {
$success[] = 'Synchronisation effectuée avec succès';
}
} catch (\Exception $e) {
$errors = [$e->getMessage()];
}
}
} else {
if ($action) {
$errors[] = 'Vous n\'avez pas le droit de synchroniser cette table';
}
}
/* Récupération et rendu final */
$query = new Query($table);
$chiffres = $this->getServiceDifferentiel()->make($query, Query::SQL_SUMMARY)->fetchSummary();
return new JsonModel(compact('table', 'chiffres', 'errors', 'success'));
}
public function detailsAction()
{
$table = $this->params()->fromRoute('table');
$action = $this->params()->fromPost('action');
$sc = $this->getServiceSchema();
$query = new Query($table);
if ($action != 'all') $query->setAction($action);
$query->setNotNull([]); // Aucune colonne ne doit être non nulle !!
$query->setLimit(101);
$lignes = $this->getServiceDifferentiel()->make($query, $query::SQL_FULL)->fetchAll();
return compact('lignes');
}
}
\ No newline at end of file
<?php
namespace UnicaenImport\Controller\Factory;
use UnicaenImport\Controller\DifferentielController;
use UnicaenImport\Service\DifferentielService;
use UnicaenImport\Service\QueryGeneratorService;
use UnicaenImport\Service\SchemaService;
use Zend\Mvc\Controller\ControllerManager as ContainerInterface;
/**
* Description of DifferentielControllerFactory
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class DifferentielControllerFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return DifferentielController
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* On quitte le ControllerManager */
$container = $container->getServiceLocator();
$controller = new DifferentielController();
$controller->setServiceSchema($container->get(SchemaService::class));
$controller->setServiceQueryGenerator($container->get(QueryGeneratorService::class));
$controller->setServiceDifferentiel($container->get(DifferentielService::class));
return $controller;
}
}
\ No newline at end of file
......@@ -33,11 +33,7 @@ class ImportControllerFactory
$controller = new ImportController();
$controller->setServiceSchema($container->get(SchemaService::class));
$controller->setServiceQueryGenerator($container->get(QueryGeneratorService::class));
$controller->setServiceDifferentiel($container->get(DifferentielService::class));
$controller->setProcessusImport($container->get(ImportProcessus::class));
$controller->setServiceSource($container->get(SourceService::class));
$controller->setFormSource($container->get('FormElementManager')->get(SourceForm::class));
return $controller;
}
......
<?php
namespace UnicaenImport\Controller\Factory;
use UnicaenImport\Form\SourceForm;
use UnicaenImport\Service\SourceService;
use Zend\Mvc\Controller\ControllerManager as ContainerInterface;
use UnicaenImport\Controller\SourceController;
/**
* Description of SourceControllerFactory
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class SourceControllerFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return SourceController
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* On quitte le ControllerManager */
$container = $container->getServiceLocator();
$controller = new SourceController;
$controller->setServiceSource($container->get(SourceService::class));
$controller->setFormSource($container->get('FormElementManager')->get(SourceForm::class));
return $controller;
}
}
\ No newline at end of file
<?php
namespace UnicaenImport\Controller\Factory;
use Zend\Mvc\Controller\ControllerManager as ContainerInterface;
use UnicaenImport\Controller\TableController;
/**
* Description of TableControllerFactory
*
* @author LECLUSE Laurent <laurent.lecluse at unicaen.fr>
*/
class TableControllerFactory
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
*
* @return TableController
*/
public function __invoke(ContainerInterface $container, $requestedName, $options = null)
{
/* On quitte le ControllerManager */
$container = $container->getServiceLocator();
$controller = new TableController;
/* Injectez vos dépendances ICI */
return $controller;
}
}
\ No newline at end of file
......@@ -2,17 +2,9 @@
namespace UnicaenImport\Controller;
use UnicaenApp\View\Model\MessengerViewModel;
use UnicaenImport\Entity\Db\Source;
use UnicaenImport\Form\Traits\SourceFormAwareTrait;
use UnicaenImport\Processus\Traits\ImportProcessusAwareTrait;
use UnicaenImport\Service\Traits\DifferentielServiceAwareTrait;
use UnicaenImport\Service\Traits\QueryGeneratorServiceAwareTrait;
use UnicaenImport\Service\Traits\SchemaServiceAwareTrait;
use UnicaenImport\Service\Traits\SourceServiceAwareTrait;
use Zend\Mvc\Controller\AbstractActionController;
use UnicaenImport\Entity\Differentiel\Query;
use Zend\View\Model\JsonModel;
/**
*
......@@ -22,42 +14,14 @@ use Zend\View\Model\JsonModel;
class ImportController extends AbstractActionController
{
use SchemaServiceAwareTrait;
use QueryGeneratorServiceAwareTrait;
use DifferentielServiceAwareTrait;
use ImportProcessusAwareTrait;
use SourceServiceAwareTrait;
use SourceFormAwareTrait;
public function indexAction()
{
$sc = $this->getServiceSchema();
$tables = $sc->getImportTables();
$mviews = $sc->getImportMviews();
return compact('tables', 'mviews');
}
public function updateViewsAndPackagesAction()
{
try {
$this->getProcessusImport()->updateViewsAndPackages();
$message = 'Mise à jour des vues différentielles et du paquetage d\'import terminés';
} catch (\Exception $e) {
$message = 'Une erreur a été rencontrée.';
throw new \UnicaenApp\Exception\LogicException("import impossible", null, $e);
}
$title = "Résultat";
return compact('message', 'title');
return [];
}
public function tableauBordAction()
{
$data = $this->getServiceSchema()->getSchema();
......@@ -67,130 +31,25 @@ class ImportController extends AbstractActionController
public function differentielAction()
{
$table = $this->params()->fromRoute('table');
$action = $this->params()->fromPost('action');
$sc = $this->getServiceSchema();
$query = new Query($table);
if ($action != 'all') $query->setAction($action);
$query->setNotNull([]); // Aucune colonne ne doit être non nulle !!
$query->setLimit(101);
$lignes = $this->getServiceDifferentiel()->make($query, $query::SQL_FULL)->fetchAll();
return compact('lignes');
}
public function synchronisationAction()
{
$errors = [];
$success = [];
$table = $this->params()->fromRoute('table');
$action = $this->params()->fromPost('action');