Commit 43fad745 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

Merge branch 'master' of https://git.unicaen.fr/open-source/OSE into ll-formule-lyon2

parents 4d2e415d 4a810520
Loading
Loading
Loading
Loading

code/Contrôle des séquences.php

deleted100755 → 0
+0 −132
Original line number Diff line number Diff line
<?php

/**
 * @var $this       \Application\View\Renderer\PhpRenderer
 * @var $controller \Zend\Mvc\Controller\AbstractController
 * @var $container  \Interop\Container\ContainerInterface
 * @var $viewName   string
 * @var $viewFile   string
 */

$bdd = new \Application\Connecteur\Bdd\BddConnecteur();
$bdd->setEntityManager($container->get(\Application\Constants::BDD));


$tables = getData($bdd);

$tableToModif = isset($_REQUEST['table-to-modif']) ? $_REQUEST['table-to-modif'] : null;

if ($tableToModif && isset($tables[$tableToModif]) && !empty($tables[$tableToModif]['sql'])) {
    foreach ($tables[$tableToModif]['sql'] as $query) {
        $bdd->exec($query);
    }
    die('OK');
}

?>
    <h1>Contrôle des valeurs des séquences</h1>
    <table class="table table-bordered table-condensed table-hover">
        <thead>
        <tr>
            <th>Table</th>
            <th>Séquence</th>
            <th>Séq. val</th>
            <th>Dernier ID</th>
            <th>SQL</th>
        </tr>
        </thead>
        <tbody>
        <?php foreach ($tables as $table => $d): extract($d); ?>
            <tr<?= $probleme ? ' class="bg-danger"' : '' ?>>
                <td><?= $table ?></td>
                <td><?= $sequence ?></td>
                <td><?= $seqVal ?></td>
                <td><?= $maxId ?></td>
                <td>
                    <?php if (!empty($sql)): ?>
                        <button class="btn btn-default btn-maj-seq" data-table="<?= $table ?>">MAJ séquence</button>
                    <?php endif; ?>
                </td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <script>

        $(function ()
        {

            $('.btn-maj-seq').click(function ()
            {
                majSeq($(this).data('table'))
            });

        });

        function majSeq(table)
        {
            var url = '<?= $_SERVER['REQUEST_URI'] ?>';

            $.post(url, {"table-to-modif": table}, function (data)
            {
                alertFlash('Réussi', 'success', 1000);
                window.location.reload();
            }).fail(function (jqXHR)
            {
                alertFlash(jqXHR.responseText, 'danger', 5000);
                console.log(jqXHR);
            });
        }

    </script>
<?php


function getData(Application\Connecteur\Bdd\BddConnecteur $bdd)
{
    $sql = "
    SELECT
      utc.table_name,
      us.sequence_name,
      us.last_number
    FROM
      USER_TAB_COLUMNS utc
      JOIN USER_SEQUENCES us ON us.sequence_name = SUBSTR(utc.table_name,1,23) || '_ID_SEQ'
    WHERE
      utc.column_name = 'ID'
    ";

    $dt = $bdd->fetch($sql, [], 'TABLE_NAME');

    $sqls = [];
    foreach ($dt as $tableName => $d) {
        $sqls[$tableName] = "SELECT '$tableName' table_name, max(id) max_id FROM $tableName";
    }

    $ids = $bdd->fetch(implode(' UNION ', $sqls), [], 'TABLE_NAME');

    $tables = [];
    foreach ($dt as $tableName => $d) {
        $sequence = $d['SEQUENCE_NAME'];
        $seqVal   = (int)$d['LAST_NUMBER'];
        $maxId    = (int)$ids[$tableName]['MAX_ID'];
        $probleme = $seqVal <= $maxId;

        $modifSqls = [];
        if ($maxId - $seqVal >= 0) {
            $modifSqls[] = "ALTER SEQUENCE $sequence INCREMENT BY " . ($maxId - $seqVal + 1);
            $modifSqls[] = "SELECT $sequence.NEXTVAL FROM dual";
            $modifSqls[] = "ALTER SEQUENCE $sequence INCREMENT BY 1";
        }

        $tables[$tableName] = [
            'sequence' => $sequence,
            'seqVal'   => $seqVal,
            'maxId'    => $maxId,
            'probleme' => $probleme,
            'sql'      => $modifSqls,
        ];
    }

    return $tables;
}
 No newline at end of file
