Commit 9b5df35a authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

On tient compte de l'ordre des colonnes des vues automatiquement

A la mise à jour, les tables des TBLs mal ordonnancé&es sont droppées
parent 01e83ff4
Loading
Loading
Loading
Loading
+19
Changes for admin/actions/update-ddl.php: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -29,6 +29,25 @@ if (file_exists($colPosFile)) {
} else {
    $positions = [];
}

$sql = "SELECT 
  tbl.table_name,
  tc.column_name,
  COALESCE(vc.column_id,0) + 1 position  
FROM 
  tbl
  JOIN user_tab_columns tc ON tc.table_name = tbl.table_name
  LEFT JOIN user_tab_columns vc ON vc.table_name = tbl.view_name AND tc.column_name = vc.column_name
WHERE 
  tbl.table_name IS NOT NULL AND tbl.view_name IS NOT NULL
ORDER BY
  tbl.view_name,
  position";
$dd  = $oa->getBdd()->select($sql);
foreach ($dd as $d) {
    $positions[$d['TABLE_NAME']][$d['POSITION'] - 1] = $d['COLUMN_NAME'];
}

$positions = $ddl->applyColumnPositions($positions);
$ddl->writeArray($colPosFile, $positions);
$c->end('Positionnement de colonnes à jour');
+76
Changes for admin/migration/OrdonnancementColonnesTbl.php: 76 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php





class OrdonnancementColonnesTbl extends AbstractMigration
{
    protected $contexte = self::CONTEXTE_PRE;

    protected $tbls     = [];



    public function description(): string
    {
        return "Suppression de tableaux de bord dont l'ordonnancement des colonnes a changé";
    }



    public function utile(): bool
    {
        $bdd = $this->manager->getBdd();

        $colPosFile  = $this->manager->getOseAdmin()->getOseDir() . 'data/ddl_columns_pos.php';
        $colonnesPos = require $colPosFile;

        $sql = "SELECT 
              tbl.table_name,
              tc.column_name,
              tc.column_id position  
            FROM 
              tbl
              JOIN user_tab_columns tc ON tc.table_name = tbl.table_name
            WHERE 
              tbl.table_name IS NOT NULL AND tbl.view_name IS NOT NULL";

        $tblcs      = $bdd->select($sql);
        $this->tbls = [];
        foreach ($tblcs as $tc) {
            $table = $tc['TABLE_NAME'];
            $col   = $tc['COLUMN_NAME'];
            $pos   = ((int)$tc['POSITION']) - 1;
            if (isset($colonnesPos[$table][$pos])) {
                if ($col != $colonnesPos[$table][$pos]) {
                    $this->tbls[$table] = true;
                }
            }
        }

        return count($this->tbls) > 0;
    }



    public function action(string $contexte)
    {
        if ($contexte == self::CONTEXTE_PRE) {
            $this->before();
        }
    }



