Commit c33fb177 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Scripts de migration v18 quasi OK

Restent les paramétrages de plafonds à injecter une fois la MAJ faite
parent 6a810ea1
Loading
Loading
Loading
Loading
+2 −2
Changes for admin/actions/test.php: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
<?php

require_once dirname(__DIR__) . '/migration/v18.php';
require_once dirname(__DIR__) . '/migration/v18Plafonds.php';

$mm  = new MigrationManager($oa, new \BddAdmin\Ddl\Ddl(), []);
$v18 = new v18($mm);
$v18 = new v18Plafonds($mm);

$v18->before();
 No newline at end of file
+51
Changes for admin/migration/v18Divers.php: 51 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php





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



    public function description(): string
    {
        return "Migration OSE 17 vers OSE 18";
    }



    public function utile(): bool
    {
        return $this->manager->hasNew('table', 'PLAFOND_PERIMETRE');
    }



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



    public function before()
    {
        $bdd = $this->manager->getBdd();
        $c   = $this->manager->getOseAdmin()->getConsole();

        try {
            $bdd->exec("ALTER TABLE TYPE_INTERVENANT DROP CONSTRAINT TYPE_INTERVENANT_CODE_UN");
            $c->msg('Suppression de la contrainte TYPE_INTERVENANT_CODE_UN en prévision de sa recréation');
        } catch (\Exception $e) {
            // rien à faire : la contrainte a déjà du être supprimée
        }
    }

}
 No newline at end of file
+98
Changes for admin/migration/v18Plafonds.php: 98 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php





class v18Plafonds extends AbstractMigration
{
    protected $contexte = self::CONTEXTE_ALL;



    public function description(): string
    {
        return "Migration des plafonds de OSE 17 vers OSE 18";
    }



    public function utile(): bool
    {
        return $this->manager->hasNew('table', 'PLAFOND_PERIMETRE');
    }



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



    public function before()
    {
        $bdd = $this->manager->getBdd();
        $c   = $this->manager->getOseAdmin()->getConsole();

        if (empty($bdd->table()->get('SAVE_V18_STATUT'))) {
            $this->manager->sauvegarderTable('STATUT_INTERVENANT', 'SAVE_V18_STATUT');
            $c->msg('Anciens statuts "STATUT_INTERVENANT" sauvegardés dans "SAVE_V18_STATUT".');
        }

        if (empty($bdd->table()->get('SAVE_V18_STRUCTURE'))) {
            $this->manager->sauvegarderTable('STRUCTURE', 'SAVE_V18_STRUCTURE');
            $c->msg('Anciennes structures "STRUCTURE" sauvegardés dans "SAVE_V18_STRUCTURE".');
        }

        if (empty($bdd->table()->get('SAVE_V18_REFERENTIEL'))) {
            $this->manager->sauvegarderTable('FONCTION_REFERENTIEL', 'SAVE_V18_REFERENTIEL');
            $c->msg('Anciennes fonctions référentielles "FONCTION_REFERENTIEL" sauvegardées dans "SAVE_V18_REFERENTIEL".');
        }

        if (empty($bdd->table()->get('SAVE_V18_PLAFOND_APP'))) {
            $this->manager->sauvegarderTable('PLAFOND_APPLICATION', 'SAVE_V18_PLAFOND_APP');
            $c->msg('Anciens paramétrages des plafonds "PLAFOND_APPLICATION" sauvegardées dans "SAVE_V18_PLAFOND_APP".');
        }

        if (!empty($bdd->table()->get('PLAFOND_APPLICATION'))) {
            $bdd->exec('DROP TABLE PLAFOND_APPLICATION');
            $c->msg('Suppression des anciens paramétrages de plafonds');
        }

        if (empty($bdd->table()->get('SAVE_V18_PLAFOND'))) {
            $this->manager->sauvegarderTable('PLAFOND', 'SAVE_V18_PLAFOND');
            $c->msg('Anciens plafonds "PLAFOND" sauvegardées dans "SAVE_V18_PLAFOND".');
        }

        if (!empty($bdd->table()->get('PLAFOND'))) {
            $bdd->exec('DROP TABLE PLAFOND');
            $c->msg('Suppression des anciens plafonds');
        }
    }



    protected function after()
    {
        
    }



    public function preMigrationIndicateurs()
    {
        $bdd = $this->manager->getBdd();
        $c   = $this->manager->getOseAdmin()->getConsole();

        $c->begin('Préparation à la mise à jour des indicateurs');

        $c->end('Préparation à la migration des indicateurs terminée');
    }

}
 No newline at end of file
+88 −7
Changes for admin/migration/v18Statuts.php: 88 added lines, 7 removed lines.
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@



class v18 extends AbstractMigration
class v18Statuts extends AbstractMigration
{
    protected $contexte = self::CONTEXTE_ALL;

@@ -12,15 +12,14 @@ class v18 extends AbstractMigration

    public function description(): string
    {
        return "Migration de OSE 17 vers OSE 18";
        return "Migration des statuts de OSE 17 vers OSE 18";
    }



    public function utile(): bool
    {
        return $this->manager->hasOld('table', 'STATUT_INTERVENANT')
            && $this->manager->hasNew('table', 'STATUT');
        return $this->manager->hasOld('table', 'STATUT_INTERVENANT');
    }


@@ -38,19 +37,85 @@ class v18 extends AbstractMigration