+17 −26
Original line number Diff line number Diff line
@@ -7,22 +7,7 @@
 * @var $sl         \Zend\ServiceManager\ServiceLocatorInterface
 */

spl_autoload_register(function ($class) {
    if (0 === strpos($class, 'BddAdmin')) {
        $dir   = dirname(__DIR__) . '/admin/src/';
        $class = $dir . str_replace('\\', '/', $class) . '.php';

        require_once $class;
    }
});

$bdd    = new \BddAdmin\Bdd([
    'host'     => AppConfig::get('bdd', 'host'),
    'port'     => AppConfig::get('bdd', 'port'),
    'dbname'   => AppConfig::get('bdd', 'dbname'),
    'username' => AppConfig::get('bdd', 'username'),
    'password' => AppConfig::get('bdd', 'password'),
]);
$bdd    = adminBdd();
$schema = new \BddAdmin\Schema($bdd);

/*$tables = [
@@ -49,7 +34,7 @@ $schema = new \BddAdmin\Schema($bdd);

$list = [
    'ANNEE', 'INTERVENANT', 'CORPS', 'GRADE', 'GROUPE_TYPE_FORMATION', 'TYPE_FORMATION', 'ETAPE', 'ELEMENT_PEDAGOGIQUE',
'CHEMIN_PEDAGOGIQUE', 'VOLUME_HORAIRE_ENS', 'TYPE_INTERVENTION'
    'CHEMIN_PEDAGOGIQUE', 'VOLUME_HORAIRE_ENS', 'TYPE_INTERVENTION',
];

$tables = [];
@@ -144,7 +129,13 @@ foreach ($cls as $cl) {
                    },
                    new go.Binding("text", "name")),
                $(go.TextBlock,
                    {margin: new go.Margin(0, 5), column: 2,stroke: "#ef9b0b",font: "normal 9px sans-serif", alignment: go.Spot.Left},
                    {
                        margin: new go.Margin(0, 5),
                        column: 2,
                        stroke: "#ef9b0b",
                        font: "normal 9px sans-serif",
                        alignment: go.Spot.Left
                    },
                    new go.Binding("text", "type"))
            );

+16 −5
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@
include_once dirname(__DIR__) . '/module/Application/Application.php';





class AppConfig
{
    const LOCAL_APPLICATION_CONFIG_FILE = __DIR__ . '/../config.local.php';
@@ -52,6 +55,12 @@ class AppConfig
            }
        }

        if (self::$config && $section) {
            if (isset(self::$config[$section])) {
                return self::$config[$section];
            }
        }

        return self::$config;
    }

@@ -143,6 +152,7 @@ class AppConfig
        if (!self::$global) {
            self::$global = self::makeGlobal();
        }

        return self::$global;
    }
}
@@ -152,4 +162,5 @@ class AppConfig


AppConfig::init();

return AppConfig::getGlobal();
 No newline at end of file
+19 −0
Original line number Diff line number Diff line
@@ -108,3 +108,22 @@ function vhlDump(\Application\Entity\VolumeHoraireListe $volumeHoraireListe): \O

    return $dumper;
}


function adminBdd(): \BddAdmin\Bdd
{
    if (!class_exists('BddAdmin\Bdd')) {
        spl_autoload_register(function ($class) {
            if (0 === strpos($class, 'BddAdmin')) {
                $dir   = getcwd() . '/admin/src/';
                $class = $dir . str_replace('\\', '/', $class) . '.php';

                require_once $class;
            }
        });
    }

    $bdd = new BddAdmin\Bdd(AppConfig::get('bdd'));

    return $bdd;
}
 No newline at end of file