Suppression du répertoire batch (voir scripts/jobs)
This commit is contained in:
parent
d28ba0de01
commit
1d827af35a
@ -1,70 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|
||||
// Define application environment
|
||||
define('APPLICATION_ENV', 'production');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Aide.",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help))
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
|
||||
$db = Zend_Db::factory($dbConfig->db);
|
||||
|
||||
$commandesM = new Application_Model_EnrichissementIdentifiants($db);
|
||||
|
||||
$sql = $commandesM->select()
|
||||
->where('idProfil != ?', 0)
|
||||
->where("dateStart != '0000-00-00 00:00:00'")
|
||||
->where("dateStop = '0000-00-00 00:00:00'");
|
||||
$result = $commandesM->fetchAll($sql);
|
||||
if (count($result)>0){
|
||||
exit;
|
||||
}
|
||||
|
||||
//Si pas de traitement en cours alors on lance
|
||||
$sql = $commandesM->select()
|
||||
->where('idProfil != ?', 0)
|
||||
->where("dateStart = '0000-00-00 00:00:00'")
|
||||
->where("dateStop = '0000-00-00 00:00:00'")
|
||||
->order('dateAdded ASC')->limit(1);
|
||||
$result = $commandesM->fetchAll($sql);
|
||||
if (count($result)>0) {
|
||||
$info = $result->current();
|
||||
echo "Lancement enrichissement $info->id\n";
|
||||
exec(realpath(dirname(__FILE__))."/enrichissement.php --id ".$info->id." &");
|
||||
}
|
@ -1,246 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
|
||||
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|
||||
// Define application environment
|
||||
define('APPLICATION_ENV', 'production');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Aide.",
|
||||
'id=s' => "Identifiant du traitement",
|
||||
'file=s' => "Identifiant pour les traitements par fichier"
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help) || !isset($opts->id) && !isset($opts->file) )
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/configuration.ini');
|
||||
|
||||
//MetadataCache pour la base de données
|
||||
$frontendOptions = array(
|
||||
'lifetime' => 14400,
|
||||
'automatic_serialization' => true
|
||||
);
|
||||
$backendOptions = array();
|
||||
$cache = Zend_Cache::factory('Core','Apc', $frontendOptions, $backendOptions);
|
||||
Zend_Db_Table_Abstract::setDefaultMetadataCache($cache);
|
||||
|
||||
//Définition bdd
|
||||
try {
|
||||
$db = Zend_Db::factory($config->databases->db);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
//Définition bdd metier
|
||||
try {
|
||||
$dbMetier = Zend_Db::factory($config->databases->jo);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
|
||||
$liste = array();
|
||||
|
||||
if ($opts->id)
|
||||
{
|
||||
//Read SIRETs
|
||||
$commandesM = new Application_Model_EnrichissementIdentifiants($db);
|
||||
$commande = $commandesM->find(intval($opts->id))->current();
|
||||
$identifiants = json_decode($commande->identifiants, true);
|
||||
|
||||
//Read profil for data extract
|
||||
$profilM = new Application_Model_EnrichissementProfils($db);
|
||||
$profil = $profilM->find(intval($commande->idProfil))->current();
|
||||
$dataProfil = json_decode($profil->criteres, true);
|
||||
}
|
||||
else if ($opts->file)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//Something is needed
|
||||
if ( count($identifiants)==0 || count($dataProfil)==0 ) {
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
//Let's go
|
||||
$mois = substr($commande->dateAdded,0,4).substr($commande->dateAdded,5,2);
|
||||
|
||||
if(!file_exists($config->path->data.'/'.$mois))
|
||||
mkdir($config->path->data.'/'.$mois);
|
||||
|
||||
$path = $config->path->data.'/'.$mois;
|
||||
$outFile = $profil['login'].'_'.$opts->id.'_'.date('YmdHis').'.csv';
|
||||
|
||||
require_once 'Scores/Enrichissement.php';
|
||||
$dico = new Enrichissement();
|
||||
$fields = $dico->getFields();
|
||||
|
||||
//Entete, Valeur de remplacement et Requete SQL
|
||||
$tabEntete = array('siren', 'nic');
|
||||
$tabEnteteLabel = array('SIREN', 'NIC');
|
||||
$sql = 'SELECT LPAD(siren, 9, 000000000) AS siren, LPAD(nic,5,00000) AS nic,';
|
||||
foreach ( $dataProfil as $item ) {
|
||||
//Définition de l'entete
|
||||
$tabEnteteLabel[] = $fields[$item]['label'];
|
||||
$tabEntete[] = $item;
|
||||
|
||||
//Construction de la requete SQL
|
||||
if ( array_key_exists('sql', $fields[$item]) ) {
|
||||
$sql.= ' '.$fields[$item]['sql'].', ';
|
||||
} else {
|
||||
$sql.= ' '.$fields[$item]['column'].' AS '.$item.',';
|
||||
}
|
||||
}
|
||||
//Ajouter le champ presentRcs
|
||||
$tabEntete[] = 'presentRcs';
|
||||
$tabEnteteLabel[] = 'RCS';
|
||||
$sql .= ' presentRcs';
|
||||
|
||||
//Pour chaque identifiant traiter les données
|
||||
$row = 0;
|
||||
$fp = fopen($path.'/'.$outFile, 'w');
|
||||
//Ecrire l'entete
|
||||
if (count($tabEnteteLabel)>0){
|
||||
fputcsv($fp, $tabEnteteLabel, ',', '"');
|
||||
}
|
||||
//Mise à jour des éléments
|
||||
if ($opts->id) {
|
||||
$commandesM->update(array(
|
||||
'dateStart'=>date('Y-m-d H:i:s'),
|
||||
'fichier' => basename($outFile)
|
||||
),
|
||||
"id = ".$commande->id);
|
||||
}
|
||||
|
||||
$model = $sql;
|
||||
$traite = 0;
|
||||
//Date de debut de traitement.
|
||||
$dateStart = date('YmdHms');
|
||||
foreach ($identifiants as $siret )
|
||||
{
|
||||
$sql = $model.' FROM etablissements_act WHERE siren='.substr($siret,0,9).' AND nic='.substr($siret,9,5);
|
||||
try {
|
||||
$result = $dbMetier->fetchAll($sql);
|
||||
$traite++;
|
||||
} catch(Exception $e) {
|
||||
echo $sql;
|
||||
}
|
||||
$tabData = $result[0];
|
||||
//Trier pour la sortie
|
||||
$tabSortie = array();
|
||||
foreach($tabEntete as $key){
|
||||
$tabSortie[] = isset($tabData[$key]) ? $tabData[$key] : '';
|
||||
}
|
||||
fputcsv($fp, $tabSortie, ',', '"');
|
||||
|
||||
//Mise à jour des lignes traitées dans la base
|
||||
if ($opts->id) {
|
||||
$commandesM->update(array('nbLigneTraites'=>$row), "id = ".$commande->id);
|
||||
}
|
||||
|
||||
$row++;
|
||||
}
|
||||
fclose($fp);
|
||||
if ($opts->id) {
|
||||
$commandesM->update( array('dateStop' => date('Y-m-d H:i:s')) , "id = ".$commande->id);
|
||||
}
|
||||
|
||||
|
||||
/* == FUNCTION == */
|
||||
|
||||
/**
|
||||
* Verifie si un SIREN est valide
|
||||
* @param Le code SIREN dont on veut vérifier la validité.
|
||||
* @return Un booléen qui vaut 'true' si le code SIREN passé en
|
||||
* paramètre est valide, false sinon.
|
||||
*/
|
||||
function sirenValide($siren) {
|
||||
if ( (strlen($siren) != 9) || (is_nan($siren)) )
|
||||
$estValide = false;
|
||||
else {
|
||||
// Donc le SIREN est un numérique à 9 chiffres
|
||||
$somme = 0;
|
||||
$tmp = 0;
|
||||
for ($cpt = 0; $cpt<strlen($siren); $cpt++) {
|
||||
if (($cpt % 2) == 1) { // Les positions paires : 2ème, 4ème, 6ème et 8ème chiffre
|
||||
$tmp = substr($siren, $cpt, 1) * 2; // On le multiplie par 2
|
||||
if ($tmp > 9)
|
||||
$tmp-= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
||||
}
|
||||
else
|
||||
$tmp = substr($siren, $cpt, 1);
|
||||
$somme+= intval($tmp);
|
||||
}
|
||||
if (($somme % 10) == 0)
|
||||
$estValide = true; // Si la somme est un multiple de 10 alors le SIREN est valide
|
||||
else
|
||||
$estValide = false;
|
||||
}
|
||||
return $estValide;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifie si un SIRET est valide
|
||||
* @param Le code SIRET dont on veut vérifier la validité.
|
||||
* @return Un booléen qui vaut 'true' si le code SIRET passé en
|
||||
* paramètre est valide, false sinon.
|
||||
*/
|
||||
function siretValide($siret) {
|
||||
if ( (strlen($siret) != 14) || (is_nan($siret)) )
|
||||
$estValide = false;
|
||||
else {
|
||||
// Donc le SIRET est un numérique à 14 chiffres
|
||||
// Les 9 premiers chiffres sont ceux du SIREN (ou RCS), les 4 suivants
|
||||
// correspondent au numéro d'établissement
|
||||
// et enfin le dernier chiffre est une clef de LUHN.
|
||||
$somme = 0;
|
||||
$tmp = 0;
|
||||
for ($cpt = 0; $cpt<strlen($siret); $cpt++) {
|
||||
if (($cpt % 2) == 0) { // Les positions impaires : 1er, 3è, 5è, etc...
|
||||
$tmp = substr($siret, $cpt, 1) * 2; // On le multiplie par 2
|
||||
if ($tmp > 9)
|
||||
$tmp-= 9; // Si le résultat est supérieur à 9, on lui soustrait 9
|
||||
}
|
||||
else
|
||||
$tmp = substr($siret, $cpt, 1);
|
||||
$somme+= intval($tmp);
|
||||
}
|
||||
if (($somme % 10) == 0)
|
||||
$estValide = true; // Si la somme est un multiple de 10 alors le SIRET est valide
|
||||
else
|
||||
$estValide = false;
|
||||
}
|
||||
return $estValide;
|
||||
}
|
@ -1,228 +0,0 @@
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|
||||
// Define application environment
|
||||
define('APPLICATION_ENV', 'production');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
require_once APPLICATION_PATH . '/../library/Zend/Loader/Autoloader.php';
|
||||
|
||||
Class extract
|
||||
{
|
||||
protected $db;
|
||||
protected $dbMetier;
|
||||
protected $reference;
|
||||
|
||||
public function __construct($reference)
|
||||
{
|
||||
$this->reference = $reference;
|
||||
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
|
||||
try {
|
||||
$this->db = Zend_Db::factory($dbConfig->db);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
}
|
||||
|
||||
public function getHttp()
|
||||
{
|
||||
/* Depuis le navigateur */
|
||||
}
|
||||
|
||||
protected function getCj($liste)
|
||||
{
|
||||
foreach($liste as $valeur)
|
||||
{
|
||||
if(strlen($valeur) < 5) {
|
||||
$sql = $this->db->select('formejuridique', array('fjCode'))
|
||||
->from('formejuridique')
|
||||
->where('fjCode LIKE "'.$valeur.'%"');
|
||||
} else {
|
||||
$sql = $this->db->select('formejuridique', array('fjCode'))
|
||||
->from('formejuridique')
|
||||
->where('fjCode = "'.$valeur.'"');
|
||||
}
|
||||
$result = $this->db->fetchAll($sql);
|
||||
foreach ($result as $code) {
|
||||
if(strlen($code['fjCode']) > 2) {
|
||||
$return[] = $code['fjCode'];
|
||||
}
|
||||
}
|
||||
}
|
||||
return ($return);
|
||||
}
|
||||
|
||||
protected function localisationArbo($name, $valeur)
|
||||
{
|
||||
if(strlen($valeur) == 2) {
|
||||
switch($name) {
|
||||
case 'adr_reg':
|
||||
$return = array();
|
||||
$sql = $this->db->select()
|
||||
->from('departements')
|
||||
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
|
||||
->where('codeRegionInsee ='.$valeur);
|
||||
$result = $this->db->fetchAll($sql);
|
||||
foreach ($result as $res) {
|
||||
$return[] = trim($res['INSEE']);
|
||||
}
|
||||
break;
|
||||
case 'adr_dept':
|
||||
$return = array();
|
||||
$sql = $this->db->select()
|
||||
->from('departements')
|
||||
->join(array('cp' => 'codepostaux'), 'cp.codepos LIKE CONCAT(departements.numdep, "%")', array('INSEE'))
|
||||
->where('numdep ='.$valeur);
|
||||
$result = $this->db->fetchAll($sql);
|
||||
foreach ($result as $res) {
|
||||
$return[] = trim($res['INSEE']);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ($return);
|
||||
}
|
||||
|
||||
public function getMinMax($name, $valeur)
|
||||
{
|
||||
$valeur = explode(',', $valeur);
|
||||
if(count($valeur) > 1)
|
||||
{
|
||||
$sql = 'SELECT min, max FROM minmax WHERE cle ="'.$name.'"';
|
||||
$result = $this->db->query($sql);
|
||||
$result = $result->fetchAll();
|
||||
if(empty($valeur[0])){
|
||||
echo $name;
|
||||
$valeur[0] = $result[0]['min'];
|
||||
}
|
||||
if(empty($valeur[1])){
|
||||
$valeur[1] = $result[0]['max'];
|
||||
}
|
||||
}
|
||||
return ($valeur);
|
||||
}
|
||||
|
||||
protected function nafArbo($key, $valeur)
|
||||
{
|
||||
$value = array();
|
||||
$valeur = trim($valeur);
|
||||
|
||||
if(strlen($valeur) == 1)
|
||||
{
|
||||
$sql = 'SELECT * FROM naf WHERE parent ='.$valeur;
|
||||
$result =$this->db->query($sql);
|
||||
$result = $result->fetchAll();
|
||||
foreach($result as $code) $where .= " code LIKE '".trim($code['code'])."%' and niveau = 5 or ";
|
||||
$where = substr($where, 0, (strlen($where)) - 3);
|
||||
$sql = 'SELECT * FROM naf '.$where;
|
||||
$result = $this->db->query($sql);
|
||||
$result = $result->fetchAll();
|
||||
foreach($result as $code) $value[] = $code['code'];
|
||||
} else if(strlen($valeur) < 5){
|
||||
//$sql = $table->select()->where('code LIKE "'.trim($valeur).'%" and niveau = 5');
|
||||
$sql = 'SELECT * FROM naf WHERE code LIKE "'.trim($valeur).'%" and niveau = 5';
|
||||
$result = $this->db->query($sql);
|
||||
$result = $result->fetchAll();
|
||||
foreach($result as $code) $value[] = $code['code'];
|
||||
} else if(strlen($valeur) == 5) {
|
||||
$value[] = $valeur;
|
||||
}
|
||||
return ($value);
|
||||
}
|
||||
|
||||
public function getCli()
|
||||
{
|
||||
require_once('Scores/Ciblage.php');
|
||||
//require_once('Scores/Field.php');
|
||||
|
||||
$sql = 'SELECT id, idDefinition, uniteInsee FROM comptages WHERE id = '.$this->reference;
|
||||
$fetch = $this->db->query($sql);
|
||||
$result = $fetch->fetchAll();
|
||||
$idComptage = $result[0]['id'];
|
||||
$uniteInsee = $result[0]['uniteInsee'];
|
||||
|
||||
$sql = 'SELECT id, criteres.criteres FROM criteres WHERE id ='.$result[0]['idDefinition'];
|
||||
$fetch = $this->db->query($sql);
|
||||
$result = $fetch->fetchAll();
|
||||
$idCriteres = $result[0]['id'];
|
||||
|
||||
$structure = json_decode($result[0]['criteres']);
|
||||
$element = array();
|
||||
foreach ($structure as $name => $valeur){
|
||||
if($name == 'adr_com') {
|
||||
$liste = explode(',', $valeur);
|
||||
$codes = array();
|
||||
foreach ($liste as $element) {
|
||||
$val = explode(':', $element);
|
||||
if(!empty($val[1]))
|
||||
$codes = array_merge($this->localisationArbo($val[0], $val[1]), $codes);
|
||||
}
|
||||
$array['adr_com'] = $codes;
|
||||
}
|
||||
else if($name == 'cj') {
|
||||
$array['cj'] = $this->getCj(explode(',', $valeur));
|
||||
}
|
||||
else if($name == 'ape_etab') {
|
||||
$values = array();
|
||||
$nafs = explode(',', $structure->ape_etab);
|
||||
foreach($nafs as $naf) {
|
||||
if($naf != ' ') {
|
||||
$values = array_merge($values, $this->nafArbo('ape_etab', $naf));
|
||||
}
|
||||
}
|
||||
$array['ape_etab'] = $values;
|
||||
}else {
|
||||
$valeur = $this->getMinMax($name, $valeur);
|
||||
$array[$name] = $valeur;
|
||||
}
|
||||
}
|
||||
unset($array['vil']);
|
||||
unset($array['adr_com']);
|
||||
unset($array['adr_dept']);
|
||||
$array['bilTca'] = array(4, 5, 6);
|
||||
$ciblage = new Ciblage($array, true);
|
||||
$res = $ciblage->execute(true);
|
||||
|
||||
$data = array(
|
||||
'idComptage' => $idComptage,
|
||||
'idCriteres' => $idCriteres,
|
||||
'idProfil' => 1,
|
||||
'reference' => 'batch',
|
||||
'identifiants' => json_encode($res),
|
||||
'nbLigneTotales' => count($res),
|
||||
'nbLigneTraites' => count($res),
|
||||
'uniteInsee' => $uniteInsee,
|
||||
'error' => 0
|
||||
);
|
||||
$this->db->insert('enrichissement_identifiants',$data);
|
||||
$fd = fopen($idComptage.'_batch'.date('Y-m-d-hms').'.csv', 'x+');
|
||||
try {
|
||||
$array = array();
|
||||
foreach($res as $field) {
|
||||
fputcsv($fd, array($field), ';');
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
fclose($fd);
|
||||
echo count($res).' Success !';
|
||||
}
|
||||
}
|
||||
|
||||
$a = new extract('38');
|
||||
$a->getCli();
|
@ -1,110 +0,0 @@
|
||||
#!/usr/bin/php
|
||||
<?php
|
||||
// Define path to application directory
|
||||
defined('APPLICATION_PATH')
|
||||
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
|
||||
|
||||
// Define application environment
|
||||
define('APPLICATION_ENV', 'production');
|
||||
|
||||
// Ensure library/ is on include_path
|
||||
set_include_path(implode(PATH_SEPARATOR, array(
|
||||
realpath(APPLICATION_PATH . '/../library'),
|
||||
get_include_path(),
|
||||
)));
|
||||
|
||||
/** Zend_Application */
|
||||
require_once 'Zend/Application.php';
|
||||
|
||||
// Create application, bootstrap, and run
|
||||
$application = new Zend_Application(
|
||||
APPLICATION_ENV,
|
||||
APPLICATION_PATH . '/configs/application.ini'
|
||||
);
|
||||
|
||||
try {
|
||||
$opts = new Zend_Console_Getopt(
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Aide.",
|
||||
'cron' => "Mode automatique",
|
||||
'manuel' => "Mode manuel",
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
} catch (Zend_Console_Getopt_Exception $e) {
|
||||
echo $e->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help))
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
}
|
||||
|
||||
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
|
||||
try {
|
||||
$db = Zend_Db::factory($dbConfig->db);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
//Définition bdd metier
|
||||
try {
|
||||
$dbMetier = Zend_Db::factory($dbConfig->jo);
|
||||
} catch ( Exception $e ) {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
|
||||
$keys = array(
|
||||
'dateCrea_ent',
|
||||
'dateCrea_etab',
|
||||
'nbActio',
|
||||
'nbPart',
|
||||
'age_etab',
|
||||
'age_entrep',
|
||||
'nbEtab',
|
||||
'eff_entrep',
|
||||
'eff_etab',
|
||||
'capital',
|
||||
'dateImmat',
|
||||
'bilAnnee',
|
||||
'bilCloture',
|
||||
'bilEE',
|
||||
'bilFL',
|
||||
'bilFK',
|
||||
'bilFR',
|
||||
'bilGF',
|
||||
'bilGP',
|
||||
'bilGW',
|
||||
'bilHD',
|
||||
'bilHH',
|
||||
'bilHL',
|
||||
'bilHM',
|
||||
'bilHN',
|
||||
'bilYP',
|
||||
);
|
||||
|
||||
$sql = 'TRUNCATE TABLE fields_minmax';
|
||||
if ( !$db->query($sql) ) {
|
||||
die ('Impossible de vider la table fields_minmax');
|
||||
}
|
||||
|
||||
foreach($keys as $key) {
|
||||
|
||||
//Lecture
|
||||
$sql = 'SELECT MIN('.$key.') AS min, MAX('.$key.') AS max FROM etablissements_act';
|
||||
$stmt = $dbMetier->query($sql);
|
||||
$result = $stmt->fetchObject();
|
||||
|
||||
//Insertion
|
||||
$data = array(
|
||||
'cle' => $key,
|
||||
'min' => $result->min,
|
||||
'max' => $result->max,
|
||||
);
|
||||
$db->insert('fields_minmax', $data);
|
||||
if ($opts->manuel) echo $key.' -> min:'.$result->min.' max:'.$result->max."\n";
|
||||
}
|
||||
if ($opts->manuel) print("Terminé\n");
|
Loading…
Reference in New Issue
Block a user