[Koha-cvs] koha/C4 Biblio.pm [dev_week]
Joshua Ferraro
jmf at kados.org
Sun Sep 24 21:51:04 CEST 2006
CVSROOT: /sources/koha
Module name: koha
Branch: dev_week
Changes by: Joshua Ferraro <kados> 06/09/24 19:51:04
Modified files:
C4 : Biblio.pm
Log message:
I'm in the middle of a major Biblio cleaning, just committing so I have
some version conrol. I'll post a mail describing the changes when I've
finished.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Biblio.pm?cvsroot=koha&only_with_tag=dev_week&r1=1.115.2.51.2.18&r2=1.115.2.51.2.19
Patches:
Index: Biblio.pm
===================================================================
RCS file: /sources/koha/koha/C4/Biblio.pm,v
retrieving revision 1.115.2.51.2.18
retrieving revision 1.115.2.51.2.19
diff -u -b -r1.115.2.51.2.18 -r1.115.2.51.2.19
--- Biblio.pm 24 Sep 2006 15:24:06 -0000 1.115.2.51.2.18
+++ Biblio.pm 24 Sep 2006 19:51:04 -0000 1.115.2.51.2.19
@@ -34,13 +34,17 @@
@ISA = qw(Exporter);
@EXPORT = qw(
- &updateBiblio &updateBiblioItem &updateItem
+
+ &AddBiblio
+ &ModBiblio
+ &DelBiblio
+
&newbiblio &newbiblioitem
&modnote &newsubject &newsubtitle
&checkitems
- &newitems &modbibitem
+ &newitems
&modsubtitle &modsubject &modaddauthor &moditem &countitems
&getbiblio &getstacks
&getbiblioitembybiblionumber
@@ -54,15 +58,15 @@
&MARCgettagslib
&MARCmoditemonefield
- &DeleteBiblio
+ &NEWnewitem
+
+ &NEWmoditem
+ &ModBiblioframework
- &NEWnewbiblio &NEWnewitem
- &NEWmodbiblio &NEWmoditem
&NEWdelitem
- &NEWmodbiblioframework
&zebraop
- &MARCaddbiblio &MARCadditem &MARCmodLCindex
+ &MARCaddbiblio &MARCadditem
&MARCmodsubfield &MARCaddsubfield
&MARCmodbiblio &MARCmoditem
&MARCkoha2marcBiblio &MARCmarc2koha
@@ -84,9 +88,277 @@
=head1 DESCRIPTION
+There are three types of routines
+
+=head1 EXPORTED FUNCTIONS
+
+=head2 AddBiblio
+
+=over 4
+
+($biblionumber,$oldbibnum,$oldbibitemnum) = AddBiblio($dbh,$record,$frameworkcode);
+
+Adds a new biblio to koha
+
+=back
+
+=cut
+
+sub AddBiblio {
+ my ( $dbh, $record, $frameworkcode) = @_;
+ my $oldbibnum;
+ my $oldbibitemnum;
+
+ # transform the data into koha-table style data
+ my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
+
+ #
+ $oldbibnum = OLDnewbiblio( $dbh, $olddata );
+ $olddata->{'biblionumber'} = $oldbibnum;
+ $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
+
+ # search subtiles, addiauthors and subjects
+ my ( $tagfield, $tagsubfield ) =
+ MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
+ my @addiauthfields = $record->field($tagfield);
+ foreach my $addiauthfield (@addiauthfields) {
+ my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
+ foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
+ OLDmodaddauthor( $dbh, $oldbibnum,
+ $addiauthsubfields[$subfieldcount] );
+ }
+ }
+ ( $tagfield, $tagsubfield ) =
+ MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
+ my @subtitlefields = $record->field($tagfield);
+ foreach my $subtitlefield (@subtitlefields) {
+ my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
+ foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
+ OLDnewsubtitle( $dbh, $oldbibnum,
+ $subtitlesubfields[$subfieldcount] );
+ }
+ }
+ ( $tagfield, $tagsubfield ) =
+ MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
+ my @subj = $record->field($tagfield);
+ my @subjects;
+ foreach my $subject (@subj) {
+ my @subjsubfield = $subject->subfield($tagsubfield);
+ foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
+ push @subjects, $subjsubfield[$subfieldcount];
+ }
+ }
+ OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
+
+ # we must add bibnum and bibitemnum in MARC::Record...
+ # we build the new field with biblionumber and biblioitemnumber
+ # we drop the original field
+ # we add the new builded field.
+ # NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
+ # (steve and paul : thinks 090 is a good choice)
+ my $sth = $dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?");
+ $sth->execute("biblio.biblionumber");
+ ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
+ $sth->execute("biblioitems.biblioitemnumber");
+ ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
+
+ my $newfield;
+ # biblionumber & biblioitemnumber are in different fields
+ if ( $tagfield1 != $tagfield2 ) {
+ # deal with biblionumber
+ if ($tagfield1<10) {
+ $newfield = MARC::Field->new(
+ $tagfield1, $oldbibnum,
+ );
+ } else {
+ $newfield = MARC::Field->new(
+ $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
+ );
+ }
+ # drop old field and create new one...
+ my $old_field = $record->field($tagfield1);
+ $record->delete_field($old_field);
+ $record->append_fields($newfield);
+ # deal with biblioitemnumber
+ if ($tagfield2<10) {
+ $newfield = MARC::Field->new(
+ $tagfield2, $oldbibitemnum,
+ );
+ } else {
+ $newfield = MARC::Field->new(
+ $tagfield2, '', '', "$tagsubfield2" => $oldbibitemnum,
+ );
+ }
+ # drop old field and create new one...
+ $old_field = $record->field($tagfield2);
+ $record->delete_field($old_field);
+ $record->insert_fields_ordered($newfield);
+ # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
+ } else {
+ my $newfield = MARC::Field->new(
+ $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
+ "$tagsubfield2" => $oldbibitemnum
+ );
+ # drop old field and create new one...
+ my $old_field = $record->field($tagfield1);
+ $record->delete_field($old_field);
+ $record->insert_fields_ordered($newfield);
+ }
+
+ ###NEU specific add cataloguers cardnumber as well
+ my $cardtag=C4::Context->preference('cataloguersfield');
+ if ($cardtag) {
+ my $tag=substr($cardtag,0,3);
+ my $subf=substr($cardtag,3,1);
+ my $me= C4::Context->userenv;
+ my $cataloger=$me->{'cardnumber'} if ($me);
+ my $newtag= MARC::Field->new($tag, '', '', $subf => $cataloger) if ($me);
+ $record->delete_field($newtag);
+ $record->insert_fields_ordered($newtag);
+ }
+
+ # now add the record
+ my $biblionumber = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
+ return ( $biblionumber, $oldbibnum, $oldbibitemnum );
+}
+
+=head2 ModBiblio
+
+=over 4
+
+ModBiblio($dbh,$record,$biblionumber,$frameworkcode);
+
+Exported function to modify a biblio
+
+=back
+
+=cut
+
+sub ModBiblio {
+ my ($dbh,$record,$biblionumber,$frameworkcode) =@_;
+
+ $frameworkcode="" unless $frameworkcode;
+
+ # update the MARC record with the new record data
+ &MARCmodbiblio($dbh,$biblionumber,$record,$frameworkcode,1);
+
+ # loat the koha-style data
+ my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
+
+ # modify the other koha tables
+ my $oldbiblionumber = _koha_modify_biblio($dbh,$oldbiblio);
+ _koha_modify_biblioitem($dbh,$oldbiblio);
+
+ # now, modify addi authors, subject, addititles.
+ my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
+ my @addiauthfields = $record->field($tagfield);
+ foreach my $addiauthfield (@addiauthfields) {
+ my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
+ foreach my $subfieldcount (0..$#addiauthsubfields) {
+ OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
+ }
+ }
+ ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
+ my @subtitlefields = $record->field($tagfield);
+ foreach my $subtitlefield (@subtitlefields) {
+ my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
+ # delete & create subtitle again because OLDmodsubtitle can't handle new subtitles
+ # between 2 modifs
+ $dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
+ foreach my $subfieldcount (0..$#subtitlesubfields) {
+ foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
+ OLDnewsubtitle($dbh,$oldbiblionumber,$subtit);
+ }
+ }
+ }
+ ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
+ my @subj = $record->field($tagfield);
+ my @subjects;
+ foreach my $subject (@subj) {
+ my @subjsubfield = $subject->subfield($tagsubfield);
+ foreach my $subfieldcount (0..$#subjsubfield) {
+ push @subjects,$subjsubfield[$subfieldcount];
+ }
+ }
+ OLDmodsubject($dbh,$oldbiblionumber,1, at subjects);
+ return 1;
+}
+
+=head2 DelBiblio
+
+=over 4
+
+my $error = &DelBiblio($dbh,$bibid);
+
+Delete biblio record from Zebra and Koha tables (biblio,biblioitems,items)
+Also backs it up to deleted* tables
+
+return:
+C<$error> : undef unless an error occurs
+
+=back
+
+=cut
+
+sub DelBiblio {
+ my ( $dbh, $biblionumber ) = @_;
+ my $error; # for error handling
+
+ # First make sure there are no items with issues are still attached
+ my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
+ $sth->execute($biblionumber);
+ while ( my $biblioitemnumber = $sth->fetchrow ) {
+ my @issues = C4::Search::itemissues($biblioitemnumber);
+ foreach my $issue (@issues) {
+ if ( ($issue->{date_due}) && ($issue->{date_due} ne "Available") ) {
+ #FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
+ # instead of hard-coded strings
+ $error.="Item is checked out to a patron -- you must return it before deleting the Biblio";
+ }
+ }
+ }
+ return $error if $error;
+
+ # Delete from Zebra
+ # get the xml of the record from Zebra
+ my $xmlrecord = getRecord("biblioserver","Local-number=$biblionumber");
+ my $serviceOptions;
+ $serviceOptions->{'databaseName'} = "biblios";
+ $serviceOptions->{'record'} = $xmlrecord;
+ $error = &z3950_extended_services("biblioserver","update","recordDelete",$serviceOptions);
+ return $error if $error;
+
+ # run commit operation
+ #if ( (C4::Context->preference("commitImmediately")) ) {
+ $error = &z3950_extended_services("biblioserver","commit");
+ #}
+ #zebraop($dbh,$biblionumber,"recordDelete","biblioserver");
+ return $error if $error;
+
+ # delete biblio from Koha tables and save in deletedbiblio
+ $error = &_kohaDeleteBiblio( $dbh, $biblionumber );
+ return $error if $error;
+
+ # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
+ my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
+ $sth->execute($biblionumber);
+ while ( my $biblioitemnumber = $sth->fetchrow ) {
+
+ # delete this biblioitem
+ $error = &_kohaDeleteBiblioitems( $dbh, $biblioitemnumber );
+ return $error if $error;
+
+ # delete items
+ my $items_sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblioitemnumber=?");
+ $items_sth->execute($biblioitemnumber);
+ while ( my $itemnumber = $items_sth->fetchrow ) {
+ $error = &_kohaDeleteItems( $dbh, $itemnumber );
+ return $error if $error;
+ }
+ }
+}
-=head1 FUNCTIONS
=head2 z3950_extended_services
@@ -275,16 +547,20 @@
sub MARCfind_MARCbibid_from_oldbiblionumber {
my ( $dbh, $oldbiblionumber ) = @_;
-# my $sth =
- # $dbh->prepare("select bibid from marc_biblio where biblionumber=?");
- # $sth->execute($oldbiblionumber);
- # my ($bibid) = $sth->fetchrow;
return $oldbiblionumber;
}
+=item MARCaddbiblio
+
+&MARCaddbiblio($dbh,$newrec,$biblionumber,$frameworkcode);
+
+Add MARC data for a biblio to koha
+
+=cut
+
sub MARCaddbiblio {
# pass the MARC::Record to this function, and it will create the records in the marc tables
- my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
+ my ($dbh,$record,$biblionumber,$frameworkcode) = @_;
my @fields=$record->fields();
if (!$frameworkcode){
$frameworkcode="";
@@ -293,7 +569,7 @@
$sth->execute( $frameworkcode,$biblionumber );
$sth->finish;
my $encoding = C4::Context->preference("marcflavour");
- $sth =$dbh->prepare("update biblioitems set marc=? where biblionumber=?" );
+ $sth =$dbh->prepare("update biblioitems set marc=? where biblionumber=?");
$sth->execute( $record->as_usmarc() , $biblionumber);
$sth->finish;
@@ -302,22 +578,18 @@
}
sub MARCadditem {
-
# pass the MARC::Record to this function, and it will create the records in the marc tables
my ($dbh,$record,$biblionumber) = @_;
-my $newrec=&MARCgetbiblio($dbh,$biblionumber);
-# 2nd recreate it
+ my $newrec=&MARCgetbiblio($dbh,$biblionumber);
+
+ # 2nd recreate it
my @fields = $record->fields();
foreach my $field (@fields) {
$newrec->append_fields($field);
}
-my $bibid=&MARCaddbiblio($dbh,$newrec,$biblionumber);
- return $bibid;
-}
-
-sub MARCaddsubfield {
-
+ my $biblionumber=&MARCaddbiblio($dbh,$newrec,$biblionumber);
+ return $biblionumber;
}
sub MARCgetbiblio {
@@ -408,31 +680,38 @@
if ($field->subfield($itemnumbersubfield) eq $itemnumber ){
- $newrecord->add_fields($field);
+ $newrecord->insert_fields_ordered($field);
}
}
return $newrecord;
}
+=item MARCmodbiblio
+
+MARCmodbibio($dbh,$bibid,$record,$frameworkcode,1);
+
+Modify a biblio record with the option to save items data
+
+=cut
+
sub MARCmodbiblio {
- my ($dbh,$bibid,$record,$frameworkcode,$delete)=@_;
+ my ($dbh,$biblionumber,$record,$frameworkcode,$keep_items)=@_;
- # delete original marcrecord
- my $newrec=&MARCdelbiblio($dbh,$bibid,$delete);
+ # delete original record but save the items
+ my $newrec=&MARCdelbiblio($dbh,$biblionumber,$keep_items);
# recreate it and add the new fields
my @fields = $record->fields();
foreach my $field (@fields) {
- $newrec->append_fields($field);
+ # this requires a more recent version of MARC::Record
+ # but ensures the fields are in order
+ $newrec->insert_fields_ordered($field);
}
- # correct the leader
+ # give back our old leader
$newrec->leader($record->leader());
-
- &MARCmodLCindex($dbh,$newrec,$frameworkcode);
-
- # add it back
- &MARCaddbiblio($dbh,$newrec,$bibid,$frameworkcode,$bibid);
+ # add the record back with the items info preserved
+ &MARCaddbiblio($dbh,$newrec,$biblionumber,$frameworkcode);
}
sub MARCdelbiblio {
@@ -526,7 +805,7 @@
$tag->update($tagsubfield =>$newvalue);
$record->delete_field($tag);
- $record->add_fields($tag);
+ $record->insert_fields_ordered($tag);
&MARCmoditem($dbh,$record,$biblionumber,$itemnumber,0);
}
@@ -846,11 +1125,11 @@
if ($tag) {
$tag->update( $tagsubfield=> $value );
$record->delete_field($tag);
- $record->add_fields($tag);
+ $record->insert_fields_ordered($tag);
}else {
- $record->add_fields( $tagfield, " ", " ", $tagsubfield => $value );
+ $record->insert_fields_ordered( $tagfield, " ", " ", $tagsubfield => $value );
}
}
@@ -942,7 +1221,7 @@
if ($prevvalue) {
if ($prevtag ne '000') {
- $record->add_fields((sprintf "%03s",$prevtag),$prevvalue);
+ $record->insert_fields_ordered((sprintf "%03s",$prevtag),$prevvalue);
} else {
$record->leader($prevvalue);
@@ -951,7 +1230,7 @@
}
} else {
if ($field) {
- $record->add_fields($field);
+ $record->insert_fields_ordered($field);
}
}
$indicators{@$rtags[$i]}.=' ';
@@ -977,7 +1256,7 @@
}
}
# the last has not been included inside the loop... do it now !
- $record->add_fields($field) if $field;
+ $record->insert_fields_ordered($field) if $field;
# warn "HTML2MARC=".$record->as_formatted;
$record->encoding( 'UTF-8' );
# $record->MARC::File::USMARC::update_leader();
@@ -1106,262 +1385,24 @@
$sth->execute( $bibid, $tag, $subfield, $tagorder, $subfieldorder );
}
-sub NEWnewbiblio {
- my ( $dbh, $record, $frameworkcode) = @_;
- my $oldbibnum;
- my $oldbibitemnum;
- my $olddata = MARCmarc2koha( $dbh, $record,$frameworkcode );
- $oldbibnum = OLDnewbiblio( $dbh, $olddata );
- $olddata->{'biblionumber'} = $oldbibnum;
- $oldbibitemnum = OLDnewbiblioitem( $dbh, $olddata );
-
- # search subtiles, addiauthors and subjects
- my ( $tagfield, $tagsubfield ) =
- MARCfind_marc_from_kohafield( $dbh, "additionalauthors.author",$frameworkcode );
- my @addiauthfields = $record->field($tagfield);
- foreach my $addiauthfield (@addiauthfields) {
- my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
- foreach my $subfieldcount ( 0 .. $#addiauthsubfields ) {
- OLDmodaddauthor( $dbh, $oldbibnum,
- $addiauthsubfields[$subfieldcount] );
- }
- }
- ( $tagfield, $tagsubfield ) =
- MARCfind_marc_from_kohafield( $dbh, "bibliosubtitle.subtitle",$frameworkcode );
- my @subtitlefields = $record->field($tagfield);
- foreach my $subtitlefield (@subtitlefields) {
- my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
- foreach my $subfieldcount ( 0 .. $#subtitlesubfields ) {
- OLDnewsubtitle( $dbh, $oldbibnum,
- $subtitlesubfields[$subfieldcount] );
- }
- }
- ( $tagfield, $tagsubfield ) =
- MARCfind_marc_from_kohafield( $dbh, "bibliosubject.subject",$frameworkcode );
- my @subj = $record->field($tagfield);
- my @subjects;
- foreach my $subject (@subj) {
- my @subjsubfield = $subject->subfield($tagsubfield);
- foreach my $subfieldcount ( 0 .. $#subjsubfield ) {
- push @subjects, $subjsubfield[$subfieldcount];
- }
- }
- OLDmodsubject( $dbh, $oldbibnum, 1, @subjects );
+=item ModBiblioframework
- # we must add bibnum and bibitemnum in MARC::Record...
- # we build the new field with biblionumber and biblioitemnumber
- # we drop the original field
- # we add the new builded field.
-# NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber
- # (steve and paul : thinks 090 is a good choice)
- my $sth =
- $dbh->prepare(
-"select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"
- );
- $sth->execute("biblio.biblionumber");
- ( my $tagfield1, my $tagsubfield1 ) = $sth->fetchrow;
- $sth->execute("biblioitems.biblioitemnumber");
- ( my $tagfield2, my $tagsubfield2 ) = $sth->fetchrow;
-
- my $newfield;
- # biblionumber & biblioitemnumber are in different fields
- if ( $tagfield1 != $tagfield2 ) {
- # deal with biblionumber
- if ($tagfield1<10) {
- $newfield = MARC::Field->new(
- $tagfield1, $oldbibnum,
- );
- } else {
- $newfield = MARC::Field->new(
- $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
- );
- }
- # drop old field and create new one...
- my $old_field = $record->field($tagfield1);
- $record->delete_field($old_field);
- $record->append_fields($newfield);
- # deal with biblioitemnumber
- if ($tagfield2<10) {
- $newfield = MARC::Field->new(
- $tagfield2, $oldbibitemnum,
- );
- } else {
- $newfield = MARC::Field->new(
- $tagfield2, '', '', "$tagsubfield2" => $oldbibitemnum,
- );
- }
- # drop old field and create new one...
- $old_field = $record->field($tagfield2);
- $record->delete_field($old_field);
- $record->add_fields($newfield);
- # biblionumber & biblioitemnumber are in the same field (can't be <10 as fields <10 have only 1 value)
- } else {
- my $newfield = MARC::Field->new(
- $tagfield1, '', '', "$tagsubfield1" => $oldbibnum,
- "$tagsubfield2" => $oldbibitemnum
- );
- # drop old field and create new one...
- my $old_field = $record->field($tagfield1);
- $record->delete_field($old_field);
- $record->add_fields($newfield);
- }
-# warn "REC : ".$record->as_formatted;
-###NEU specific add cataloguers cardnumber as well
-my $cardtag=C4::Context->preference('cataloguersfield');
-if ($cardtag){
-my $tag=substr($cardtag,0,3);
-my $subf=substr($cardtag,3,1);
-my $me= C4::Context->userenv;
-my $cataloger=$me->{'cardnumber'} if ($me);
-my $newtag= MARC::Field->new($tag, '', '', $subf => $cataloger) if ($me);
-$record->delete_field($newtag);
-$record->add_fields($newtag);
-}
-## We must add the indexing fields for LC in MARC record--TG
- &MARCmodLCindex($dbh,$record,$frameworkcode);
-
-
- my $bibid = MARCaddbiblio( $dbh, $record, $oldbibnum, $frameworkcode );
- return ( $bibid, $oldbibnum, $oldbibitemnum );
-}
+=over 4
+ModBiblioframework($dbh,$biblionumber,$frameworkcode);
+Exported function to modify a biblio framework
-sub MARCmodLCindex{
-my ($dbh,$record,$frameworkcode)=@_;
-if(!$frameworkcode){
-$frameworkcode="";
-}
-my ($tagfield,$tagsubfield,$tagsubfieldsub);
-($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"biblioitems.classification",$frameworkcode);
-($tagfield,$tagsubfieldsub) = MARCfind_marc_from_kohafield($dbh,"biblioitems.subclass",$frameworkcode);
-my $tag=$record->field($tagfield);
-if ($tag){
-my ($lcsort)=calculatelc($tag->subfield($tagsubfield)).$tag->subfield($tagsubfieldsub);
+=back
- &MARCkoha2marcOnefield( undef, $record, "biblioitems.lcsort", $lcsort,$frameworkcode);
-}
-return $record;
-}
+=cut
-sub NEWmodbiblioframework {
+sub ModBiblioframework {
my ($dbh,$bibid,$frameworkcode) =@_;
my $sth = $dbh->prepare("Update biblio SET frameworkcode=? WHERE biblionumber=$bibid");
$sth->execute($frameworkcode);
return 1;
}
-sub NEWmodbiblio {
- my ($dbh,$record,$bibid,$frameworkcode) =@_;
-
- $frameworkcode="" unless $frameworkcode;
-
- &MARCmodbiblio($dbh,$bibid,$record,$frameworkcode,1);
- my $oldbiblio = MARCmarc2koha($dbh,$record,$frameworkcode);
-
-
- my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
-
-
- OLDmodbibitem($dbh,$oldbiblio);
-
- # now, modify addi authors, subject, addititles.
- my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author",$frameworkcode);
- my @addiauthfields = $record->field($tagfield);
- foreach my $addiauthfield (@addiauthfields) {
- my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
- foreach my $subfieldcount (0..$#addiauthsubfields) {
- OLDmodaddauthor($dbh,$oldbiblionumber,$addiauthsubfields[$subfieldcount]);
- }
- }
- ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle",$frameworkcode);
- my @subtitlefields = $record->field($tagfield);
- foreach my $subtitlefield (@subtitlefields) {
- my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
- # delete & create subtitle again because OLDmodsubtitle can't handle new subtitles
- # between 2 modifs
- $dbh->do("delete from bibliosubtitle where biblionumber=$oldbiblionumber");
- foreach my $subfieldcount (0..$#subtitlesubfields) {
- foreach my $subtit(split /\||#/,$subtitlesubfields[$subfieldcount]) {
- OLDnewsubtitle($dbh,$oldbiblionumber,$subtit);
- }
- }
- }
- ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject",$frameworkcode);
- my @subj = $record->field($tagfield);
- my @subjects;
- foreach my $subject (@subj) {
- my @subjsubfield = $subject->subfield($tagsubfield);
- foreach my $subfieldcount (0..$#subjsubfield) {
- push @subjects,$subjsubfield[$subfieldcount];
- }
- }
- OLDmodsubject($dbh,$oldbiblionumber,1, at subjects);
- return 1;
-}
-
-=item DeleteBiblio
-
-Delete complete biblio record from Zebra and Koha tables (biblio,biblioitems,items)
-
-=cut
-
-sub DeleteBiblio {
- my ( $dbh, $biblionumber ) = @_;
- my $error; # for error handling
-
- # First make sure there are no items with issues are still attached
- my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
- $sth->execute($biblionumber);
- while ( my $biblioitemnumber = $sth->fetchrow ) {
- my @issues = C4::Search::itemissues($biblioitemnumber);
- foreach my $issue (@issues) {
- if ( ($issue->{date_due}) && ($issue->{date_due} ne "Available") ) {
- #FIXME: we need a status system in Biblio like in Circ to return standard codes and messages
- # instead of hard-coded strings
- $error.="Item is checked out to a patron -- you must return it before deleting the Biblio";
- }
- }
- }
- return $error if $error;
-
- # Delete from Zebra
- # get the xml of the record from Zebra
- my $xmlrecord = getRecord("biblioserver","Local-number=$biblionumber");
- my $serviceOptions;
- $serviceOptions->{'databaseName'} = "biblios";
- $serviceOptions->{'record'} = $xmlrecord;
- $error = &z3950_extended_services("biblioserver","update","recordDelete",$serviceOptions);
- return $error if $error;
-
- # run commit operation
- #if ( (C4::Context->preference("commitImmediately")) ) {
- $error = &z3950_extended_services("biblioserver","commit");
- #}
- #zebraop($dbh,$biblionumber,"recordDelete","biblioserver");
- return $error if $error;
-
- # delete biblio from Koha tables and save in deletedbiblio
- $error = &_KohaDeleteBiblio( $dbh, $biblionumber );
- return $error if $error;
-
- # delete biblioitems and items from Koha tables and save in deletedbiblioitems,deleteditems
- my $sth = $dbh->prepare("SELECT biblioitemnumber FROM biblioitems WHERE biblionumber=?");
- $sth->execute($biblionumber);
- while ( my $biblioitemnumber = $sth->fetchrow ) {
-
- # delete this biblioitem
- $error = &_KohaDeleteBiblioitems( $dbh, $biblioitemnumber );
- return $error if $error;
-
- # delete items
- my $items_sth = $dbh->prepare("SELECT itemnumber FROM items WHERE biblioitemnumber=?");
- $items_sth->execute($biblioitemnumber);
- while ( my $itemnumber = $items_sth->fetchrow ) {
- $error = &_KohaDeleteItems( $dbh, $itemnumber );
- return $error if $error;
- }
- }
-}
sub NEWnewitem {
my ( $dbh, $record, $bibid ) = @_;
@@ -1424,7 +1465,7 @@
if ( $tag) {
$tag->update($tagsubfield => $newvalue);
$record->delete_field($tag);
- $record->add_fields($tag);
+ $record->insert_fields_ordered($tag);
}
}
}
@@ -1472,10 +1513,6 @@
modify/adds subjects
-=item OLDmodbibitem($dbh, $biblioitem);
-
-modify a biblioitem
-
=item OLDmodnote($dbh,$bibitemnum,$note
modify a note for a biblioitem
@@ -1545,18 +1582,20 @@
return ($bibnum);
}
-sub OLDmodbiblio {
- my ( $dbh, $biblio ) = @_;
+=item _koha_modify_biblio
- # my $dbh = C4Connect;
- my $query;
- my $sth;
+over 4
- $query = "";
- $sth =
- $dbh->prepare(
-"Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?"
- );
+Internal function for updating the biblio table
+
+=back
+
+=cut
+
+sub _koha_modify_biblio {
+ my ( $dbh, $biblio ) = @_;
+ # FIXME: this code could be made more portable by not hard-coding the values that are supposed to be in biblio table
+ my $sth = $dbh->prepare("Update biblio set title = ?, author = ?, abstract = ?, copyrightdate = ?, seriestitle = ?, serial = ?, unititle = ?, notes = ? where biblionumber = ?");
$sth->execute(
$biblio->{'title'}, $biblio->{'author'},
$biblio->{'abstract'}, $biblio->{'copyrightdate'},
@@ -1564,7 +1603,6 @@
$biblio->{'unititle'}, $biblio->{'notes'},
$biblio->{'biblionumber'}
);
-
$sth->finish;
return ( $biblio->{'biblionumber'} );
}
@@ -1667,7 +1705,7 @@
return ($error);
} # sub modsubject
-sub OLDmodbibitem {
+sub _koha_modify_biblioitem {
my ( $dbh, $biblioitem ) = @_;
my $query;
##Recalculate LC in case it changed --TG
@@ -1718,7 +1756,7 @@
if ( $dbh->errstr ) {
warn "$query";
}
-} # sub modbibitem
+}
sub OLDmodnote {
my ( $dbh, $bibitemnum, $note ) = @_;
@@ -2030,9 +2068,9 @@
# $dbh->disconnect;
}
-=item _KohaDeleteBiblio
+=item _kohaDeleteBiblio
-$error = _KohaDeleteBiblio($dbh,$biblionumber);
+$error = _kohaDeleteBiblio($dbh,$biblionumber);
Internal sub for deleting from biblio table -- also saves to deletedbiblio
@@ -2042,7 +2080,7 @@
=cut
# FIXME: add error handling
-sub _KohaDeleteBiblio {
+sub _kohaDeleteBiblio {
my ( $dbh, $biblionumber ) = @_;
# get all the data for this biblio
@@ -2074,9 +2112,9 @@
return undef;
}
-=item _KohaDeleteBiblioitems
+=item _kohaDeleteBiblioitems
-$error = _KohaDeleteBiblioitems($dbh,$biblioitemnumber);
+$error = _kohaDeleteBiblioitems($dbh,$biblioitemnumber);
Internal sub for deleting from biblioitems table -- also saves to deletedbiblioitems
@@ -2086,7 +2124,7 @@
=cut
# FIXME: add error handling
-sub _KohaDeleteBiblioitems {
+sub _kohaDeleteBiblioitems {
my ( $dbh, $biblioitemnumber ) = @_;
# get all the data for this biblioitem
@@ -2119,9 +2157,9 @@
}
-=item _KohaDeleteItems
+=item _kohaDeleteItems
-$error = _KohaDeleteItems($dbh,$itemnumber);
+$error = _kohaDeleteItems($dbh,$itemnumber);
Internal sub for deleting from items table -- also saves to deleteditems
@@ -2131,7 +2169,7 @@
=cut
# FIXME: add error handling
-sub _KohaDeleteItems {
+sub _kohaDeleteItems {
my ( $dbh, $itemnumber ) = @_;
# get all the data for this item
@@ -2253,12 +2291,6 @@
return ($error);
} # sub modsubject
-sub modbibitem {
- my ($biblioitem) = @_;
- my $dbh = C4::Context->dbh;
- &OLDmodbibitem( $dbh, $biblioitem );
-} # sub modbibitem
-
sub modnote {
my ( $bibitemnum, $note ) = @_;
my $dbh = C4::Context->dbh;
@@ -2836,6 +2868,7 @@
# but it is clear it should be nabbed from zebra rather than from
# the koha tables
$record=MARCgetbiblio($dbh,$biblionumber);
+ $record = $record->as_xml_record() if $record;
#warn "RECORD".$record->as_usmarc();
$shadow="biblioservershadow";
@@ -2871,6 +2904,7 @@
} elsif($error==10004 && $recon==0) {##Lost connection -reconnect
$recon=1;
goto "reconnect";
+ # as a last resort, we save the data to the filesystem to be indexed in batch
} elsif ($error) {
warn "Error-$server $op $biblionumber /errcode:, $error, /MSG:,$errmsg,$addinfo \n";
$Zpackage->destroy();
@@ -2966,7 +3000,9 @@
$recordSyntax = "xml" unless $recordSyntax;
my $Zconn = C4::Context->Zconn($server,0,1,1,$recordSyntax);
my $rs = $Zconn->search(new ZOOM::Query::CCL2RPN($koha_query,$Zconn));
+ if ($rs->record(0)) {
return $rs->record(0)->raw();
+ }
}
@@ -2983,8 +3019,13 @@
=cut
-# $Id: Biblio.pm,v 1.115.2.51.2.18 2006/09/24 15:24:06 kados Exp $
+# $Id: Biblio.pm,v 1.115.2.51.2.19 2006/09/24 19:51:04 kados Exp $
# $Log: Biblio.pm,v $
+# Revision 1.115.2.51.2.19 2006/09/24 19:51:04 kados
+# I'm in the middle of a major Biblio cleaning, just committing so I have
+# some version conrol. I'll post a mail describing the changes when I've
+# finished.
+#
# Revision 1.115.2.51.2.18 2006/09/24 15:24:06 kados
# remove Zebraauth routine, fold the functionality into Zconn
# Zconn can now take several arguments ... this will probably
More information about the Koha-cvs
mailing list