koha-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Koha-cvs] CVS: koha/C4 Biblio.pm,1.44,1.45 Breeding.pm,1.1,1.2 Search.p


From: Paul POULAIN
Subject: [Koha-cvs] CVS: koha/C4 Biblio.pm,1.44,1.45 Breeding.pm,1.1,1.2 Search.pm,1.62,1.63 Z3950.pm,1.8,1.9
Date: Tue, 29 Apr 2003 09:50:54 -0700

Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1:/tmp/cvs-serv5011/C4

Modified Files:
        Biblio.pm Breeding.pm Search.pm Z3950.pm 
Log Message:
really proud of this commit :-)
z3950 search and import seems to works fine.
Let me explain how :
* a "search z3950" button is added in the addbiblio template.
* when clicked, a popup appears and z3950/search.pl is called
* z3950/search.pl calls addz3950search in the DB
* the z3950 daemon retrieve the records and stores them in z3950results AND in 
marc_breeding table.
* as long as there as searches pending, the popup auto refresh every 2 seconds, 
and says how many searches are pending.
* when the user clicks on a z3950 result => the parent popup is called with the 
requested biblio, and auto-filled

Note :
* character encoding support : (It's a nightmare...) In the z3950servers table, 
a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in this 
column. Depending on this, the char_decode in C4::Biblio.pm replaces 
marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import 
this value has been added too, for a better support.
* the marc_breeding and z3950* tables have been modified : they have an 
encoding column and the random z3950 number is stored too for convenience => 
it's the key I use to list only requested biblios in the popup.


Index: Biblio.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Biblio.pm,v
retrieving revision 1.44
retrieving revision 1.45
diff -C2 -r1.44 -r1.45
*** Biblio.pm   28 Apr 2003 13:07:14 -0000      1.44
--- Biblio.pm   29 Apr 2003 16:50:49 -0000      1.45
***************
*** 2,5 ****
--- 2,20 ----
  # $Id$
  # $Log$
+ # Revision 1.45  2003/04/29 16:50:49  tipaul
+ # really proud of this commit :-)
+ # z3950 search and import seems to works fine.
+ # Let me explain how :
+ # * a "search z3950" button is added in the addbiblio template.
+ # * when clicked, a popup appears and z3950/search.pl is called
+ # * z3950/search.pl calls addz3950search in the DB
+ # * the z3950 daemon retrieve the records and stores them in z3950results AND 
in marc_breeding table.
+ # * as long as there as searches pending, the popup auto refresh every 2 
seconds, and says how many searches are pending.
+ # * when the user clicks on a z3950 result => the parent popup is called with 
the requested biblio, and auto-filled
+ #
+ # Note :
+ # * character encoding support : (It's a nightmare...) In the z3950servers 
table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in 
this column. Depending on this, the char_decode in C4::Biblio.pm replaces 
marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import 
this value has been added too, for a better support.
+ # * the marc_breeding and z3950* tables have been modified : they have an 
encoding column and the random z3950 number is stored too for convenience => 
it's the key I use to list only requested biblios in the popup.
+ #
  # Revision 1.44  2003/04/28 13:07:14  tipaul
  # Those fixes solves the "internal server error" with MARC::Record 1.12.
***************
*** 2138,2144 ****
        # converts ISO 5426 coded string to ISO 8859-1
        # sloppy code : should be improved in next issue
!       my ($string) = @_ ;
        $_ = $string ;
!       if (C4::Context->preference("marcflavour") eq "UNIMARC") {
                s/\xe1/Æ/gm ;
                s/\xe2/Ð/gm ;
--- 2153,2160 ----
        # converts ISO 5426 coded string to ISO 8859-1
        # sloppy code : should be improved in next issue
!       my ($string,$encoding) = @_ ;
        $_ = $string ;
! #     $encoding = C4::Context->preference("marcflavour") unless $encoding;
!       if ($encoding eq "UNIMARC") {
                s/\xe1/Æ/gm ;
                s/\xe2/Ð/gm ;
***************
*** 2202,2206 ****
                s/\xd0\x43/Ç/gm ;
                s/\xd0\x63/ç/gm ;
!       } else {
                if(/[\xc1-\xff]/) {
                        s/\xe1\x61/à/gm ;
--- 2218,2224 ----
                s/\xd0\x43/Ç/gm ;
                s/\xd0\x63/ç/gm ;
!               # this handles non-sorting blocks (if implementation requires 
this)
!               $string = nsb_clean($_) ;
!       } elsif ($encoding eq "USMARC") {
                if(/[\xc1-\xff]/) {
                        s/\xe1\x61/à/gm ;
***************
*** 2255,2262 ****
                        s/\xea\x41/Å/gm ;
                        s/\xea\x61/å/gm ;
                }
        }
-       # this handles non-sorting blocks (if implementation requires this)
-       $string = nsb_clean($_) ;
        return($string) ;
  }
--- 2273,2280 ----
                        s/\xea\x41/Å/gm ;
                        s/\xea\x61/å/gm ;
+                       # this handles non-sorting blocks (if implementation 
requires this)
+                       $string = nsb_clean($_) ;
                }
        }
        return($string) ;
  }

