Bug 11254: make reservoir search normalize ISBNs
authorFridolyn SOMERS <fridolyn.somers@biblibre.com>
Fri, 15 Nov 2013 09:43:21 +0000 (10:43 +0100)
committerKyle M Hall <kyle@bywatersolutions.com>
Wed, 13 Aug 2014 18:27:04 +0000 (14:27 -0400)
When importing records, the ISBN is normalized and stored
into database (see C4::ImportBatch::_add_biblio_fields).  But when
searching with ISBN into reservoir, it is not normalized
(see C4::Breeding::BreedingSearch).  So search does not match.

This patch adds the normalisation to reservoir search.  Also, it
replaces call private method _isbn_cleanup by GetNormalizedISBN,
the correct public method.  Also allows the reservoir search
on ISBN with hyphens.

This is intended to fix only reservoir searches.

Revised Test plan
-----------------
 1) Back up DB
 2) Save copy of attached example somewhere findable
 2) Home -> Tools -> Stage MARC records for import
 3) Click Browse and select the example MARC file
 4) Click Upload file
 5) Tweak as desired then click Stage for import
 6) Click Manage staged records
 7) Click Import this batch into the catalog
 8) Home -> Cataloging
 9) In the Cataloging search text box type 978-0-691-14289-0 and
     click Submit
    -- ISBN13 with hypens not found in reservoir
10) In the Cataloging search text box type 9780691142890 and
     click Submit
    -- ISBN13 without hypens not found in reservoir
11) In the Cataloging search text box type 0-691-14289-0 and
     click Submit
    -- ISBN10 with hypens not found in reservoir
12) In the Cataloging search text box type 0691142890 and
     click Submit
    -- ISBN10 without hypens found in reservoir
13) Apply patch
14) Repeat steps 9-12, this time it is always found! :)

Signed-off-by: Mark Tompsett <mtompset@hotmail.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
(cherry picked from commit cac06afeb1f03200cfc7ab48162c184be8d1526b)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>

Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
(cherry picked from commit 0ddc2b90f9068ef8a30efb845dd84b70041cf7e5)

C4/Breeding.pm
C4/ImportBatch.pm
cataloguing/addbooks.pl

index 96de7bf..caaf103 100644 (file)
@@ -108,7 +108,7 @@ sub ImportBreeding {
             # if isbn found and biblio does not exist, add it. If isbn found and biblio exists, 
             # overwrite or ignore depending on user choice
             # drop every "special" char : spaces, - ...
-            $oldbiblio->{isbn} = C4::Koha::_isbn_cleanup($oldbiblio->{isbn}); # FIXME C4::Koha::_isbn_cleanup should be public
+            $oldbiblio->{isbn} = C4::Koha::GetNormalizedISBN($oldbiblio->{isbn});
             # search if biblio exists
             my $biblioitemnumber;
             if ($oldbiblio->{isbn}) {
@@ -173,6 +173,9 @@ sub BreedingSearch {
     my $sth;
     my @results;
 
+    # normalise ISBN like at import
+    $isbn = C4::Koha::GetNormalizedISBN($isbn);
+
     $query = "SELECT import_record_id, file_name, isbn, title, author
               FROM  import_biblios 
               JOIN import_records USING (import_record_id)
index 3ce5c67..4a60fd9 100644 (file)
@@ -1399,7 +1399,7 @@ sub _add_biblio_fields {
     my ($title, $author, $isbn, $issn) = _parse_biblio_fields($marc_record);
     my $dbh = C4::Context->dbh;
     # FIXME no controlnumber, originalsource
-    $isbn = C4::Koha::_isbn_cleanup($isbn); # FIXME C4::Koha::_isbn_cleanup should be made public
+    $isbn = C4::Koha::GetNormalizedISBN($isbn);
     my $sth = $dbh->prepare("INSERT INTO import_biblios (import_record_id, title, author, isbn, issn) VALUES (?, ?, ?, ?, ?)");
     $sth->execute($import_record_id, $title, $author, $isbn, $issn);
     $sth->finish();
index 35cfa2c..0cfd7e8 100755 (executable)
@@ -116,7 +116,9 @@ if ($query) {
 #check is on isbn legnth 13 for new isbn and 10 for old isbn
     my ( $title, $isbn );
     if ($query=~/\d/) {
-        my $querylength = length $query;
+        my $clean_query = $query;
+        $clean_query =~ s/-//g; # remove hyphens
+        my $querylength = length $clean_query;
         if ( $querylength == 13 || $querylength == 10 ) {
             $isbn = $query;
         }