Ajout traitement par fichier
This commit is contained in:
parent
c891e32acb
commit
5ddbce7e70
@ -28,7 +28,8 @@ try {
|
||||
//Options
|
||||
array(
|
||||
'help|?' => "Aide.",
|
||||
'id=s' => "Identifiant du traitement",
|
||||
'id=s' => "Identifiant du traitement",
|
||||
'file=s' => "Traitement manuel avec spécification du fichier"
|
||||
)
|
||||
);
|
||||
$opts->parse();
|
||||
@ -38,7 +39,7 @@ try {
|
||||
}
|
||||
|
||||
//Usage
|
||||
if(isset($opts->help) || !isset($opts->id))
|
||||
if(isset($opts->help) || !isset($opts->id) || !isset($opts->file) )
|
||||
{
|
||||
echo $opts->getUsageMessage();
|
||||
exit;
|
||||
@ -233,9 +234,13 @@ try {
|
||||
exit ( $e->getMessage() );
|
||||
}
|
||||
|
||||
$commandesM = new Application_Model_Commandes($db);
|
||||
$commande = $commandesM->find(intval($opts->id))->current();
|
||||
$file = basename($commande->fichier);
|
||||
if ($opts->id) {
|
||||
$commandesM = new Application_Model_Commandes($db);
|
||||
$commande = $commandesM->find(intval($opts->id))->current();
|
||||
$file = basename($commande->fichier);
|
||||
} else {
|
||||
$file = $opts->file;
|
||||
}
|
||||
$extension = strrchr($file,'.');
|
||||
$file = str_replace($extension, '', $file);
|
||||
|
||||
@ -244,8 +249,11 @@ if (!file_exists($path->data.'/export')) mkdir($path->data.'/export');
|
||||
$outFile = $path->data.'/export/'.$file.'-'.date('YmdHis').'.csv';
|
||||
$inFile = $path->data.'/clients/'.$file.'.csv';
|
||||
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
$profil = $profilM->find($commande->idProfil)->current();
|
||||
if ($opts->id) {
|
||||
$profilM = new Application_Model_Profil($db);
|
||||
$profil = $profilM->find($commande->idProfil)->current();
|
||||
$profilEntete = json_decode($profil->criteres, true);
|
||||
}
|
||||
|
||||
//Chargement des classes metier
|
||||
require_once realpath(dirname(__FILE__)).'/../config/config.php';
|
||||
@ -328,8 +336,9 @@ if (($handle = fopen($inFile, 'r')) !== FALSE) {
|
||||
}
|
||||
|
||||
//Ajout des entetes provenant du profil
|
||||
$profilEntete = json_decode($profil->criteres, true);
|
||||
$tabExtract = array_merge($tabExtract, $profilEntete);
|
||||
if ($opts->id) {
|
||||
$tabExtract = array_merge($tabExtract, $profilEntete);
|
||||
}
|
||||
|
||||
$nbIdentifiant = count($tabIdentifiant);
|
||||
//echo "Chargement de $row lignes dont $nbIdentifiant lignes avec identifiants.\n";
|
||||
@ -393,7 +402,9 @@ $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);
|
||||
if ($opts->id) {
|
||||
$commandesM->update(array('dateStart'=>date('Y-m-d H:i:s')), "id = ".$commande->id);
|
||||
}
|
||||
foreach($tabIdentifiant as $item)
|
||||
{
|
||||
echo "Ligne $row\n";
|
||||
@ -509,11 +520,17 @@ foreach($tabIdentifiant as $item)
|
||||
fputcsv($fp, $fields, ',', '"');
|
||||
}
|
||||
$row++;
|
||||
|
||||
//Mise à jour des lignes traitées dans la base
|
||||
$commandesM->update(array('nbLigneT'=>$row), "id = ".$commande->id);
|
||||
if ($opts->id) {
|
||||
$commandesM->update(array('nbLigneT'=>$row), "id = ".$commande->id);
|
||||
}
|
||||
}
|
||||
fclose($fp);
|
||||
$commandesM->update(array('dateStop'=>date('Y-m-d H:i:s')), "id = ".$commande->id);
|
||||
if ($opts->id) {
|
||||
$commandesM->update(array('dateStop'=>date('Y-m-d H:i:s')), "id = ".$commande->id);
|
||||
}
|
||||
|
||||
|
||||
/* == FUNCTION DATA == */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user