Lines 5-16
use C4::Context;
Link Here
|
5 |
use Getopt::Long; |
5 |
use Getopt::Long; |
6 |
use Pod::Usage; |
6 |
use Pod::Usage; |
7 |
|
7 |
|
8 |
my $gt_biblionumber; |
8 |
my $start_biblionumber; |
9 |
my $batch_size; |
9 |
my $batch_size; |
10 |
my $help; |
10 |
my $help; |
11 |
GetOptions( |
11 |
GetOptions( |
12 |
'gt_biblionumber=i' => \$gt_biblionumber, |
12 |
'startbiblionumber=i' => \$start_biblionumber, |
13 |
'batch_size=i' => \$batch_size, |
13 |
'batchsize=i' => \$batch_size, |
14 |
'h|help|?' => \$help |
14 |
'h|help|?' => \$help |
15 |
); |
15 |
); |
16 |
if ($help) { |
16 |
if ($help) { |
Lines 18-48
if ($help) {
Link Here
|
18 |
} |
18 |
} |
19 |
|
19 |
|
20 |
my $dbh = C4::Context->dbh; |
20 |
my $dbh = C4::Context->dbh; |
21 |
my $step = $batch_size || 25000; |
21 |
$batch_size ||= 25000; # TODO: Assert positive number |
22 |
my $offset = 0; |
22 |
|
23 |
my $prev_biblionumber; |
23 |
if (!$start_biblionumber) { |
24 |
my ($max_biblionumber) = @{ $dbh->selectcol_arrayref(qq{SELECT MAX(`biblionumber`) FROM `biblio`}) }; |
24 |
my ($min_biblionumber) = @{ $dbh->selectcol_arrayref(qq{SELECT MIN(`biblionumber`) FROM `biblio`}) }; |
25 |
my @ranges; |
25 |
$start_biblionumber = $min_biblionumber; |
26 |
my $biblionumber; |
26 |
} |
27 |
|
27 |
|
28 |
while (1) { |
28 |
while (1) { |
29 |
my $query = $gt_biblionumber ? |
29 |
my $offset = $batch_size - 1; |
30 |
qq{SELECT `biblionumber` FROM `biblio` WHERE `biblionumber` >= $gt_biblionumber ORDER BY `biblionumber` ASC LIMIT 1 OFFSET $offset} : |
30 |
my $query = |
31 |
qq{SELECT `biblionumber` FROM `biblio` ORDER BY `biblionumber` ASC LIMIT 1 OFFSET $offset}; |
31 |
qq{SELECT `biblionumber` FROM `biblio` WHERE `biblionumber` >= $start_biblionumber ORDER BY `biblionumber` ASC LIMIT 2 OFFSET $offset}; |
32 |
my ($biblionumber) = @{ $dbh->selectcol_arrayref($query) }; |
32 |
my ($end_biblionumber, $next_biblionumber) = @{ $dbh->selectcol_arrayref($query) }; |
33 |
if (!$biblionumber) { |
33 |
if (!$end_biblionumber) { |
34 |
push @ranges, [$prev_biblionumber, $max_biblionumber]; |
34 |
if ($start_biblionumber) { |
|
|
35 |
my ($max_biblionumber) = @{ $dbh->selectcol_arrayref(qq{SELECT MAX(`biblionumber`) FROM `biblio`}) }; |
36 |
if($max_biblionumber >= $start_biblionumber) { |
37 |
# @TODO: Option for argument and range separator? |
38 |
print join(' ', ($start_biblionumber, $max_biblionumber)) . "\n"; |
39 |
|
40 |
} |
41 |
} |
35 |
last; |
42 |
last; |
36 |
} |
43 |
} |
37 |
elsif ($prev_biblionumber) { |
44 |
else { |
38 |
push @ranges, [$prev_biblionumber, $biblionumber - 1]; |
45 |
print join(' ', ($start_biblionumber, $end_biblionumber)) . "\n"; |
|
|
46 |
} |
47 |
if ($next_biblionumber) { |
48 |
$start_biblionumber = $next_biblionumber; |
49 |
} |
50 |
else { |
51 |
last; |
39 |
} |
52 |
} |
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 |
} |
53 |
} |
47 |
|
54 |
|
48 |
=head1 NAME |
55 |
=head1 NAME |
Lines 51-57
record batches - This script outputs ranges of biblionumbers
Link Here
|
51 |
|
58 |
|
52 |
=head1 SYNOPSIS |
59 |
=head1 SYNOPSIS |
53 |
|
60 |
|
54 |
record_batches.pl [-h|--help] [--gt_biblionumber=BIBLIONUMBER] |
61 |
record_batches.pl [-h|--help] [--start_biblionumber=BIBLIONUMBER] |
55 |
|
62 |
|
56 |
=head1 OPTIONS |
63 |
=head1 OPTIONS |
57 |
|
64 |
|
Lines 61-68
record_batches.pl [-h|--help] [--gt_biblionumber=BIBLIONUMBER]
Link Here
|
61 |
|
68 |
|
62 |
Print a brief help message. |
69 |
Print a brief help message. |
63 |
|
70 |
|
64 |
=item B<--gt_biblionumber> |
71 |
=item B<--startbiblionumber> |
65 |
|
72 |
|
66 |
--gt_biblionumber=BIBLIONUMBER Output batches with biblionumber >= BIBLIONUMBER |
73 |
--startbiblionumber=BIBLIONUMBER Output batches with biblionumber >= BIBLIONUMBER |
67 |
|
74 |
|
68 |
=item B<--batch_size> |
75 |
=item B<--batchsize> |
69 |
- |
|
|