Bugzilla – Attachment 179014 Details for
Bug 26869
Enable batch record modification to create items on existing bibs
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 26869: Add MARC modification template mapping validation
Bug-26869-Add-MARC-modification-template-mapping-v.patch (text/plain), 3.92 KB, created by
Martin Renvoize (ashimema)
on 2025-03-06 13:30:18 UTC
(
hide
)
Description:
Bug 26869: Add MARC modification template mapping validation
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-03-06 13:30:18 UTC
Size:
3.92 KB
patch
obsolete
>From 319549ab71b3fbc82086147a321033f95a76545d Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Fri, 10 May 2024 12:33:04 +0000 >Subject: [PATCH] Bug 26869: Add MARC modification template mapping validation > >Follow the same test plan as above, but attempt to add an item without having at least homebranch, holdingbranch and type subfields. >Notice you now get an error with an appropriate message and the item is not added. > >Signed-off by: Chris Rowlands <chris.rowlands6@nhs.net> >Signed-off-by: Lisette Scheer <lisette@bywatersolutions.com> >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > Koha/BackgroundJob/BatchUpdateBiblio.pm | 67 +++++++++++++++++++++++-- > 1 file changed, 64 insertions(+), 3 deletions(-) > >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index 4381a0926eb..f46565afa84 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -86,9 +86,15 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { > my $biblio = Koha::Biblios->find($biblionumber); > my $record = $biblio->metadata->record; > C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); >- my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); >- my $biblioitemnumber = $biblio->biblioitem->biblioitemnumber; >- C4::Items::AddItemFromMarc( $record, $biblionumber, { biblioitemnumber => $biblioitemnumber } ); >+ my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); >+ >+ if ( marc_record_contains_item_data($record) ) { >+ my ( $can_add_item, $add_item_error_message ) = can_add_item_from_marc_record($record); >+ return $add_item_error_message unless $can_add_item; >+ >+ my $biblioitemnumber = $biblio->biblioitem->biblioitemnumber; >+ C4::Items::AddItemFromMarc( $record, $biblionumber, { biblioitemnumber => $biblioitemnumber } ); >+ } > > C4::Biblio::ModBiblio( > $record, >@@ -173,4 +179,59 @@ sub additional_report { > }; > } > >+=head3 marc_record_contains_item_data >+ >+Verify if marc record contains item data >+ >+=cut >+ >+sub marc_record_contains_item_data { >+ my ($record) = @_; >+ >+ my $itemfield = C4::Context->preference('marcflavour') eq 'UNIMARC' ? '995' : '952'; >+ my @item_fields = $record->field($itemfield); >+ return scalar @item_fields; >+} >+ >+=head3 can_add_item_from_marc_record >+ >+Checks if adding an item from MARC can be done by checking mandatory fields >+ >+=cut >+ >+sub can_add_item_from_marc_record { >+ my ($record) = @_; >+ >+ # Check that holdingbranch is set >+ my $holdingbranch_mss = Koha::MarcSubfieldStructures->find( >+ { >+ kohafield => 'items.holdingbranch', >+ } >+ ); >+ my @holdingbranch_exists = >+ grep { $_->subfield( $holdingbranch_mss->tagsubfield ) } $record->field( $holdingbranch_mss->tagfield ); >+ return ( 0, "No holdingbranch subfield found" ) unless ( scalar @holdingbranch_exists ); >+ >+ # Check that homebranch is set >+ my $homebranch_mss = Koha::MarcSubfieldStructures->find( >+ { >+ kohafield => 'items.homebranch', >+ } >+ ); >+ my @homebranch_exists = >+ grep { $_->subfield( $homebranch_mss->tagsubfield ) } $record->field( $homebranch_mss->tagfield ); >+ return ( 0, "No homebranch subfield found" ) unless ( scalar @homebranch_exists ); >+ >+ # Check that itemtype is set >+ my $item_mss = Koha::MarcSubfieldStructures->find( >+ { >+ kohafield => C4::Context->preference('item-level_itypes') ? 'items.itype' : 'biblioitems.itemtype', >+ } >+ ); >+ my @itemtype_exists = grep { $_->subfield( $item_mss->tagsubfield ) } $record->field( $item_mss->tagfield ); >+ return ( 0, "No itemtype subfield found" ) unless ( scalar @itemtype_exists ); >+ >+ return 1; >+} >+ > 1; >-- >2.48.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 26869
:
112687
|
162383
|
162387
|
162388
|
166541
|
167312
|
170305
|
170306
|
176397
|
176398
|
179013
| 179014 |
179015
|
179016