diff --git a/FEATURES/17352 b/FEATURES/17352 new file mode 100644 index 0000000000000000000000000000000000000000..e13be545ba6967f6834fbc8e8be68712906c8af2 --- /dev/null +++ b/FEATURES/17352 @@ -0,0 +1,10 @@ + '17352' => + ['Label' => $this->_('Visualisation du fichier envoyé par le SIGB pour chaque notice'), + 'Desc' => $this->_('Bokeh conserve le dernier fichier reçu du SIGB pour chaque notice. Celui-ce est téléchargeable à partir d'Inspector Gadget. Nécessite une activation.'), + 'Image' => '', + 'Video' => '', + 'Category' => 'Catalogue', + 'Right' => function($feature_description, $user) {return true;}, + 'Wiki' => '', + 'Test' => '', + 'Date' => '2018-04-13'], \ No newline at end of file diff --git a/VERSIONS_WIP/17352 b/VERSIONS_WIP/17352 new file mode 100644 index 0000000000000000000000000000000000000000..8f017955532bd82806a731016421b5e9bf1c10f4 --- /dev/null +++ b/VERSIONS_WIP/17352 @@ -0,0 +1 @@ + - ticket #17352 : Cosmogramme: Bokeh conserve le dernier fichier reçu du SIGB pour chaque notice. Celui-ce est téléchargeable à partir d'Inspector Gadget. Nécessite une activation. \ No newline at end of file diff --git a/application/modules/opac/controllers/AbonneController.php b/application/modules/opac/controllers/AbonneController.php index 38f4a80f32e763387b0390f37853b50d5443ab23..456d0eb482d38caddaa656c7a64e752849be043e 100644 --- a/application/modules/opac/controllers/AbonneController.php +++ b/application/modules/opac/controllers/AbonneController.php @@ -989,13 +989,8 @@ class AbonneController extends ZendAfi_Controller_Action { $datas[] = $exemplaire->toUnimarcIso2709(); } - $response = $this->_response; - $response->clearAllHeaders(); $filename = 'prets_' . $this->_user->getId() . '-' . uniqid() . '.txt'; - - $response->setHeader('Content-Type', 'application/octet-stream; name="' . $filename . '"', true); - $response->setHeader('Content-Disposition', 'attachment; filename="'.$filename.'"', true); - $response->setBody(implode('', $datas)); + $this->_helper->binaryDownload(implode($datas), $filename); } diff --git a/application/modules/opac/controllers/RechercheController.php b/application/modules/opac/controllers/RechercheController.php index 5c7b3423157387a6ecb88445987d045d085b3fe3..15bb40bf4991c5e2c45fe46806200ecc40534a8c 100644 --- a/application/modules/opac/controllers/RechercheController.php +++ b/application/modules/opac/controllers/RechercheController.php @@ -746,32 +746,21 @@ class RechercheController extends ZendAfi_Controller_Action { public function downloadRecordAction() { - if (!$record = Class_Notice::find($this->_getParam('id', 0))) { - $this->_redirect('/'); - return; - } + if (!$record = Class_Notice::find($this->_getParam('id', 0))) + return $this->_redirect('/'); - $this->_helper->getHelper('ViewRenderer')->setNoRender(true); - if ($layout = Zend_Layout::getMvcInstance()) - $layout->disableLayout(); - - $response = Zend_Controller_Front::getInstance()->getResponse(); - $response->canSendHeaders(true); + $this->_helper->binaryDownload($record->getUnimarc(), $record->getId() . '.txt'); + } - $response->clearAllHeaders(); - $response->setHeader('Content-Type', 'application/octet-stream; name="' . $record->getId() . '.txt"', true); - $response->setHeader('Content-Transfer-Encoding', 'binary', true); - $unimarc = $record->getUnimarc(); - $response->setHeader('Content-Length', strlen($unimarc), true); - $response->setHeader('Expires', '0'); - $response->setHeader('Cache-Control', 'no-cache, must-revalidate'); - $response->setHeader('Pragma', 'no-cache'); - $response->setHeader('Content-Disposition', 'attachment; filename="' . $record->getId() . '.txt"', true); + public function downloadItemAction() { + if (!$item = Class_Exemplaire::find($this->_getParam('id', 0))) + return $this->_redirect('/'); - $response->sendHeaders(); + if (!$raw_record = Class_Cosmogramme_Integration_RawRecord::findFor($item)) + return $this->_redirect('/'); - echo $unimarc; + $this->_helper->binaryDownload($raw_record->getData(), $raw_record->getName()); } diff --git a/cosmogramme/php/classes/classe_notice_integration.php b/cosmogramme/php/classes/classe_notice_integration.php index 3dd347cea0eceae8d54a828d7d88372bb628ffa5..ac0c46bd3834f70c135aad0381d00c90e19f2319 100644 --- a/cosmogramme/php/classes/classe_notice_integration.php +++ b/cosmogramme/php/classes/classe_notice_integration.php @@ -75,6 +75,9 @@ class notice_integration { protected $_codif_provider; + protected $_raw_data; + + public function __construct() { $this->indexation = indexation::getInstance(); $this->filtrer_fulltext = Class_CosmoVar::get("filtrer_fulltext"); @@ -146,6 +149,8 @@ class notice_integration { public function traiteNotice($data) { global $sql; + $this->_raw_data = $data; + $id_bib = $this->id_bib; if(!$this->analyseur) @@ -156,7 +161,7 @@ class notice_integration { unset($this->notice); - if(!$this->analyseur->ouvrirNotice($data,$this->id_profil,$this->sigb,$this->type_doc_force)) { + if(!$this->analyseur->ouvrirNotice($data, $this->id_profil, $this->sigb, $this->type_doc_force)) { $this->erreur=$this->analyseur->getLastError(); return 0; } @@ -489,6 +494,7 @@ class notice_integration { $notice = Class_Notice::newInstance($this->noticeToDBEnreg()); $notice->save(); + $this->statut = static::RECORD_INSERT; return $notice->getId(); } @@ -746,6 +752,11 @@ class notice_integration { if($record = Class_Notice::find($id_notice)) $record->setDateMaj(dateDuJour(2))->save(); + (new Class_Cosmogramme_Integration_RawRecord($this->_raw_data, + $this->notice['id_origine'], + $this->id_int_bib)) + ->save(); + Class_Exemplaire::clearCache(); Class_Notice::clearCache(); } diff --git a/library/Class/AdminVar.php b/library/Class/AdminVar.php index eba089f45b0593a8330535f9a8a7258cb2ac7133..0a564dd66a9aa7b4c95b9f39ca0946c0a1f3ad19 100644 --- a/library/Class/AdminVar.php +++ b/library/Class/AdminVar.php @@ -396,7 +396,8 @@ class Class_AdminVarLoader extends Storm_Model_Loader { protected function _getCosmogrammeVars() { return [ 'DATE_LAST_FULL_INTEGRATION_USERS' => Class_AdminVar_Meta::newDefault($this->_('Date du dernier import total des abonnés (modifié par cosmogramme)')), - 'INTEGRATIONS_TOO_LONG_ALERT_THRESHOLD' => Class_AdminVar_Meta::newDefault($this->_('Seuil d\'alerte en heures pour détecter que les traitements d\'intégration prennent trop de temps. Par défaut: 2', ['value' => 2])) + 'INTEGRATIONS_TOO_LONG_ALERT_THRESHOLD' => Class_AdminVar_Meta::newDefault($this->_('Seuil d\'alerte en heures pour détecter que les traitements d\'intégration prennent trop de temps. Par défaut: 2', ['value' => 2])), + 'KEEP_LAST_SIGB_RECORD' => Class_AdminVar_Meta::newOnOff($this->_('Conserve le dernier fichier transmis par le SIGB pour chaque notice. Celui-ci est téléchargeable à partir de l\'Inspecteur Gadget.'))->bePrivate(), ]; } @@ -957,6 +958,11 @@ class Class_AdminVarLoader extends Storm_Model_Loader { return Class_AdminVar::isBibNumEnabled() && Class_AdminVar::get('SITO_IN_ALBUMS'); } + + + public function shouldKeepLastSigbRecord() { + return Class_AdminVar::isModuleEnabled('KEEP_LAST_SIGB_RECORD'); + } } diff --git a/library/Class/Cosmogramme/Integration/PhaseNotice.php b/library/Class/Cosmogramme/Integration/PhaseNotice.php index 98e0668c8e1820405d4ef2851dc5b24988b8a729..df330376e2705f14621f7383c40a77dbcb974724 100644 --- a/library/Class/Cosmogramme/Integration/PhaseNotice.php +++ b/library/Class/Cosmogramme/Integration/PhaseNotice.php @@ -127,4 +127,4 @@ class Class_Cosmogramme_Integration_PhaseNotice public static function setServiceRunner($runner) { static::$_service_runner = $runner; } -} \ No newline at end of file +} diff --git a/library/Class/Cosmogramme/Integration/RawRecord.php b/library/Class/Cosmogramme/Integration/RawRecord.php new file mode 100644 index 0000000000000000000000000000000000000000..adf999966e019d9eed2c7d4d3eae893229b65567 --- /dev/null +++ b/library/Class/Cosmogramme/Integration/RawRecord.php @@ -0,0 +1,123 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Cosmogramme_Integration_RawRecord { + use Trait_Versionable; + + protected + $_library_id, + $_data, + $_id, + $_date; + + + public static function hasVersionFor($item) { + return static::isActive() + ? static::_newFor($item)->hasVersion() + : false; + } + + + public static function findFor($item) { + if (!static::isActive()) + return; + + $instance = static::_newFor($item); + return ($instance = $instance->loadLastVersion()) + ? $instance + : null; + } + + + public static function isActive() { + return Class_AdminVar::shouldKeepLastSigbRecord(); + } + + + protected static function _newFor($item) { + return new static('', $item->getIdOrigine(), $item->getIdIntBib()); + } + + + public function __construct($data, $id, $library_id) { + $this->_library_id = $library_id; + $this->_data = $data; + $this->_id = $id; + } + + + public function getId() { + return $this->_id; + } + + + public function getLibraryId() { + return $this->_library_id; + } + + + public function getData() { + return $this->_data; + } + + + public function getName() { + return 'raw_record_' + . implode('_', + [$this->_library_id, + $this->_id, + $this->_humanDate()]); + } + + + public function save() { + if (!$this->_isValid()) + return; + + $this->newVersionWith(['id' => $this->_id, + 'library_id' => $this->_library_id, + 'data' => $this->_data]); + } + + + protected function _isValid() { + return static::isActive() && is_string($this->_data); + } + + + public function loadLastVersion() { + if (!static::isActive() + || (!$version = $this->getLastVersion())) + return; + + $this->_data = $version->getData()['data']; + $this->_date = $version->getDate(); + return $this; + } + + + protected function _humanDate() { + return $this->_date + ? date('Y-m-d', $this->_date) + : ''; + } +} diff --git a/library/Class/Version/FilePersistence/RawRecord.php b/library/Class/Version/FilePersistence/RawRecord.php new file mode 100644 index 0000000000000000000000000000000000000000..c1eb7d049daf2d866a7d6de59baedcaa31440829 --- /dev/null +++ b/library/Class/Version/FilePersistence/RawRecord.php @@ -0,0 +1,43 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Version_FilePersistence_RawRecord extends Class_Version_FilePersistence { + protected function _getMaxStack() { + return 1; + } + + + protected function _getFolderPath($versions) { + return $this->_getRootPath() + . implode('/', [static::BASE_PATH, + $this->_sanitize($versions->getName()), + $this->_sanitize($versions->getLibraryId()), + $this->_sanitize($versions->getKey())]); + } + + + protected function _fileName() { + return + $this->getTimeSource()->dateFormat('Y-m-d_His') + . '.json'; + } +} diff --git a/library/Class/Versions/RawRecord.php b/library/Class/Versions/RawRecord.php new file mode 100644 index 0000000000000000000000000000000000000000..b09950195f1cbdb96fb155ee7da77a91a9a39cee --- /dev/null +++ b/library/Class/Versions/RawRecord.php @@ -0,0 +1,41 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class Class_Versions_RawRecord extends Class_Versions { + protected static + $_file_persistence = 'Class_Version_FilePersistence_RawRecord'; + + protected + $_name = 'raw_record', + $_library_id; + + + public function __construct($model) { + parent::__construct($model); + $this->_library_id = $model->getLibraryId(); + } + + + public function getLibraryId() { + return $this->_library_id; + } +} diff --git a/library/ZendAfi/Controller/Action/Helper/BinaryDownload.php b/library/ZendAfi/Controller/Action/Helper/BinaryDownload.php new file mode 100644 index 0000000000000000000000000000000000000000..df355b09a7e1127209223f92311fadc61fbdf48a --- /dev/null +++ b/library/ZendAfi/Controller/Action/Helper/BinaryDownload.php @@ -0,0 +1,51 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class ZendAfi_Controller_Action_Helper_BinaryDownload + extends Zend_Controller_Action_Helper_Abstract { + + public function direct($content, $filename) { + Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer') + ->setNoRender(true); + + if ($layout = Zend_Layout::getMvcInstance()) + $layout->disableLayout(); + + $response = $this->getResponse(); + $response->canSendHeaders(true); + + $response->clearAllHeaders(); + $response->setHeader('Content-Type', 'application/octet-stream; name="' . $filename . '"', true); + $response->setHeader('Content-Transfer-Encoding', 'binary', true); + + $response->setHeader('Content-Length', strlen($content), true); + $response->setHeader('Expires', '0'); + $response->setHeader('Cache-Control', 'no-cache, must-revalidate'); + $response->setHeader('Pragma', 'no-cache'); + + $response->setHeader('Content-Disposition', 'attachment; filename="' . $filename . '"', true); + + $response->sendHeaders(); + + echo $content; + } +} diff --git a/library/ZendAfi/View/Helper/Notice/Unimarc.php b/library/ZendAfi/View/Helper/Notice/Unimarc.php index ae5e038dd35176244664760d1bb35da0eb25bd9b..d0fc9699269513a95ca5c09096219b45a7c93e96 100644 --- a/library/ZendAfi/View/Helper/Notice/Unimarc.php +++ b/library/ZendAfi/View/Helper/Notice/Unimarc.php @@ -127,7 +127,9 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { $html .= $this->_tag('strong', $label . ' : ') . call_user_func([$item, $getter]) . $this->_tag('br'); - $html .= $this->renderItem995($item); + + $html .= $this->renderItem995($item) + . $this->renderItemDownload($item); return $this->_tag('h3', $item->getBibLibelle() . ' ' . $item->getCodeBarres()) . $this->_tag('div', $html); @@ -139,6 +141,25 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement { } + protected function renderItemDownload($item) { + if (!Class_Cosmogramme_Integration_RawRecord::hasVersionFor($item)) + return ''; + + $download_url = $this->view->url(['controller' => 'recherche', + 'action' => 'download-item', + 'id' => $item->getId()], + null, true); + + $button = (new Class_Entity) + ->setText($this->_('Télécharger le fichier d\'origine')) + ->setImage(Class_Admin_Skin::current()->renderActionIconOn('down', $this->view)) + ->setAttribs(['style' => 'float:right;', + 'onclick' => 'document.location.href=\'' . $download_url .'\'']); + + return $this->view->admin_Button($button); + } + + public function __call($name, $args) { if ('visit' != substr($name, 0, 5)) throw new RuntimeException('Call to unknown method ' . get_class($this) . '::' . $name); diff --git a/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php b/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php new file mode 100644 index 0000000000000000000000000000000000000000..08534617a10c63216d7a0aa49a942dc3bd134603 --- /dev/null +++ b/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php @@ -0,0 +1,50 @@ +<?php +/** + * Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved. + * + * BOKEH is free software; you can redistribute it and/or modify + * it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by + * the Free Software Foundation. + * + * There are special exceptions to the terms and conditions of the AGPL as it + * is applied to this software (see README file). + * + * BOKEH is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + * + * You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE + * along with BOKEH; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + +class RawRecordUnimarcVersionTest extends ModelTestCase { + protected + $_storm_default_to_volatile = true, + $_record; + + public function setUp() { + parent::setUp(); + + $marc = file_get_contents(__DIR__ . '/audiard_herosdiscret.uni'); + $this->_record = new Class_Cosmogramme_Integration_RawRecord($marc, '694479', 12); + } + + + /** @test */ + public function whenNotActivatedShouldNotHaveCreatedOneVersion() { + Class_AdminVar::set('KEEP_LAST_SIGB_RECORD', 0); + $this->_record->save(); + $this->assertEquals(0, $this->_record->numberOfVersions()); + } + + + /** @test */ + public function whenActivatedShouldHaveCreatedOneVersion() { + Class_AdminVar::set('KEEP_LAST_SIGB_RECORD', 1); + $this->_record->save(); + $this->assertEquals(1, $this->_record->numberOfVersions()); + } +} diff --git a/tests/scenarios/RawRecordHistory/audiard_herosdiscret.uni b/tests/scenarios/RawRecordHistory/audiard_herosdiscret.uni new file mode 100644 index 0000000000000000000000000000000000000000..602bdcce7151f8d2b11b93c83f4bdcd181f26234 --- /dev/null +++ b/tests/scenarios/RawRecordHistory/audiard_herosdiscret.uni @@ -0,0 +1 @@ +01518ngm0 2200349 450 001000700000071002700007073001800034100001300052200004500065210001900110215001600129300013500145345001800280606002200298686001300320686004100333686003500374700007300409702005300482702005200535702004800587702004500635702004900680702005300729702003400782702003300816702003800849801001700887932001000904992012500914995012901039694479 a826030-9bStudio Canal a5050582603095 a201411061 aUn héros très discretfJacques Audiard cAliceleod1996 a1 DVD, 1h41 aD'après le roman de Jean-François Deniau. - Bonus : interview du réalisateur et Alain Le Henry. Scènes commentées. Making of. b826030-9cDVD acinéma français aF2PCDM4 aFictiontFiction2Code_Statistique_1 aFilmtFilm2Code_Statistique_2 1aAudiardbJacques31000251106g3006Metteur en scène ou réalisateur 1aDesplatbAlexandre3100025081142306Compositeur 1aDeniaubJean-François3100013496740706Auteur 1aKassovitzbMathieu3100021986940056Acteur 1aGrinbergbAnouk3130350006040056Acteur 1aKiberlainbSandrine310003627044005gActeur 1aTrintignantbJean-Louis3100022982340056Acteur 1aDupontelbAlbert40056Acteur 1aBarentinbNadia40056Acteur 1aLe HenrybAlain40006Intervenant 2aFrc20150829 aDrame uhttp://ecx.images-amazon.com/images/I/51%2BE27GCzjL._SL160_.jpgvhttp://ecx.images-amazon.com/images/I/51%2BE27GCzjL.jpg aMédiathèquef31879003220456kF AUDm20150829qdrgfopv12[DISPO][Disponible][0][1][][0][0][0][0]42015-02-1367778197 \ No newline at end of file