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

dev #17352 : record history with generic versions

parent 296f30a7
Branches
Tags
3 merge requests!2660Master,!2594Master,!2549Dev#17352 cosmogramme garder l unimarc natif d une notice
Pipeline #3575 passed with stage
in 31 minutes and 39 seconds
......@@ -75,7 +75,7 @@ class notice_integration {
protected $_codif_provider;
protected $_record_history;
protected $_raw_data;
public function __construct() {
......@@ -149,6 +149,8 @@ class notice_integration {
public function traiteNotice($data) {
global $sql;
$this->_raw_data = $data;
$id_bib = $this->id_bib;
if(!$this->analyseur)
......@@ -493,9 +495,6 @@ class notice_integration {
$notice = Class_Notice::newInstance($this->noticeToDBEnreg());
$notice->save();
if ($this->_record_history)
$this->_record_history->setRecord($notice);
$this->statut = static::RECORD_INSERT;
return $notice->getId();
}
......@@ -639,9 +638,6 @@ class notice_integration {
if ($this->statut == static::RECORD_UPDATE)
return $id_notice;
if ($this->_record_history)
$this->_record_history->setRecord($existing_notice);
return $this->_realUpdate($existing_notice);
}
......@@ -753,12 +749,14 @@ class notice_integration {
foreach($exemplaires as $exemplaire)
$exemplaire->save();
if ($this->_record_history)
$this->_record_history->setItems($exemplaires);
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();
}
......@@ -1401,12 +1399,6 @@ class notice_integration {
$this->_codif_provider = $provider;
return $this;
}
public function setRecordHistory($history) {
$this->_record_history = $history;
return $this;
}
}
......
......@@ -47,13 +47,7 @@ class Class_Cosmogramme_Integration_PhaseNotice
$integration->getProfil(),
$integration->getTypeDoc());
$integrator->setServiceRunner(static::$_service_runner);
$history = new Class_Cosmogramme_Integration_RecordHistory($data, $integration);
$integrator->setRecordHistory($history);
$integrator->traiteNotice($data);
$history->save();
$this->_incrementCount($integrator->getStatut());
}
......
......@@ -20,101 +20,40 @@
*/
class Class_Cosmogramme_Integration_RecordHistory {
use Trait_StaticFileSystem, Trait_TimeSource;
const BASE_PATH = 'records';
class Class_Cosmogramme_Integration_RawRecord {
use Trait_Versionable;
protected
$_data,
$_folder_manager,
$_library_id,
$_record_id,
$_item_ids = [];
public static function hasHistory($item) {
if (!$id = $item->getId())
return false;
if (!$id_bib = $item->getIdIntBib())
return false;
$_data,
$_id;
return (new static('', new Class_Entity(['IdBib' => $id_bib])))
->itemHasHistory($id);
public static function hasVersionFor($item) {
return (new static('', $item->getIdOrigine(), $item->getIdIntBib()))
->hasVersion();
}
public function __construct($data, $integration) {
public function __construct($data, $id, $library_id) {
$this->_library_id = $library_id;
$this->_data = $data;
$this->_library_id = $integration->getIdBib();
$this->_id = $id;
}
public function itemHasHistory($id) {
if (!$path = $this->_getPathOf($id))
return false;
return $this->getFileSystem()->file_exists($path);
public function getId() {
return $this->_id;
}
public function setRecord($record) {
$this->_record_id = $record->getId();
return $this;
}
public function setItems($items) {
$this->_item_ids = array_map(function($item) { return $item->getId(); },
$items);
return $this;
public function getLibraryId() {
return $this->_library_id;
}
public function save() {
foreach($this->_item_ids as $item_id)
$this->_saveForItem($item_id);
return $this;
}
protected function _saveForItem($id) {
if (!$id)
return $this;
if (!$path = $this->_getPathOf($id))
return $this;
$this->getFileSystem()
->file_put_contents($path, $this->_data);
return $this;
}
protected function _getPathOf($id) {
if (!$this->getFolderManager()
->ensure($folder = $this->_getFolderPath()))
return;
return $folder . '/'. $id;
}
protected function _getFolderPath() {
return PATH_TEMP . implode('/', [static::BASE_PATH,
$this->_library_id,
$this->_record_id]);
}
public function getFolderManager() {
if (null === $this->_folder_manager)
$this->_folder_manager = Class_Folder_Manager::newInstanceLimitedTo(PATH_TEMP);
return $this->_folder_manager;
$this->newVersionWith(['id' => $this->_id,
'library_id' => $this->_library_id,
'data' => $this->_data]);
}
}
<?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';
}
}
<?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;
}
}
......@@ -142,7 +142,7 @@ class ZendAfi_View_Helper_Notice_Unimarc extends Zend_View_Helper_HtmlElement {
protected function renderItemDownload($item) {
if (!Class_Cosmogramme_Integration_RecordHistory::hasHistory($item))
if (!Class_Cosmogramme_Integration_RawRecord::hasVersionFor($item))
return '';
$download_url = $this->view->url(['controller' => 'recherche',
......
<?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();
Class_Versions_RawRecord::defaultToFile();
$marc = file_get_contents(__DIR__ . '/audiard_herosdiscret.uni');
$this->_record = new Class_Cosmogramme_Integration_RawRecord($marc, '694479', 12);
$this->_record->save();
}
/** @test */
public function shouldHaveCreatedOneVersion() {
$this->assertEquals(1, $this->_record->numberOfVersions());
}
}
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
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