Use exclusively Doctrine/DBAL

This commit is contained in:
Michael RICOIS 2016-11-02 15:27:52 +01:00
parent a716480d11
commit fa604ac26c

View File

@ -87,21 +87,19 @@ if ($opts->cron) {
// --- Lire les fichiers dans sdv1.flux_filein (jalpdfsed/PDF) avec dateExecute = 0
try {
$fileinM = new Application_Model_Sdv1FluxFileIn();
$sql = $fileinM->select()
->where('client=?','jalpdfsed')
->where('name=?', 'PDF')
->where('dateExecute=?','0000-00-00 00:00:00');
$fileResult = $fileinM->fetchAll($sql);
} catch (Zend_Db_Exception $e) {
$fileSql = "SELECT * FROM sdv1.flux_filein WHERE client='jalpdfsed' AND name='PDF'
AND dateExecute='0000-00-00 00:00:00'";
$fileStmt = $conn->executeQuery($fileSql);
}
catch (\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n"; exit;
}
if ( $fileResult === null ) {
if ($fileStmt->rowCount() > 0) {
echo date('Y-m-d H:i:s')." - Aucun fichier à traiter\n";
} else {
foreach( $fileResult as $item) {
}
else {
while($item = $fileStmt->fetch(\PDO::FETCH_OBJ)) {
$fileName = $item->depotFile;
$filePath = $c->profil->path->shared . '/clients/jalpdfsed/send/' . $fileName;
@ -126,10 +124,11 @@ if ($opts->cron) {
$fileDate = date('Ymd', filectime($filePath));
$isInsert = false;
$jalM = new Application_Model_OctdeJalpdfsed();
$sql = $jalM->select()->where('pdfName=?', $fileName);
$exist = $jalM->fetchRow($sql);
if ( $exist === null ) {
$jalSql = "SELECT pdfName FROM octde.jalpdfsed WHERE pdfName=:file";
$jalStmt = $conn->prepare($jalSql);
$jalStmt->bindValue('file', $fileName);
$jalStmt->execute();
if ($jalStmt->rowCount()) {
$data = array(
'pdfName' => $fileName,
'idJalEd' => $idJalEd,
@ -143,24 +142,28 @@ if ($opts->cron) {
);
// --- Renseigner octde.jalpdfsed
try {
$isInsert = $jalM->insert($data);
} catch (Zend_Db_Exception $e) {
$isInsert = $conn->insert('octde.jalpdfsed', $data);
}
catch (\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
continue;
}
} else {
}
else {
$exist = $jalStmt->fetch(\PDO::FETCH_OBJ);
// --- Vérification de la taille des fichiers
if ($fileSize != $exist->pdfSize) {
// --- Renseigner octde.jalpdfsed
try {
$isInsert = $jalM->update(array(
$isInsert = $conn->update('octde.jalpdfsed', array(
'pdfSize' => $fileSize,
'pdfPage' => $filePage,
'pdfVer' => $fileVersion,
'pdfDate' => $fileDate,
'dateDeliver' => '0000-00-00 00:00:00',
), "id=".$exist->id);
} catch (Zend_Db_Exception $e) {
), array('id' => $exist->id));
}
catch (\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
continue;
}
@ -172,8 +175,11 @@ if ($opts->cron) {
if (copy($filePath, $c->profil->path->shared . '/clients/orone/recv/' . $fileName)) {
// --- Definir sdv1.flux_filein dateExecute
try {
$fileinM->update(array('dateExecute' => date('YmdHis')), 'id='.$item->id);
} catch (Zend_Db_Exception $e) {
$conn->update('sdv1.flux_filein', array(
'dateExecute' => date('YmdHis')),
array('id' => $item->id));
}
catch (\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
}
}
@ -199,10 +205,10 @@ if ($opts->deliver || $opts->cron) {
// --- Lire tous les fichiers avec dateDeliver = 0
if ($from == 'db') {
try {
$jalM = new Application_Model_OctdeJalpdfsed();
$sql = $jalM->select()->where('dateDeliver=?', '0000-00-00 00:00:00');
$fileList = $jalM->fetchAll($sql);
} catch(Zend_Db_Exception $e) {
$jalSql = "SELECT * FROM octde.jalpdfsed WHERE dateDeliver = '0000-00-00 00:00:00'";
$jalStmt = $conn->executeQuery($jalSql);
}
catch(\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
}
}
@ -211,19 +217,18 @@ if ($opts->deliver || $opts->cron) {
exit;
}
if ($fileList === null) {
if ($jalStmt->rowCount() == 0) {
echo date('Y-m-d H:i:s')." - Aucun nouveau fichier pour orone\n";
} else {
// --- Envoyer les fichiers pour orone, simplement marquer dans teletransmission
foreach ($fileList as $item) {
while($item = $jalStmt->fetch(\PDO::FETCH_OBJ)) {
echo date('Y-m-d H:i:s')." - Fichier $item->pdfName\n";
$filePath = $c->profil->path->shared . '/clients/orone/recv/' . $item->pdfName;
if ( file_exists($filePath) ) {
if (file_exists($filePath)) {
$isInsert = false;
$size = filesize($filePath);
try {
$fileoutM = new Application_Model_Sdv1FluxFileOut();
$isInsert = $fileoutM->insert(array(
$conn->insert('sdv1.flux_fileout', array(
'client' => 'orone',
'name' => 'PDF',
'nbLines' => 0,
@ -234,7 +239,8 @@ if ($opts->deliver || $opts->cron) {
'depotType' => 'FTP',
'depotDate' => '0000-00-00 00:00:00',
));
} catch (Zend_Db_Exception $e) {
}
catch (\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
continue;
}
@ -242,8 +248,11 @@ if ($opts->deliver || $opts->cron) {
// --- Definir octde.jalpdfsed dateDeliver
if ($isInsert) {
try {
$jalM->update(array('dateDeliver' => date('YmdHis')), 'id='.$item->id);
} catch(Zend_Db_Exception $e) {
$conn->update('octde.jalpdfsed',
array('dateDeliver' => date('YmdHis')),
array('id' => $item->id));
}
catch(\Doctrine\DBAL\DBALException $e) {
echo date('Y-m-d H:i:s')." - ".$e->getMessage()."\n";
}
}