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 builded 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 builded 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 179-188 print "done.\n"; Link Here
179
186
180
sub print_usage {
187
sub print_usage {
181
    print "build_oai_sets.pl: Build OAI-PMH sets, according to mappings defined in Koha\n";
188
    print "build_oai_sets.pl: Build OAI-PMH sets, according to mappings defined in Koha\n";
182
    print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]]\n\n";
189
    print "Usage: build_oai_sets.pl [-h] [-v] [-i] [-l LENGTH [-o OFFSET]] [ -s set_id]\n\n";
183
    print "\t-h\t\tPrint this help and exit\n";
190
    print "\t-h\t\tPrint this help and exit\n";
184
    print "\t-v\t\tBe verbose\n";
191
    print "\t-v\t\tBe verbose\n";
185
    print "\t-i\t\tEmbed items informations, mandatory if you defined mappings on item fields\n";
192
    print "\t-i\t\tEmbed items informations, mandatory if you defined mappings on item fields\n";
186
    print "\t-l LENGTH\tProcess LENGTH biblios\n";
193
    print "\t-l LENGTH\tProcess LENGTH biblios\n";
187
    print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n\n";
194
    print "\t-o OFFSET\tIf LENGTH is defined, start processing from OFFSET\n";
195
    print "\t-s set_id\tIf set_id is defined, only add recods for this OAI-PMH set\n\n";
188
}
196
}
(-)a/t/db_dependent/OAI/Sets.t (-2 / +7 lines)
Lines 18-24 Link Here
18
18
19
use Modern::Perl;
19
use Modern::Perl;
20
20
21
use Test::More tests => 153;
21
use Test::More tests => 157;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
use MARC::Record;
24
use MARC::Record;
Lines 144-149 is_deeply ($oai_sets->[1]->{descriptions}, ['descSet2'], 'description field is " Link Here
144
144
145
ok(!defined($oai_sets->[2]), 'There are only 2 sets');
145
ok(!defined($oai_sets->[2]), 'There are only 2 sets');
146
146
147
my $selective_oai_sets = GetOAISets( { set_id => $oai_sets->[0]->{id} } );
148
is( scalar @$selective_oai_sets, 1, 'Only 1 set retrieved via set_id' );
149
is_deeply( $oai_sets->[0], $selective_oai_sets->[0], 'Correct OAI set retrieved using selective get' );
147
150
148
# ---------- Testing GetOAISet ------------------
151
# ---------- Testing GetOAISet ------------------
149
ok (!defined(GetOAISet), 'GetOAISet without argument is undef');
152
ok (!defined(GetOAISet), 'GetOAISet without argument is undef');
Lines 330-335 is ($mappings->{$set2_id}->[0]->{marcsubfield}, 'c', 'marcsubfield field is "c"' Link Here
330
is ($mappings->{$set2_id}->[0]->{operator}, 'equal', 'operator field is "equal"');
333
is ($mappings->{$set2_id}->[0]->{operator}, 'equal', 'operator field is "equal"');
331
is ($mappings->{$set2_id}->[0]->{marcvalue}, 'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"');
334
is ($mappings->{$set2_id}->[0]->{marcvalue}, 'myOtherMarcValue', 'marcvalue field is "myOtherMarcValue"');
332
335
336
my $selective_mappings = GetOAISetsMappings( { set_id => $set1_id } );
337
is( scalar keys %$selective_mappings, 1, 'Selective mappings only returns mappings for selected set_id' );
338
is_deeply($selective_mappings->{$set1_id},$mappings->{$set1_id}, 'Correct mapping returned for selective mappings');
333
339
334
# ---------- Testing GetOAISetMappings ----------
340
# ---------- Testing GetOAISetMappings ----------
335
ok (!defined(GetOAISetMappings), 'GetOAISetMappings without argument is undef');
341
ok (!defined(GetOAISetMappings), 'GetOAISetMappings without argument is undef');
336
- 

Return to bug 37486