[Koha-patches] [PATCH 35/35] Removing hyphens from isbn and issn when cataloging a biblio. It removes hyphens from isbn and issn only in marcxml, not in the field isbn in biblioitems where it is in the original format

Juan Romay Sieira juan.sieira at xercode.es
Thu Jul 14 19:01:45 CEST 2011


---
 C4/Biblio.pm                                   |   34 ++++++++++++++++++++++++
 C4/Search.pm                                   |    1 +
 installer/data/mysql/en/mandatory/sysprefs.sql |    1 +
 installer/data/mysql/updatedatabase.pl         |    7 +++++
 kohaversion.pl                                 |    2 +-
 5 files changed, 44 insertions(+), 1 deletions(-)

diff --git a/C4/Biblio.pm b/C4/Biblio.pm
index d797f40..332d476 100644
--- a/C4/Biblio.pm
+++ b/C4/Biblio.pm
@@ -3461,6 +3461,40 @@ sub ModBiblioMarc {
         # the previous version of the record
         $oldRecord = GetMarcBiblio($biblionumber);
     }
+    
+    # 
+    if (C4::Context->preference("IsbnIssnRemoveHyphens")){
+           my $isbn;
+           my $issn;
+               if ( $encoding eq 'UNIMARC' ) {
+                       if ( my $f010 = $record->field('010') ) {
+                               if ( $f010->subfield('a') ) {
+                                       $isbn = $f010->subfield('a');
+                                       $isbn =~ s/-//g;
+                                       $f010->update( 'a' => $isbn );
+                               }
+                       }
+                       if ( my $f011 = $record->field('011') ) {
+                               if ( $f011->subfield('a') ) {
+                                       $issn = $f011->subfield('a');
+                                       $issn =~ s/-//g;
+                                       $f011->update( 'a' => $issn );
+                               }
+                       }
+               } else {
+                       if ( my $f020 = $record->field('020') ) {
+                               $isbn = $f020->subfield('a');
+                               $isbn =~ s/-//g;
+                               $f020->update( 'a' => $isbn );
+                       }
+                       if ( my $f022 = $record->field('022') ) {
+                               $issn = $f022->subfield('a');
+                               $issn =~ s/-//g;
+                               $f022->update( 'a' => $issn );
+                       }
+               }
+    }
+    
     $sth = $dbh->prepare("UPDATE biblioitems SET marc=?,marcxml=? WHERE biblionumber=?");
     $sth->execute( $record->as_usmarc(), $record->as_xml_record($encoding), $biblionumber );
     $sth->finish;
diff --git a/C4/Search.pm b/C4/Search.pm
index c3cff65..2bc934f 100644
--- a/C4/Search.pm
+++ b/C4/Search.pm
@@ -1159,6 +1159,7 @@ sub buildQuery {
                 }
                 # ISBN,ISSN,Standard Number, don't need special treatment
                 elsif ( $index eq 'nb' || $index eq 'ns' ) {
+                	$operand =~ s/-//g if (C4::Context->preference("IsbnIssnRemoveHyphens"));
                     (
                         $stemming,      $auto_truncation,
                         $weight_fields, $fuzzy_enabled,
diff --git a/installer/data/mysql/en/mandatory/sysprefs.sql b/installer/data/mysql/en/mandatory/sysprefs.sql
index 0abf9d8..991c80a 100755
--- a/installer/data/mysql/en/mandatory/sysprefs.sql
+++ b/installer/data/mysql/en/mandatory/sysprefs.sql
@@ -314,3 +314,4 @@ INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('OpacHiddenItems','','This syspref allows to define custom rules for hiding specific items at opac. See docs/opac/OpacHiddenItems.txt for more informations.','','Textarea');
 INSERT INTO `systempreferences` (variable,value,explanation,options,type) VALUES('numSearchRSSResults',50,'Specify the maximum number of results to display on a RSS page of results',NULL,'Integer');
 INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES ('OpacRenewalBranch','checkoutbranch','Choose how the branch for an OPAC renewal is recorded in statistics','itemhomebranch|patronhomebranch|checkoutbranch|null','Choice');
+INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('IsbnIssnRemoveHyphens', '1', '', 'Remove or not hyphens from ISBN and ISSN', 'YesNo');
diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl
index 8fb9656..23daacf 100755
--- a/installer/data/mysql/updatedatabase.pl
+++ b/installer/data/mysql/updatedatabase.pl
@@ -4370,6 +4370,13 @@ if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
     SetVersion($DBversion);
 }
 
+$DBversion = "3.05.00.005";
+if (C4::Context->preference("Version") < TransformToNum($DBversion)) {
+    $dbh->do("INSERT INTO `systempreferences` (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('IsbnIssnRemoveHyphens', '1', '', 'Remove or not hyphens from ISBN and ISSN', 'YesNo');");
+    print "Upgrade to $DBversion done (Add SysPref to remove hyphens or not into isbn and issn)\n";
+    SetVersion($DBversion);
+}
+
 =head1 FUNCTIONS
 
 =head2 DropAllForeignKeys($table)
diff --git a/kohaversion.pl b/kohaversion.pl
index 00bdbec..9021eb0 100644
--- a/kohaversion.pl
+++ b/kohaversion.pl
@@ -16,7 +16,7 @@ the kohaversion is divided in 4 parts :
 use strict;
 
 sub kohaversion {
-    our $VERSION = '3.05.00.004';
+    our $VERSION = '3.05.00.005';
     # version needs to be set this way
     # so that it can be picked up by Makefile.PL
     # during install
-- 
1.7.1



More information about the Koha-patches mailing list