Bugzilla – Attachment 170306 Details for
Bug 26869
Enable batch record modification to create 952/item 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.68 KB, created by
Pedro Amorim
on 2024-08-14 08:24:45 UTC
(
hide
)
Description:
Bug 26869: Add MARC modification template mapping validation
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2024-08-14 08:24:45 UTC
Size:
3.68 KB
patch
obsolete
>From 388615b541048888349b01206af30d7cacb9e37e 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> >--- > Koha/BackgroundJob/BatchUpdateBiblio.pm | 65 ++++++++++++++++++++++++- > 1 file changed, 63 insertions(+), 2 deletions(-) > >diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm >index 36cc8258d1..e2ffb95721 100644 >--- a/Koha/BackgroundJob/BatchUpdateBiblio.pm >+++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm >@@ -87,8 +87,14 @@ sub process { > 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 } ); >+ >+ 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, $biblionumber, $frameworkcode, { > overlay_context => $args->{overlay_context}, >@@ -166,4 +172,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.39.2
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