issue #0001708 : Batch AltiScore

This commit is contained in:
Michael RICOIS 2013-09-16 15:24:13 +00:00
parent 4b7f7471ab
commit d7e9f0a268
2 changed files with 172 additions and 13 deletions

View File

@ -34,23 +34,62 @@ class IndexController extends Zend_Controller_Action
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
require_once 'Scores/WsScores.php';
//'login' and 'hach' detecte from AuthAdapter
$user = new Scores_Utilisateur();
$login = $user->getLogin();
$idClient = $user->getIdClient();
$request = $this->getRequest();
$version = $request->getParam('v', 1);
$ws = new WsScores();
$reponse = $ws->getPortefeuilleCsv($login, $idClient);
if (intval($version) == 2) {
$log = Zend_Registry::get('config')->profil->path->data.'/log/altisys.log';
$log = Zend_Registry::get('config')->profil->path->data.'/log/altisys.log';
$user = new Scores_Utilisateur();
$login = $user->getLogin();
$idClient = $user->getIdClient();
$file = 'listesurv-score-'.$login.'-'.$idClient.'.csv';
$content_type = 'application/csv-tab-delimited-table';
$c = Zend_Registry::get('config');
$path = realpath($c->profil->path->files).'/';
//Envoi du fichier sur la sortie standard
if ( file_exists($path.$file) ) {
header('Content-Transfer-Encoding: none');
header('Content-type: ' . $content_type.'');
header('Content-Length: ' . filesize($path.$file));
header('Content-MD5: ' . base64_encode(md5_file($path.$file)));
header('Content-Disposition: filename="' . basename($path.$file) . '"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression', '0');
echo file_get_contents($path.$file);
file_put_contents($log, date('Y-m-d H:i:s')." APPEL ALTISYS - OK $file\n", FILE_APPEND);
} else {
echo 'Impossible de charger le fichier.';
file_put_contents($log, date('Y-m-d H:i:s')." APPEL ALTISYS - ERREUR $file\n", FILE_APPEND);
}
} else {
require_once 'Scores/WsScores.php';
$user = new Scores_Utilisateur();
$login = $user->getLogin();
$idClient = $user->getIdClient();
$ws = new WsScores();
$reponse = $ws->getPortefeuilleCsv($login, $idClient);
$log = Zend_Registry::get('config')->profil->path->data.'/log/altisys.log';
if ($reponse === false){
file_put_contents($log, date('Y-m-d H:i:s')." - URL = ERREUR\n", FILE_APPEND);
echo "Erreur";
} elseif (!empty($reponse->result->Url)) {
file_put_contents($log, date('Y-m-d H:i:s')." - URL = ".$reponse->result->Url."\n", FILE_APPEND);
echo $reponse->result->Url;
}
if ($reponse === false){
file_put_contents($log, date('Y-m-d H:i:s')." - URL = ERREUR\n", FILE_APPEND);
echo "Erreur";
} elseif (!empty($reponse->result->Url)) {
file_put_contents($log, date('Y-m-d H:i:s')." - URL = ".$reponse->result->Url."\n", FILE_APPEND);
echo $reponse->result->Url;
}
}

View File

@ -0,0 +1,120 @@
<?php
// Define path to application directory
defined('APPLICATION_PATH')
|| define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
// Define application environment
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('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|?' => "Affiche l'aide.",
'cron' => "Mandatory for automatic mode",
'get=s' => "Relance la commande pour un login",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(count($opts->getOptions())==0 || isset($opts->help))
{
echo "Demande et télécharge le portefeuille au format csv pour le client";
echo "\n\n";
echo $opts->getUsageMessage();
echo "\n";
exit;
}
$c = new Zend_Config($application->getOptions());
Zend_Registry::set('config', $c);
//Liste des logins avec leur hash
$logins = array(
'kpun1' => 'd21346ccbcf24c6a69ed01f82e04cc39',
'olymp2' => 'a1b7d26be20e7bc7ee5daa05bafda09c',
'efood' => 'c04a8b5249ed0deaac0b55c8c7719dd6',
'groupmsurv' => '7405a5afba5a1e5f27982eb22d2bf542',
'initialadm' => '041c15646e425682859e396734ec2240',
'paprec1' => 'e8854054f29792d67a5c43bbb764653e',
);
if ( $opts->get ) {
if ( in_array($opts->get, array(array_keys($logins))) ) {
$logins = array($opts->get => $logins[$opts->get]);
}
}
require_once 'Scores/WsScores.php';
foreach ($logins as $login => $hash ) {
echo date('Y-m-dTH:i:s') . " - Login : " . $login;
$ws = new WsScores($login, $hash);
//Faire la demande du protefeuille en CSV,
$response = $ws->getPortefeuilleCsv($login);
if ( $response !== false ) {
//Wait for the file
sleep(10);
$url = $response->result->Url;
echo " URL = " . $url;
$file = basename($url);
$path = $c->profil->path->files;
//Télécharger le fichier
try {
$client = new Zend_Http_Client($url);
$client->setStream();
$response = $client->request('GET');
if ( copy($response->getStreamName(), $path . DIRECTORY_SEPARATOR . $file) ) {
echo " - Fichier créer.";
}
} catch (Zend_Http_Client_Exception $e) {
echo " - Erreur ".$e->getMessage();
}
}
echo PHP_EOL;
}