package C4::Biblio;
-# New subs added by tgarip@neu.edu.tr 05/11/05
+# New XML API added by tgarip@neu.edu.tr 25/08/06
# Copyright 2000-2002 Katipo Communications
#
# This file is part of Koha.
use strict;
require Exporter;
use C4::Context;
-use MARC::Record;
-use MARC::File::USMARC;
-use MARC::File::XML;
use XML::Simple;
use Encode;
use utf8;
-use Data::Dumper;
+
use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
&NEWdelitem
&NEWmodbiblioframework
-&MARCgetallitems
+
&MARCfind_marc_from_kohafield
&MARCfind_frameworkcode
&MARCfind_itemtype
&MARCgettagslib
&MARCitemsgettagslib
-&MARCkoha2marc
-&MARCmarc2koha
-&MARCkoha2marcOnefield
+
&MARCfind_attr_from_kohafield
&MARChtml2xml
-&MARCgetbiblio
-&MARCgetitem
&XMLgetbiblio
&XMLgetbibliohash
&XMLmarc2koha_onerecord
&XML_readline
&XML_readline_onerecord
+&XML_readline_asarray
&XML_writeline
+&XML_writeline_id
&XMLmoditemonefield
-
+&XMLkoha2marc
+&XML_separate
+&XML_record_header
+&ZEBRAdelbiblio
&ZEBRAgetrecord
-
&ZEBRAop
&ZEBRAopserver
&ZEBRA_readyXML
&ZEBRA_readyXML_noheader
-
+&ZEBRAopcommit
&newbiblio
&modbiblio
&DisplayISBN
foreach my $control (@$controlfields){
if ($control->{'tag'} eq $tag){
return $control->{'content'} if $control->{'content'};
-
}
}
}
}## if tag is mapped
return "";
}
+sub XML_readline_asarray{
+my ($xml,$kohafield,$recordtype,$tag,$subf)=@_;
+#$xml represents one record of MARCXML as perlhashed
+## returns an array of read fields--useful for readind repeated fields
+### $recordtype is needed for mapping the correct field if supplied
+### If only $tag is give reads the whole tag
+my @value;
+ ($tag,$subf)=MARCfind_marc_from_kohafield($kohafield,$recordtype) if $kohafield;
+if ($tag){
+my $biblio=$xml->{'datafield'};
+my $controlfields=$xml->{'controlfield'};
+my $leader=$xml->{'leader'};
+ if ($tag>9){
+ foreach my $data (@$biblio){
+ if ($data->{'tag'} eq $tag){
+ foreach my $subfield ( $data->{'subfield'}){
+ foreach my $code ( @$subfield){
+ if ($code->{'code'} eq $subf || !$subf){
+ push @value, $code->{'content'};
+ }
+ }
+ }
+ }
+ }
+ }else{
+ if ($tag eq "000" || $tag eq "LDR"){
+ push @value, $leader->[0] if $leader->[0];
+ }else{
+ foreach my $control (@$controlfields){
+ if ($control->{'tag'} eq $tag){
+ push @value, $control->{'content'} if $control->{'content'};
+
+ }
+ }
+ }
+ }##tag
+}## if tag is mapped
+return @value;
+}
sub XML_readline{
my ($xml,$kohafield,$recordtype,$tag,$subf)=@_;
my $biblio=$xml->{'datafield'};
my $controlfield=$xml->{'controlfield'};
($tag,$subf)=MARCfind_marc_from_kohafield($kohafield,$recordtype) if $kohafield;
-my $updated=0;
+my $updated;
if ($tag>9){
foreach my $data (@$biblio){
if ($data->{'tag'} eq $tag){
}
}
## Tag did not exist
- if (!$updated){
+ if (!$updated){
if ($subf){
push @$biblio,
{
'tag' =>$tag
} ;
}
- }## created now
- }else{
- foreach my $control(@$controlfield){
+ }## created now
+ }elsif ($tag>0){
+ foreach my $control (@$controlfield){
if ($control->{'tag'} eq $tag){
$control->{'content'}=$newvalue;
$updated=1;
return $xml;
}
+sub XML_writeline_id {
+### This routine is similar to XML_writeline but replaces a given value and do not create a new field
+## Useful for repeating fields
+## Currently usedin authorities
+my ($xml,$oldvalue,$newvalue,$tag,$subf)=@_;
+$newvalue= Encode::decode('utf8',$newvalue) if $newvalue;
+my $biblio=$xml->{'datafield'};
+my $controlfield=$xml->{'controlfield'};
+ if ($tag>9){
+ foreach my $data (@$biblio){
+ if ($data->{'tag'} eq $tag){
+ my @subfields=$data->{'subfield'};
+ foreach my $subfield ( @subfields){
+ foreach my $code ( @$subfield){
+ if ($code->{'code'} eq $subf && $code->{'content'} eq $oldvalue){
+ $code->{'content'}=$newvalue;
+ }
+ }
+ }
+ }
+ }
+ }else{
+ foreach my $control(@$controlfield){
+ if ($control->{'tag'} eq $tag && $control->{'content'} eq $oldvalue ){
+ $control->{'content'}=$newvalue;
+ }
+ }
+ }
+return $xml;
+}
+
sub XML_xml2hash{
##make a perl hash from xml file
my ($xml)=@_;
sub XML_xml2hash_onerecord{
##make a perl hash from xml file
my ($xml)=@_;
+return undef unless $xml;
my $hashed = XMLin( $xml ,KeyAttr =>['leader','controlfield','datafield'],ForceArray => ['leader','controlfield','datafield','subfield'],KeepRoot=>0);
return $hashed;
}
sub XMLgetitemhash{
## Utility to return s hashed MARCXML
my ( $dbh, $itemnumber,$barcode ) = @_;
-my $xml=XMLgeitem( $dbh, $itemnumber,$barcode);
+my $xml=XMLgetitem( $dbh, $itemnumber,$barcode);
my $xmlhash=XML_xml2hash_onerecord($xml);
return $xmlhash;
}
}
}else{
- my $sth2=$dbh->prepare("SELECT marctokoha from koha_attr where recordtype like 'biblios' and tagfield is not null" );
+ my $sth2=$dbh->prepare("SELECT kohafield from koha_attr where recordtype like 'biblios' and tagfield is not null" );
$sth2->execute();
my $field;
while ($field=$sth2->fetchrow) {
push @items, $itemresult;
}
}else{
- my $sth2=$dbh->prepare("SELECT marctokoha from koha_attr where recordtype like 'holdings' and tagfield is not null" );
+ my $sth2=$dbh->prepare("SELECT kohafield from koha_attr where recordtype like 'holdings' and tagfield is not null" );
foreach my $holding (@$holdings){
$sth2->execute();
my $field;
$result->{$field}=$val if $val;
}
}else{
- my $sth2=$dbh->prepare("SELECT marctokoha from koha_attr where recordtype like ? and tagfield is not null" );
+ my $sth2=$dbh->prepare("SELECT kohafield from koha_attr where recordtype like ? and tagfield is not null" );
$sth2->execute($related_record);
my $field;
while ($field=$sth2->fetchrow) {
$sth->finish;
}else{
NEWmoditem($dbh,$recordhash,$biblionumber,$itemnumber);
+ }
+
}
+sub XMLkoha2marc {
+# warn "MARCkoha2marc";
+## This routine is still used for acqui management
+##Returns a XML recordhash from a kohahash
+ my ($dbh,$result,$recordtype) = @_;
+###create a basic MARCXML
+# find today's date
+my ($sec,$min,$hour,$mday,$mon,$year) = localtime();
+ $year += 1900;
+ $mon += 1;
+ my $timestamp = sprintf("%4d%02d%02d%02d%02d%02d.0",
+ $year,$mon,$mday,$hour,$min,$sec);
+$year=substr($year,2,2);
+ my $accdate=sprintf("%2d%02d%02d",$year,$mon,$mday);
+my ($titletag,$titlesubf)=MARCfind_marc_from_kohafield("title","biblios");
+##create a dummy record
+my $xml="<record><leader> naa a22 7ar4500</leader><controlfield tag='xxx'></controlfield><datafield ind1='' ind2='' tag='$titletag'></datafield></record>";
+## Now build XML
+ my $record = XML_xml2hash($xml);
+ my $sth2=$dbh->prepare("SELECT kohafield from koha_attr where tagfield is not null and recordtype=?");
+ $sth2->execute($recordtype);
+ my $field;
+ while (($field)=$sth2->fetchrow) {
+ $record=XML_writeline($record,$field,$result->{$field},$recordtype) if $result->{$field};
+ }
+return $record;
}
+
#
#
# MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC MARC
#
-## Script to deal with MARC read write operations
+## Script to deal with MARCXML related tables
##Sub to match kohafield to Z3950 -attributes
-sub MARCgetbiblio {
- # Returns MARC::Record of the biblio passed in parameter.
- ### Takes a new parameter of $title_author =1 which parses the record obly on those fields and nothing else
- ### Its useful when Koha requires only title&author for performance issues
- my ( $dbh, $biblionumber, $title_author ) = @_;
- my $sth =
- $dbh->prepare("select marc from biblio where biblionumber=? " );
- $sth->execute( $biblionumber);
- my ($marc)=$sth->fetchrow;
-my $record;
- if ($title_author){
- $record = MARC::File::USMARC::decode($marc,\&func_title_author);
- }else{
- $record = MARC::File::USMARC::decode($marc);
- }
-$sth->finish;
- return $record;
-}
-
-
-
-
-
-sub MARCgetitem {
-# warn "MARCgetitem";
- # Returns MARC::Record of the item passed in parameter uses either itemnumber or barcode
- my ( $dbh, $itemnumber,$barcode ) = @_;
-my $sth;
-if ($itemnumber){
- $sth = $dbh->prepare("select i.marc from items i where i.itemnumber=?" );
- $sth->execute($itemnumber);
-}else{
- $sth = $dbh->prepare("select i.marc from items i where i.barcode=?" );
- $sth->execute($barcode);
-}
- my ($marc)=$sth->fetchrow;
- my $record = MARC::File::USMARC::decode($marc);
-
- return ($record);
-}
-
-sub MARCgetallitems {
-# warn "MARCgetallitems";
- # Returns an array of MARC::Record of the items passed in parameter as biblionumber
- my ( $dbh, $biblionumber ) = @_;
-my @results;
-my $sth = $dbh->prepare("select marc from items where biblionumber =?" );
- $sth->execute($biblionumber);
-
- while(my ($marc)=$sth->fetchrow_array){
- my $record = MARC::File::USMARC::decode($marc);
- push @results,$record;
-}
-return @results;
-}
-
-
-
-
-
sub MARCfind_frameworkcode {
# warn "MARCfind_frameworkcode";
sub MARChtml2xml {
# warn "MARChtml2xml ";
- my ($tags,$subfields,$values,$indicator,$ind_tag) = @_;
-# use MARC::File::XML;
- my $xml= marc_record_header('UTF-8'); #### we do not need a collection wrapper
+ my ($tags,$subfields,$values,$indicator,$ind_tag,$tagindex) = @_;
+ my $xml= "<record>";
my $prevvalue;
my $prevtag=-1;
@$values[$i] =~ s/"/"/g;
@$values[$i] =~ s/'/'/g;
- if ((@$tags[$i] ne $prevtag)){
- $j++ unless (@$tags[$i] eq "");
+ if ((@$tags[$i].@$tagindex[$i] ne $prevtag)){
+ my $tag=@$tags[$i];
+ $j++ unless ($tag eq "");
## warn "IND:".substr(@$indicator[$j],0,1).substr(@$indicator[$j],1,1)." ".@$tags[$i];
if (!$first){
$xml.="</datafield>\n";
- if ((@$tags[$i] > 10) && (@$values[$i] ne "")){
+ if (($tag> 10) && (@$values[$i] ne "")){
my $ind1 = substr(@$indicator[$j],0,1);
my $ind2 = substr(@$indicator[$j],1,1);
- $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml.="<datafield tag=\"$tag\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
$xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
$first=0;
} else {
$first=1;
}
- } else {
+ } else {
if (@$values[$i] ne "") {
# leader
- if (@$tags[$i] eq "000") {
+ if ($tag eq "000") {
##Force the leader to UTF8
substr(@$values[$i],9,1)="a";
$xml.="<leader>@$values[$i]</leader>\n";
$first=1;
# rest of the fixed fields
- } elsif (@$tags[$i] < 10) {
- $xml.="<controlfield tag=\"@$tags[$i]\">@$values[$i]</controlfield>\n";
+ } elsif ($tag < 10) {
+ $xml.="<controlfield tag=\"$tag\">@$values[$i]</controlfield>\n";
$first=1;
} else {
my $ind1 = substr(@$indicator[$j],0,1);
my $ind2 = substr(@$indicator[$j],1,1);
- $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml.="<datafield tag=\"$tag\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
$xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
$first=0;
}
}
}
} else { # @$tags[$i] eq $prevtag
- if (@$values[$i] eq "") {
- }
- else {
+ unless (@$values[$i] eq "") {
+ my $tag=@$tags[$i];
if ($first){
my $ind1 = substr(@$indicator[$j],0,1);
my $ind2 = substr(@$indicator[$j],1,1);
- $xml.="<datafield tag=\"@$tags[$i]\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
+ $xml.="<datafield tag=\"$tag\" ind1=\"$ind1\" ind2=\"$ind2\">\n";
$first=0;
}
$xml.="<subfield code=\"@$subfields[$i]\">@$values[$i]</subfield>\n";
}
}
- $prevtag = @$tags[$i];
+ $prevtag = @$tags[$i].@$tagindex[$i];
}
$xml.="</record>";
# warn $xml;
$xml=Encode::decode('utf8',$xml);
return $xml;
}
-sub marc_record_header {
+sub XML_record_header {
#### this one is for <record>
my $format = shift;
my $enc = shift || 'UTF-8';
-sub MARCkoha2marc {
-# warn "MARCkoha2marc";
-## This routine most probably will be depreaceated -- it is still used for acqui management
-##Returns a MARC record from a hash
- my ($dbh,$result,$recordtype) = @_;
- my $record = MARC::Record->new();
- my $sth2=$dbh->prepare("SELECT marctokoha from koha_attr where tagfield is not null and recordtype=?");
- $sth2->execute($recordtype);
- my $field;
- while (($field)=$sth2->fetchrow) {
- $record=&MARCkoha2marcOnefield($record,$field,$result->{$field},$recordtype) if $result->{$field};
- }
-return $record;
-}
-sub MARCmarc2koha {
-# warn "MARCmarc2koha";
-##Returns a hash from MARC record
- my ($dbh,$record,$related_record) = @_;
- my $result;
-if (!$related_record){$related_record="biblios";}
- my $sth2=$dbh->prepare("SELECT marctokoha from koha_attr where recordtype like ? and tagfield is not null" );
- $sth2->execute($related_record);
- my $field;
- while ($field=$sth2->fetchrow) {
- $result=&MARCmarc2kohaOneField($field,$record,$result,$related_record);
- }
-## we only need the following for biblio data
-if ($related_record eq "biblios"){
-# modify copyrightdate to keep only the 1st year found
- my $temp = $result->{'copyrightdate'};
- $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
- if ($1>0) {
- $result->{'copyrightdate'} = $1;
- } else { # if no cYYYY, get the 1st date.
- $temp =~ m/(\d\d\d\d)/;
- $result->{'copyrightdate'} = $1;
- }
-# modify publicationyear to keep only the 1st year found
- $temp = $result->{'publicationyear'};
- $temp =~ m/c(\d\d\d\d)/; # search cYYYY first
- if ($1>0) {
- $result->{'publicationyear'} = $1;
- } else { # if no cYYYY, get the 1st date.
- $temp =~ m/(\d\d\d\d)/;
- $result->{'publicationyear'} = $1;
- }
-}
- return $result;
-}
-
-sub MARCkoha2marcOnefield {
-##Updates or creates one field in MARC record
- my ( $record, $kohafieldname, $value,$recordtype ) = @_;
-my ( $tagfield, $tagsubfield ) = MARCfind_marc_from_kohafield($kohafieldname,$recordtype);
-if ($tagfield){
-my $tag = $record->field($tagfield);
- if ( $tagfield>9) {
- if ($tag) {
- if ($value){## We may be trying to delete a subfield value
- $tag->update( $tagsubfield=> $value );
- }else{
- $tag->delete_subfield(code=>$tagsubfield);
- }
- $record->delete_field($tag);
- $record->insert_fields_ordered($tag);
- }else {
- my $newtag=MARC::Field->new( $tagfield, " ", " ", $tagsubfield => $value);
- $record->insert_fields_ordered($newtag);
- }
- }else {
- if ($tag) {
- if ($value){
- $tag->update( $value );
- $record->delete_field($tag);
- $record->insert_fields_ordered($tag);
- }else{
- $record->delete_field($tag);
- }
- }else {
- my $newtag=MARC::Field->new( $tagfield => $value);
- $record->insert_fields_ordered($newtag);
- }
- }
-}## $tagfield defined
- return $record;
-}
-
-sub MARCmarc2kohaOneField {
- my ( $kohafield, $record, $result,$recordtype ) = @_;
- # # warn "kohatable / $kohafield / $result / ";
- my $res = "";
-
- my ( $tagfield, $subfield ) = MARCfind_marc_from_kohafield($kohafield,$recordtype);
-if ($tagfield){
- foreach my $field ( $record->field($tagfield) ) {
- if ($field->tag()<10) {
- if ($result->{$kohafield}) {
- $result->{$kohafield} .= " | ".$field->data();
- } else {
- $result->{$kohafield} = $field->data();
- }
- } else {
- if ( $field->subfields ) {
- my @subfields = $field->subfields();
- foreach my $subfieldcount ( 0 .. $#subfields ) {
- if ($subfields[$subfieldcount][0] eq $subfield) {
- if ( $result->{$kohafield} ) {
- $result->{$kohafield} .= " | " . $subfields[$subfieldcount][1];
- }
- else {
- $result->{$kohafield} = $subfields[$subfieldcount][1];
- }
- }
- }
- }
- }
- }
-}
- return $result;
-}
sub NEWdelbiblio {
-
my ( $dbh, $biblionumber ) = @_;
-my $sth=$dbh->prepare("SELECT itemnumber FROM items where biblionumber=?");
-
-$sth->execute($biblionumber);
- while (my $itemnumber =$sth->fetchrow){
- OLDdelitem($dbh,$itemnumber) ;
- }
-
- ZEBRAop($dbh,$biblionumber,"recordDelete","biblioserver");
-OLDdelbiblio($dbh,$biblionumber) ;
-
+ZEBRAop($dbh,$biblionumber,"recordDelete","biblioserver");
}
+
sub NEWnewitem {
my ( $dbh, $xmlhash, $biblionumber ) = @_;
my $itemtype= MARCfind_itemtype($dbh,$biblionumber);
##Add biblionumber to $record
$xmlhash=XML_writeline($xmlhash,"biblionumber",$biblionumber,"holdings");
-# MARCkoha2marcOnefield($record,"biblionumber",$biblionumber,"holdings");
my $sth=$dbh->prepare("select notforloan from itemtypes where itemtype='$itemtype'");
$sth->execute();
my $notforloan=$sth->fetchrow;
$sth->execute($itemnumber);
my $biblionumber=$sth->fetchrow;
OLDdelitem( $dbh, $itemnumber ) ;
-ZEBRAop($dbh,$biblionumber,"recordDelete","biblioserver");
+ZEBRAop($dbh,$biblionumber,"specialUpdate","biblioserver");
}
## We must add the indexing fields for LC in MARC record--TG
-## XMLmodLCindex($dbh,$xmlhash);
+ XMLmodLCindex($dbh,$xmlhash);
OLDmodbiblio ($dbh,$xmlhash,$biblionumber,$frameworkcode);
my $ok=ZEBRAop($dbh,$biblionumber,"specialUpdate","biblioserver");
return ($biblionumber);
my $author=XML_readline_onerecord($xmlhash,"author","biblios");
my $xml=XML_hash2xml($xmlhash);
-#my $marc=MARC::Record->new_from_xml($xml,'UTF-8');## this will be depreceated
$isbn=~ s/(\.|\?|\;|\=|\-|\/|\\|\||\:|\*|\!|\,|\(|\)|\[|\]|\{|\}|\/)//g;
$issn=~ s/(\.|\?|\;|\=|\-|\/|\\|\||\:|\*|\!|\,|\(|\)|\[|\]|\{|\}|\/)//g;
$isbn=~s/^\s+|\s+$//g;
#
#
-sub ZEBRAgetrecord {
-my $biblionumber=shift;
-my @oConnection;
- $oConnection[0]=C4::Context->Zconn("biblioserver");
-my $field=MARCfind_attr_from_kohafield("biblionumber");
-my $query=$field." ".$biblionumber;
-my $oResult= $oConnection[0]->search_pqf($query);
-my $event;
-my $i;
- while (($i = ZOOM::event(\@oConnection)) != 0) {
- $event = $oConnection[$i-1]->last_event();
- last if $event == ZOOM::Event::ZEND;
- }# while
-if ($oResult->size()){
-my $xmlrecord=$oResult->record(0)->raw() ;
-$oConnection[0]->destroy;
-$xmlrecord=Encode::decode('utf8',$xmlrecord);
-my $hashed=XML_xml2hash($xmlrecord);
-my ( $xmlrecord, @itemsrecord) = XML_separate($hashed);
-return ($xmlrecord, @itemsrecord);
-}else{
-return (undef,undef);
-}
+sub ZEBRAdelbiblio {
+## Zebra calls this routine to delete after it deletes biblio from ZEBRAddb
+ my ( $dbh, $biblionumber ) = @_;
+my $sth=$dbh->prepare("SELECT itemnumber FROM items where biblionumber=?");
+
+$sth->execute($biblionumber);
+ while (my $itemnumber =$sth->fetchrow){
+ OLDdelitem($dbh,$itemnumber) ;
+ }
+OLDdelbiblio($dbh,$biblionumber) ;
}
+sub ZEBRAgetrecord{
+my $biblionumber=shift;
+my @kohafield="biblionumber";
+my @value=$biblionumber;
+my ($count,@result)=C4::Search::ZEBRAsearch_kohafields(\@kohafield,\@value);
+
+ if ($count>0){
+ my ( $xmlrecord, @itemsrecord) = XML_separate($result[0]);
+ return ($xmlrecord, @itemsrecord);
+ }else{
+ return (undef,undef);
+ }
+}
sub ZEBRAop {
### Puts the zebra update in queue writes in zebraserver table
my ($dbh,$biblionumber,$op,$server)=@_;
-my ($record);
-
+if (!$biblionumber){
+warn "Zebra received no biblionumber";
+}else{
my $sth=$dbh->prepare("insert into zebraqueue (biblio_auth_number ,server,operation) values(?,?,?)");
$sth->execute($biblionumber,$server,$op);
}
-
+}
sub ZEBRAopserver{
###Accepts a $server variable thus we can use it to update biblios, authorities or other zebra dbs
-my ($record,$op,$server)=@_;
-my @Zconnbiblio;
+my ($record,$op,$server,$biblionumber)=@_;
+
my @port;
-my $Zpackage;
+
my $tried=0;
my $recon=0;
my $reconnect=0;
my $shadow=$server."shadow";
reconnect:
-$Zconnbiblio[0]=C4::Context->Zconnauth($server);
+ my $Zconnbiblio=C4::Context->Zconnauth($server);
if ($record){
-my $Zpackage = $Zconnbiblio[0]->package();
+my $Zpackage = $Zconnbiblio->package();
$Zpackage->option(action => $op);
$Zpackage->option(record => $record);
+ $Zpackage->option(recordIdOpaque => $biblionumber);
retry:
$Zpackage->send("update");
-my $i;
-my $event;
-while (($i = ZOOM::event(\@Zconnbiblio)) != 0) {
- $event = $Zconnbiblio[0]->last_event();
- last if $event == ZOOM::Event::ZEND;
-}
- my($error, $errmsg, $addinfo, $diagset) = $Zconnbiblio[0]->error_x();
+ my($error, $errmsg, $addinfo, $diagset) = $Zconnbiblio->error_x();
if ($error==10007 && $tried<3) {## timeout --another 30 looonng seconds for this update
sleep 1; ## wait a sec!
$tried=$tried+1;
sleep 1; ## wait a sec!
$recon=1;
$Zpackage->destroy();
- $Zconnbiblio[0]->destroy();
+ $Zconnbiblio->destroy();
goto "reconnect";
}elsif ($error){
# warn "Error-$server $op /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
$Zpackage->destroy();
- $Zconnbiblio[0]->destroy();
- # ZEBRAopfiles($dbh,$biblionumber,$record,$op,$server);
+ $Zconnbiblio->destroy();
return 0;
}
- ## System preference batchMode=1 means wea are bulk importing
- ## DO NOT COMMIT while in batchMode for faster operation
- my $batchmode=C4::Context->preference('batchMode');
- if (C4::Context->$shadow >0 && !$batchmode){
- $Zpackage->send('commit');
- while (($i = ZOOM::event(\@Zconnbiblio)) != 0) {
- $event = $Zconnbiblio[0]->last_event();
- last if $event == ZOOM::Event::ZEND;
- }
- my($error, $errmsg, $addinfo, $diagset) = $Zconnbiblio[0]->error_x();
- if ($error) { ## This is serious ZEBRA server is not updating
- $Zpackage->destroy();
- $Zconnbiblio[0]->destroy();
- return 0;
- }
- }##commit
-#
+
$Zpackage->destroy();
-$Zconnbiblio[0]->destroy();
+$Zconnbiblio->destroy();
return 1;
}
return 0;
}
+
+sub ZEBRAopcommit {
+my $server=shift;
+
+my $Zconnbiblio=C4::Context->Zconnauth($server);
+
+my $Zpackage = $Zconnbiblio->package();
+ $Zpackage->send('commit');
+
+ my($error, $errmsg, $addinfo, $diagset) = $Zconnbiblio->error_x();
+ if ($error) { ## This is serious ZEBRA server is not updating
+ $Zpackage->destroy();
+ $Zconnbiblio->destroy();
+ return 0;
+ }
+$Zpackage->destroy();
+$Zconnbiblio->destroy();
+return 1;
+}
sub ZEBRA_readyXML{
my ($dbh,$biblionumber)=@_;
my $biblioxml=XMLgetbiblio($dbh,$biblionumber);
#
sub newbiblio {
-## Used in acqui management -- creates the biblio from hash rather than marc-record
+## Used in acqui management -- creates the biblio from koha hash
my ($biblio) = @_;
my $dbh = C4::Context->dbh;
-my $record=MARCkoha2marc($dbh,$biblio,"biblios");
-$record->encoding('UTF-8');
+my $record=XMLkoha2marc($dbh,$biblio,"biblios");
my $biblionumber=NEWnewbiblio($dbh,$record);
return ($biblionumber);
}
sub modbiblio {
-## Used in acqui management -- modifies the biblio from hash rather than marc-record
+## Used in acqui management -- modifies the biblio from koha hash rather than xml-hash
my ($biblio) = @_;
my $dbh = C4::Context->dbh;
-my $record=MARCkoha2marc($dbh,$biblio,"biblios");
+my $record=XMLkoha2marc($dbh,$biblio,"biblios");
my $biblionumber=NEWmodbiblio($dbh,$record,$biblio->{biblionumber});
return ($biblionumber);
}
sub getkohafields{
#returns MySQL like fieldnames to emulate searches on sql like fieldnames
-my $type=@_;
+my $type=shift;
## Either opac or intranet to select appropriate fields
## Assumes intranet
$type="intra" unless $type;
my $i=0;
my @results;
$type=$type."show";
-my $sth=$dbh->prepare("SELECT * FROM koha_attr where $type=1 order by liblibrarian");
+my $sth=$dbh->prepare("SELECT * FROM koha_attr where $type=1 order by label");
$sth->execute();
while (my $data=$sth->fetchrow_hashref){
$results[$i]=$data;
sub itemcalculator{
## Sublimentary function to obtain sorted LC for items. Not exported
my ($dbh,$biblionumber,$callnumber)=@_;
-my $xml=XMLgetbiblio($dbh,$biblionumber);
-my $xmlhash=XML_xml2hash_onerecord($xml);
+my $xmlhash=XMLgetbibliohash($dbh,$biblionumber);
my $lc=XML_readline_onerecord($xmlhash,"classification","biblios");
my $cutter=XML_readline_onerecord($xmlhash,"subclass","biblios");
my $all=$lc." ".$cutter;