121 lines
2.7 KiB
PHP
121 lines
2.7 KiB
PHP
<?php
|
|
// --- Define path to application directory
|
|
defined('APPLICATION_PATH')
|
|
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
|
|
|
|
// --- Define application environment
|
|
defined('APPLICATION_ENV')
|
|
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
|
|
|
|
// --- Composer autoload
|
|
require_once realpath(__DIR__ . '/../../vendor/autoload.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',
|
|
'groupmsurv' => '7405a5afba5a1e5f27982eb22d2bf542',
|
|
'initialadm' => '041c15646e425682859e396734ec2240',
|
|
'paprec1' => '582a6470d2fb8a44c8c7ad6387f56bd4',
|
|
'cerba1 ' => '78d178eff3744f534aa0346265e0fd20',
|
|
);
|
|
|
|
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;
|
|
|
|
try {
|
|
$ws = new WsScores($login, $hash);
|
|
} catch(Exception $e) {
|
|
echo " - Erreur ".$e->getMessage()."\n";
|
|
continue;
|
|
}
|
|
|
|
//Faire la demande du protefeuille en CSV,
|
|
try {
|
|
$response = $ws->getPortefeuilleCsv($login);
|
|
} catch(Exception $e) {
|
|
echo " - Erreur ".$e->getMessage()."\n";
|
|
continue;
|
|
}
|
|
|
|
if ( $response !== false ) {
|
|
|
|
//Wait for the file
|
|
sleep(10);
|
|
|
|
$url = $response->result->Url;
|
|
|
|
echo " URL = " . $url;
|
|
|
|
$file = basename($url);
|
|
$path = $c->profil->path->shared.'/files';
|
|
|
|
//Télécharger le fichier
|
|
try {
|
|
$client = new Zend_Http_Client($url);
|
|
$client->setStream();
|
|
$response = $client->request('GET');
|
|
if ( copy($response->getStreamName(), $path . '/' . $file) ) {
|
|
echo " - Fichier créer.";
|
|
}
|
|
} catch (Zend_Http_Client_Exception $e) {
|
|
echo " - Erreur ".$e->getMessage();
|
|
}
|
|
|
|
}
|
|
|
|
echo "\n";
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|