Bugzilla – Attachment 180251 Details for
Bug 39518
Add the option to define the basket name in a MARC file when adding to a basket
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 39518: Update object methods and unit tests
Bug-39518-Update-object-methods-and-unit-tests.patch (text/plain), 5.85 KB, created by
Matt Blenkinsop
on 2025-04-02 08:01:45 UTC
(
hide
)
Description:
Bug 39518: Update object methods and unit tests
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2025-04-02 08:01:45 UTC
Size:
5.85 KB
patch
obsolete
>From 8c2416cb67c6246f845b236a65b23bc4691a2a56 Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@openfifth.co.uk> >Date: Wed, 2 Apr 2025 08:01:03 +0000 >Subject: [PATCH] Bug 39518: Update object methods and unit tests > >--- > Koha/MarcOrder.pm | 79 ++++++++++++++++++++++++++------- > t/db_dependent/Koha/MarcOrder.t | 57 +++++++++++++++++++++++- > 2 files changed, 119 insertions(+), 17 deletions(-) > >diff --git a/Koha/MarcOrder.pm b/Koha/MarcOrder.pm >index fa8cc831fe4..56633fcae86 100644 >--- a/Koha/MarcOrder.pm >+++ b/Koha/MarcOrder.pm >@@ -236,8 +236,10 @@ sub _create_basket_for_file { > my $filename = $args->{filename}; > my $vendor_id = $args->{vendor_id}; > >+ my $basket_name = _check_file_for_basket_name($args); >+ > # aqbasketname.basketname has a max length of 50 characters so long file names will need to be truncated >- my $basketname = length($filename) > 50 ? substr( $filename, 0, 50 ) : $filename; >+ my $basketname = length($basket_name) > 50 ? substr( $basket_name, 0, 50 ) : $basket_name; > > my $basketno = NewBasket( > $vendor_id, 0, $basketname, q{}, >@@ -543,23 +545,11 @@ sub add_items_from_import_record { > sub match_file_to_account { > my ( $self, $args ) = @_; > >- my $match = 0; >- my $filename = $args->{filename}; >- my $filepath = $args->{filepath}; >- my $profile = $args->{profile}; >- my $format = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML'; >+ my $profile = $args->{profile}; > >- my ( $errors, $marcrecords ); >- if ( $format eq 'MARCXML' ) { >- ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); >- } elsif ( $format eq 'ISO2709' ) { >- ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( >- $filepath, $profile->record_type, >- $profile->encoding >- ); >- } >+ my $match = 0; >+ my $match_record = _retrieve_first_record_from_batch($args); > >- my $match_record = @{$marcrecords}[0]; > my ( $field, $subfield ) = split /\$/, $profile->match_field; > > my $field_value = $match_record->subfield( $field, $subfield ) || ''; >@@ -572,6 +562,36 @@ sub match_file_to_account { > return $match; > } > >+=head3 _check_file_for_basket_name >+ >+ my $basket_name = _check_file_for_basket_name({ >+ filename => $filename, >+ filepath => $filepath, >+ profile => $profile >+ }); >+ >+ Checks to see if the account has a basket name field assigned. >+ If yes, it retrieves this value to use as the name. >+ If not, to uses the filename. >+ >+=cut >+ >+sub _check_file_for_basket_name { >+ my ( $self, $args ) = @_; >+ >+ my $profile = $args->{profile}; >+ my $filename = $args->{filename}; >+ return $filename if !$profile->basket_name_field; >+ >+ my $first_record = _retrieve_first_record_from_batch($args); >+ >+ my ( $field, $subfield ) = split /\$/, $profile->basket_name_field; >+ >+ my $field_value = $first_record->subfield( $field, $subfield ) || ''; >+ >+ return $field_value ? $field_value : $filename; >+} >+ > =head3 import_batches_list > > Fetches import batches matching the batch to be added to the basket and returns these to the template >@@ -1251,4 +1271,31 @@ sub _create_item_fields_from_syspref { > return $item_fields; > } > >+=head3 _retrieve_first_record_from_batch >+ >+=cut >+ >+sub _retrieve_first_record_from_batch { >+ my ($args) = @_; >+ >+ my $filename = $args->{filename}; >+ my $filepath = $args->{filepath}; >+ my $profile = $args->{profile}; >+ my $format = index( $filename, '.mrc' ) != -1 ? 'ISO2709' : 'MARCXML'; >+ >+ my ( $errors, $marcrecords ); >+ if ( $format eq 'MARCXML' ) { >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromMARCXMLFile( $filepath, $profile->encoding ); >+ } elsif ( $format eq 'ISO2709' ) { >+ ( $errors, $marcrecords ) = C4::ImportBatch::RecordsFromISO2709File( >+ $filepath, $profile->record_type, >+ $profile->encoding >+ ); >+ } >+ >+ my $first_record = @{$marcrecords}[0]; >+ return $first_record; >+ >+} >+ > 1; >diff --git a/t/db_dependent/Koha/MarcOrder.t b/t/db_dependent/Koha/MarcOrder.t >index b9e05cfb546..c849652a53c 100755 >--- a/t/db_dependent/Koha/MarcOrder.t >+++ b/t/db_dependent/Koha/MarcOrder.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 5; >+use Test::More tests => 6; > > use Koha::MarcOrder; > use Koha::MarcOrderAccount; >@@ -627,3 +627,58 @@ subtest 'match_file_to_account' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest '_check_file_for_basket_name' => sub { >+ plan tests => 2; >+ >+ $schema->storage->txn_begin; >+ >+ my ( $fh, $name ) = tempfile( SUFFIX => '.marcxml' ); >+ >+ my $rec = MARC::Record->new; >+ my $fld = MARC::Field->new( '975', '', '', 'p', 'This is a basket' ); >+ $rec->append_fields($fld); >+ my $str = $rec->as_xml; >+ >+ print $fh $str; >+ >+ close $fh; >+ >+ my $account1 = Koha::MarcOrderAccount->new( >+ { >+ basket_name_field => '975$p', >+ encoding => 'UTF-8', >+ description => 'test', >+ } >+ )->store; >+ >+ my $basket_name = Koha::MarcOrder->_check_file_for_basket_name( >+ { >+ filename => $name, >+ filepath => $name, >+ profile => $account1, >+ } >+ ); >+ >+ is( $basket_name, "This is a basket", 'Basket name identified correctly' ); >+ >+ my $account2 = Koha::MarcOrderAccount->new( >+ { >+ basket_name_field => '975$z', >+ encoding => 'UTF-8', >+ description => 'test', >+ } >+ )->store; >+ >+ my $basket_name2 = Koha::MarcOrder->_check_file_for_basket_name( >+ { >+ filename => $name, >+ filepath => $name, >+ profile => $account2, >+ } >+ ); >+ >+ is( $basket_name2, $name, 'No filename provided in the file' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >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 39518
:
180248
|
180249
|
180250
|
180251
|
180271
|
180277
|
180278
|
180279
|
180280
|
180281
|
180286
|
180287
|
180288
|
180289
|
180290
|
180293
|
180294
|
180295
|
180296
|
180297
|
180553
|
180554
|
180555
|
180556
|
180557