From bd8c251459fb750bf0ae70ef33151b417f4c6684 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 20 Jun 2022 10:59:07 +0200 Subject: [PATCH] Bug 32030: Create a local bibliographic record for resources When a new resource is created we create a new bibliographic record in Koha that is linked at the title level Signed-off-by: Jonathan Field Signed-off-by: Martin Renvoize Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/ERM/EHoldings/Resource.pm | 34 +++++++++++++++++++ Koha/ERM/EHoldings/Title.pm | 6 ++-- .../definitions/erm_eholdings_title.yaml | 6 ++++ installer/data/mysql/atomicupdate/erm.pl | 2 ++ installer/data/mysql/kohastructure.sql | 2 ++ .../components/ERM/EHoldingsTitlesFormAdd.vue | 1 + .../components/ERM/EHoldingsTitlesShow.vue | 18 +++++----- 7 files changed, 59 insertions(+), 10 deletions(-) diff --git a/Koha/ERM/EHoldings/Resource.pm b/Koha/ERM/EHoldings/Resource.pm index da2ddbaf7d..a7badbbb35 100644 --- a/Koha/ERM/EHoldings/Resource.pm +++ b/Koha/ERM/EHoldings/Resource.pm @@ -17,8 +17,11 @@ package Koha::ERM::EHoldings::Resource; use Modern::Perl; +use MARC::Record; + use Koha::Database; +use Koha::Biblios; use Koha::ERM::EHoldings::Title; use Koha::ERM::EHoldings::Package; @@ -34,6 +37,37 @@ Koha::ERM::EHoldings::Resource - Koha EHolding resource Object class =cut +=head3 store + +=cut + +sub store { + my ($self) = @_; + + # FIXME This is terrible and ugly, we need to: + # * Provide a mapping for each attribute of title + # * Deal with marcflavour + # * Create a txn + my $title = $self->title; + my $biblio = $title->biblio_id ? Koha::Biblios->find($title->biblio_id) : undef; + my $marc_record = $biblio ? $biblio->metadata->record : MARC::Record->new; + eval {$marc_record->field('245')->delete_subfield('a');}; + $marc_record->add_fields(MARC::Field->new(245, '', '', a => $title->publication_title)); + + my $biblio_id; + if ( $biblio ) { + $biblio_id = $title->biblio_id; + C4::Biblio::ModBiblio($marc_record, $title->biblio_id, ''); + } else { + ( $biblio_id ) = C4::Biblio::AddBiblio($marc_record, ''); + } + + $title->biblio_id($biblio_id)->store; + + $self = $self->SUPER::store; + return $self; +} + =head3 package Return the package for this resource diff --git a/Koha/ERM/EHoldings/Title.pm b/Koha/ERM/EHoldings/Title.pm index b2ada02e27..7802581f37 100644 --- a/Koha/ERM/EHoldings/Title.pm +++ b/Koha/ERM/EHoldings/Title.pm @@ -46,8 +46,10 @@ sub resources { sub { $self->resources->delete; - for my $resources (@$resources) { - $self->_result->add_to_erm_eholdings_resources($resources); + # Cannot use the dbic RS, we need to trigger ->store overwrite + for my $resource (@$resources) { + Koha::ERM::EHoldings::Resource->new( + { %$resource, title_id => $self->title_id } )->store; } } ); diff --git a/api/v1/swagger/definitions/erm_eholdings_title.yaml b/api/v1/swagger/definitions/erm_eholdings_title.yaml index 6e6112a699..e60a1fb0f9 100644 --- a/api/v1/swagger/definitions/erm_eholdings_title.yaml +++ b/api/v1/swagger/definitions/erm_eholdings_title.yaml @@ -5,6 +5,12 @@ properties: type: integer description: internally assigned identifier readOnly: true + biblio_id: + type: + - integer + - "null" + description: internally assigned identifier for the linked biblio + readOnly: true vendor_id: description: foreign key to aqbooksellers type: diff --git a/installer/data/mysql/atomicupdate/erm.pl b/installer/data/mysql/atomicupdate/erm.pl index 60a933221f..98eceb1568 100755 --- a/installer/data/mysql/atomicupdate/erm.pl +++ b/installer/data/mysql/atomicupdate/erm.pl @@ -215,6 +215,7 @@ return { $dbh->do(q{ CREATE TABLE `erm_eholdings_titles` ( `title_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', + `biblio_id` INT(11) DEFAULT NULL, `vendor_id` INT(11) DEFAULT NULL, `publication_title` VARCHAR(255) DEFAULT NULL, `external_id` VARCHAR(255) DEFAULT NULL, @@ -242,6 +243,7 @@ return { `preceeding_publication_title_id` VARCHAR(255) DEFAULT NULL, `access_type` VARCHAR(255) DEFAULT NULL, CONSTRAINT `erm_eholdings_titles_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `erm_eholdings_titles_ibfk_2` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY(`title_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; }); diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index f0358f8142..09101b7ca1 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2928,6 +2928,7 @@ CREATE TABLE `erm_eholdings_packages_agreements` ( DROP TABLE IF EXISTS `erm_eholdings_titles`; CREATE TABLE `erm_eholdings_titles` ( `title_id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', + `biblio_id` INT(11) DEFAULT NULL, `vendor_id` INT(11) DEFAULT NULL, `publication_title` VARCHAR(255) DEFAULT NULL, `external_id` VARCHAR(255) DEFAULT NULL, @@ -2955,6 +2956,7 @@ CREATE TABLE `erm_eholdings_titles` ( `preceeding_publication_title_id` VARCHAR(255) DEFAULT NULL, `access_type` VARCHAR(255) DEFAULT NULL, CONSTRAINT `erm_eholdings_titles_ibfk_1` FOREIGN KEY (`vendor_id`) REFERENCES `aqbooksellers` (`id`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `erm_eholdings_titles_ibfk_2` FOREIGN KEY (`biblio_id`) REFERENCES `biblio` (`biblionumber`) ON DELETE SET NULL ON UPDATE CASCADE, PRIMARY KEY(`title_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormAdd.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormAdd.vue index 2284321d36..7de8ea1a7c 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormAdd.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormAdd.vue @@ -480,6 +480,7 @@ export default { apiUrl += '/' + title.title_id } delete title.title_id + delete title.biblio_id title.resources.forEach(r => { r.started_on = r.started_on ? $date_to_rfc3339(r.started_on) : null diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesShow.vue b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesShow.vue index 9f526c21f8..9ee2ccaba8 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesShow.vue +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesShow.vue @@ -21,17 +21,21 @@
  1. - + - {{ title.title_id}} + {{ title.title_id }}
  2. {{ title.publication_title }} + + {{ $t("Local bibliographic record") }} +
  3. @@ -250,9 +254,7 @@ @@ -340,7 +342,7 @@ export default { }, methods: { async getTitle(title_id) { - const title= await fetchTitle(title_id) + const title = await fetchTitle(title_id) this.title = title this.initialized = true }, -- 2.39.5