Skip to content
Snippets Groups Projects
Commit 81c49dc8 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

rel #21286 : prepare to migrate one cosmogramme integration phase in object mode

parent d04013cb
Branches
Tags
3 merge requests!780Master,!755Stable,!750Hotline#21286 holds not deleted with full import
......@@ -82,7 +82,7 @@ abstract class Class_Cosmogramme_FileParser {
public function _goto($position) {
if ($this->_file_handle && $position > 0)
$fileSystem->fseek($this->_file_handle, $position);
$this->getFileSystem()->fseek($this->_file_handle, $position);
return $this;
}
......
......@@ -91,5 +91,10 @@ class Class_Cosmogramme_Integration extends Storm_Model_Abstract {
return [];
return unserialize(stripslashes($this->getWarnings()));
}
public function isPergame() {
return $this->getBib()->isPergame();
}
}
?>
\ No newline at end of file
......@@ -21,6 +21,8 @@
class Class_Cosmogramme_Integration_PhaseReservation {
use Trait_TimeSource;
protected $_phase, $_log, $_printer, $_chrono, $_is_time_out;
protected $_label = 'Intégration des fichiers de réservations';
......@@ -75,7 +77,8 @@ class Class_Cosmogramme_Integration_PhaseReservation {
$this->_headerOf($integration);
$this->_cleanIfTotal($integration);
$parser = Class_Cosmogramme_FileParser::openFor(Class_CosmoVar::get('integration_path') . $integration->getFichier(),
$file_path = Class_CosmoVar::get('integration_path') . $integration->getFichier();
$parser = Class_Cosmogramme_FileParser::openFor($file_path,
$this->_phase->getData('pointeur'),
$profil);
......@@ -83,12 +86,12 @@ class Class_Cosmogramme_Integration_PhaseReservation {
if (!$parser->isValid()) {
Class_CosmoVar::increment('traitement_erreurs');
$this->_log->ecrire('<span class="rouge">Impossible d\'ouvrir le fichier : '
. $integration->getFichier()
. $file_path
. '</span><br>');
return;
}
$this->_runFile($parser);
$this->_runFile($parser, $integration);
if (!$this->_isTimeOut()) {
$integration->setTraite($this->getTimeSource()->dateYmd())
......@@ -113,7 +116,7 @@ class Class_Cosmogramme_Integration_PhaseReservation {
}
protected function _runFile($parser) {
protected function _runFile($parser, $integration) {
while(true) {
if ($this->_isTimeOut())
return;
......@@ -178,7 +181,7 @@ class Class_Cosmogramme_Integration_PhaseReservation {
protected function _lineOk($line) {
return $ret['statut'] == 'ok';
return $line['statut'] == 'ok';
}
......
......@@ -22,21 +22,122 @@
class Class_Cosmogramme_Integration_Transaction {
protected $_is_pergame = false;
protected $_type, $_profil, $_accents, $_fields;
protected $_type, $_profil, $_accents, $_bib, $_fields, $_date_format;
public function __construct($integration) {
$this->_is_pergame = in_array($integration->getBib()->getSigb(), [1, 13]);
$this->_is_pergame = $integration->isPergame();
$this->_type = $integration->getTypeOperation();
$this->_profil = $integration->getProfilDonnees();
$this->_accents = $this->_profil->getAccents();
$this->_bib = $integration->getBib();
$attribs = unserialize($this->_profil->getAttributs());
$this->_fields = explode(';', $attribs[1]['champs']);
$this->_date_format = new Class_Cosmogramme_Integration_TransactionDateFormat();
}
public function importHold($data) {
$data = $this->_utfEncode($data);
$data = explode(chr(9), $data);
$hold = $this->_is_pergame ?
$this->_importPergameHold($data) : $this->_importOthersHold($data);
$hold->setIdSite($this->_bib->getId());
if (1 > $hold->getOrdreabon())
$hold->setOrdreabon(1);
$hold->setDateResa($this->_date_format->format($hold->getDateResa()))
->save();
}
protected function _importPergameHold($data) {
if (!$model = Class_Reservation::findFirstBy(['id_pergame' => $data[0],
'id_site' => $this->_bib->getId()]))
$model = Class_Reservation::newInstance();
return $model->updateAttributes(['id_pergame' => $data[0],
'idabon' => $data[1],
'ordreabon' => $data[2],
'support' => $data[3],
'id_notice_origine' => $data[4],
'date_resa' => $data[5]]);
}
protected function _importOthersHold($data) {
$map = [];
foreach($this->_fields as $k => $name)
$map[strtolower($name)] = $data[$k];
if (!array_key_exists('id_pergame', $map)
|| (!$model = Class_Reservation::findFirstBy(['id_pergame' => $map['id_pergame'],
'id_site' => $this->_bib->getId()])))
$model = Class_Reservation::newInstance();
return $model->updateAttributes($map);
}
protected function _utfEncode($value) {
if (!trim($value) || !$this->_isDos())
return $value;
$new = '';
foreach(str_split($value) as $char)
$new .= $this->_dosDecode($char);
return utf8_encode($new);
}
protected function _dosDecode($char) {
$mapping = [0xe9 => 'é',
0xe8 => 'è',
0xeb => 'ë',
0xe4 => 'ä',
0xe2 => 'â',
0xef => 'ï',
0xcf => 'Ï',
0xee => 'î',
0xce => 'Î',
0xf4 => 'ô',
0xf6 => 'ö',
0xd6 => 'Ö',
0xfc => 'ü',
0xdc => 'Ü',
0xfb => 'û',
0xe7 => 'ç',
0xc7 => 'Ç'];
return array_key_exists($char, $mapping) ?
$mapping[$char] : $char;
}
protected function _isDos() {
return 3 == $this->_accents;
}
}
class Class_Cosmogramme_Integration_TransactionDateFormat {
public function format($value) {
$value = str_replace('/', '-', $value);
$parts = explode('-', $value);
if (4 == $parts[0])
return implode('-', $parts);
$year = $parts[2];
$day = (int)$parts[0];
$month = (int)$parts[1];
$day = strlen($day) == 1 ? '0' . $day : $day;
$month = strlen($month) == 1 ? '0' . $month : $month;
return $year . '-' . $month . '-' . $day;
}
}
?>
\ No newline at end of file
......@@ -156,6 +156,11 @@ class Class_IntBib extends Storm_Model_Abstract {
public function isValidRecurrent() {
return $this->isRecurrent() && '0000000' != $this->getPlanifJours();
}
public function isPergame() {
return in_array($this->getSigb(), [1, 13]);
}
}
?>
\ No newline at end of file
......@@ -30,6 +30,10 @@ abstract class PhaseReservationTestCase extends Storm_Test_ModelTestCase {
$this->fixture('Class_CosmoVar',
['id' => 'traitement_phase', 'valeur' => 'Base bloquée']);
$this->fixture('Class_CosmoVar',
['id' => 'integration_path', 'valeur' => realpath(dirname(__FILE__)) . '/']);
$this->fixture('Class_CosmoVar', ['id' => 'import_type_operation', 'liste' => '']);
Class_CosmoVar::addLabelInList('import_type_operation',
Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL,
......@@ -38,14 +42,18 @@ abstract class PhaseReservationTestCase extends Storm_Test_ModelTestCase {
$this->fixture('Class_CosmoVar', ['id' => 'import_format', 'liste' => '']);
Class_CosmoVar::addLabelInList('import_format', 3, 'Ascii séparé par des "|"');
$bib = $this->fixture('Class_IntBib', ['id' => 2, 'nom_court' => 'Annexe 2']);
$bib = $this->fixture('Class_IntBib',
['id' => 2,
'nom_court' => 'Annexe 2',
'sigb' => 1]);
$profil = $this->fixture('Class_Cosmogramme_ProfilDonnees',
['id' => 102,
'libelle' => 'Réservations Pergame',
'accents' => 2,
'type_fichier' => Class_Cosmogramme_ProfilDonnees::FILE_TYPE_HOLDS,
'format' => 3,
'attributs' => 'ID_PERGAME;IDABON;ORDREABON;SUPPORT;ID_NOTICE_ORIGINE;DATE_RESA']);
'attributs' => 'a:4:{i:0;a:6:{s:8:"type_doc";a:11:{i:0;a:3:{s:4:"code";s:1:"0";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:1;a:3:{s:4:"code";s:1:"1";s:5:"label";s:5:"am;na";s:8:"zone_995";s:6:"LIV;MS";}i:2;a:3:{s:4:"code";s:1:"2";s:5:"label";s:2:"as";s:8:"zone_995";s:3:"PER";}i:3;a:3:{s:4:"code";s:1:"3";s:5:"label";s:3:"i;j";s:8:"zone_995";s:17:"CD;LIVCD;LIVK7;K7";}i:4;a:3:{s:4:"code";s:1:"4";s:5:"label";s:1:"g";s:8:"zone_995";s:20:"DIAPO;DVD;VHS;VHD;VD";}i:5;a:3:{s:4:"code";s:1:"5";s:5:"label";s:3:"l;m";s:8:"zone_995";s:3:"CDR";}i:6;a:3:{s:4:"code";s:1:"6";s:5:"label";s:3:"c;d";s:8:"zone_995";s:3:"MM;";}i:7;a:3:{s:4:"code";s:1:"7";s:5:"label";s:3:"f;k";s:8:"zone_995";s:21:"PHOTO;EST;EKTA;CPL;CP";}i:8;a:3:{s:4:"code";s:1:"8";s:5:"label";s:0:"";s:8:"zone_995";s:3:"DOS";}i:9;a:3:{s:4:"code";s:1:"9";s:5:"label";s:0:"";s:8:"zone_995";s:0:"";}i:10;a:3:{s:4:"code";s:2:"10";s:5:"label";s:0:"";s:8:"zone_995";s:6:"WEB;MF";}}s:17:"champ_code_barres";s:1:"f";s:11:"champ_genre";s:0:"";s:13:"champ_section";s:1:"q";s:17:"champ_emplacement";s:1:"u";s:12:"champ_annexe";s:1:"a";}i:1;a:1:{s:6:"champs";s:63:"ID_PERGAME;IDABON;ORDREABON;SUPPORT;ID_NOTICE_ORIGINE;DATE_RESA";}i:2;a:1:{s:6:"champs";s:63:"ID_PERGAME;IDABON;ORDREABON;SUPPORT;ID_NOTICE_ORIGINE;DATE_RESA";}i:3;a:1:{s:6:"champs";s:63:"ID_PERGAME;IDABON;ORDREABON;SUPPORT;ID_NOTICE_ORIGINE;DATE_RESA";}}']);
$this->_log = $this->mock()
->whenCalled('ecrire')
......@@ -54,6 +62,8 @@ abstract class PhaseReservationTestCase extends Storm_Test_ModelTestCase {
$this->_chrono = new Class_Cosmogramme_Integration_Chronometre();
$this->_prepareFixtures();
$this->_phase = (new Class_Cosmogramme_Integration_PhaseReservation($this->_getPreviousPhase(),
$this->_log,
$this->_chrono))
......@@ -123,7 +133,7 @@ class PhaseReservationValidCronFirstRunTest extends PhaseReservationTestCase {
'profil_donnees' => Class_Cosmogramme_ProfilDonnees::find(102),
'type_operation' => Class_Cosmogramme_Integration::TYPE_OPERATION_TOTAL,
'traite' => 'non',
'fichier' => 'integre546673.pan',
'fichier' => 'holds.txt',
'pointeur_reprise' => 0]);
$this->fixture('Class_Reservation',
......@@ -151,7 +161,7 @@ class PhaseReservationValidCronFirstRunTest extends PhaseReservationTestCase {
/** @test */
public function logShouldContainsFileName() {
$this->assertLogContains('integre546673.pan');
$this->assertLogContains('holds.txt');
}
......@@ -177,4 +187,16 @@ class PhaseReservationValidCronFirstRunTest extends PhaseReservationTestCase {
public function existingHoldShouldHaveBeenDeleted() {
$this->assertNull(Class_Reservation::find(4455));
}
/** @test */
public function shouldHave25Holds() {
$this->assertEquals(25, Class_Reservation::count());
}
/** @test */
public function shouldNotImportPergameHeader() {
$this->assertNull(Class_Reservation::findFirstBy(['id_pergame' => 'BIB_T_RESERVE']));
}
}
BIB_T_RESERVE|ID_RESERVE|ID_ABON|ORDRE_ABON|SUPPORT|ID_NOTICE|DATE_RESERVE|ANNEXE|RANG
26798|3429|1|1|190003|2015-02-03|1|1
26799|9459|1|1|189582|2015-02-03|1|1
26830|9993|1|1|115891|2015-02-04|1|1
26831|10647|1|1|188281|2015-02-04|1|7
26837|15476|1|1|190154|2015-02-04|1|2
26842|12317|1|1|190279|2015-02-05|1|5
26844|3912|1|1|189471|2015-02-05|1|1
26845|9808|1|1|193546|2015-02-05|1|1
26851|10647|1|1|117175|2015-02-05|1|1
26860|17379|1|1|160501|2015-02-06|1|1
26864|16960|1|1|193225|2015-02-06|1|1
26867|9690|1|1|190280|2015-02-06|1|5
26871|9138|1|1|188251|2015-02-06|1|1
26874|17233|1|1|168485|2015-02-07|1|1
26876|17301|1|1|154561|2015-02-07|1|1
26879|55|1|1|184963|2015-02-07|1|2
26881|15386|1|1|188749|2015-02-07|1|1
26884|7256|1|1|160496|2015-02-07|1|1
26886|16877|1|1|80170|2015-02-07|1|1
26891|15476|1|1|192825|2015-02-07|1|1
26893|8764|1|1|145243|2015-02-09|1|1
26897|1353|1|1|193175|2015-02-09|1|1
26900|9037|1|1|140832|2015-02-09|1|1
26904|13642|1|1|92429|2015-02-09|1|1
26905|13642|1|1|152208|2015-02-09|1|1
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment