diff --git a/FEATURES/17352 b/FEATURES/17352 index a21e13fa6bdc9b8cdf35ee71e389eb6fa2b911cf..e13be545ba6967f6834fbc8e8be68712906c8af2 100644 --- a/FEATURES/17352 +++ b/FEATURES/17352 @@ -1,10 +1,10 @@ '17352' => - ['Label' => $this->_('Cosmogramme: garder l'unimarc natif d'une notice'), - 'Desc' => '', + ['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' => '', + 'Category' => 'Catalogue', 'Right' => function($feature_description, $user) {return true;}, 'Wiki' => '', 'Test' => '', - 'Date' => '2017-12-08'], \ No newline at end of file + 'Date' => '2018-04-13'], \ No newline at end of file diff --git a/VERSIONS_WIP/17352 b/VERSIONS_WIP/17352 index d42f28617b9f183b73af8e5a6b723df8a2217866..8f017955532bd82806a731016421b5e9bf1c10f4 100644 --- a/VERSIONS_WIP/17352 +++ b/VERSIONS_WIP/17352 @@ -1 +1 @@ - - ticket #17352 : Cosmogramme: garder l'unimarc natif d'une notice \ No newline at end of file + - 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/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/RawRecord.php b/library/Class/Cosmogramme/Integration/RawRecord.php index 34255efab3acec10d85ee822e6c4b345071bbc5e..adf999966e019d9eed2c7d4d3eae893229b65567 100644 --- a/library/Class/Cosmogramme/Integration/RawRecord.php +++ b/library/Class/Cosmogramme/Integration/RawRecord.php @@ -29,20 +29,35 @@ class Class_Cosmogramme_Integration_RawRecord { $_id, $_date; + public static function hasVersionFor($item) { - return (new static('', $item->getIdOrigine(), $item->getIdIntBib())) - ->hasVersion(); + return static::isActive() + ? static::_newFor($item)->hasVersion() + : false; } public static function findFor($item) { - $instance = new static('', $item->getIdOrigine(), $item->getIdIntBib()); + 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; @@ -85,12 +100,13 @@ class Class_Cosmogramme_Integration_RawRecord { protected function _isValid() { - return is_string($this->_data); + return static::isActive() && is_string($this->_data); } public function loadLastVersion() { - if (!$version = $this->getLastVersion()) + if (!static::isActive() + || (!$version = $this->getLastVersion())) return; $this->_data = $version->getData()['data']; diff --git a/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php b/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php index 5475cc6123658b0fadd96ba0348b75afceb256a1..08534617a10c63216d7a0aa49a942dc3bd134603 100644 --- a/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php +++ b/tests/scenarios/RawRecordHistory/RawRecordVersionTest.php @@ -27,17 +27,24 @@ class RawRecordUnimarcVersionTest extends ModelTestCase { public function setUp() { parent::setUp(); - Class_Versions_RawRecord::defaultToFile(); $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 shouldHaveCreatedOneVersion() { + public function whenActivatedShouldHaveCreatedOneVersion() { + Class_AdminVar::set('KEEP_LAST_SIGB_RECORD', 1); + $this->_record->save(); $this->assertEquals(1, $this->_record->numberOfVersions()); } }