Bugzilla – Attachment 14155 Details for
Bug 9295
Introduce operator equal/ notequal to OAI set mapping instead of hardcoded 'equal' value
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9295 [ENH] Introduce operator equal/ notequal to OAI set mapping instead of hardcoded 'equal' value.
Bug-9295-ENH-Introduce-operator-equal-notequal-to-.patch (text/plain), 10.83 KB, created by
Mirko Tietgen
on 2012-12-15 00:37:29 UTC
(
hide
)
Description:
Bug 9295 [ENH] Introduce operator equal/ notequal to OAI set mapping instead of hardcoded 'equal' value.
Filename:
MIME Type:
Creator:
Mirko Tietgen
Created:
2012-12-15 00:37:29 UTC
Size:
10.83 KB
patch
obsolete
>From 0197454717795bef348661a9f64856c2d7743dfc Mon Sep 17 00:00:00 2001 >From: Mirko Tietgen <mirko@abunchofthings.net> >Date: Fri, 14 Dec 2012 18:01:37 +0100 >Subject: [PATCH] Bug 9295 [ENH] 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; >--- > C4/OAI/Sets.pm | 29 ++++++++++++++----- > admin/oai_set_mappings.pl | 4 ++- > installer/data/mysql/kohastructure.sql | 1 + > installer/data/mysql/updatedatabase.pl | 9 ++++++ > .../prog/en/modules/admin/oai_set_mappings.tt | 17 +++++++++-- > .../prog/en/modules/help/admin/oai_set_mappings.tt | 6 ++-- > 6 files changed, 51 insertions(+), 15 deletions(-) > >diff --git a/C4/OAI/Sets.pm b/C4/OAI/Sets.pm >index 8c28f7b..5de22ba 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 1a9762c..18a48bb 100755 >--- a/admin/oai_set_mappings.pl >+++ b/admin/oai_set_mappings.pl >@@ -55,15 +55,17 @@ 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; > my $i = 0; > while($i < @marcfields and $i < @marcsubfields and $i < @marcvalues) { >- if($marcfields[$i] and $marcsubfields[$i] and $marcvalues[$i]) { >+ if($marcfields[$i] and $marcsubfields[$i]) { > 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 ddf4b0f..8c9b7ff 100644 >--- a/installer/data/mysql/kohastructure.sql >+++ b/installer/data/mysql/kohastructure.sql >@@ -1422,6 +1422,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 39e4bde..3a2b7ae 100755 >--- a/installer/data/mysql/updatedatabase.pl >+++ b/installer/data/mysql/updatedatabase.pl >@@ -6181,6 +6181,15 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) { > SetVersion ($DBversion); > } > >+$DBversion = "3.09.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 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 1724c06..4b8ae11 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 >@@ -52,7 +52,7 @@ function returnToSetsPage() { > <tr> > <th>Field</th> > <th>Subfield</th> >- <th> </th> >+ <th>Operator</th> > <th>Value</th> > <th> </th> > </tr> >@@ -63,7 +63,15 @@ function returnToSetsPage() { > <tr> > <td><input type="text" name="marcfield" size="3" value="[% mapping.marcfield %]" /></td> > <td style="text-align:center"><input type="text" name="marcsubfield" size="1" value="[% mapping.marcsubfield %]" /></td> >- <td>is equal to</td> >+ <td><select name=operator> >+ [% IF mapping.operator == 'equal' %] >+ <option selected value="equal">is equal to</option> >+ <option value="notequal">not equal to</option> >+ [% ELSE %] >+ <option value="equal">is equal to</option> >+ <option selected value="notequal">not equal to</option> >+ [% END %] >+ </select></td> > <td><input type="text" name="marcvalue" value="[% mapping.marcvalue %]" /></td> > <td style="text-align:center"> > [% IF ( loop.last ) %] >@@ -78,7 +86,10 @@ function returnToSetsPage() { > <tr> > <td><input type="text" name="marcfield" size="3" /></td> > <td style="text-align:center"><input type="text" name="marcsubfield" size="1" /></td> >- <td>is equal to</td> >+ <td><select name=operator> >+ <option value="equal">is equal to</option> >+ <option value="notequal">not equal to</option> >+ </select></td> > <td><input type="text" name="marcvalue" /></td> > <td><input type="button" id="ORbutton" value="OR" onclick="newCondition()"/></td> > </tr> >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 979ac12..cad37a7 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 @@ > <h2>Defining a mapping</h2> > > <ol> >- <li>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.</li> >+ <li>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.</li> > <li>If you want to add another condition, click on 'OR' button and repeat step 1.</li> > <li>Click on 'Save'</li> > </ol> > >-<p>To delete a condition, just leave at least one of 'Field', 'Subfield' or 'Value' empty and click on 'Save'.</p> >+<p>To delete a condition, just leave at least one of 'Field' or 'Subfield' empty and click on 'Save'.</p> > >-<p>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'.</p> >+<p>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'.</p> > > <p>And it is case sensitive : a record having 999$9 = 'xxx' will not belong to a set where condition is 999$9 = 'XXX'.</p> > >-- >1.7.2.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9295
:
14155
|
14156
|
16443
|
21404
|
21419