webservice/scripts/jobs/getActesAsso.php

134 lines
3.7 KiB
PHP
Raw Normal View History

2013-11-05 11:18:30 +00:00
<?php
2015-09-17 19:57:13 +00:00
// --- Define path to application directory
2013-11-05 11:18:30 +00:00
defined('APPLICATION_PATH')
2015-09-17 19:57:13 +00:00
|| define('APPLICATION_PATH', realpath(__DIR__ . '/../../application'));
2013-11-05 11:18:30 +00:00
2015-09-17 19:57:13 +00:00
// --- Define application environment
2013-11-05 11:18:30 +00:00
defined('APPLICATION_ENV')
|| define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));
2015-09-17 19:57:13 +00:00
// --- Ensure library/ is on include_path
2013-11-05 11:18:30 +00:00
set_include_path(implode(PATH_SEPARATOR, array(
2015-09-17 19:57:13 +00:00
realpath(APPLICATION_PATH . '/../../library'),
get_include_path(),
2013-11-05 11:18:30 +00:00
)));
2015-09-17 19:57:13 +00:00
require_once realpath(__DIR__ . '/../../vendor/autoload.php');
2014-02-07 16:14:36 +00:00
2015-09-17 19:57:13 +00:00
// --- Create application, bootstrap, and run
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
2014-02-07 16:14:36 +00:00
2013-11-05 11:18:30 +00:00
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 = '';
2015-07-03 13:28:52 +00:00
$c = new Zend_Config($application->getOptions());
2013-11-05 11:18:30 +00:00
//Lire la base de données - Récupérer les éléments sans fichier
//Connect to the database
try {
2015-07-03 13:28:52 +00:00
$db = Zend_Db::factory($c->profil->db->metier);
2013-11-05 11:18:30 +00:00
$db->getConnection();
} catch (Zend_Db_Adapter_Exception $e) {
} catch (Zend_Exception $e) {
}
$baseUrl = 'http://extranetrec.scores-decisions.com/fichier/pdfassociation/actes/';
2015-07-03 13:28:52 +00:00
$path = $c->profil->path->secure . '/associations/actes/';
2013-11-05 11:18:30 +00:00
//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
2015-07-03 13:28:52 +00:00
$mail = new Scores_Mail_Method($c->profil->mail);
2013-11-05 11:18:30 +00:00
$mail->setFrom('production@scores-decisions.com', 'Production');
$mail->addTo('support@scores-decisions.com', 'Support');
2015-07-03 13:28:52 +00:00
$mail->setSubjectC($reportSubject);
$mail->setBodyTextC($reportMsg);