Commit 97a83a14 authored by Laurent Lécluse's avatar Laurent Lécluse

Quasi finalisation de l'optimisation du calcul des TBLs

parent 026c1c2e
Pipeline #7813 failed with stage
in 5 seconds
......@@ -51,6 +51,23 @@ return [
],
],
'console' => [
'router' => [
'routes' => [
'unicaen-tbl' => [
'options' => [
'type' => 'catchall',
'route' => 'UnicaenTbl build-procedures',
'defaults' => [
'controller' => AdminController::class,
'action' => 'build-procedures',
],
],
],
],
],
],
'doctrine' => [
'driver' => [
'unicaen_tbl_driver' => [
......@@ -105,7 +122,7 @@ return [
],
[
'controller' => AdminController::class,
'action' => ['update-actuproc'],
'action' => ['build-procedures'],
'privileges' => [Privileges::UNICAEN_TBL_UPDATE_ACTUPROC],
],
[
......
......@@ -32,18 +32,15 @@ class AdminController extends AbstractActionController
public function updateActuprocAction()
public function buildProceduresAction()
{
echo 'Construction des procédures de mise à jour des tableaux de bord...'."\n";
try {
$this->getServiceQueryGenerator()->updateProcedures();
$message = 'Mise à jour des packages d\'actualisation terminée.';
echo 'Procédures finalisées'."\n";
} catch (\Exception $e) {
$message = 'Une erreur a été rencontrée.';
throw new \UnicaenApp\Exception\LogicException("mise à jour impossible", null, $e);
echo 'Une erreur a été rencontrée : '.$e->getMessage().'.'."\n";
}
$title = "Résultat";
return compact('message', 'title');
}
......@@ -57,14 +54,19 @@ class AdminController extends AbstractActionController
}
$form = $this->getFormActualisation();
$options = $this->getServiceSchema()->getTableauBords()[$tableauBord]->getColumns();
$options = array_keys($options);
$options = array_combine($options,$options);
$form->get('param')->setValueOptions($options);
$form->setAttribute('action', $this->url()->fromRoute('unicaen-tbl/actualisation', ['tableauBord' => $tableauBord]));
if ($this->getRequest()->isPost()) {
$form->setData($this->getRequest()->getPost());
if ($form->isValid()) {
try{
$params = $form->extractArrayParams();
$this->getServiceTableauBord()->calculer($tableauBord, $params);
$param = $form->get('param')->getValue();
$value = $form->get('value')->getValue();
$this->getServiceTableauBord()->calculer($tableauBord, $param, $value);
$this->flashMessenger()->addSuccessMessage('Actualisation réussie');
}catch(\Exception $e){
$this->flashMessenger()->addErrorMessage($e->getMessage());
......
......@@ -22,6 +22,11 @@ class Column
*/
protected $key;
/**
* @var bool
*/
protected $inView = true;
/**
......@@ -96,6 +101,30 @@ class Column
/**
* @return bool
*/
public function isInView(): bool
{
return $this->inView;
}
/**
* @param bool $inView
*
* @return Column
*/
public function setInView(bool $inView): Column
{
$this->inView = $inView;
return $this;
}
/**
* The __toString method allows a class to decide how it will react when it is converted to a string.
*
......
......@@ -17,17 +17,22 @@ class ActualisationForm extends Form implements InputFilterProviderInterface
public function init()
{
for ($i = 1; $i <= 5; $i++) {
$this->add([
'name' => 'c' . $i,
'type' => 'Text',
]);
$this->add([
'name' => 'param',
'type' => 'Select',
'options' => [
'label' => 'Nom du champ éventuel',
'empty_option' => "- Tout sans filtre -",
],
]);
$this->add([
'name' => 'v' . $i,
'type' => 'Text',
]);
}
$this->add([
'name' => 'value',
'type' => 'Text',
'options' => [
'label' => 'Valeur',
],
]);
$this->add([
'name' => 'submit',
......@@ -41,28 +46,6 @@ class ActualisationForm extends Form implements InputFilterProviderInterface
/**
* @param $object
*
* @return array
*/
public function extractArrayParams()
{
$data = [];
for ($i = 1; $i <= 5; $i++) {
$c = $this->get('c' . $i)->getValue();
$v = $this->get('v' . $i)->getValue();
if (!empty($c)) {
$data[$c] = $v;
}
}
return $data;
}
/**
* Should return an array specification compatible with
* {@link Zend\InputFilter\Factory::createInputFilter()}.
......@@ -72,16 +55,8 @@ class ActualisationForm extends Form implements InputFilterProviderInterface
public function getInputFilterSpecification()
{
return [
'c1' => ['required' => false],
'v1' => ['required' => false],
'c2' => ['required' => false],
'v2' => ['required' => false],
'c3' => ['required' => false],
'v3' => ['required' => false],
'c4' => ['required' => false],
'v4' => ['required' => false],
'c5' => ['required' => false],
'v5' => ['required' => false],
'param' => ['required' => false],
'value' => ['required' => false],
];
}
......
......@@ -219,8 +219,8 @@ class QueryGeneratorService extends AbstractService
$view = strtoupper($tbl->getViewName(true));
$sequence = strtoupper($tbl->getSequenceName(true));
if (empty($tbl->getKeyColumns())){
throw new \Exception('Le tableau de bord '.$tbl->getName().' n\'a pas de contrainte d\'unicité.');
if (empty($tbl->getKeyColumns())) {
throw new \Exception('Le tableau de bord ' . $tbl->getName() . ' n\'a pas de contrainte d\'unicité.');
}
$maxKeyColLen = 0;
......@@ -237,7 +237,7 @@ class QueryGeneratorService extends AbstractService
}
}
$join = [];
$join = [];
$testNull = [];
foreach ($tbl->getKeyColumns() as $column) {
$colLen = strlen($column);
......@@ -250,28 +250,41 @@ class QueryGeneratorService extends AbstractService
}
$testNull[] = "d.$column IS NULL\n";
}
$join = trim(implode(" AND ", $join));
$join = trim(implode(" AND ", $join));
$testNull = trim(implode(" AND ", $testNull));
$testDiff = [];
$cols = [];
$cols = [];
foreach ($tbl->getColumns() as $column) {
$colLen = strlen($column);
$colAjust = str_pad('', $maxColLen - $colLen);
if ($column->isNullable()) {
$testDiff[] = "COALESCE(t.$column,0)$colAjust = COALESCE(v.$column,0)\n";
if ($column->isInView()) {
if ($column->isNullable()) {
$testDiff[] = "COALESCE(t.$column,0)$colAjust = COALESCE(v.$column,0)\n";
} else {
$testDiff[] = "t.$column$colAjust = v.$column\n";
}
}
if ($column == 'ID') {
$cols[] = 'ID';
} else {
$testDiff[] = "t.$column$colAjust = v.$column\n";
$cols[] = "v.$column";
}
$cols[] = "v.$column";
}
$testDiff = trim(implode(" AND ", $testDiff));
foreach ($cols as $c => $col) {
if ('ID' == $col) {
$cols[$c] = "CASE WHEN
$testDiff
THEN -1 ELSE t.ID END ID";
}
}
$cols = trim(implode(",\n ", $cols));
$view = $this->getViewDefinition($view);
$view = str_replace( '\'', '\'\'', $view);
$view = str_replace( "\n", "\n ", $view);
$view = str_replace('\'', '\'\'', $view);
$view = str_replace("\n", "\n ", $view);
$sql = " PROCEDURE C_$tableauBord(param VARCHAR2, value VARCHAR2) IS
TYPE r_cursor IS REF CURSOR;
......@@ -292,9 +305,6 @@ class QueryGeneratorService extends AbstractService
OPEN c FOR '
SELECT
CASE WHEN
$testDiff
THEN -1 ELSE t.ID END ID,
$cols
FROM
(' || QUERY_APPLY_PARAM(viewQuery,param,value) || ') v
......@@ -311,7 +321,7 @@ class QueryGeneratorService extends AbstractService
$testNull
THEN
DELETE FROM $table WHERE id = d.id;
ELSIF d.id != -1 THEN
ELSIF d.id <> -1 THEN
UPDATE $table SET row = d WHERE id = d.id;
END IF;
END LOOP;
......@@ -321,7 +331,7 @@ class QueryGeneratorService extends AbstractService
return $sql;
}
/**
......@@ -385,8 +395,8 @@ class QueryGeneratorService extends AbstractService
$view = $this->getViewDefinition($view);
$view = str_replace( '\'', '\'\'', $view);
$view = str_replace( "\n", "\n ", $view);
$view = str_replace('\'', '\'\'', $view);
$view = str_replace("\n", "\n ", $view);
$sql = " PROCEDURE C_$tableauBord( PARAMS UNICAEN_TBL.T_PARAMS ) IS
conds CLOB;
......
......@@ -131,11 +131,12 @@ class SchemaService extends AbstractService
$t->setCustomCalculProc($tbl['custom-calcul-proc']);
foreach ($tbl['columns'] as $col) {
if ($col['in-table'] && $col['in-view']) {
if ($col['in-table']) {
$c = new Column();
$c->setName($col['name']);
$c->setNullable($col['nullable']);
$c->setKey($col['in-constraint']);
$c->setInView($col['in-view']);
$t->addColumn($c);
}
}
......
......@@ -69,9 +69,9 @@ class TableauBordService extends AbstractService
*
* @return $this
*/
public function calculer($tableauBord, $params = null)
public function calculer($tableauBord, ?string $param = null, ?string $value = null)
{
$this->execFunction('CALCULER', $tableauBord, $params);
$this->execFunction('CALCULER', $tableauBord, $param, $value);
return $this;
}
......@@ -84,9 +84,9 @@ class TableauBordService extends AbstractService
*
* @return $this
*/
public function demandeCalcul($tableauBord, $params = null)
public function demandeCalcul($tableauBord, ?string $param = null, ?string $value = null)
{
return $this->execFunction('DEMANDE_CALCUL', $tableauBord, $params);
return $this->execFunction('DEMANDE_CALCUL', $tableauBord, $param, $value);
}
......@@ -125,7 +125,7 @@ class TableauBordService extends AbstractService
*
* @return $this
*/
private function execFunction($funcName, $tableauBord, $params = null)
private function execFunction($funcName, $tableauBord, ?string $param = null, ?string $value = null)
{
/* Formatage du nom du tableau de bord */
if ($tableauBord instanceof TableauBord) {
......@@ -134,18 +134,9 @@ class TableauBordService extends AbstractService
$sqltn = self::escape($tableauBord);
/* Formatage du passage des paramètres */
if ($params) {
if (is_array($params)) {
$p = [];
foreach ($params as $name => $value) {
$p[] = self::escape($name) . ',' . self::escape($value);
}
$sqlpr = 'UNICAEN_TBL.MAKE_PARAMS(' . implode(', ', $p) . ')';
} else {
$sqlpr = self::escape($params);
}
if ($param) {
/* Construction et exécution de la requête, puis retour */
$sql = 'BEGIN UNICAEN_TBL.' . $funcName . '(' . $sqltn . ', ' . $sqlpr . '); END;';
$sql = 'BEGIN UNICAEN_TBL.' . $funcName . '(' . $sqltn . ', ' . self::escape($param) . ', ' . self::escape($value) . '); END;';
} else {
/* Construction et exécution de la requête, puis retour */
$sql = 'BEGIN UNICAEN_TBL.' . $funcName . '(' . $sqltn . '); END;';
......
......@@ -9,19 +9,8 @@ use UnicaenTbl\Form\ActualisationForm;
echo '<h1 class="page-header">Actualisation de tableau de bord</h1>';
echo $this->messenger()->addCurrentMessagesFromFlashMessenger();
echo $this->form()->openTag($form->prepare());
?>
<div class="row">
<div class="col-md-6"><label>Paramètres</label></div>
<div class="col-md-6"><label>Valeurs</label></div>
</div>
<?php for($i=1;$i<=5;$i++): ?>
<div class="row">
<div class="col-md-6"><?php echo $this->formControlGroup($form->get('c'.$i)) ?></div>
<div class="col-md-6"><?php echo $this->formControlGroup($form->get('v'.$i)) ?></div>
</div>
<?php endfor; ?>
<?php echo $this->formSubmit($form->get('submit'));
echo $this->formControlGroup($form->get('param'));
echo $this->formControlGroup($form->get('value'));
echo $this->formSubmit($form->get('submit'));
echo $this->form()->closeTag();
\ No newline at end of file
......@@ -15,8 +15,6 @@ use UnicaenTbl\Entity\TableauBord;
</style>
<h1 class="page-header">Tableaux de bord internes de calcul intermédiaire</h1>
<?php echo $this->partial('unicaen-tbl/admin/menu', ['active'=> 'index'] ); ?>
<?php foreach ($tbls as $tbl): ?>
<div class="panel panel-default">
<div class="panel-heading">
......
<?php
use UnicaenTbl\Provider\Privilege\Privileges;
/* @var $active string */
$pages = [
'index' => [
'url' => $this->url('unicaen-tbl'),
'label' => 'Liste',
'visible' => $this->isAllowed(Privileges::getResourceId(Privileges::UNICAEN_TBL_ADMIN)),
'popover' => false,
'icon' => 'glyphicon glyphicon-list',
],
'majp' => [
'url' => $this->url('unicaen-tbl/update-actuproc'),
'label' => 'Mise à jour des procédures d\'actualisation',
'visible' => $this->isAllowed(Privileges::getResourceId(Privileges::UNICAEN_TBL_UPDATE_ACTUPROC)),
'popover' => false,
'icon' => 'glyphicon glyphicon-wrench',
],
];
?>
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Menu Tableaux de bord</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Tableaux de bord</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<?php foreach ($pages as $page => $params) {
if ($params['visible']) {
$lip = [];
$ap = [
'href' => $params['url'],
'data-placement' => 'bottom',
];
if ($page == $active) {
$lip['class'] = 'active';
}
if ($params['popover']){
$ap['class'] = 'ajax-popover';
}
echo $this->tag('li', $lip)->html(
$this->tag('a', $ap)->html($this->tag('span',['class' => $params['icon']])->text().' '.$params['label'])
);
}
} ?>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
\ No newline at end of file
<h1 class="page-header">Mise à jour des procédures d'actualisation</h1>
<?php
echo $this->partial('unicaen-tbl/admin/menu', ['active' => 'majp']);
echo $this->messenger()->setMessage($message, \UnicaenApp\View\Helper\Messenger::SUCCESS);
\ No newline at end of file
Markdown is supported
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