batch/1.1/old/testUpdateLogs.php
2013-06-19 08:24:49 +00:00

103 lines
3.7 KiB
PHP
Raw Blame History

#!/usr/bin/php -c/var/www/batch/config/php_batch_sd.ini
<?php
error_reporting(E_ALL & ~E_NOTICE);
include_once(FWK_PATH.'common/chiffres.php');
include_once(FWK_PATH.'common/dates.php');
include_once(INCLUDE_PATH.'insee/classMInsee.php');
include_once(INCLUDE_PATH.'insee/classMSirene.php');
include_once(INCLUDE_PATH.'partenaires/classMBilans.php');
include_once(INCLUDE_PATH.'partenaires/classMBourse.php');
include_once(INCLUDE_PATH.'partenaires/classMLiens.php');
include_once(INCLUDE_PATH.'scores/classMFinancier.php');
include_once(INCLUDE_PATH.'scores/classMSolvabilite.php');
include_once(INCLUDE_PATH.'partenaires/classMTva.php');
include_once(INCLUDE_PATH.'partenaires/classMMap.php');
include_once(INCLUDE_PATH.'partenaires/classMGreffes.php');
include_once(INCLUDE_PATH.'tmp/configMRatios.php');
include_once(INCLUDE_PATH.'scores/classMScores.php');
include_once(FWK_PATH.'mail/sendMail.php');
include_once(INCLUDE_PATH.'scores/classMRegression.php');
//$iDb=new WDB('jo');
$iDb=new WDB('sdv1');
$iDb2=new WDB('sdv1');
$tabUser=array();
$argv=$_SERVER['argv'];
if (trim($argv[1])<>'') $strClient=" AND idClient=".$argv[1];
else $strClient='';
$tabUtis=$iDb->select('utilisateurs',
"login, idClient",
"1 $strClient", false, MYSQL_ASSOC);
foreach ($tabUtis as $tabUti) {
$tabUser['_'.$tabUti['login']]=$tabUti['idClient'];
}
$nbCpt=count($tabUser);
foreach ($tabUser as $login=>$idClient) {
$iCpt++;
$login=substr($login,1);
if ($iCpt<128) continue;
$tabLogs=$iDb->select( 'logs',
"count(*) AS nb",
"login='$login' AND page='identite' AND source IN(0,5)", false, MYSQL_ASSOC);
$nbLim=$tabLogs[0]['nb'];
for ($iLim=0;$iLim<=$nbLim;$iLim+=100000) {
echo date('Y/m/d H:i:s')." - Compte $iCpt/$nbCpt : Traitement de '$login' $iLim/$nbLim ... ";
$tabLogs=$iDb->select( 'logs',
"id, login, page, siren, nic, params, idClient, test, actifInsee, source, raisonSociale, cp, ville, dateHeure*1 AS dateHeure",
"login='$login' AND page='identite' AND source IN(0,5) LIMIT $iLim,100000", false, MYSQL_ASSOC);
$nb=count($tabLogs);
if ($nb==0) break;
echo "$nb logs <20> traiter".EOL;
foreach ($tabLogs as $tabLog) {
$idLog=$tabLog['id'];
$siren=$tabLog['siren'];
$nic=$tabLog['nic'];
$ref=$tabLogs['params'];
if ($idClient==0 || $idClient==1 || $idClient==122 || $idClient==123) $test=1;
else $test=0;
$tabRdvInsee=array();
if ($siren>1000 && $nic>9) $strNic=" AND nic=$nic ";
elseif ($siren==0 && $ref>0) $strNic=" AND id=$ref ";
elseif ($siren>1000) $strNic=" AND siege=1 ORDER BY actif DESC, nic DESC ";
else continue;
$rep=$iDb2->select('jo.etablissements', 'siren, nic, actif, siege, raisonSociale, adr_cp, adr_ville, source', "siren=$siren $strNic", false, MYSQL_ASSOC);
$tabRep=$rep[0];
$rs= $tabRep['raisonSociale'];
$cp= $tabRep['adr_cp'];
$vil=$tabRep['adr_ville'];
$tabRdvInsee['source']=$tabRep['source'];
if ($tabRep['actif']==0) {
$tabRdvInsee['actifInsee']=0;
} else {
$tabRdvInsee['actifInsee']=1;
if ($siren>1000 && $tabLog['dateHeure']>20090921000000) {
$rep=$iDb2->select('jo.rncs_entrep', 'count(*) AS nb', "siren=$siren", false, MYSQL_ASSOC);
$tabRep=$rep[0];
if ($tabRep['nb']>0) $tabRdvInsee['source']=5;
}
}
$tabUpdate=array_merge($tabRdvInsee,
array( 'idClient' => $idClient,
'test' => $test,
'raisonSociale' => $rs,
'cp' => $cp,
'ville' => $vil,
'dateHeure' => $tabLog['dateHeure'],
));
//print_r($tabLog);
//print_r($tabUpdate);
//die();
$iDb2->update('logs', $tabUpdate, "id=$idLog");
}
}
}
?>