use C4::Context;
use C4::Koha;
use C4::Biblio;
-use C4::Matcher;
require Exporter;
SetImportBatchStatus
GetImportBatchOverlayAction
SetImportBatchOverlayAction
+ GetImportBatchMatcher
+ SetImportBatchMatcher
GetImportRecordOverlayStatus
SetImportRecordOverlayStatus
GetImportRecordStatus
&$progress_callback($rec_num);
}
my $marc_record = MARC::Record->new_from_usmarc($rowref->{'marc'});
- my @matches = $matcher->get_matches($marc_record, $max_matches);
+ my @matches = ();
+ if (defined $matcher) {
+ @matches = $matcher->get_matches($marc_record, $max_matches);
+ }
if (scalar(@matches) > 0) {
$num_with_matches++;
SetImportRecordMatches($rowref->{'import_record_id'}, @matches);
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'auto_match');
} else {
+ SetImportRecordMatches($rowref->{'import_record_id'}, ());
SetImportRecordOverlayStatus($rowref->{'import_record_id'}, 'no_match');
}
}
}
+=head2 GetImportBatchMatcher
+
+=over 4
+
+my $matcher_id = GetImportBatchMatcher($batch_id);
+
+=back
+
+=cut
+
+sub GetImportBatchMatcher {
+ my ($batch_id) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("SELECT matcher_id FROM import_batches WHERE import_batch_id = ?");
+ $sth->execute($batch_id);
+ my ($matcher_id) = $sth->fetchrow_array();
+ $sth->finish();
+ return $matcher_id;
+
+}
+
+
+=head2 SetImportBatchMatcher
+
+=over 4
+
+SetImportBatchMatcher($batch_id, $new_matcher_id);
+
+=back
+
+=cut
+
+sub SetImportBatchMatcher {
+ my ($batch_id, $new_matcher_id) = @_;
+
+ my $dbh = C4::Context->dbh;
+ my $sth = $dbh->prepare("UPDATE import_batches SET matcher_id = ? WHERE import_batch_id = ?");
+ $sth->execute($new_matcher_id, $batch_id);
+ $sth->finish();
+
+}
+
=head2 GetImportRecordOverlayStatus
=over 4
my $sth = $dbh->prepare_cached("SELECT * FROM marc_matchers WHERE matcher_id = ?");
$sth->execute($id);
my $row = $sth->fetchrow_hashref;
+ $sth->finish();
return undef unless defined $row;
my $self = {};
DROP TABLE IF EXISTS `import_batches`;
CREATE TABLE `import_batches` (
`import_batch_id` int(11) NOT NULL auto_increment,
+ `matcher_id` int(11) default NULL,
`template_id` int(11) default NULL,
`branchcode` varchar(10) default NULL,
`num_biblios` int(11) NOT NULL default 0,
}
+$DBversion = "3.00.00.029";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+ $dbh->do("ALTER TABLE `import_batches` ADD `matcher_id` int(11) NULL AFTER `import_batch_id`");
+ print "Upgrade to $DBversion done (adding matcher_id to import_batches)\n";
+ SetVersion ($DBversion);
+}
+
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table
<p><label>Comments</label> <!-- TMPL_VAR name="comments" --></p>
<p><label>Staged</label> <!-- TMPL_VAR name="upload_timestamp" --></p>
<p><label>Status</label> <!-- TMPL_VAR name="import_status" --></p>
+<p><label>Matching rule applied</label>
+<!-- TMPL_IF name="current_matcher_id" -->
+ <!-- TMPL_VAR name="current_matcher_code" --> (<!-- TMPL_VAR name="current_matcher_description" -->)
+<!-- TMPL_ELSE -->
+ No matching rule in effect
+<!-- /TMPL_IF -->
+<!-- TMPL_IF name="can_commit" -->
+<p>
+ <form action="<!-- TMPL_VAR name="script_name" -->" method="post">
+ <input type="hidden" name="op" value="redo-matching" />
+ <input type="hidden" name="import_batch_id" value="<!-- TMPL_VAR name="import_batch_id" -->" />
+ <input type="hidden" name="current_matcher_id" value="<!-- TMPL_VAR name="current_matcher_id" -->" />
+ <select name="new_matcher_id" id="new_matcher_id">
+ <option value="">Do not look for matching records</option>
+ <!-- TMPL_LOOP name="available_matchers" -->
+ <!-- TMPL_IF name="selected" -->
+ <option value="<!-- TMPL_VAR name="matcher_id" -->" selected="selected">
+ <!-- TMPL_VAR name="code" --> (<!-- TMPL_VAR name="description" -->)
+ </option>
+ <!-- TMPL_ELSE -->
+ <option value="<!-- TMPL_VAR name="matcher_id" -->">
+ <!-- TMPL_VAR name="code" --> (<!-- TMPL_VAR name="description" -->)
+ </option>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_LOOP -->
+ </select>
+ <input type="submit" class="button" value="Apply different matching rule" />
+ </form>
+</p>
+<!-- /TMPL_IF -->
<p>
<!-- TMPL_IF name="can_commit" -->
<form action="<!-- TMPL_VAR name="script_name" -->" method="post">
<tr><td>Number of records ignored</td><td><!-- TMPL_VAR name="num_ignored" --></td></tr>
</table>
<!-- /TMPL_IF -->
+ <!-- TMPL_IF name="rematch_attempted" -->
+ <!-- TMPL_IF name="rematch_failed" -->
+ <p><span class="problem">Failed to apply different matching rule</span></p>
+ <!-- TMPL_ELSE -->
+ <p><span class="problem">Applied different matching rule. Number of records matched now
+ <!-- TMPL_VAR name="num_with_matches" -->
+ </span></p>
+ <!-- /TMPL_IF -->
+ <!-- /TMPL_IF -->
<!-- /TMPL_IF -->
<br />
# and is automatically called by Auth.pm when needed.
sub kohaversion {
- return "3.00.00.028";
+ return "3.00.00.029";
}
1;
import_biblios_list($template, $import_batch_id, $offset, $results_per_page);
} elsif ($op eq "clean-batch") {
;
+} elsif ($op eq "redo-matching") {
+ my $new_matcher_id = $input->param('new_matcher_id');
+ my $current_matcher_id = $input->param('current_matcher_id');
+ redo_matching($template, $import_batch_id, $new_matcher_id, $current_matcher_id);
+ import_biblios_list($template, $import_batch_id, $offset, $results_per_page);
}
output_html_with_http_headers $input, $cookie, $template->output;
exit 0;
+sub redo_matching {
+ my ($template, $import_batch_id, $new_matcher_id, $current_matcher_id) = @_;
+ my $rematch_failed = 0;
+ return if not defined $new_matcher_id and not defined $current_matcher_id;
+ return if $new_matcher_id == $current_matcher_id;
+ my $num_with_matches = 0;
+ if (defined $new_matcher_id and $new_matcher_id ne "") {
+ my $matcher = C4::Matcher->fetch($new_matcher_id);
+ if (defined $matcher) {
+ $num_with_matches = BatchFindBibDuplicates($import_batch_id, $matcher);
+ SetImportBatchMatcher($import_batch_id, $new_matcher_id);
+ } else {
+ $rematch_failed = 1;
+ }
+ } else {
+ $num_with_matches = BatchFindBibDuplicates($import_batch_id, undef);
+ SetImportBatchMatcher($import_batch_id, undef);
+ }
+ $template->param(rematch_failed => $rematch_failed);
+ $template->param(rematch_attempted => 1);
+ $template->param(num_with_matches => $num_with_matches);
+}
+
sub import_batches_list {
my ($template, $offset, $results_per_page) = @_;
my $batches = GetImportBatchRangeDesc($offset, $results_per_page);
if ($batch->{'import_status'} eq 'imported') {
$template->param(can_revert => 1);
}
+ if (defined $batch->{'matcher_id'}) {
+ my $matcher = C4::Matcher->fetch($batch->{'matcher_id'});
+ if (defined $matcher) {
+ $template->param('current_matcher_id' => $batch->{'matcher_id'});
+ $template->param('current_matcher_code' => $matcher->code());
+ $template->param('current_matcher_description' => $matcher->description());
+ }
+ }
+ add_matcher_list($batch->{'matcher_id'});
+}
+
+sub add_matcher_list {
+ my $current_matcher_id = shift;
+ my @matchers = C4::Matcher::GetMatcherList();
+ if (defined $current_matcher_id) {
+ for (my $i = 0; $i <= $#matchers; $i++) {
+ if ($matchers[$i]->{'matcher_id'} == $current_matcher_id) {
+ $matchers[$i]->{'selected'} = 1;
+ }
+ }
+ }
+ $template->param(available_matchers => \@matchers);
}
sub add_page_numbers {
$checked_matches = 1;
$matcher_code = $matcher->code();
$num_with_matches = BatchFindBibDuplicates($batch_id, $matcher);
+ SetImportBatchMatcher($batch_id, $matcher_id);
} else {
$matcher_failed = 1;
}