    public function before()
    {
        try {
            $this->preMigrationIndicateurs();
        } catch (\Exception $e) {
        }

        try {
            $this->preMigrationStatuts();
        } catch (\Exception $e) {
        }

        try {
            $this->preMigrationIntervenants();
        } catch (\Exception $e) {
        }

        try {
            $this->preMigrationDossiers();
        } catch (\Exception $e) {
        }

        try {
            $this->preMigrationTypePieceJointeStatuts();
        } catch (\Exception $e) {
        }

        try {
            $this->preMigrationTypeInterventionStatuts();
        } catch (\Exception $e) {
        }

        $bdd = $this->manager->getBdd();
        $c   = $this->manager->getOseAdmin()->getConsole();

        $ddl = $bdd->table()->get('TBL_WORKFLOW')['TBL_WORKFLOW'];
        if (isset($ddl['columns']['STATUT_ID'])) {
            $bdd->exec('DROP TABLE TBL_WORKFLOW');
            $c->msg('Suppression de la table TBL_WORKFLOW, qui sera recréée au nouveau format');
        }

        $ddl = $bdd->table()->get('MODELE_CONTRAT')['MODELE_CONTRAT'];
        if (!isset($ddl['columns']['STATUT_ID'])) {
            $bdd->exec("ALTER TABLE MODELE_CONTRAT RENAME COLUMN STATUT_INTERVENANT_ID TO STATUT_ID");
            $c->msg('Colonne MODELE_CONTRAT.STATUT_INTERVENANT_ID renommée en STATUT_ID');

            try {
                $bdd->exec("ALTER TABLE MODELE_CONTRAT DROP CONSTRAINT MCT_STATUT_INTERVENANT_FK");
            } catch (\Exception $e) {
                // rien à faire : la contrainte a déjà du être supprimée
            }

            $res = $bdd->select("
            SELECT
              mc.id, MIN(s.id) statut_id
            FROM
              modele_contrat mc
              JOIN SAVE_V18_STATUT old_s ON old_s.id = mc.statut_id
              JOIN statut s ON s.code = old_s.code AND s.histo_destruction IS NULL
            WHERE 
              mc.statut_id IS NOT NULL
            GROUP BY
              mc.id
            ");
            if (0 !== count($res)) {
                foreach ($res as $r) {
                    $bdd->exec("UPDATE MODELE_CONTRAT SET statut_id = :statutId WHERE id = :id", [
                        'statutId' => (int)$r['STATUT_ID'],
                        'id'       => (int)$r['ID'],
                    ]);
                }
                $c->msg('Association entre les modèles de contrats et les statuts mise à jour');
            }
        }
    }



    protected function after()
    {
        echo 'youyoud';

    }


@@ -88,6 +153,16 @@ class v18 extends AbstractMigration
            $c->msg('Anciens statuts "STATUT_INTERVENANT" sauvegardés dans "SAVE_V18_STATUT".');
        }

        if (empty($bdd->table()->get('SAVE_V18_STATUT_PRIVILEGE'))) {
            $this->manager->sauvegarderTable('STATUT_PRIVILEGE', 'SAVE_V18_STATUT_PRIVILEGE');
            $c->msg('Anciens statuts "STATUT_PRIVILEGE" sauvegardés dans "SAVE_V18_STATUT_PRIVILEGE".');
        }

        if (empty($bdd->table()->get('SAVE_V18_TA_STATUT'))) {
            $this->manager->sauvegarderTable('TYPE_AGREMENT_STATUT', 'SAVE_V18_TA_STATUT');
            $c->msg('Anciens statuts "TYPE_AGREMENT_STATUT" sauvegardés dans "SAVE_V18_TA_STATUT".');
        }


        /* Modifications préalables à faire en BDD */
        if (empty($bdd->sequence()->get('STATUT_ID_SEQ'))) {
@@ -198,7 +273,7 @@ class v18 extends AbstractMigration
          sp.statut_id statut_id,
          cp.code || '-' || p.code privilege
        FROM 
          statut_privilege sp
          SAVE_V18_STATUT_PRIVILEGE sp
          JOIN privilege p ON p.id = sp.privilege_id
          JOIN categorie_privilege cp ON cp.id = p.categorie_id
        ");
@@ -219,7 +294,7 @@ class v18 extends AbstractMigration
          tas.statut_intervenant_id statut_id,
          COALESCE(tas.duree_vie,99) duree_vie
        FROM 
          type_agrement_statut  tas
          SAVE_V18_TA_STATUT  tas
          JOIN type_agrement ta ON ta.id = tas.type_agrement_id
        WHERE 
          tas.histo_destruction is null
@@ -505,6 +580,12 @@ class v18 extends AbstractMigration
            $c->msg("Vidage de la table \"TYPE_PIECE_JOINTE_STATUT\" avant d'insérer les nouveaux paramètres");
        }

        try {
            $bdd->exec("ALTER TABLE TYPE_PIECE_JOINTE_STATUT DROP CONSTRAINT TPJS_STATUT_INTERVENANT_FK");
        } catch (\Exception $e) {
            // rien à faire : la contrainte a déjà du être supprimée
        }

        /* Modifications au niveau de la table TPJS */
        $ddl = $bdd->table()->get('TYPE_PIECE_JOINTE_STATUT')['TYPE_PIECE_JOINTE_STATUT'];
        if (!isset($ddl['columns']['ANNEE_ID'])) {
+1 −1
Changes for admin/src/OseAdmin.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ class OseAdmin
                    $vb = (int)$b;
                }

                if ($va == $vb) return $a > $b;
                if ($va == $vb) return 1;

                return $va - $vb;
            });
Loading