Bugzilla – Attachment 161994 Details for
Bug 35993
AddBiblio should add 005 just like ModBiblio updates it
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 35993: Add SimpleMarc::update_last_transaction_time
Bug-35993-Add-SimpleMarcupdatelasttransactiontime.patch (text/plain), 3.79 KB, created by
Lucas Gass (lukeg)
on 2024-02-09 18:31:50 UTC
(
hide
)
Description:
Bug 35993: Add SimpleMarc::update_last_transaction_time
Filename:
MIME Type:
Creator:
Lucas Gass (lukeg)
Created:
2024-02-09 18:31:50 UTC
Size:
3.79 KB
patch
obsolete
>From fd8ab2194f0a956de22d15b5ee3a1a0952292d18 Mon Sep 17 00:00:00 2001 >From: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Date: Mon, 5 Feb 2024 13:09:54 +0000 >Subject: [PATCH] Bug 35993: Add SimpleMarc::update_last_transaction_time > >Note: This routine does not check field existence like >ModBiblioMarc does/did (see next patch). So it inserts >a field 005 if it is not present. > >Test plan: >Run t/SimpleMARC.t > >Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl> >Signed-off-by: Phil Ringnalda <phil@chetcolibrary.org> >Signed-off-by: Lucas Gass <lucas@bywatersolutions.com> >--- > Koha/SimpleMARC.pm | 49 +++++++++++++++++++++++++++++++++++++--------- > t/SimpleMARC.t | 20 +++++++++++++++++-- > 2 files changed, 58 insertions(+), 11 deletions(-) > >diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm >index a77ce9ea9e..be7f025ea2 100644 >--- a/Koha/SimpleMARC.pm >+++ b/Koha/SimpleMARC.pm >@@ -18,21 +18,24 @@ package Koha::SimpleMARC; > > use Modern::Perl; > >+use constant LAST_TRANSACTION_FIELD => q/005/; # MARC21/UNIMARC >+ > our (@ISA, @EXPORT_OK); > BEGIN { > require Exporter; > our @ISA = qw(Exporter); > > @EXPORT_OK = qw( >- read_field >- add_field >- update_field >- copy_field >- copy_and_replace_field >- move_field >- delete_field >- field_exists >- field_equals >+ read_field >+ add_field >+ update_field >+ copy_field >+ copy_and_replace_field >+ move_field >+ delete_field >+ field_exists >+ field_equals >+ update_last_transaction_time > ); > } > >@@ -525,6 +528,33 @@ sub delete_field { > } > } > >+=head3 update_last_transaction_time >+ >+ update_last_transaction_time( { record => $record } ); >+ >+ Inserts or updates field for last transaction (005) >+ >+=cut >+ >+sub update_last_transaction_time { >+ my ($params) = @_; >+ my $record = $params->{record}; >+ >+ my @localtime = (localtime)[ 5, 4, 3, 2, 1, 0 ]; >+ $localtime[0] += 1900; # add century >+ $localtime[1]++; # month 1-based >+ >+ my $value = sprintf( "%4d%02d%02d%02d%02d%04.1f", @localtime ); >+ my $field; >+ if ( $field = $record->field(LAST_TRANSACTION_FIELD) ) { >+ $field->update($value); >+ } else { >+ $record->insert_fields_ordered( >+ MARC::Field->new( LAST_TRANSACTION_FIELD, $value ), >+ ); >+ } >+} >+ > sub _delete_field { > my ( $params ) = @_; > my $record = $params->{record}; >@@ -663,5 +693,6 @@ sub _modify_values { > } > return @$values; > } >+ > 1; > __END__ >diff --git a/t/SimpleMARC.t b/t/SimpleMARC.t >index cb53df77e5..3e8e840ff8 100755 >--- a/t/SimpleMARC.t >+++ b/t/SimpleMARC.t >@@ -2,11 +2,14 @@ > > use Modern::Perl; > >-use Test::More tests => 11; >+use Test::More tests => 12; > > use_ok("MARC::Field"); > use_ok("MARC::Record"); >-use_ok("Koha::SimpleMARC", qw( field_exists read_field update_field copy_field copy_and_replace_field move_field delete_field field_equals )); >+use_ok( >+ "Koha::SimpleMARC", >+ qw( field_exists read_field update_field copy_field copy_and_replace_field move_field delete_field field_equals update_last_transaction_time ) >+); > > sub new_record { > my $record = MARC::Record->new; >@@ -1833,3 +1836,16 @@ subtest 'field_equals' => sub { > is_deeply( $match, [1], 'first 008 control field matches "eng"' ); > }; > }; >+ >+subtest 'update_last_transaction_time' => sub { >+ plan tests => 3; >+ my $record = MARC::Record->new; >+ update_last_transaction_time( { record => $record } ); >+ my $value1 = $record->field('005')->data; >+ like( $value1, qr/^\d{14}\.0$/, 'Looks like a 005' ); >+ sleep 1; >+ update_last_transaction_time( { record => $record } ); >+ my $value2 = $record->field('005')->data; >+ like( $value2, qr/^\d{14}\.0$/, 'Still looks like a 005' ); >+ isnt( $value1, $value2, 'Should not be the same a second later' ); >+}; >-- >2.30.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 35993
:
161761
|
161762
|
161776
|
161777
|
161778
|
161805
|
161992
|
161993
|
161994
|
161995
|
165271
|
165272
|
165370
|
165371
|
165746
|
165748
|
166063