View | Details | Raw Unified | Return to bug 37486
Collapse All | Expand All

(-)a/C4/OAI/Sets.pm (-3 / +22 lines)
Lines 68-79 The hash references looks like this: Link Here
68
=cut
68
=cut
69
69
70
sub GetOAISets {
70
sub GetOAISets {
71
    my ($args) = @_;
72
    my $where  = '';
73
    my @bind   = ();
74
    if ($args) {
75
        if ( $args->{set_id} ) {
76
            $where = ' WHERE id = ? ';
77
            push( @bind, $args->{set_id} );
78
        }
79
    }
71
    my $dbh   = C4::Context->dbh;
80
    my $dbh   = C4::Context->dbh;
72
    my $query = qq{
81
    my $query = qq{
73
        SELECT * FROM oai_sets
82
        SELECT * FROM oai_sets
83
        $where
74
    };
84
    };
75
    my $sth = $dbh->prepare($query);
85
    my $sth = $dbh->prepare($query);
76
    $sth->execute;
86
    $sth->execute(@bind);
77
    my $results = $sth->fetchall_arrayref( {} );
87
    my $results = $sth->fetchall_arrayref( {} );
78
88
79
    $query = qq{
89
    $query = qq{
Lines 330-341 The first hashref keys are the sets IDs, so it looks like this: Link Here
330
=cut
340
=cut
331
341
332
sub GetOAISetsMappings {
342
sub GetOAISetsMappings {
343
    my ($args) = @_;
344
    my $where  = '';
345
    my @bind   = ();
346
    if ($args) {
347
        if ( $args->{set_id} ) {
348
            $where = " WHERE set_id = ? ";
349
            push( @bind, $args->{set_id} );
350
        }
351
    }
333
    my $dbh   = C4::Context->dbh;
352
    my $dbh   = C4::Context->dbh;
334
    my $query = qq{
353
    my $query = qq{
335
        SELECT * FROM oai_sets_mappings ORDER BY set_id, rule_order
354
        SELECT * FROM oai_sets_mappings $where ORDER BY set_id, rule_order
336
    };
355
    };
337
    my $sth = $dbh->prepare($query);
356
    my $sth = $dbh->prepare($query);
338
    $sth->execute;
357
    $sth->execute(@bind);
339
358
340
    my $mappings = {};
359
    my $mappings = {};
341
    while ( my $result = $sth->fetchrow_hashref ) {
360
    while ( my $result = $sth->fetchrow_hashref ) {
(-)a/misc/migration_tools/build_oai_sets.pl (-6 / +14 lines)
Lines 25-31 oai_sets_mappings, and then fill table oai_sets_biblios with built infos. Link Here
25
25
26
=head1 USAGE
26
=head1 USAGE
27
27
28
    build_oai_sets.pl [-h] [-v] [-r] [-i] [-l LENGTH [-o OFFSET]]
28
    build_oai_sets.pl [-h] [-v] [-r] [-i] [-l LENGTH [-o OFFSET]] [-s set_id]
29
        -h          Print help message;
29
        -h          Print help message;
30
        -v          Be verbose
30
        -v          Be verbose
31
        -r          Truncate table oai_sets_biblios before inserting new rows
31
        -r          Truncate table oai_sets_biblios before inserting new rows
Lines 33-38 oai_sets_mappings, and then fill table oai_sets_biblios with built infos. Link Here
33
                    on item fields
33
                    on item fields
34
        -l LENGTH   Process LENGTH biblios
34
        -l LENGTH   Process LENGTH biblios
35
        -o OFFSET   If LENGTH is defined, start processing from OFFSET
35
        -o OFFSET   If LENGTH is defined, start processing from OFFSET
36
        -s set_id   If set_id is defined, only add records for this OAI-PMH set
36
37
37
=cut
38
=cut
38
39
Lines 58-64 use Koha::Biblio::Metadata; Link Here
58
59
59
my %opts;
60
my %opts;
60
$Getopt::Std::STANDARD_HELP_VERSION = 1;
61
$Getopt::Std::STANDARD_HELP_VERSION = 1;
61
my $go = getopts( 'vo:l:ihr', \%opts );
62
my $go = getopts( 'vo:l:ihrs:', \%opts );
62
63
63
if ( !$go or $opts{h} ) {
64
if ( !$go or $opts{h} ) {
64
    &print_usage;
65
    &print_usage;
Lines 70-80 my $offset = $opts{o}; Link Here
70
my $length      = $opts{l};
71
my $length      = $opts{l};
71
my $embed_items = $opts{i};
72
my $embed_items = $opts{i};
72
my $reset       = $opts{r};
73
my $reset       = $opts{r};
74
my $set         = $opts{s};
75
76
my $selective_set = {};
77
if ($set) {
78
    $selective_set->{set_id} = $set;
79
}
73
80
74
my $dbh = C4::Context->dbh;
81
my $dbh = C4::Context->dbh;
75
82
76
# Get OAI sets mappings
83
# Get OAI sets mappings
77
my $mappings = GetOAISetsMappings;
84
my $mappings = GetOAISetsMappings($selective_set);
78
85
79
# Get all biblionumbers and marcxml
86
# Get all biblionumbers and marcxml
80
print "Retrieving biblios... " if $verbose;
87
print "Retrieving biblios... " if $verbose;
Lines 102-108 my $results = $sth->fetchall_arrayref( {} ); Link Here
102
print "done.\n" if $verbose;
109
print "done.\n" if $verbose;
103
110
104
# Build lists of parents sets
111
# Build lists of parents sets
105
my $sets = GetOAISets;
112
my $sets = GetOAISets($selective_set);
106
my $parentsets;
113
my $parentsets;
107
foreach my $set (@$sets) {
114
foreach my $set (@$sets) {
108
    my $setSpec = $set->{'spec'};
115
    my $setSpec = $set->{'spec'};
Lines 178-187 print "done.\n"; Link Here
178
185
179
sub print_usage {
186
sub print_usage {
180
    print "build_oai_sets.pl: Build OAI-PMH sets, according to mappings defined in Koha\n";
187
    print "build_oai_sets.pl: Build OAI-PMH sets, according to mappings defined in Koha\n";
181
    print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]]\n\n";
188
    print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]] [ -s set_id]\n\n";
182
    print "\t-h\t\tPrint this help and exit\n";
189
    print "\t-h\t\tPrint this help and exit\n";
183
    print "\t-v\t\t" . " Be verbose\n";
190
    print "\t-v\t\t" . " Be verbose\n";
184
    print "\t-i\t\tEmbed items information, mandatory if you defined mappings on item fields\n";
191
    print "\t-i\t\tEmbed items information, mandatory if you defined mappings on item fields\n";
185
    print "\t-l LENGTH\tProcess LENGTH biblios\n";
192
    print "\t-l LENGTH\tProcess LENGTH biblios\n";
186
    print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n\n";
193
    print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n";
194
    print "\t-s set_id\tIf set_id is defined, only add recods for this OAI-PMH set\n\n";
187
}
195
}
(-)a/t/db_dependent/OAI/Sets.t (-2 / +9 lines)
Lines 19-25 Link Here
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::NoWarnings;
21
use Test::NoWarnings;
22
use Test::More tests => 154;
22
use Test::More tests => 158;
23
use Test::MockModule;
23
use Test::MockModule;
24
use Test::Warn;
24
use Test::Warn;
25
use MARC::Record;
25
use MARC::Record;
Lines 149-154 is_deeply( $oai_sets->[1]->{descriptions}, ['descSet2'], 'description field is " Link Here
149
149
150
ok( !defined( $oai_sets->[2] ), 'There are only 2 sets' );
150
ok( !defined( $oai_sets->[2] ), 'There are only 2 sets' );
151
151
152
my $selective_oai_sets = GetOAISets( { set_id => $oai_sets->[0]->{id} } );
153
is( scalar @$selective_oai_sets, 1, 'Only 1 set retrieved via set_id' );
154
is_deeply( $oai_sets->[0], $selective_oai_sets->[0], 'Correct OAI set retrieved using selective get' );
155
152
# ---------- Testing GetOAISet ------------------
156
# ---------- Testing GetOAISet ------------------
153
ok( !defined(GetOAISet), 'GetOAISet without argument is undef' );
157
ok( !defined(GetOAISet), 'GetOAISet without argument is undef' );
154
158
Lines 333-338 is( $mappings->{$set2_id}->[0]->{marcsubfield}, 'c', 'marcsubfiel Link Here
333
is( $mappings->{$set2_id}->[0]->{operator},     'equal',            'operator field is "equal"' );
337
is( $mappings->{$set2_id}->[0]->{operator},     'equal',            'operator field is "equal"' );
334
is( $mappings->{$set2_id}->[0]->{marcvalue},    'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"' );
338
is( $mappings->{$set2_id}->[0]->{marcvalue},    'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"' );
335
339
340
my $selective_mappings = GetOAISetsMappings( { set_id => $set1_id } );
341
is( scalar keys %$selective_mappings, 1, 'Selective mappings only returns mappings for selected set_id' );
342
is_deeply( $selective_mappings->{$set1_id}, $mappings->{$set1_id}, 'Correct mapping returned for selective mappings' );
343
336
# ---------- Testing GetOAISetMappings ----------
344
# ---------- Testing GetOAISetMappings ----------
337
ok( !defined(GetOAISetMappings), 'GetOAISetMappings without argument is undef' );
345
ok( !defined(GetOAISetMappings), 'GetOAISetMappings without argument is undef' );
338
346
339
- 

Return to bug 37486