Bug 32030: Create a local bibliographic record for resources
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 20 Jun 2022 08:59:07 +0000 (10:59 +0200)
committerTomas Cohen Arazi <tomascohen@theke.io>
Tue, 8 Nov 2022 12:44:07 +0000 (09:44 -0300)
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 <jonathan.field@ptfs-europe.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/ERM/EHoldings/Resource.pm
Koha/ERM/EHoldings/Title.pm
api/v1/swagger/definitions/erm_eholdings_title.yaml
installer/data/mysql/atomicupdate/erm.pl
installer/data/mysql/kohastructure.sql
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesFormAdd.vue
koha-tmpl/intranet-tmpl/prog/js/vue/components/ERM/EHoldingsTitlesShow.vue

index da2ddba..a7badbb 100644 (file)
@@ -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
index b2ada02..7802581 100644 (file)
@@ -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;
                 }
             }
         );
index 6e6112a..e60a1fb 100644 (file)
@@ -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:
index 60a9332..98eceb1 100755 (executable)
@@ -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;
             });
index f0358f8..09101b7 100644 (file)
@@ -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;
 
index 2284321..7de8ea1 100644 (file)
@@ -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
index 9f526c2..9ee2cca 100644 (file)
             <fieldset class="rows">
                 <ol>
                     <li v-if="title.title_id">
-                        <label
-                            >{{ $t("Title identifier") }}:</label
-                        >
+                        <label>{{ $t("Title identifier") }}:</label>
                         <span>
-                            {{ title.title_id}}
+                            {{ title.title_id }}
                         </span>
                     </li>
                     <li>
                         <label>{{ $t("Publication title") }}:</label>
                         <span>
                             {{ title.publication_title }}
+                            <a
+                                v-if="title.biblio_id"
+                                :href="`/cgi-bin/koha/catalogue/detail.pl?biblionumber=${title.biblio_id}`"
+                            >
+                                {{ $t("Local bibliographic record") }}
+                            </a>
                         </span>
                     </li>
                     <li v-if="title.external_id">
                             </thead>
                             <tbody>
                                 <tr
-                                    v-for="(
-                                        r, counter
-                                    ) in title.resources"
+                                    v-for="(r, counter) in title.resources"
                                     v-bind:key="counter"
                                 >
                                     <td>
@@ -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
         },