Commit 821add3b authored by Laurent Lecluse's avatar Laurent Lecluse
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
Loading
Loading
Loading
Loading
+175 −42
Original line number Diff line number Diff line
@@ -10,14 +10,128 @@ return [
    'router' => [
        'routes' => [
            'import' => [
                'type'    => 'Segment',
                'type'          => 'Literal',
                'options'       => [
                    'route'    => '/import[/:action][/:table]',
                    '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',
                                ],
                            ],
                            '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',
                                'route'       => 'import/sources',
                                'resource'    => PrivilegeController::getResourceId('Import\Controller\Source', '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',
                            ],
                            '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'),
                            ],
                            'update-views-and-packages' => [
                            '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\Source',
                    'action'     => ['index'],
                    'privileges' => [Privileges::IMPORT_SOURCES_VISUALISATION],
                ],
                [
                    'controller' => 'Import\Controller\Import',
                    'action'     => ['tableau-bord'],
                    'privileges' => [Privileges::IMPORT_TBL],
                    'controller' => 'Import\Controller\Source',
                    'action'     => ['edition', 'suppression'],
                    'privileges' => [Privileges::IMPORT_SOURCES_EDITION],
                ],

                /* Tables */
                [
                    'controller' => 'Import\Controller\Import',
                    'action'     => ['synchronisation'],
                    'privileges' => [Privileges::IMPORT_ECARTS, Privileges::IMPORT_MAJ],
                    'controller' => 'Import\Controller\Table',
                    'action'     => ['index'],
                    'privileges' => [Privileges::IMPORT_TABLES_VISUALISATION],
                ],

                /* Différentiel */
                [
                    'controller' => 'Import\Controller\Import',
                    'action'     => ['update-views-and-packages'],
                    'privileges' => [Privileges::IMPORT_VUES_PROCEDURES],
                    'controller' => 'Import\Controller\Differentiel',
                    'action'     => ['index', 'synchronisation', 'details'],
                    'privileges' => [
                        Privileges::IMPORT_ECARTS,
                        Privileges::IMPORT_MAJ,
                        Privileges::IMPORT_TBL,
                        Privileges::IMPORT_VUES_PROCEDURES,
                    ],
                ],
            ],
        ],
@@ -170,6 +300,9 @@ return [
    'controllers' => [
        'factories' => [
            '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,
        ],
    ],

+103 −0
Original line number Diff line number Diff line
<?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
+40 −0
Original line number Diff line number Diff line
<?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
+0 −4
Original line number Diff line number Diff line
@@ -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;
    }
+38 −0
Original line number Diff line number Diff line
<?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
Loading