From 8369aa8431a7948d0b26c59be94ff5b90f71a7a2 Mon Sep 17 00:00:00 2001 From: Mirko Tietgen Date: Fri, 14 Dec 2012 18:01:37 +0100 Subject: [PATCH] Bug 9295: Introduce operator equal/ notequal to OAI set mapping instead of hardcoded 'equal' value. In OAI set mappings, the value "is equal to" is hardcoded. This enhancement changes it to a dropdown menu to choose between "is equal to" and "not equal to". To test: * define a set * define a mapping for said set with "is equal to" * run /misc/migration_tools/build_oai_sets.pl -r -v * confirm that you have correct entries in SQL: select * from oai_sets_biblios; * change mapping to 'not equal to', save * run /misc/migration_tools/build_oai_sets.pl -r -v * confirm that you have correct entries in SQL: select * from oai_sets_biblios; Signed-off-by: Julian Maurice Signed-off-by: Jonathan Druart Amended patch: Fix bug id in updatedb.pl Signed-off-by: Galen Charlton --- C4/OAI/Sets.pm | 29 ++++++++++++++----- admin/oai_set_mappings.pl | 2 ++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/updatedatabase.pl | 7 +++++ .../prog/en/modules/admin/oai_set_mappings.tt | 17 +++++++++-- .../en/modules/help/admin/oai_set_mappings.tt | 6 ++-- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/C4/OAI/Sets.pm b/C4/OAI/Sets.pm index 8c28f7b57d..5de22ba705 100644 --- a/C4/OAI/Sets.pm +++ b/C4/OAI/Sets.pm @@ -290,11 +290,12 @@ sub AddOAISet { GetOAISetsMappings returns mappings for all OAI Sets. Mappings define how biblios are categorized in sets. -A mapping is defined by three properties: +A mapping is defined by four properties: { marcfield => 'XXX', # the MARC field to check marcsubfield => 'Y', # the MARC subfield to check + operator => 'A', # the operator 'equal' or 'notequal'; 'equal' if '' marcvalue => 'zzzz', # the value to check } @@ -311,6 +312,7 @@ The first hashref keys are the sets IDs, so it looks like this: { marcfield => 'XXX', marcsubfield => 'Y', + operator => 'A', marcvalue => 'zzzz' }, { @@ -337,6 +339,7 @@ sub GetOAISetsMappings { push @{ $mappings->{$result->{'set_id'}} }, { marcfield => $result->{'marcfield'}, marcsubfield => $result->{'marcsubfield'}, + operator => $result->{'operator'}, marcvalue => $result->{'marcvalue'} }; } @@ -371,6 +374,7 @@ sub GetOAISetMappings { push @mappings, { marcfield => $result->{'marcfield'}, marcsubfield => $result->{'marcsubfield'}, + operator => $result->{'operator'}, marcvalue => $result->{'marcvalue'} }; } @@ -384,6 +388,7 @@ sub GetOAISetMappings { { marcfield => 'XXX', marcsubfield => 'Y', + operator => 'A', marcvalue => 'zzzz' }, ... @@ -409,12 +414,12 @@ sub ModOAISetMappings { if(scalar @$mappings > 0) { $query = qq{ - INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, marcvalue) - VALUES (?,?,?,?) + INSERT INTO oai_sets_mappings (set_id, marcfield, marcsubfield, operator, marcvalue) + VALUES (?,?,?,?,?) }; $sth = $dbh->prepare($query); foreach (@$mappings) { - $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'marcvalue'}); + $sth->execute($set_id, $_->{'marcfield'}, $_->{'marcsubfield'}, $_->{'operator'}, $_->{'marcvalue'}); } } } @@ -491,12 +496,20 @@ sub CalcOAISetsBiblio { next if not $mapping; my $field = $mapping->{'marcfield'}; my $subfield = $mapping->{'marcsubfield'}; + my $operator = $mapping->{'operator'}; my $value = $mapping->{'marcvalue'}; - my @subfield_values = $record->subfield($field, $subfield); - if(0 < grep /^$value$/, @subfield_values) { - push @biblio_sets, $set_id; - last; + if ($operator eq 'notequal') { + if(0 == grep /^$value$/, @subfield_values) { + push @biblio_sets, $set_id; + last; + } + } + else { + if(0 < grep /^$value$/, @subfield_values) { + push @biblio_sets, $set_id; + last; + } } } } diff --git a/admin/oai_set_mappings.pl b/admin/oai_set_mappings.pl index fb4ee281e5..18a48bbe94 100755 --- a/admin/oai_set_mappings.pl +++ b/admin/oai_set_mappings.pl @@ -55,6 +55,7 @@ my $op = $input->param('op'); if($op && $op eq "save") { my @marcfields = $input->param('marcfield'); my @marcsubfields = $input->param('marcsubfield'); + my @operators = $input->param('operator'); my @marcvalues = $input->param('marcvalue'); my @mappings; @@ -64,6 +65,7 @@ if($op && $op eq "save") { push @mappings, { marcfield => $marcfields[$i], marcsubfield => $marcsubfields[$i], + operator => $operators[$i], marcvalue => $marcvalues[$i] }; } diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index e2ee43bfbd..82da0182f8 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -1523,6 +1523,7 @@ CREATE TABLE `oai_sets_mappings` ( `set_id` int(11) NOT NULL, `marcfield` char(3) NOT NULL, `marcsubfield` char(1) NOT NULL, + `operator` varchar(8) NOT NULL default 'equal', `marcvalue` varchar(80) NOT NULL, CONSTRAINT `oai_sets_mappings_ibfk_1` FOREIGN KEY (`set_id`) REFERENCES `oai_sets` (`id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index 9871cfdf0c..d5769a70e2 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -7169,6 +7169,13 @@ if ( CheckVersion($DBversion) ) { SetVersion ($DBversion); } +$DBversion = "3.13.00.XXX"; +if (C4::Context->preference("Version") < TransformToNum($DBversion)) { + $dbh->do("ALTER TABLE oai_sets_mappings ADD COLUMN operator varchar(8) NOT NULL default 'equal' AFTER marcsubfield;"); + print "Upgrade to $DBversion done (Bug 9295: OAI notequal: add operator column to OAI mappings table)\n"; + SetVersion ($DBversion); +} + =head1 FUNCTIONS =head2 TableExists($table) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt index b449191549..c4a9b8769b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/oai_set_mappings.tt @@ -65,7 +65,7 @@ function hideDialogBox() { Field Subfield -   + Operator Value     @@ -77,7 +77,15 @@ function hideDialogBox() { - is equal to + [% IF ( loop.last ) %] @@ -93,7 +101,10 @@ function hideDialogBox() { - is equal to + Delete diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt index 0a181398d5..15665239b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/help/admin/oai_set_mappings.tt @@ -7,14 +7,14 @@

Defining a mapping

    -
  1. Fill the fields 'Field', 'Subfield' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9 and 'Value' with XXX.
  2. +
  3. Fill the fields 'Field', 'Subfield', 'Operator' and 'Value'. For example if you want to include in this set all records that have a 999$9 equal to 'XXX'. Fill 'Field' with 999, 'Subfield' with 9, 'Operator' with is equal to and 'Value' with XXX.
  4. If you want to add another condition, click on 'OR' button and repeat step 1.
  5. Click on 'Save'
-

To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.

+

To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.

-

Note: Actually, a condition is true if value in the corresponding subfield is strictly equal to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.

+

Note: Actually, a condition is true if value in the corresponding subfield is strictly 'equal' or 'not equal' to what is defined if 'Value'. A record having 999$9 = 'XXX YYY' will not belong to a set where condition is 999$9 = 'XXX'.

And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.

-- 2.39.5