Index: Breeding.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Breeding.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Breeding.pm 22 Apr 2003 12:22:54 -0000      1.1
--- Breeding.pm 29 Apr 2003 16:50:50 -0000      1.2
***************
*** 34,39 ****
  =head1 SYNOPSIS
  
!   use C4::Scan;
!   &ImportBreeding($marcrecords,$);
  
  =head1 DESCRIPTION
--- 34,48 ----
  =head1 SYNOPSIS
  
!       use C4::Scan;
!       &ImportBreeding($marcrecords,$overwrite_biblio,$filename,$z3950random);
! 
!       C<$marcrecord> => the MARC::Record
!       C<$overwrite_biblio> => if set to 1 a biblio with the same ISBN will be 
overwritted.
!                                                               if set to 0 a 
biblio with the same isbn will be ignored (the previous will be kept)
!                                                               if set to -1 
the biblio will be added anyway (more than 1 biblio with the same ISBN possible 
in the breeding
!       C<$encoding> => USMARC
!                                               or UNIMARC. used for 
char_decoding.
!                                               If not present, the parameter 
marcflavour is used instead
!       C<$z3950random> => the random value created during a z3950 search 
result.
  
  =head1 DESCRIPTION
***************
*** 47,51 ****
  
  sub  ImportBreeding {
!       my ($marcrecords,$overwrite_biblio,$filename) = @_;
        my @marcarray = split /\x1D/, $marcrecords;
        my $dbh = C4::Context->dbh;
--- 56,60 ----
  
  sub  ImportBreeding {
!       my ($marcrecords,$overwrite_biblio,$filename,$encoding,$z3950random) = 
@_;
        my @marcarray = split /\x1D/, $marcrecords;
        my $dbh = C4::Context->dbh;
***************
*** 53,58 ****
        my $searchissn = $dbh->prepare("select biblioitemnumber from 
biblioitems where issn=?");
        my $searchbreeding = $dbh->prepare("select id from marc_breeding where 
isbn=?");
!       my $insertsql = $dbh->prepare("insert into marc_breeding 
(file,isbn,title,author,marc) values(?,?,?,?,?)");
!       my $replacesql = $dbh->prepare("update marc_breeding set 
file=?,isbn=?,title=?,author=?,marc=? where id=?");
        # fields used for import results
        my $imported=0;
--- 62,68 ----
        my $searchissn = $dbh->prepare("select biblioitemnumber from 
biblioitems where issn=?");
        my $searchbreeding = $dbh->prepare("select id from marc_breeding where 
isbn=?");
!       my $insertsql = $dbh->prepare("insert into marc_breeding 
(file,isbn,title,author,marc,encoding,z3950random) values(?,?,?,?,?,?,?)");
!       my $replacesql = $dbh->prepare("update marc_breeding set 
file=?,isbn=?,title=?,author=?,marc=?,encoding=?,z3950random=? where id=?");
!       $encoding = C4::Context->preference("marcflavour") unless $encoding;
        # fields used for import results
        my $imported=0;
***************
*** 66,74 ****
                } else {
                        my $oldbiblio = MARCmarc2koha($dbh,$marcrecord);
!                       $oldbiblio->{title} = char_decode($oldbiblio->{title});
!                       $oldbiblio->{author} = 
char_decode($oldbiblio->{author});
                        # 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} =~ s/ |-|\.//g,
                        # search if biblio exists
                        my $biblioitemnumber;
--- 76,87 ----
                } else {
                        my $oldbiblio = MARCmarc2koha($dbh,$marcrecord);
!                       $oldbiblio->{title} = 
char_decode($oldbiblio->{title},$encoding);
!                       $oldbiblio->{author} = 
char_decode($oldbiblio->{author},$encoding);
                        # 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} =~ s/ |-|\.//g,
+                       $oldbiblio->{isbn} = substr($oldbiblio->{isbn},0,10);
+                       $oldbiblio->{issn} =~ s/ |-|\.//g,
+                       $oldbiblio->{issn} = substr($oldbiblio->{issn},0,10);
                        # search if biblio exists
                        my $biblioitemnumber;
***************
*** 92,106 ****
                                        ($breedingid) = 
$searchbreeding->fetchrow;
                                }
!                               if (!$breedingid || $overwrite_biblio) {
                                        my $recoded;
                                        $recoded = $marcrecord->as_usmarc();
!                                               if ($breedingid) {
!                                                       $replacesql 
->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$breedingid);
!                                               } else {
!                                                       $insertsql 
->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded);
!                                               }
                                        $imported++;
-                               } else {
-                                       $alreadyinfarm++;
                                }
                        }
--- 105,119 ----
                                        ($breedingid) = 
$searchbreeding->fetchrow;
                                }
!                               if ($breedingid && $overwrite_biblio eq 0) {
!                                       $alreadyinfarm++;
!                               } else {
                                        my $recoded;
                                        $recoded = $marcrecord->as_usmarc();
!                                       if ($breedingid && $overwrite_biblio eq 
1) {
!                                               $replacesql 
->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$encoding,$z3950random,$breedingid);
!                                       } else {
!                                               $insertsql 
->execute($filename,substr($oldbiblio->{isbn}.$oldbiblio->{issn},0,10),$oldbiblio->{title},$oldbiblio->{author},$recoded,$encoding,$z3950random);
!                                       }
                                        $imported++;
                                }
                        }

Index: Search.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Search.pm,v
retrieving revision 1.62
retrieving revision 1.63
diff -C2 -r1.62 -r1.63
*** Search.pm   1 Apr 2003 13:19:55 -0000       1.62
--- Search.pm   29 Apr 2003 16:50:51 -0000      1.63
***************
*** 2381,2394 ****
  =item breedingsearch
  
!   ($count, @results) = &breedingsearch($title);
  
  C<$count> is the number of items in C<@results>. C<@results> is an
! array of references-to-hash; the keys are the items from the
! C<marc_breeding> table of the Koha database.
  
  =cut
  
  sub breedingsearch {
!       my ($title,$isbn) = @_;
        my $dbh   = C4::Context->dbh;
        my $count = 0;
--- 2381,2396 ----
  =item breedingsearch
  
!   ($count, @results) = &breedingsearch($title,$isbn,$random);
! C<$title> contains the title,
! C<$isbn> contains isbn or issn,
! C<$random> contains the random seed from a z3950 search.
  
  C<$count> is the number of items in C<@results>. C<@results> is an
! array of references-to-hash; the keys are the items from the C<marc_breeding> 
table of the Koha database.
  
  =cut
  
  sub breedingsearch {
!       my ($title,$isbn,$z3950random) = @_;
        my $dbh   = C4::Context->dbh;
        my $count = 0;
***************
*** 2398,2409 ****
  
        $query = "Select id,file,isbn,title,author from marc_breeding where ";
!       if ($title) {
!               $query .= "title like \"$title%\"";
!       }
!       if ($title && $isbn) {
!               $query .= " and ";
!       }
!       if ($isbn) {
!               $query .= "isbn like \"$isbn%\"";
        }
        $sth   = $dbh->prepare($query);
--- 2400,2415 ----
  
        $query = "Select id,file,isbn,title,author from marc_breeding where ";
!       if ($z3950random) {
!               $query .= "z3950random = \"$z3950random\"";
!       } else {
!               if ($title) {
!                       $query .= "title like \"$title%\"";
!               }
!               if ($title && $isbn) {
!                       $query .= " and ";
!               }
!               if ($isbn) {
!                       $query .= "isbn like \"$isbn%\"";
!               }
        }
        $sth   = $dbh->prepare($query);

Index: Z3950.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Z3950.pm,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -r1.8 -r1.9
*** Z3950.pm    29 Apr 2003 08:09:45 -0000      1.8
--- Z3950.pm    29 Apr 2003 16:50:51 -0000      1.9
***************
*** 70,73 ****
--- 70,74 ----
        &z3950servername
        &addz3950queue
+       &checkz3950searchdone
  );
  
***************
*** 199,212 ****
                        push @serverlist, $server;
                } elsif ($server eq 'DEFAULT' || $server eq 'CHECKED' ) {
!                       $sth=$dbh->prepare("select host,port,db,userid,password 
,name from z3950servers where checked <> 0 ");
                        $sth->execute;
!                       while ( my ($host, $port, $db, $userid, 
$password,$servername) = $sth->fetchrow ) {
!                               push @serverlist, 
"$servername/$host\:$port/$db/$userid/$password";
                        } # while
                } else {
!                       $sth=$dbh->prepare("select host,port,db,userid,password 
from z3950servers where id=? ");
                        $sth->execute($server);
!                       my ($host, $port, $db, $userid, $password) = 
$sth->fetchrow;
!                       push @serverlist, 
"$server/$host\:$port/$db/$userid/$password";
                }
        }
--- 200,213 ----
                        push @serverlist, $server;
                } elsif ($server eq 'DEFAULT' || $server eq 'CHECKED' ) {
!                       $sth=$dbh->prepare("select host,port,db,userid,password 
,name,syntax from z3950servers where checked <> 0 ");
                        $sth->execute;
!                       while ( my ($host, $port, $db, $userid, 
$password,$servername,$syntax) = $sth->fetchrow ) {
!                               push @serverlist, 
"$servername/$host\:$port/$db/$userid/$password/$syntax";
                        } # while
                } else {
!                       $sth=$dbh->prepare("select 
host,port,db,userid,password,syntax from z3950servers where id=? ");
                        $sth->execute($server);
!                       my ($host, $port, $db, $userid, $password,$syntax) = 
$sth->fetchrow;
!                       push @serverlist, 
"$server/$host\:$port/$db/$userid/$password/$syntax";
                }
        }
***************
*** 215,219 ****
  
        $serverlist = join(" ", @serverlist);
!       chop $serverlist;
  
        # FIXME - Is this test supposed to test whether @serverlist is
--- 216,220 ----
  
        $serverlist = join(" ", @serverlist);
! #     chop $serverlist;
  
        # FIXME - Is this test supposed to test whether @serverlist is
***************
*** 267,270 ****
--- 268,297 ----
  } # sub addz3950queue
  
+ =item &checkz3950searchdone
+ 
+   $numberpending= &   &checkz3950searchdone($random);
+ 
+ Returns the number of pending z3950 requests
+ 
+ C<$random> is the random z3950 query number.
+ 
+ =cut
+ sub checkz3950searchdone {
+       my ($z3950random) = @_;
+       my $dbh = C4::Context->dbh;
+       # first, check that the deamon already created the requests...
+       my $sth = $dbh->prepare("select count(*) from z3950queue,z3950results 
where z3950queue.id = z3950results.queryid and z3950queue.identifier=?");
+       $sth->execute($z3950random);
+       my ($result) = $sth->fetchrow;
+       if ($result eq 0) { # search not yet begun => should be searches to do !
+               return "??";
+       }
+       # second, count pending requests
+       $sth = $dbh->prepare("select count(*) from z3950queue,z3950results 
where z3950queue.id = z3950results.queryid and z3950results.enddate is null and 
z3950queue.identifier=?");
+       $sth->execute($z3950random);
+       ($result) = $sth->fetchrow;
+       return $result;
+ }
+ 
  1;
  __END__
***************
*** 280,283 ****
--- 307,325 ----
  #--------------------------------------
  # $Log$
+ # Revision 1.9  2003/04/29 16:50:51  tipaul
+ # really proud of this commit :-)
+ # z3950 search and import seems to works fine.
+ # Let me explain how :
+ # * a "search z3950" button is added in the addbiblio template.
+ # * when clicked, a popup appears and z3950/search.pl is called
+ # * z3950/search.pl calls addz3950search in the DB
+ # * the z3950 daemon retrieve the records and stores them in z3950results AND 
in marc_breeding table.
+ # * as long as there as searches pending, the popup auto refresh every 2 
seconds, and says how many searches are pending.
+ # * when the user clicks on a z3950 result => the parent popup is called with 
the requested biblio, and auto-filled
+ #
+ # Note :
+ # * character encoding support : (It's a nightmare...) In the z3950servers 
table, a "encoding" column has been added. You can put "UNIMARC" or "USMARC" in 
this column. Depending on this, the char_decode in C4::Biblio.pm replaces 
marc-char-encode by an iso 8859-1 encoding. Note that in the breeding import 
this value has been added too, for a better support.
+ # * the marc_breeding and z3950* tables have been modified : they have an 
encoding column and the random z3950 number is stored too for convenience => 
it's the key I use to list only requested biblios in the popup.
+ #
  # Revision 1.8  2003/04/29 08:09:45  tipaul
  # z3950 support is coming...




reply via email to

[Prev in Thread] Current Thread [Next in Thread]