extranet/scripts/jobs/getAltiScore.php
2015-06-12 10:05:20 +00:00

142 lines
3.6 KiB
PHP

<?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(),
)));
//Use classmap autoloader - useful with opcode and realpath cache
require_once 'Zend/Loader/AutoloaderFactory.php';
require_once 'Zend/Loader/ClassMapAutoloader.php';
Zend_Loader_AutoloaderFactory::factory(array(
'Zend_Loader_ClassMapAutoloader' => array(
__DIR__ . '/../../library/Zend/autoload_classmap.php',
__DIR__ . '/../../library/Application/autoload_classmap.php',
__DIR__ . '/../../library/Scores/autoload_classmap.php',
__DIR__ . '/../../application/autoload_classmap.php',
),
'Zend_Loader_StandardAutoloader' => array(
'prefixes' => array(
'Zend' => __DIR__ . '/../../library/Zend',
'Application' => __DIR__ . '/../../library/Application',
'Scores' => __DIR__ . '/../../library/Scores',
'Metier' => __DIR__ . '/../../library/Metier',
),
'fallback_autoloader' => true
)
));
// Zend_Application - Use it if you don't have autoloaders
//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',
'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;
$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 "\n";
}