webservice/scripts/jobs/getActesAsso.php

165 lines
4.9 KiB
PHP
Raw Normal View History

2013-11-05 11:18:30 +00:00
<?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(),
)));
2014-02-07 16:14:36 +00:00
//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',
2014-06-11 08:10:03 +00:00
'SdMetier' => __DIR__ . '/../../library/SdMetier',
2014-02-07 16:14:36 +00:00
'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'
);
2013-11-05 11:18:30 +00:00
$c = new Zend_Config($application->getOptions());
Zend_Registry::set('config', $c);
require_once 'WsScore/Configure.php';
$oldconfig = new Configure();
try {
$opts = new Zend_Console_Getopt(
//Options
array(
'help|?' => "Aide.",
)
);
$opts->parse();
} catch (Zend_Console_Getopt_Exception $e) {
echo $e->getUsageMessage();
exit;
}
//Usage
if(isset($opts->help))
{
echo $opts->getUsageMessage();
exit;
}
function getFilePdf($url, $file)
{
$result = true;
$fp = fopen($file, 'w');
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp);
$data = curl_exec($ch);
// Check if any error occured
if(curl_errno($ch))
{
$result = false;
}
curl_close($ch);
fclose($fp);
return $result;
}
$reportSubject = '';
$reportMsg = '';
//Lire la base de données - Récupérer les éléments sans fichier
//Connect to the database
try {
$db = Zend_Db::factory($this->dbConfig->db->jo);
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
} catch (Zend_Exception $e) {
}
$baseUrl = 'http://extranetrec.scores-decisions.com/fichier/pdfassociation/actes/';
$path = SECURE_STORAGE . 'associations/actes/';
//Lecture des données
$acteM = new Application_Model_AssoActes($db);
$sql = $acteM->select()->where('pdfLink=?', '');
$acteList = $acteM->fetchAll($sql);
if ($acteList->count()>0) {
foreach ($acteList->toArray() as $item) {
$date = substr($item['date_acte'],0,4).substr($item['date_acte'],5,2).substr($item['date_acte'],8,2);
if (intval($item['siren'])==0) {
$file = 'ST-'.$item['waldec'].'-'.$date;
} else {
$file = 'ST-'.$item['siren'].'-'.$date;
}
//Télécharger le fichier
$isDownload = getFilePdf($baseUrl.$file, $path.$file);
if ($isDownload && file_exists($path.$file)) {
//Récupérer les informations du PDF
$pdfInfos = array();
$pdfInfos['pdfLink'] = $file;
$pdfInfos['pdfSize'] = filesize($path.$file);
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
//Get PDF version
$handle = fopen($path.$file, 'r');
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, 4096);
if (preg_match("/^\%PDF\-(.*)\s/U", $buffer, $matches)) {
$version = $matches[1];
}
break;
}
fclose($handle);
}
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
$pdfInfos['pdfVer'] = $version;
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
//Get PDF number of pages
$pdf = new Zend_Pdf($path.$file, null, true);
$pdfInfos['pdfPage'] = count($pdf->pages);
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
//Modifier la ligne dans la base de données
$acteM->update($pdfInfos, 'id='.$item['id']);
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
}
}
}
2014-02-07 16:14:36 +00:00
$reportMsg = "\n-= CLI getActesAsso.";
2013-11-05 11:18:30 +00:00
//Envoyer un mail de rapport
$mail = new Zend_Mail();
$tr = new Zend_Mail_Transport_Smtp('smtp.celeste.fr');
$mail->setDefaultTransport($tr);
$mail->setFrom('production@scores-decisions.com', 'Production');
$mail->addTo('support@scores-decisions.com', 'Support');
$mail->setSubject($reportSubject);
$mail->setBodyText(mb_convert_encoding($reportMsg, 'ISO-8859-1', 'UTF-8'));
$mail->send();