    protected function before()
    {
        $bdd = $this->manager->getBdd();

        foreach ($this->tbls as $table => $null) {
            $bdd->table()->drop($table);
        }
    }

}
+19 −19
Changes for data/ddl/table/TBL_SERVICE.php: 19 added lines, 19 removed lines.
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 4,
            'position'    => 2,
            'commentaire' => NULL,
        ],
        'ELEMENT_PEDAGOGIQUE_HISTO'      => [
@@ -30,7 +30,7 @@ return [
            'precision'   => 1,
            'nullable'    => FALSE,
            'default'     => '1',
            'position'    => 17,
            'position'    => 15,
            'commentaire' => NULL,
        ],
        'ELEMENT_PEDAGOGIQUE_ID'         => [
@@ -42,7 +42,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 11,
            'position'    => 9,
            'commentaire' => NULL,
        ],
        'ELEMENT_PEDAGOGIQUE_PERIODE_ID' => [
@@ -54,7 +54,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 13,
            'position'    => 11,
            'commentaire' => NULL,
        ],
        'ETAPE_HISTO'                    => [
@@ -66,7 +66,7 @@ return [
            'precision'   => 1,
            'nullable'    => FALSE,
            'default'     => '1',
            'position'    => 18,
            'position'    => 16,
            'commentaire' => 'Témoin (1 si l\'étape est supprimée)',
        ],
        'ETAPE_ID'                       => [
@@ -78,7 +78,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 14,
            'position'    => 12,
            'commentaire' => NULL,
        ],
        'HAS_HEURES_MAUVAISE_PERIODE'    => [
@@ -90,7 +90,7 @@ return [
            'precision'   => 1,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 19,
            'position'    => 17,
            'commentaire' => 'Témoin (1 si heures saisies au mauvais semestre)',
        ],
        'HEURES'                         => [
@@ -102,7 +102,7 @@ return [
            'precision'   => 126,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 2,
            'position'    => 19,
            'commentaire' => 'NB d\'heures saisi',
        ],
        'ID'                             => [
@@ -126,7 +126,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 5,
            'position'    => 3,
            'commentaire' => NULL,
        ],
        'INTERVENANT_STRUCTURE_ID'       => [
@@ -138,7 +138,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 6,
            'position'    => 4,
            'commentaire' => NULL,
        ],
        'NBVH'                           => [
@@ -150,7 +150,7 @@ return [
            'precision'   => 126,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 20,
            'position'    => 18,
            'commentaire' => 'Nombre de volumes horaires saisis',
        ],
        'PEUT_SAISIR_SERVICE'            => [
@@ -162,7 +162,7 @@ return [
            'precision'   => 1,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 10,
            'position'    => 8,
            'commentaire' => NULL,
        ],
        'SERVICE_ID'                     => [
@@ -174,7 +174,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 12,
            'position'    => 10,
            'commentaire' => NULL,
        ],
        'STRUCTURE_ID'                   => [
@@ -186,7 +186,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 7,
            'position'    => 5,
            'commentaire' => NULL,
        ],
        'TYPE_INTERVENANT_CODE'          => [
@@ -198,7 +198,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 9,
            'position'    => 7,
            'commentaire' => NULL,
        ],
        'TYPE_INTERVENANT_ID'            => [
@@ -210,7 +210,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 8,
            'position'    => 6,
            'commentaire' => NULL,
        ],
        'TYPE_VOLUME_HORAIRE_CODE'       => [
@@ -222,7 +222,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 16,
            'position'    => 14,
            'commentaire' => NULL,
        ],
        'TYPE_VOLUME_HORAIRE_ID'         => [
@@ -234,7 +234,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 15,
            'position'    => 13,
            'commentaire' => NULL,
        ],
        'VALIDE'                         => [
@@ -246,7 +246,7 @@ return [
            'precision'   => 126,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 3,
            'position'    => 20,
            'commentaire' => 'Nombre de volumes horaires validés',
        ],
    ],
+8 −8
Changes for data/ddl/table/TBL_VALIDATION_REFERENTIEL.php: 8 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 5,
            'position'    => 2,
            'commentaire' => NULL,
        ],
        'AUTO_VALIDATION'        => [
@@ -30,7 +30,7 @@ return [
            'precision'   => 1,
            'nullable'    => FALSE,
            'default'     => '0',
            'position'    => 3,
            'position'    => 8,
            'commentaire' => 'Témoin (0 ou 1)',
        ],
        'ID'                     => [
@@ -54,7 +54,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 6,
            'position'    => 3,
            'commentaire' => NULL,
        ],
        'SERVICE_REFERENTIEL_ID' => [
@@ -66,7 +66,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 9,
            'position'    => 6,
            'commentaire' => NULL,
        ],
        'STRUCTURE_ID'           => [
@@ -78,7 +78,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 7,
            'position'    => 4,
            'commentaire' => NULL,
        ],
        'TYPE_VOLUME_HORAIRE_ID' => [
@@ -90,7 +90,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 8,
            'position'    => 5,
            'commentaire' => NULL,
        ],
        'VALIDATION_ID'          => [
@@ -102,7 +102,7 @@ return [
            'precision'   => NULL,
            'nullable'    => TRUE,
            'default'     => NULL,
            'position'    => 4,
            'position'    => 9,
            'commentaire' => 'Si validé',
        ],
        'VOLUME_HORAIRE_REF_ID'  => [
@@ -114,7 +114,7 @@ return [
            'precision'   => NULL,
            'nullable'    => FALSE,
            'default'     => NULL,
            'position'    => 2,
            'position'    => 7,
            'commentaire' => NULL,
        ],
    ],
+2 −2
Changes for data/ddl_columns_pos.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -1457,8 +1457,6 @@ return [
    ],
    'TBL_SERVICE'                    => [
        'ID',
        'HEURES',
        'VALIDE',
        'ANNEE_ID',
        'INTERVENANT_ID',
        'INTERVENANT_STRUCTURE_ID',
@@ -1476,6 +1474,8 @@ return [
        'ETAPE_HISTO',
        'HAS_HEURES_MAUVAISE_PERIODE',
        'NBVH',
        'HEURES',
        'VALIDE',
    ],
    'TBL_SERVICE_REFERENTIEL'        => [
        'ID',