Compare commits
4 Commits
cc2ee726c0
...
8e8136a818
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8e8136a818 | ||
|
|
093df5de53 | ||
|
|
603b76e1aa | ||
|
|
6f9290dfaa |
@@ -16,7 +16,7 @@ $where_clause = 'WHERE 1 = 1';
|
|||||||
|
|
||||||
$sql = '
|
$sql = '
|
||||||
WITH arbre (parent, id, link, code, name, level, path) AS (
|
WITH arbre (parent, id, link, code, name, level, path) AS (
|
||||||
SELECT 0, id, link, code, libelle, 0, "{0} [" || id || "]"
|
SELECT 0, id, link, code, libelle, 0, "{" || plugin || "} [" || id || "]"
|
||||||
FROM v_items_tree WHERE parent IS NULL
|
FROM v_items_tree WHERE parent IS NULL
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
141
bin/import_09_marches.php
Normal file
141
bin/import_09_marches.php
Normal file
@@ -0,0 +1,141 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once('smeti_db.inc.php');
|
||||||
|
|
||||||
|
SMETI_db::init();
|
||||||
|
|
||||||
|
echo 'Chargement collectivités ';
|
||||||
|
$sql = SMETI_db::$pdo->prepare("SELECT code, item, libelle FROM v_items WHERE plugin = ( SELECT id FROM plugins WHERE libelle = 'Collectivités' )");
|
||||||
|
$sql->execute();
|
||||||
|
$coll = $sql->fetchAll(PDO::FETCH_NUM);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$libelle = 'Marchés';
|
||||||
|
|
||||||
|
echo 'VACUUM ';
|
||||||
|
SMETI_db::removePlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout du plugin '$libelle' ";
|
||||||
|
SMETI_db::addPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Plugin courant : '$libelle' ";
|
||||||
|
SMETI_db::setCurPlugin($libelle);
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
echo "Ajout d'une racine: '$libelle' ";
|
||||||
|
// Ajouter un item
|
||||||
|
SMETI_db::$libelle = $libelle;
|
||||||
|
SMETI_db::$code = 'MARC';
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Ajouter un lien sur cet item
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
// Positionner ce lien comme parent
|
||||||
|
SMETI_db::$parent = SMETI_db::$item;
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
$pile_index = 0;
|
||||||
|
$pile_code[$pile_index] = SMETI_db::$code;
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$item;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
|
||||||
|
echo 'Chargement des données'.PHP_EOL;
|
||||||
|
$counter = 0;
|
||||||
|
$shipments = json_decode(file_get_contents("../data/json/BMO/09_MARCHES.json"), true);
|
||||||
|
$nb_shipments = count($shipments);
|
||||||
|
foreach($shipments as $element)
|
||||||
|
{
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
progressBar($counter, $nb_shipments);
|
||||||
|
// Gestion d'une barre de progression
|
||||||
|
|
||||||
|
// On ne reprend pas les vieux marchés
|
||||||
|
if (($element['marcdatlim']/10000) < 2019) continue;
|
||||||
|
|
||||||
|
// A-t-on changé de collectivité ?
|
||||||
|
if ($element['collcod'] != $pile_code[$pile_index-1])
|
||||||
|
{
|
||||||
|
// chercher la collectivité
|
||||||
|
$n = count($coll);
|
||||||
|
for($i=0;$i<$n;$i++)
|
||||||
|
if ($element['collcod'] == $coll[$i][0])
|
||||||
|
break;
|
||||||
|
if ($i == $n) continue;
|
||||||
|
// Revenir au niveau 'plugin' de la pile
|
||||||
|
$pile_index -= 2;
|
||||||
|
|
||||||
|
// Ajout d'un lien (symbolique)
|
||||||
|
SMETI_db::$link = 1;
|
||||||
|
SMETI_db::$item = $coll[$i][1];
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Ajout d'un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
|
||||||
|
// Conserver ce noeud dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['collcod'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
|
||||||
|
// Rajouter un élément vide dans la pile
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = '';
|
||||||
|
$pile_item[$pile_index] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// A-t-on changé de Catégorie de famille ?
|
||||||
|
if ($element['marcann'] != $pile_code[$pile_index])
|
||||||
|
{
|
||||||
|
// Dépiler
|
||||||
|
$pile_index -= 1;
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = 'MARC'.$pile_code[$pile_index].$element['mpcacod'];
|
||||||
|
SMETI_db::$libelle = 'Marchés '.$element['marcann'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
// Empiler
|
||||||
|
$pile_index += 1;
|
||||||
|
$pile_code[$pile_index] = $element['marcann'];
|
||||||
|
$pile_item[$pile_index] = SMETI_db::$child;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rajouter un item
|
||||||
|
SMETI_db::$code = sprintf("%04d%06d",$element['marcnum'],$element['marcnum']);
|
||||||
|
SMETI_db::$libelle = $element['marcobj'];
|
||||||
|
SMETI_db::$req1->execute();
|
||||||
|
// Rajouter un lien
|
||||||
|
SMETI_db::$item = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$link = 0;
|
||||||
|
SMETI_db::$req2->execute();
|
||||||
|
// Rajouter un noeud
|
||||||
|
SMETI_db::$child = SMETI_db::$pdo->lastInsertId();
|
||||||
|
SMETI_db::$parent = $pile_item[$pile_index];
|
||||||
|
SMETI_db::$req3->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enlever la barre de progression
|
||||||
|
clearLine();
|
||||||
|
// Enlever la barre de progression
|
||||||
|
|
||||||
|
echo 'OK'.PHP_EOL;
|
||||||
|
|
||||||
|
?>
|
||||||
@@ -3,4 +3,8 @@ sqlite3 ../data/$1 < ../data/SQL/init.sql
|
|||||||
for script in import_??_*.php
|
for script in import_??_*.php
|
||||||
do
|
do
|
||||||
php $script ../data/$1
|
php $script ../data/$1
|
||||||
|
if [ $? -ne 0 ];
|
||||||
|
then
|
||||||
|
break
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|||||||
1
data/.gitignore
vendored
Normal file
1
data/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.sqlite
|
||||||
BIN
data/base.sqlite
BIN
data/base.sqlite
Binary file not shown.
Reference in New Issue
Block a user