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

(-)a/Koha/BiblioUtils.pm (-3 / +17 lines)
Lines 111-121 The iterator is a Koha::MetadataIterator object. Link Here
111
=cut
111
=cut
112
112
113
sub get_all_biblios_iterator {
113
sub get_all_biblios_iterator {
114
    my ($self, $params) = @_;
114
    my $database = Koha::Database->new();
115
    my $database = Koha::Database->new();
115
    my $schema   = $database->schema();
116
    my $schema   = $database->schema();
116
    my $rs =
117
    $params //= {};
117
      $schema->resultset('Biblio')->search( {},
118
118
        { columns => [qw/ biblionumber /] } );
119
    my $conditions = {};
120
121
    if ($params->{start_biblionumber}) {
122
        $conditions->{biblionumber}->{'>='} = $params->{start_biblionumber};
123
    }
124
125
    if ($params->{end_biblionumber}) {
126
        $conditions->{biblionumber}->{'<='} = $params->{end_biblionumber};
127
    }
128
129
    my $rs = $schema->resultset('Biblio')->search(
130
        $conditions,
131
        { columns => [qw/ biblionumber /] }
132
    );
119
    my $next_func = sub {
133
    my $next_func = sub {
120
        # Warn and skip bad records, otherwise we break the loop
134
        # Warn and skip bad records, otherwise we break the loop
121
        while (1) {
135
        while (1) {
(-)a/misc/record_batches.pl (+68 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use C4::Context;
5
use Getopt::Long;
6
use Pod::Usage;
7
8
my $gt_biblionumber;
9
my $batch_size;
10
my $help;
11
GetOptions(
12
    'gt_biblionumber=i' => \$gt_biblionumber,
13
    'batch_size=i' => \$batch_size,
14
    'h|help|?' => \$help
15
);
16
if ($help) {
17
    pod2usage(1);
18
}
19
20
my $dbh = C4::Context->dbh;
21
my $step = $batch_size || 25000;
22
my $offset = 0;
23
my $prev_biblionumber;
24
my ($max_biblionumber) = @{ $dbh->selectcol_arrayref(qq{SELECT MAX(`biblionumber`) FROM `biblio`}) };
25
my @ranges;
26
my $biblionumber;
27
28
while (1) {
29
    my $query = $gt_biblionumber ?
30
        qq{SELECT `biblionumber` FROM `biblio` WHERE `biblionumber` >= $gt_biblionumber ORDER BY `biblionumber` ASC LIMIT 1 OFFSET $offset} :
31
        qq{SELECT `biblionumber` FROM `biblio` ORDER BY `biblionumber` ASC LIMIT 1 OFFSET $offset};
32
    my ($biblionumber) = @{ $dbh->selectcol_arrayref($query) };
33
    if (!$biblionumber) {
34
        push @ranges, [$prev_biblionumber, $max_biblionumber];
35
        last;
36
    }
37
    elsif ($prev_biblionumber) {
38
        push @ranges, [$prev_biblionumber, $biblionumber - 1];
39
    }
40
    $prev_biblionumber = $biblionumber;
41
    $offset += $step;
42
}
43
44
foreach my $range (@ranges) {
45
    print join(' ', @{$range}) . "\n"; # @TODO: Option for argument and range separtor?
46
}
47
48
=head1 NAME
49
50
record batches - This script outputs ranges of biblionumbers
51
52
=head1 SYNOPSIS
53
54
record_batches.pl [-h|--help] [--gt_biblionumber=BIBLIONUMBER]
55
56
=head1 OPTIONS
57
58
=over
59
60
=item B<-h|--help>
61
62
Print a brief help message.
63
64
=item B<--gt_biblionumber>
65
66
 --gt_biblionumber=BIBLIONUMBER Output batches with biblionumber >= BIBLIONUMBER
67
68
=item B<--batch_size>
(-)a/misc/search_tools/rebuild_elastic_search.pl (-5 / +25 lines)
Lines 64-69 Only index the supplied biblionumber, mostly for testing purposes. May be Link Here
64
repeated. This also applies to authorities via authid, so if you're using it,
64
repeated. This also applies to authorities via authid, so if you're using it,
65
you probably only want to do one or the other at a time.
65
you probably only want to do one or the other at a time.
66
66
67
=item B<-sbn|--start-bnumber>
68
69
Only index biblios with biblionumber greater or equal than supplied
70
biblionumber.
71
72
=item B<-ebn|--end-bnumber>
73
74
Only index biblios with biblionumber less or equal to supplied biblionumber.
75
67
=item B<-v|--verbose>
76
=item B<-v|--verbose>
68
77
69
By default, this program only emits warnings and errors. This makes it talk
78
By default, this program only emits warnings and errors. This makes it talk
Lines 94-102 use Pod::Usage; Link Here
94
103
95
my $verbose = 0;
104
my $verbose = 0;
96
my $commit = 5000;
105
my $commit = 5000;
97
my ($delete, $help, $man);
106
my (
98
my ($index_biblios, $index_authorities);
107
    $delete,
99
my (@biblionumbers);
108
    $help,
109
    $man,
110
    $index_biblios,
111
    $index_authorities,
112
    @biblionumbers,
113
    $start_biblionumber,
114
    $end_biblionumber
115
);
100
116
101
$|=1; # flushes output
117
$|=1; # flushes output
102
118
Lines 106-111 GetOptions( Link Here
106
    'a|authorities' => \$index_authorities,
122
    'a|authorities' => \$index_authorities,
107
    'b|biblios' => \$index_biblios,
123
    'b|biblios' => \$index_biblios,
108
    'bn|bnumber=i' => \@biblionumbers,
124
    'bn|bnumber=i' => \@biblionumbers,
125
    'sbn|start-bnumber=i' => \$start_biblionumber,
126
    'ebn|end-bnumber=i' => \$end_biblionumber,
109
    'v|verbose+'       => \$verbose,
127
    'v|verbose+'       => \$verbose,
110
    'h|help'           => \$help,
128
    'h|help'           => \$help,
111
    'man'              => \$man,
129
    'man'              => \$man,
Lines 131-137 if ($index_biblios) { Link Here
131
            return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 ));
149
            return ($r, Koha::BiblioUtils->get_from_biblionumber($r, item_data => 1 ));
132
        };
150
        };
133
    } else {
151
    } else {
134
        my $records = Koha::BiblioUtils->get_all_biblios_iterator();
152
        my $records = Koha::BiblioUtils->get_all_biblios_iterator({
153
            'start_biblionumber' => $start_biblionumber,
154
            'end_biblionumber' => $end_biblionumber,
155
        });
135
        $next = sub {
156
        $next = sub {
136
            $records->next();
157
            $records->next();
137
        }
158
        }
138
- 

Return to bug 21872