Cron et batch

This commit is contained in:
Michael RICOIS 2012-01-15 21:13:32 +00:00
parent b0281df4f7
commit e36a8d52dd
2 changed files with 51 additions and 35 deletions

View File

@ -43,6 +43,24 @@ if(isset($opts->help))
exit;
}
//Traitement des actions
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
$db = Zend_Db::factory($dbConfig);
$commandesM = new Application_Model_Commandes($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->toArray())>0){
exit;
}
//Si pas de traitement en cours alors on lance
$sql = $commandesM->select()
->where('idProfil != ?', 0)
->where("dateStop = '0000-00-00 00:00:00'");
$result = $commandesM->fetchAll($sql, 'dateAdded ASC', 1);
exec(realpath(dirname(__FILE__))."/enrichisement.php --id ".$result->id." &");

View File

@ -28,8 +28,7 @@ try {
//Options
array(
'help|?' => "Aide.",
'ignore=i' => "Nombre de ligne à ignoré.",
'file=s' => "Définir le chemin du fichier",
'id=s' => "Identifiant du traitement",
)
);
$opts->parse();
@ -39,7 +38,7 @@ try {
}
//Usage
if(isset($opts->help) || !isset($opts->file))
if(isset($opts->help) || !isset($opts->id))
{
echo $opts->getUsageMessage();
exit;
@ -225,24 +224,20 @@ $tabDico = array(
'annonces',
),
);
$file = basename($opts->file);
//Définition bdd
$dbConfig = new Zend_Config_Ini(APPLICATION_PATH . '/configs/configuration.ini', 'databases');
$db = Zend_Db::factory($dbConfig);
$commandesM = new Application_Model_Commandes($db);
$commande = $commandesM->find(intval($opts->id));
$file = basename($commande->fichier);
$extension = strrchr($file,'.');
$file = str_replace($extension, '', $file);
$outFile = $file.'-'.date('YmdHis').'.csv';
define('MYSQL_HOST', '192.168.78.230');
define('MYSQL_USER', 'wsuser');
define('MYSQL_PASS', 'scores');
define('MYSQL_DEFAULT_DB', 'jo');
//Définition bdd
$dbConfig = array(
'host' => MYSQL_HOST,
'username' => MYSQL_USER,
'password' => MYSQL_PASS,
'dbname' => MYSQL_DEFAULT_DB,
);
$db = Zend_Db::factory('PDO_MYSQL', $dbConfig);
$profilM = new Application_Model_Profil($db);
$profil = $profilM->find($commande->idProfil);
//Chargement des classes metier
require_once realpath(dirname(__FILE__)).'/../config/config.php';
@ -302,15 +297,19 @@ if (($handle = fopen($opts->file, 'r')) !== FALSE) {
$tabData[$row-1][$colname] = $data[$c];
}
}
}
$row++;
}
fclose($handle);
}
//Ajout des entetes provenant du profil
$profilEntete = json_decode($profil->criteres, true);
$tabExtract = array_merge($tabExtract, $profilEntete);
$nbIdentifiant = count($tabIdentifiant);
echo "Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants.\n";
//echo "Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants.\n";
$rowTotal = $nbIdentifiant;
//Liste des champs SQL
@ -367,10 +366,15 @@ unset($tabExtract);
//Vérification et création des données
$row = 0;
$fp = fopen($outFile, 'w');
if (count($tabEntete)>0){
fputcsv($fp, $tabEntete, ',', '"');
}
$commandesM->update(array('dateStart'=>date('Y-m-d H:i:s')), "id = ".$commande->id);
foreach($tabIdentifiant as $item)
{
echo "Lignes ".($row+1)." / $rowTotal";
$commandesM->update(array('nbLigne'=>$row), "id = ".$commande->id);
$siretValide = false;
$sirenValide = false;
@ -404,8 +408,6 @@ foreach($tabIdentifiant as $item)
$tabData[$row]['SiretValide'] = ($siretValide===true) ? 1 : 0;
if ( $sirenValide===false || intval($siren)==0 ){
echo " - Siren Invalide -";
echo "\n";
$row++;
continue;
}
@ -474,23 +476,19 @@ foreach($tabIdentifiant as $item)
}
}
}
}
echo "\n";
$row++;
}
}
//Mettre dans l'ordre les données
$tabSortie = array();
$row = 0;
foreach($tabData as $data){
//Trier pour la sortie
foreach($tabEntete as $key){
$tabSortie[$row][] = isset($tabData[$row][$key]) ? $tabData[$row][$key] : '';
}
foreach ($tabSortie as $fields) {
fputcsv($fp, $fields, ',', '"');
}
$row++;
}
writeCSV($tabSortie, $tabEntete, $outFile);
fclose($fp);
$commandesM->update(array('dateStop'=>date('Y-m-d H:i:s')), "id = ".$commande->id);
/* == FUNCTION DATA == */