Bugzilla – Attachment 163432 Details for
Bug 31791
Add the ability to lock records to prevent modification through the Koha staff interface
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31791: Add 'source_record_id' param to {Add,Mod}Biblio(Marc)
Bug-31791-Add-sourcerecordid-param-to-AddModBiblio.patch (text/plain), 9.06 KB, created by
Martin Renvoize (ashimema)
on 2024-03-19 14:13:38 UTC
(
hide
)
Description:
Bug 31791: Add 'source_record_id' param to {Add,Mod}Biblio(Marc)
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2024-03-19 14:13:38 UTC
Size:
9.06 KB
patch
obsolete
>From 0852d27dc0fc84393fd9cf6ce5a9e1414d21f0ff Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@theke.io> >Date: Thu, 8 Feb 2024 20:18:07 -0300 >Subject: [PATCH] Bug 31791: Add 'source_record_id' param to > {Add,Mod}Biblio(Marc) > >Sponsored-by: ByWater Solutions >Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com> >--- > C4/Biblio.pm | 43 ++++++++++++++++++---- > t/db_dependent/Biblio.t | 53 ++++++++++++++++++++++++++- > t/db_dependent/Biblio/ModBiblioMarc.t | 40 +++++++++++++++++++- > 3 files changed, 126 insertions(+), 10 deletions(-) > >diff --git a/C4/Biblio.pm b/C4/Biblio.pm >index 97048ca5f35..5a0b665547e 100644 >--- a/C4/Biblio.pm >+++ b/C4/Biblio.pm >@@ -178,7 +178,7 @@ The MARC record (in biblio_metadata.metadata) contains the complete marc record, > > =head2 AddBiblio > >- ($biblionumber,$biblioitemnumber) = AddBiblio($record,$frameworkcode); >+ ( $biblionumber, $biblioitemnumber ) = AddBiblio( $record, $frameworkcode, $options ); > > Exported function (core API) for adding a new biblio to koha. > >@@ -199,6 +199,8 @@ Unless C<disable_autolink> is passed AddBiblio will link record headings > to authorities based on settings in the system preferences. This flag allows > us to not link records when the authority linker is saving modifications. > >+=item B<record_source_id>: set as the record source when saving the record >+ > =back > > =cut >@@ -293,7 +295,13 @@ sub AddBiblio { > } > > # now add the record, don't index while we are in the transaction though >- ModBiblioMarc( $record, $biblionumber, { skip_record_index => 1 } ); >+ ModBiblioMarc( >+ $record, $biblionumber, >+ { >+ skip_record_index => 1, >+ record_source_id => $options->{record_source_id}, >+ } >+ ); > > # update OAI-PMH sets > if(C4::Context->preference("OAI-PMH:AutoUpdateSets")) { >@@ -360,6 +368,10 @@ task to rebuild the holds queue for the biblio if I<RealTimeHoldsQueue> is enabl > > Used when the indexing schedulling will be handled by the caller > >+=item C<record_source_id> >+ >+Set as the record source when saving the record. >+ > =back > > Returns 1 on success 0 on failure >@@ -370,7 +382,14 @@ sub ModBiblio { > my ( $record, $biblionumber, $frameworkcode, $options ) = @_; > > $options //= {}; >- my $mod_biblio_marc_options = { skip_record_index => $options->{'skip_record_index'} // 0 }; >+ my $mod_biblio_marc_options = { >+ skip_record_index => $options->{'skip_record_index'} // 0, >+ ( >+ ( exists $options->{record_source_id} ) >+ ? ( record_source_id => $options->{record_source_id} ) >+ : () >+ ) >+ }; > > if (!$record) { > carp 'No record passed to ModBiblio'; >@@ -2795,7 +2814,7 @@ sub _koha_delete_biblio_metadata { > > =head2 ModBiblioMarc > >- ModBiblioMarc($newrec, $biblionumber, $options); >+ ModBiblioMarc( $newrec, $biblionumber, $options ); > > Add MARC XML data for a biblio to koha > >@@ -2805,7 +2824,9 @@ The C<$options> argument is a hashref with additional parameters: > > =over 4 > >-=item C<skip_record_index>: used when the indexing scheduling will be handled by the caller >+=item B<skip_record_index>: used when the indexing scheduling will be handled by the caller >+ >+=item B<record_source_id>: set as the record source when saving the record > > =back > >@@ -2885,8 +2906,16 @@ sub ModBiblioMarc { > Koha::Util::MARC::set_marc_field($record, C4::Context->preference('MarcFieldForModifierName'), $borrowername); > } > >- $m_rs->metadata( $record->as_xml_record($encoding) ); >- $m_rs->store; >+ $m_rs->set( >+ { >+ metadata => $record->as_xml_record($encoding), >+ ( >+ exists $options->{record_source_id} >+ ? ( record_source_id => $options->{record_source_id} ) >+ : () >+ ) >+ } >+ )->store; > > unless ( $skip_record_index ) { > my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); >diff --git a/t/db_dependent/Biblio.t b/t/db_dependent/Biblio.t >index 4f096f7fe1c..5a7ed6cfaa6 100755 >--- a/t/db_dependent/Biblio.t >+++ b/t/db_dependent/Biblio.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 20; >+use Test::More tests => 21; > use Test::MockModule; > use Test::Warn; > use List::MoreUtils qw( uniq ); >@@ -45,7 +45,7 @@ Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); > my $builder = t::lib::TestBuilder->new; > > subtest 'AddBiblio' => sub { >- plan tests => 9; >+ plan tests => 10; > > my $marcflavour = 'MARC21'; > t::lib::Mocks::mock_preference( 'marcflavour', $marcflavour ); >@@ -99,6 +99,25 @@ subtest 'AddBiblio' => sub { > warning_like { $builder->build_sample_biblio(); } > qr/My biblionumber is \d+ and my frameworkcode is /, "The biblionumber is correctly passed to BiblioAutoLink"; > >+ subtest 'record_source_id param tests' => sub { >+ >+ plan tests => 2; >+ >+ my $source = $builder->build_object( { class => 'Koha::RecordSources' } ); >+ >+ my $record = MARC::Record->new; >+ $record->append_fields( MARC::Field->new( '245', ' ', ' ', a => 'Some title' ) ); >+ >+ my ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => undef } ); >+ my $metadata = Koha::Biblios->find($biblio_id)->metadata; >+ >+ is( $metadata->record_source_id, undef, 'Record source is not defined' ); >+ >+ ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => $source->id } ); >+ $metadata = Koha::Biblios->find($biblio_id)->metadata; >+ >+ is( $metadata->record_source_id, $source->id, 'Record source is stored as expected' ); >+ }; > }; > > subtest 'GetMarcSubfieldStructureFromKohaField' => sub { >@@ -1022,6 +1041,36 @@ subtest 'ModBiblio on invalid record' => sub { > ); > }; > >+subtest 'ModBiblio - record_source_id param tests' => sub { >+ >+ plan tests => 4; >+ >+ my $source = $builder->build_object( { class => 'Koha::RecordSources' } ); >+ >+ my $record = MARC::Record->new; >+ $record->append_fields( MARC::Field->new( '245', ' ', ' ', a => 'Some title' ) ); >+ >+ my ($biblio_id) = C4::Biblio::AddBiblio( $record, '', { record_source_id => undef } ); >+ my $metadata = Koha::Biblios->find($biblio_id)->metadata; >+ >+ is( $metadata->record_source_id, undef, 'Record source is not defined' ); >+ >+ C4::Biblio::ModBiblio( $record, $biblio_id, '', { record_source_id => $source->id } ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, $source->id, 'Record source is stored as expected' ); >+ >+ C4::Biblio::ModBiblio( $record, $biblio_id, '' ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, $source->id, 'Record source not passed, remains untouched' ); >+ >+ C4::Biblio::ModBiblio( $record, $biblio_id, '', { record_source_id => undef } ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, undef, 'Record source is not defined' ); >+}; >+ > # Cleanup > Koha::Caches->get_instance->clear_from_cache( "MarcSubfieldStructure-" ); > $schema->storage->txn_rollback; >diff --git a/t/db_dependent/Biblio/ModBiblioMarc.t b/t/db_dependent/Biblio/ModBiblioMarc.t >index fc38684c39b..a1fb6cf5968 100755 >--- a/t/db_dependent/Biblio/ModBiblioMarc.t >+++ b/t/db_dependent/Biblio/ModBiblioMarc.t >@@ -17,7 +17,7 @@ > > use Modern::Perl; > >-use Test::More tests => 2; >+use Test::More tests => 3; > use t::lib::Mocks; > use t::lib::TestBuilder; > use MARC::Record; >@@ -27,6 +27,8 @@ use Koha::Database; > use Koha::Biblios; > > my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ > $schema->storage->txn_begin; > > subtest "Check MARC field length calculation" => sub { >@@ -82,3 +84,39 @@ subtest "StripWhitespaceChars tests" => sub { > }; > > $schema->storage->txn_rollback; >+ >+subtest "record_source_id parameter tests" => sub { >+ >+ plan tests => 5; >+ >+ $schema->storage->txn_begin; >+ >+ my $biblio = $builder->build_sample_biblio; >+ my $source = $builder->build_object( { class => 'Koha::RecordSources' } ); >+ >+ my $metadata = $biblio->metadata; >+ >+ is( $metadata->record_source_id, undef, 'Record source not set for biblio' ); >+ >+ C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => undef } ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, undef, 'Record source not set for biblio' ); >+ >+ C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => $source->id } ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, $source->id, 'Record source set for biblio' ); >+ >+ C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, $source->id, 'Record source param not passed, no change' ); >+ >+ C4::Biblio::ModBiblioMarc( $metadata->record, $biblio->id, { record_source_id => undef } ); >+ $metadata->discard_changes; >+ >+ is( $metadata->record_source_id, undef, 'Record source passed but undef, unset for biblio' ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.44.0
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 31791
:
163371
|
163372
|
163373
|
163374
|
163375
|
163376
|
163377
|
163378
|
163405
|
163408
|
163410
|
163411
|
163413
|
163414
|
163415
|
163416
|
163426
|
163427
|
163428
|
163429
|
163430
|
163431
|
163432
|
163433
|
163434
|
163531
|
163532
|
163533
|
163534
|
163535
|
163536
|
163537
|
163538
|
163539
|
163545
|
164193
|
164194
|
164195
|
164196
|
164197
|
164696
|
164697
|
164698
|
164699
|
164700
|
164701
|
164702
|
164703
|
164704
|
164705
|
165044
|
165045
|
165046
|
165047
|
165048
|
165049
|
165050
|
165051
|
165052
|
165053
|
165697