From b69facedc4f0c1c2194244df9d97460851b273a5 Mon Sep 17 00:00:00 2001
From: Galen Charlton
Date: Wed, 14 Nov 2007 17:11:34 -0600
Subject: [PATCH] matching enhancements -- allow matching rule to be changed on
the fly
Enhancement to store the matching rule associated with an
import batch and to allow the current matching rule in
effect to be changed and the duplicate detection redone.
Signed-off-by: Chris Cormack
Signed-off-by: Joshua Ferraro
---
C4/ImportBatch.pm | 52 ++++++++++++++++++-
C4/Matcher.pm | 1 +
installer/data/mysql/kohastructure.sql | 1 +
installer/data/mysql/updatedatabase.pl | 7 +++
.../en/modules/tools/manage-marc-import.tmpl | 39 ++++++++++++++
kohaversion.pl | 2 +-
tools/manage-marc-import.pl | 50 ++++++++++++++++++
tools/stage-marc-import.pl | 1 +
8 files changed, 150 insertions(+), 3 deletions(-)
diff --git a/C4/ImportBatch.pm b/C4/ImportBatch.pm
index 05dae6719d..dfd0506a8c 100644
--- a/C4/ImportBatch.pm
+++ b/C4/ImportBatch.pm
@@ -21,7 +21,6 @@ use strict;
use C4::Context;
use C4::Koha;
use C4::Biblio;
-use C4::Matcher;
require Exporter;
@@ -69,6 +68,8 @@ use C4::ImportBatch;
SetImportBatchStatus
GetImportBatchOverlayAction
SetImportBatchOverlayAction
+ GetImportBatchMatcher
+ SetImportBatchMatcher
GetImportRecordOverlayStatus
SetImportRecordOverlayStatus
GetImportRecordStatus
@@ -390,12 +391,16 @@ sub BatchFindBibDuplicates {
&$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');
}
}
@@ -842,6 +847,49 @@ sub SetImportBatchOverlayAction {
}
+=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
diff --git a/C4/Matcher.pm b/C4/Matcher.pm
index 16f42c268f..505ff27f36 100644
--- a/C4/Matcher.pm
+++ b/C4/Matcher.pm
@@ -166,6 +166,7 @@ sub fetch {
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 = {};
diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql
index 739e08d402..3d3b6a2125 100644
--- a/installer/data/mysql/kohastructure.sql
+++ b/installer/data/mysql/kohastructure.sql
@@ -846,6 +846,7 @@ CREATE TABLE `ethnicity` (
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,
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 6242034cba..688c26214a 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -673,6 +673,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
}
+$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
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl
index 4d05c0621c..0153499f7b 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/manage-marc-import.tmpl
@@ -37,6 +37,36 @@
+
+
+ ()
+
+ No matching rule in effect
+
+
+
+
+
+