Lines 26-35
use C4::Biblio qw(
Link Here
|
26 |
); |
26 |
); |
27 |
use C4::Log qw( cronlogaction ); |
27 |
use C4::Log qw( cronlogaction ); |
28 |
use Koha::Biblios; |
28 |
use Koha::Biblios; |
29 |
use Getopt::Long qw( GetOptions ); |
29 |
use Getopt::Long qw( GetOptions ); |
30 |
use Pod::Usage qw( pod2usage ); |
30 |
use Pod::Usage qw( pod2usage ); |
31 |
use Time::HiRes qw( time ); |
31 |
use Time::HiRes qw( time ); |
32 |
use POSIX qw( ceil strftime ); |
32 |
use POSIX qw( ceil strftime ); |
33 |
use Module::Load::Conditional qw( can_load ); |
33 |
use Module::Load::Conditional qw( can_load ); |
34 |
|
34 |
|
35 |
use Koha::Database; |
35 |
use Koha::Database; |
Lines 54-61
my $commit = 100;
Link Here
|
54 |
my $tagtolink; |
54 |
my $tagtolink; |
55 |
my $allowrelink = C4::Context->preference("LinkerRelink") // ''; |
55 |
my $allowrelink = C4::Context->preference("LinkerRelink") // ''; |
56 |
|
56 |
|
57 |
my $command_line_options = join(" ", @ARGV); |
57 |
my $command_line_options = join( " ", @ARGV ); |
58 |
my $result = GetOptions( |
58 |
my $result = GetOptions( |
59 |
'v|verbose' => \$verbose, |
59 |
'v|verbose' => \$verbose, |
60 |
't|test' => \$test_only, |
60 |
't|test' => \$test_only, |
61 |
'l|link-report' => \$link_report, |
61 |
'l|link-report' => \$link_report, |
Lines 74-81
if ( not $result or $want_help ) {
Link Here
|
74 |
|
74 |
|
75 |
cronlogaction( { info => $command_line_options } ); |
75 |
cronlogaction( { info => $command_line_options } ); |
76 |
|
76 |
|
77 |
my $linker_module = |
77 |
my $linker_module = "C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' ); |
78 |
"C4::Linker::" . ( C4::Context->preference("LinkerModule") || 'Default' ); |
|
|
79 |
unless ( can_load( modules => { $linker_module => undef } ) ) { |
78 |
unless ( can_load( modules => { $linker_module => undef } ) ) { |
80 |
$linker_module = 'C4::Linker::Default'; |
79 |
$linker_module = 'C4::Linker::Default'; |
81 |
unless ( can_load( modules => { $linker_module => undef } ) ) { |
80 |
unless ( can_load( modules => { $linker_module => undef } ) ) { |
Lines 96-122
my $num_bad_bibs = 0;
Link Here
|
96 |
my %unlinked_headings; |
95 |
my %unlinked_headings; |
97 |
my %linked_headings; |
96 |
my %linked_headings; |
98 |
my %fuzzy_headings; |
97 |
my %fuzzy_headings; |
99 |
my $dbh = C4::Context->dbh; |
98 |
my $dbh = C4::Context->dbh; |
100 |
my @updated_biblios = (); |
99 |
my @updated_biblios = (); |
101 |
my $indexer = Koha::SearchEngine::Indexer->new({ index => $Koha::SearchEngine::BIBLIOS_INDEX }); |
100 |
my $indexer = Koha::SearchEngine::Indexer->new( { index => $Koha::SearchEngine::BIBLIOS_INDEX } ); |
102 |
|
101 |
|
103 |
my $schema = Koha::Database->schema; |
102 |
my $schema = Koha::Database->schema; |
104 |
$schema->txn_begin; |
103 |
$schema->txn_begin; |
105 |
process_bibs( $linker, $bib_limit, $auth_limit, $commit, { tagtolink => $tagtolink, allowrelink => $allowrelink }); |
104 |
process_bibs( $linker, $bib_limit, $auth_limit, $commit, { tagtolink => $tagtolink, allowrelink => $allowrelink } ); |
106 |
|
105 |
|
107 |
exit 0; |
106 |
exit 0; |
108 |
|
107 |
|
109 |
sub process_bibs { |
108 |
sub process_bibs { |
110 |
my ( $linker, $bib_limit, $auth_limit, $commit, $args ) = @_; |
109 |
my ( $linker, $bib_limit, $auth_limit, $commit, $args ) = @_; |
111 |
my $tagtolink = $args->{tagtolink}; |
110 |
my $tagtolink = $args->{tagtolink}; |
112 |
my $allowrelink = $args->{allowrelink}; |
111 |
my $allowrelink = $args->{allowrelink}; |
113 |
my $bib_where = ''; |
112 |
my $bib_where = ''; |
114 |
my $starttime = time(); |
113 |
my $starttime = time(); |
115 |
if ($bib_limit) { |
114 |
if ($bib_limit) { |
116 |
$bib_where = "WHERE $bib_limit"; |
115 |
$bib_where = "WHERE $bib_limit"; |
117 |
} |
116 |
} |
118 |
my $sql = |
117 |
my $sql = "SELECT biblionumber FROM biblio $bib_where ORDER BY biblionumber ASC"; |
119 |
"SELECT biblionumber FROM biblio $bib_where ORDER BY biblionumber ASC"; |
|
|
120 |
my $sth = $dbh->prepare($sql); |
118 |
my $sth = $dbh->prepare($sql); |
121 |
$sth->execute(); |
119 |
$sth->execute(); |
122 |
my $linker_args = { tagtolink => $tagtolink, allowrelink => $allowrelink }; |
120 |
my $linker_args = { tagtolink => $tagtolink, allowrelink => $allowrelink }; |
Lines 141-150
sub process_bibs {
Link Here
|
141 |
for ( values %unlinked_headings ) { $headings_unlinked += $_; } |
139 |
for ( values %unlinked_headings ) { $headings_unlinked += $_; } |
142 |
for ( values %fuzzy_headings ) { $headings_fuzzy += $_; } |
140 |
for ( values %fuzzy_headings ) { $headings_fuzzy += $_; } |
143 |
|
141 |
|
144 |
my $endtime = time(); |
142 |
my $endtime = time(); |
145 |
my $totaltime = ceil (($endtime - $starttime) * 1000); |
143 |
my $totaltime = ceil( ( $endtime - $starttime ) * 1000 ); |
146 |
$starttime = strftime('%D %T', localtime($starttime)); |
144 |
$starttime = strftime( '%D %T', localtime($starttime) ); |
147 |
$endtime = strftime('%D %T', localtime($endtime)); |
145 |
$endtime = strftime( '%D %T', localtime($endtime) ); |
148 |
|
146 |
|
149 |
my $summary = <<_SUMMARY_; |
147 |
my $summary = <<_SUMMARY_; |
150 |
|
148 |
|
Lines 173-181
Linked headings (from most frequent to least):
Link Here
|
173 |
|
171 |
|
174 |
_LINKED_HEADER_ |
172 |
_LINKED_HEADER_ |
175 |
|
173 |
|
176 |
@keys = sort { |
174 |
@keys = sort { $linked_headings{$b} <=> $linked_headings{$a} or "\L$a" cmp "\L$b" } keys %linked_headings; |
177 |
$linked_headings{$b} <=> $linked_headings{$a} or "\L$a" cmp "\L$b" |
|
|
178 |
} keys %linked_headings; |
179 |
foreach my $key (@keys) { |
175 |
foreach my $key (@keys) { |
180 |
print "$key:\t" . $linked_headings{$key} . " occurrences\n"; |
176 |
print "$key:\t" . $linked_headings{$key} . " occurrences\n"; |
181 |
} |
177 |
} |
Lines 187-196
Unlinked headings (from most frequent to least):
Link Here
|
187 |
|
183 |
|
188 |
_UNLINKED_HEADER_ |
184 |
_UNLINKED_HEADER_ |
189 |
|
185 |
|
190 |
@keys = sort { |
186 |
@keys = sort { $unlinked_headings{$b} <=> $unlinked_headings{$a} or "\L$a" cmp "\L$b" } keys %unlinked_headings; |
191 |
$unlinked_headings{$b} <=> $unlinked_headings{$a} |
|
|
192 |
or "\L$a" cmp "\L$b" |
193 |
} keys %unlinked_headings; |
194 |
foreach my $key (@keys) { |
187 |
foreach my $key (@keys) { |
195 |
print "$key:\t" . $unlinked_headings{$key} . " occurrences\n"; |
188 |
print "$key:\t" . $unlinked_headings{$key} . " occurrences\n"; |
196 |
} |
189 |
} |
Lines 202-210
Fuzzily-matched headings (from most frequent to least):
Link Here
|
202 |
|
195 |
|
203 |
_FUZZY_HEADER_ |
196 |
_FUZZY_HEADER_ |
204 |
|
197 |
|
205 |
@keys = sort { |
198 |
@keys = sort { $fuzzy_headings{$b} <=> $fuzzy_headings{$a} or "\L$a" cmp "\L$b" } keys %fuzzy_headings; |
206 |
$fuzzy_headings{$b} <=> $fuzzy_headings{$a} or "\L$a" cmp "\L$b" |
|
|
207 |
} keys %fuzzy_headings; |
208 |
foreach my $key (@keys) { |
199 |
foreach my $key (@keys) { |
209 |
print "$key:\t" . $fuzzy_headings{$key} . " occurrences\n"; |
200 |
print "$key:\t" . $fuzzy_headings{$key} . " occurrences\n"; |
210 |
} |
201 |
} |
Lines 215-226
_FUZZY_HEADER_
Link Here
|
215 |
sub process_bib { |
206 |
sub process_bib { |
216 |
my $linker = shift; |
207 |
my $linker = shift; |
217 |
my $biblionumber = shift; |
208 |
my $biblionumber = shift; |
218 |
my $args = shift; |
209 |
my $args = shift; |
219 |
my $tagtolink = $args->{tagtolink}; |
210 |
my $tagtolink = $args->{tagtolink}; |
220 |
my $allowrelink = $args->{allowrelink}; |
211 |
my $allowrelink = $args->{allowrelink}; |
221 |
my $biblio = Koha::Biblios->find($biblionumber); |
212 |
my $biblio = Koha::Biblios->find($biblionumber); |
222 |
my $record; |
213 |
my $record; |
223 |
eval { $record = $biblio->metadata->record; }; |
214 |
eval { $record = $biblio->metadata->record; }; |
|
|
215 |
|
224 |
unless ( defined $record ) { |
216 |
unless ( defined $record ) { |
225 |
warn "Could not retrieve bib $biblionumber from the database - record is corrupt."; |
217 |
warn "Could not retrieve bib $biblionumber from the database - record is corrupt."; |
226 |
$num_bad_bibs++; |
218 |
$num_bad_bibs++; |
Lines 262-273
sub process_bib {
Link Here
|
262 |
); |
254 |
); |
263 |
} |
255 |
} |
264 |
if ( not $test_only ) { |
256 |
if ( not $test_only ) { |
265 |
ModBiblio( $record, $biblionumber, $frameworkcode, { |
257 |
ModBiblio( |
266 |
disable_autolink => 1, |
258 |
$record, |
267 |
skip_holds_queue => 1, |
259 |
$biblionumber, |
268 |
skip_record_index =>1 |
260 |
$frameworkcode, |
269 |
}); |
261 |
{ |
|
|
262 |
disable_autolink => 1, |
263 |
skip_holds_queue => 1, |
264 |
skip_record_index => 1 |
265 |
} |
266 |
); |
270 |
push @updated_biblios, $biblionumber; |
267 |
push @updated_biblios, $biblionumber; |
|
|
268 |
|
271 |
#Last param is to note ModBiblio was called from linking script and bib should not be linked again |
269 |
#Last param is to note ModBiblio was called from linking script and bib should not be linked again |
272 |
$num_bibs_modified++; |
270 |
$num_bibs_modified++; |
273 |
} |
271 |
} |