Bugzilla – Attachment 191337 Details for
Bug 37486
Selectively populate OAI-PMH set by set_id using build_oai_sets.pl
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37486: Only build OAI-PMH set for one set at a time
Bug-37486-Only-build-OAI-PMH-set-for-one-set-at-a-.patch (text/plain), 6.93 KB, created by
David Cook
on 2026-01-13 05:49:23 UTC
(
hide
)
Description:
Bug 37486: Only build OAI-PMH set for one set at a time
Filename:
MIME Type:
Creator:
David Cook
Created:
2026-01-13 05:49:23 UTC
Size:
6.93 KB
patch
obsolete
>From 1bf911f3cc117234511a351ee85c9d8ba5346b35 Mon Sep 17 00:00:00 2001 >From: David Cook <dcook@prosentient.com.au> >Date: Mon, 9 Dec 2024 05:01:19 +0000 >Subject: [PATCH] Bug 37486: Only build OAI-PMH set for one set at a time > >This change adds a "-s" parameter to build_oai_sets.pl, so that >you can selectively build OAI-PMH sets. > >This is useful when you have many sets, and you just need >to build or rebuild 1 set. > >Test plan: >0. Apply the patch and koha-plack --restart kohadev >1. Go to http://localhost:8081/cgi-bin/koha/admin/oai_sets.pl >2. Create setA and setB >3. Add mapping for setA: >245$a is equal to Gairm. >4. Add mapping for setB: >245$a is equal to Continuous delivery / >5. In the database, run the following SQL: >select * from oai_sets; > >6. Identify the ID for setB >7. Run the following command where XXXX is the ID for setB: >perl misc/migration_tools/build_oai_sets.pl -v -s XXXX > >8. Note that the only data added to the "oai_sets_biblios" >table is for setB > >9. prove t/db_dependent/OAI/Sets.t >--- > C4/OAI/Sets.pm | 25 ++++++++++++++++++++++--- > misc/migration_tools/build_oai_sets.pl | 20 ++++++++++++++------ > t/db_dependent/OAI/Sets.t | 10 +++++++++- > 3 files changed, 45 insertions(+), 10 deletions(-) > >diff --git a/C4/OAI/Sets.pm b/C4/OAI/Sets.pm >index ccc2d96db84..444a178537b 100644 >--- a/C4/OAI/Sets.pm >+++ b/C4/OAI/Sets.pm >@@ -68,12 +68,22 @@ The hash references looks like this: > =cut > > sub GetOAISets { >+ my ($args) = @_; >+ my $where = ''; >+ my @bind = (); >+ if ($args) { >+ if ( $args->{set_id} ) { >+ $where = ' WHERE id = ? '; >+ push( @bind, $args->{set_id} ); >+ } >+ } > my $dbh = C4::Context->dbh; > my $query = qq{ > SELECT * FROM oai_sets >+ $where > }; > my $sth = $dbh->prepare($query); >- $sth->execute; >+ $sth->execute(@bind); > my $results = $sth->fetchall_arrayref( {} ); > > $query = qq{ >@@ -330,12 +340,21 @@ The first hashref keys are the sets IDs, so it looks like this: > =cut > > sub GetOAISetsMappings { >+ my ($args) = @_; >+ my $where = ''; >+ my @bind = (); >+ if ($args) { >+ if ( $args->{set_id} ) { >+ $where = " WHERE set_id = ? "; >+ push( @bind, $args->{set_id} ); >+ } >+ } > my $dbh = C4::Context->dbh; > my $query = qq{ >- SELECT * FROM oai_sets_mappings ORDER BY set_id, rule_order >+ SELECT * FROM oai_sets_mappings $where ORDER BY set_id, rule_order > }; > my $sth = $dbh->prepare($query); >- $sth->execute; >+ $sth->execute(@bind); > > my $mappings = {}; > while ( my $result = $sth->fetchrow_hashref ) { >diff --git a/misc/migration_tools/build_oai_sets.pl b/misc/migration_tools/build_oai_sets.pl >index d3f6b48c0b8..9e353a36083 100755 >--- a/misc/migration_tools/build_oai_sets.pl >+++ b/misc/migration_tools/build_oai_sets.pl >@@ -25,7 +25,7 @@ oai_sets_mappings, and then fill table oai_sets_biblios with built infos. > > =head1 USAGE > >- build_oai_sets.pl [-h] [-v] [-r] [-i] [-l LENGTH [-o OFFSET]] >+ build_oai_sets.pl [-h] [-v] [-r] [-i] [-l LENGTH [-o OFFSET]] [-s set_id] > -h Print help message; > -v Be verbose > -r Truncate table oai_sets_biblios before inserting new rows >@@ -33,6 +33,7 @@ oai_sets_mappings, and then fill table oai_sets_biblios with built infos. > on item fields > -l LENGTH Process LENGTH biblios > -o OFFSET If LENGTH is defined, start processing from OFFSET >+ -s set_id If set_id is defined, only add records for this OAI-PMH set > > =cut > >@@ -58,7 +59,7 @@ use Koha::Biblio::Metadata; > > my %opts; > $Getopt::Std::STANDARD_HELP_VERSION = 1; >-my $go = getopts( 'vo:l:ihr', \%opts ); >+my $go = getopts( 'vo:l:ihrs:', \%opts ); > > if ( !$go or $opts{h} ) { > &print_usage; >@@ -70,11 +71,17 @@ my $offset = $opts{o}; > my $length = $opts{l}; > my $embed_items = $opts{i}; > my $reset = $opts{r}; >+my $set = $opts{s}; >+ >+my $selective_set = {}; >+if ($set) { >+ $selective_set->{set_id} = $set; >+} > > my $dbh = C4::Context->dbh; > > # Get OAI sets mappings >-my $mappings = GetOAISetsMappings; >+my $mappings = GetOAISetsMappings($selective_set); > > # Get all biblionumbers and marcxml > print "Retrieving biblios... " if $verbose; >@@ -102,7 +109,7 @@ my $results = $sth->fetchall_arrayref( {} ); > print "done.\n" if $verbose; > > # Build lists of parents sets >-my $sets = GetOAISets; >+my $sets = GetOAISets($selective_set); > my $parentsets; > foreach my $set (@$sets) { > my $setSpec = $set->{'spec'}; >@@ -178,10 +185,11 @@ print "done.\n"; > > sub print_usage { > print "build_oai_sets.pl: Build OAI-PMH sets, according to mappings defined in Koha\n"; >- print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]]\n\n"; >+ print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]] [ -s set_id]\n\n"; > print "\t-h\t\tPrint this help and exit\n"; > print "\t-v\t\t" . " Be verbose\n"; > print "\t-i\t\tEmbed items information, mandatory if you defined mappings on item fields\n"; > print "\t-l LENGTH\tProcess LENGTH biblios\n"; >- print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n\n"; >+ print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n"; >+ print "\t-s set_id\tIf set_id is defined, only add recods for this OAI-PMH set\n\n"; > } >diff --git a/t/db_dependent/OAI/Sets.t b/t/db_dependent/OAI/Sets.t >index fe46c89b1c9..636c9d1e90b 100755 >--- a/t/db_dependent/OAI/Sets.t >+++ b/t/db_dependent/OAI/Sets.t >@@ -19,7 +19,7 @@ > use Modern::Perl; > > use Test::NoWarnings; >-use Test::More tests => 154; >+use Test::More tests => 158; > use Test::MockModule; > use Test::Warn; > use MARC::Record; >@@ -149,6 +149,10 @@ is_deeply( $oai_sets->[1]->{descriptions}, ['descSet2'], 'description field is " > > ok( !defined( $oai_sets->[2] ), 'There are only 2 sets' ); > >+my $selective_oai_sets = GetOAISets( { set_id => $oai_sets->[0]->{id} } ); >+is( scalar @$selective_oai_sets, 1, 'Only 1 set retrieved via set_id' ); >+is_deeply( $oai_sets->[0], $selective_oai_sets->[0], 'Correct OAI set retrieved using selective get' ); >+ > # ---------- Testing GetOAISet ------------------ > ok( !defined(GetOAISet), 'GetOAISet without argument is undef' ); > >@@ -333,6 +337,10 @@ is( $mappings->{$set2_id}->[0]->{marcsubfield}, 'c', 'marcsubfiel > is( $mappings->{$set2_id}->[0]->{operator}, 'equal', 'operator field is "equal"' ); > is( $mappings->{$set2_id}->[0]->{marcvalue}, 'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"' ); > >+my $selective_mappings = GetOAISetsMappings( { set_id => $set1_id } ); >+is( scalar keys %$selective_mappings, 1, 'Selective mappings only returns mappings for selected set_id' ); >+is_deeply( $selective_mappings->{$set1_id}, $mappings->{$set1_id}, 'Correct mapping returned for selective mappings' ); >+ > # ---------- Testing GetOAISetMappings ---------- > ok( !defined(GetOAISetMappings), 'GetOAISetMappings without argument is undef' ); > >-- >2.39.5
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 37486
:
175286
|
175287
|
176287
|
176288
|
191337
|
192001