-package C4::Biblio;
+package C4::Biblio;
# $Id$
# $Log$
+# Revision 1.21 2002/10/13 11:34:14 arensb
+# Replaced expressions of the form "$x = $x <op> $y" with "$x <op>= $y".
+# Thus, $x = $x+2 becomes $x += 2, and so forth.
+#
+# Revision 1.20 2002/10/13 08:28:32 arensb
+# Deleted unused variables.
+# Removed trailing whitespace.
+#
+# Revision 1.19 2002/10/13 05:56:10 arensb
+# Added some FIXME comments.
+#
+# Revision 1.18 2002/10/11 12:34:53 arensb
+# Replaced &requireDBI with C4::Context->dbh
+#
+# Revision 1.17 2002/10/10 14:48:25 tipaul
+# bugfixes
+#
+# Revision 1.16 2002/10/07 14:04:26 tipaul
+# road to 1.3.1 : viewing MARC biblio
+#
+# Revision 1.15 2002/10/05 09:49:25 arensb
+# Merged with arensb-context branch: use C4::Context->dbh instead of
+# &C4Connect, and generally prefer C4::Context over C4::Database.
+#
+# Revision 1.14 2002/10/03 11:28:18 tipaul
+# Extending Context.pm to add stopword management and using it in MARC-API.
+# First benchmarks show a medium speed improvement, which is nice as this part is heavily called.
+#
+# Revision 1.13 2002/10/02 16:26:44 tipaul
+# road to 1.3.1
+#
+# Revision 1.12.2.4 2002/10/05 07:09:31 arensb
+# Merged in changes from main branch.
+#
+# Revision 1.12.2.3 2002/10/05 06:12:10 arensb
+# Added a whole mess of FIXME comments.
+#
+# Revision 1.12.2.2 2002/10/05 04:03:14 arensb
+# Added some missing semicolons.
+#
+# Revision 1.12.2.1 2002/10/04 02:24:01 arensb
+# Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
+# C4Connect.
+#
+# Revision 1.12.2.3 2002/10/05 06:12:10 arensb
+# Added a whole mess of FIXME comments.
+#
+# Revision 1.12.2.2 2002/10/05 04:03:14 arensb
+# Added some missing semicolons.
+#
+# Revision 1.12.2.1 2002/10/04 02:24:01 arensb
+# Use C4::Connect instead of C4::Database, C4::Connect->dbh instead
+# C4Connect.
+#
# Revision 1.12 2002/10/01 11:48:51 arensb
# Added some FIXME comments, mostly marking duplicate functions.
#
#
-# move from 1.2 to 1.4 version :
+# move from 1.2 to 1.4 version :
# 1.2 and previous version uses a specific API to manage biblios. This API uses old-DB style parameters.
# In the 1.4 version, we want to do 2 differents things :
# - keep populating the old-DB, that has a LOT less datas than MARC
use strict;
require Exporter;
+use C4::Context;
use C4::Database;
use MARC::Record;
-use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
+use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
$VERSION = 0.01;
# as the old-style API and the ALL one are the only public functions.
#
@EXPORT = qw(
- &updateBiblio &updateBiblioItem &updateItem
- &itemcount &newbiblio &newbiblioitem
+ &updateBiblio &updateBiblioItem &updateItem
+ &itemcount &newbiblio &newbiblioitem
&modnote &newsubject &newsubtitle
&modbiblio &checkitems
&newitems &modbibitem
- &modsubtitle &modsubject &modaddauthor &moditem &countitems
- &delitem &deletebiblioitem &delbiblio
+ &modsubtitle &modsubject &modaddauthor &moditem &countitems
+ &delitem &deletebiblioitem &delbiblio
&getitemtypes &getbiblio
&getbiblioitembybiblionumber
&getbiblioitem &getitemsbybiblioitem &isbnsearch
&skip
&newcompletebiblioitem
+ &MARCfind_oldbiblionumber_from_MARCbibid
+ &MARCfind_MARCbibid_from_oldbiblionumber
+
&ALLnewbiblio &ALLnewitem
&MARCgettagslib
&MARCaddbiblio &MARCadditem
- &MARCmodsubfield &MARCaddsubfield
+ &MARCmodsubfield &MARCaddsubfield
&MARCmodbiblio &MARCmoditem
- &MARCfindsubfield
+ &MARCfindsubfield
&MARCkoha2marcBiblio &MARCmarc2koha &MARCkoha2marcItem
&MARCgetbiblio &MARCgetitem
&MARCaddword &MARCdelword
);
-%EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
-
-# your exported package globals go here,
-# as well as any optionally exported functions
-
-@EXPORT_OK = qw($Var1 %Hashit); # FIXME - These are never used
-
-
-# non-exported package globals go here
-use vars qw(@more $stuff); # FIXME - These are never used
-
-# initalize package globals, first exported ones
-
-# FIXME - These are never used
-my $Var1 = '';
-my %Hashit = ();
-
-
-# then the others (which are still accessible as $Some::Module::stuff)
-# FIXME - These are never used
-my $stuff = '';
-my @more = ();
-
-# all file-scoped lexicals must be created before
-# the functions below that use them.
-
-# file-private lexicals go here
-# FIXME - These are never used
-my $priv_var = '';
-my %secret_hash = ();
-
-# here's a file-private function as a closure,
-# callable as &$priv_func; it cannot be prototyped.
-# FIXME - This is never used
-my $priv_func = sub {
- # stuff goes here.
- };
-
-# make all your functions, whether exported or not;
#
#
#
#
# all the following subs takes a MARC::Record as parameter and manage
-# the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
+# the MARC-DB. They are called by the 1.0/1.2 xxx subs, and by the
# ALLxxx subs (xxx deals with old-DB parameters, the ALLxxx deals with MARC-DB parameter)
=head1 SYNOPSIS
=head2 &MARCaddsubfield($dbh,$bibid,$tagid,$indicator,$tagorder,$subfieldcode,$subfieldorder,$subfieldvalue);
adds a subfield in a biblio (in the MARC tables only).
-
+
=head2 $MARCRecord = &MARCgetbiblio($dbh,$bibid);
Returns a MARC::Record for the biblio $bibid.
my ($dbh,$forlibrarian)= @_;
my $sth;
if ($forlibrarian eq 1) {
- $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib from marc_subfield_structure");
+ $sth=$dbh->prepare("select tagfield,liblibrarian as lib from marc_tag_structure");
+ } else {
+ $sth=$dbh->prepare("select tagfield,libopac as lib from marc_tag_structure");
+ }
+ $sth->execute;
+ my ($lib,$tag,$res,$tab);
+ while ( ($tag,$lib,$tab) = $sth->fetchrow) {
+ $res->{$tag}->{lib}=$lib;
+ $res->{$tab}->{tab}="";
+ }
+
+ if ($forlibrarian eq 1) {
+ $sth=$dbh->prepare("select tagfield,tagsubfield,liblibrarian as lib,tab from marc_subfield_structure");
} else {
- $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib from marc_subfield_structure");
+ $sth=$dbh->prepare("select tagfield,tagsubfield,libopac as lib,tab from marc_subfield_structure");
}
$sth->execute;
- my $lib;
- my $tag;
+
my $subfield;
- my $res;
- while ( ($tag,$subfield,$lib) = $sth->fetchrow) {
- $res->{$tag}->{$subfield}=$lib;
+ while ( ($tag,$subfield,$lib,$tab) = $sth->fetchrow) {
+ $res->{$tag}->{$subfield}->{lib}=$lib;
+ $res->{$tag}->{$subfield}->{tab}=$tab;
}
return $res;
}
my ($dbh,$bibid)=@_;
my $record = MARC::Record->new();
#---- TODO : the leader is missing
- my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
- from marc_subfield_table
+ my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
+ from marc_subfield_table
where bibid=? order by tagorder,subfieldorder
");
my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
$sth->execute($bibid);
+ my $prevtagorder=1;
+ my $prevtag;
+ my %subfieldlist={};
while (my $row=$sth->fetchrow_hashref) {
- if ($row->{'valuebloblink'}) { #---- search blob if there is one
- $sth2->execute($row->{'valuebloblink'});
- my $row2=$sth2->fetchrow_hashref;
- $sth2->finish;
- $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
- }
- if ($record->field($row->{'tag'})) {
- my $field;
-#--- this test must stay as this, because of strange behaviour of mySQL/Perl DBI with char var containing a number...
-#--- sometimes, eliminates 0 at beginning, sometimes no ;-\\\
- if (length($row->{'tag'}) <3) {
- $row->{'tag'} = "0".$row->{'tag'};
- }
- $field =$record->field($row->{'tag'});
- if ($field) {
- my $x = $field->add_subfields($row->{'subfieldcode'},$row->{'subfieldvalue'});
- $record->delete_field($field);
- $record->add_fields($field);
- }
- } else {
- if (length($row->{'tag'}) < 3) {
- $row->{'tag'} = "0".$row->{'tag'};
- }
- my $temp = MARC::Field->new($row->{'tag'}," "," ", $row->{'subfieldcode'} => $row->{'subfieldvalue'});
- $record->add_fields($temp);
+ if ($row->{'valuebloblink'}) { #---- search blob if there is one
+ $sth2->execute($row->{'valuebloblink'});
+ my $row2=$sth2->fetchrow_hashref;
+ $sth2->finish;
+ $row->{'subfieldvalue'}=$row2->{'subfieldvalue'};
+ }
+ if ($row->{tagorder} ne $prevtagorder) {
+ my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
+ $record->add_fields($field);
+ $prevtagorder=$row->{tagorder};
+ $prevtag = $row->{tag};
+ %subfieldlist={};
+ %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
+ } else {
+ %subfieldlist->{$row->{'subfieldcode'}} = $row->{'subfieldvalue'};
+ $prevtag= $row->{tag};
+ }
}
-
- }
- return $record;
+ # the last has not been included inside the loop... do it now !
+ my $field = MARC::Field->new( $prevtag, "", "", %subfieldlist);
+ $record->add_fields($field);
+ return $record;
}
sub MARCgetitem {
# Returns MARC::Record of the biblio passed in parameter.
$sth2->execute($bibid,$itemnumber);
my ($tagorder) = $sth2->fetchrow_array();
#---- TODO : the leader is missing
- my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
- from marc_subfield_table
+ my $sth=$dbh->prepare("select bibid,subfieldid,tag,tagorder,tag_indicator,subfieldcode,subfieldorder,subfieldvalue,valuebloblink
+ from marc_subfield_table
where bibid=? and tagorder=? order by subfieldorder
");
+ # FIXME - There's already a $sth2 in this scope.
my $sth2=$dbh->prepare("select subfieldvalue from marc_blob_subfield where blobidlink=?");
$sth->execute($bibid,$tagorder);
while (my $row=$sth->fetchrow_hashref) {
}
# otherwise, skip through each subfield...
my @fields = $record->fields();
-# search old MARC item
+# search old MARC item
my $sth2 = $dbh->prepare("select tagorder from marc_subfield_table,marc_subfield_structure where marc_subfield_table.tag=marc_subfield_structure.tagfield and marc_subfield_table.subfieldcode=marc_subfield_structure.tagsubfield and bibid=? and kohafield='items.itemnumber' and subfieldvalue=?");
$sth2->execute($bibid,$itemnumber);
my ($tagorder) = $sth2->fetchrow_array();
sub MARCfindsubfieldid {
my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
my $sth=$dbh->prepare("select subfieldid from marc_subfield_table
- where bibid=? and tag=? and tagorder=?
+ where bibid=? and tag=? and tagorder=?
and subfieldcode=? and subfieldorder=?");
$sth->execute($bibid,$tag,$tagorder,$subfield,$subfieldorder);
my ($res) = $sth->fetchrow;
# delete a subfield for $bibid / tag / tagorder / subfield / subfieldorder
my ($dbh,$bibid,$tag,$tagorder,$subfield,$subfieldorder) = @_;
$dbh->do("delete from marc_subfield_table where bibid='$bibid' and
- tag='$tag' and tagorder='$tagorder'
+ tag='$tag' and tagorder='$tagorder'
and subfieldcode='$subfield' and subfieldorder='$subfieldorder
");
}
my $record = MARC::Record->new();
#--- if bibid, then retrieve old-style koha data
if ($biblionumber>0) {
- my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
- from biblio where biblionumber=?");
+ my $sth2=$dbh->prepare("select biblionumber,author,title,unititle,notes,abstract,serial,seriestitle,copyrightdate,timestamp
+ from biblio where biblionumber=?");
$sth2->execute($biblionumber);
my $row=$sth2->fetchrow_hashref;
my $code;
if ($biblioitemnumber>0) {
my $sth2=$dbh->prepare(" SELECT biblioitemnumber,biblionumber,volume,number,classification,
itemtype,url,isbn,issn,dewey,subclass,publicationyear,publishercode,
- volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
+ volumedate,volumeddesc,timestamp,illus,pages,notes,size,place
FROM biblioitems
WHERE biblionumber=? and biblioitemnumber=?
- ");
+ ");
$sth2->execute($biblionumber,$biblioitemnumber);
my $row=$sth2->fetchrow_hashref;
my $code;
my $sth2=$dbh->prepare("SELECT itemnumber,biblionumber,multivolumepart,biblioitemnumber,barcode,dateaccessioned,
booksellerid,homebranch,price,replacementprice,replacementpricedate,datelastborrowed,
datelastseen,multivolume,stack,notforloan,itemlost,wthdrawn,bulk,issues,renewals,
- reserves,restricted,binding,itemnotes,holdingbranch,timestamp
+ reserves,restricted,binding,itemnotes,holdingbranch,timestamp
FROM items
WHERE itemnumber=?");
$sth2->execute($itemnumber);
while (($field)=$sth2->fetchrow) {
$result=&MARCmarc2kohaOneField($sth,"biblio",$field,$record,$result);
}
+ # FIXME - There's already a $sth2 in this scope.
my $sth2=$dbh->prepare("SHOW COLUMNS from biblioitems");
$sth2->execute;
+ # FIXME - There's already a $field in this scope.
my $field;
while (($field)=$sth2->fetchrow) {
$result=&MARCmarc2kohaOneField($sth,"biblioitems",$field,$record,$result);
}
+ # FIXME - There's already a $sth2 in this scope.
my $sth2=$dbh->prepare("SHOW COLUMNS from items");
$sth2->execute;
+ # FIXME - There's already a $field in this scope.
my $field;
while (($field)=$sth2->fetchrow) {
$result = &MARCmarc2kohaOneField($sth,"items",$field,$record,$result);
}
-# additional authors : specific
+# additional authors : specific
$result = &MARCmarc2kohaOneField($sth,"additionalauthors","additionalauthors",$record,$result);
return $result;
}
$sentence =~ s/(\.|\?|\:|\!|\'|,|\-)/ /g;
my @words = split / /,$sentence;
# build stopword list
- my $sth2 =$dbh->prepare("select word from stopwords");
- $sth2->execute;
- my $stopwords;
- my $stopword;
- while(($stopword) = $sth2->fetchrow_array) {
- $stopwords->{$stopword} = $stopword;
- }
+# my $sth2 =$dbh->prepare("select word from stopwords");
+# $sth2->execute;
+# my $stopwords;
+# my $stopword;
+# while(($stopword) = $sth2->fetchrow_array) {
+# $stopwords->{$stopword} = $stopword;
+# }
+ my $stopwords= C4::Context->stopwords;
my $sth=$dbh->prepare("insert into marc_word (bibid, tag, tagorder, subfieldid, subfieldorder, word, sndx_word)
values (?,?,?,?,?,?,soundex(?))");
foreach my $word (@words) {
#
#
-# ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
+# ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL ALL
#
#
# all the following subs are useful to manage MARC-DB with complete MARC records.
print "Error in ALLnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
die;
}
- my $newfield = MARC::Field->new( $tagfield1,'','',
+ my $newfield = MARC::Field->new( $tagfield1,'','',
"$tagsubfield1" => $oldbibnum,
"$tagsubfield2" => $oldbibitemnum);
# drop old field and create new one...
my $itemnumber;
my $error;
($itemnumber,$error) = &OLDnewitems($dbh,$item,$item->{'barcode'});
-# search MARC biblionumber
+# search MARC biblionumber
my $bibid=&MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{'biblionumber'});
# calculate tagorder
my $sth = $dbh->prepare("select max(tagorder) from marc_subfield_table where bibid=?");
They all are the exact copy of 1.0/1.2 version of the sub
without the OLD. The OLDxxx is called by the original xxx sub.
the 1.4 xxx sub also builds MARC::Record an calls the MARCxxx
-
+
WARNING : there is 1 difference between initialxxx and OLDxxx :
the db header $dbh is always passed as parameter
to avoid over-DB connexion
=head2 OLDdeletebiblioitem($dbh,$biblioitemnumber);
deletes a biblioitem
NOTE : not standard sub name. Should be OLDdelbiblioitem()
-
+
=head2 OLDdelbiblio($dbh,$biblio);
delete a biblio
# my $dbh = C4Connect;
my $query;
my $sth;
-
+
$biblio->{'title'} = $dbh->quote($biblio->{'title'});
$biblio->{'author'} = $dbh->quote($biblio->{'author'});
$biblio->{'abstract'} = $dbh->quote($biblio->{'abstract'});
$biblio->{'serial'} = $dbh->quote($biblio->{'serial'});
$biblio->{'unititle'} = $dbh->quote($biblio->{'unititle'});
$biblio->{'notes'} = $dbh->quote($biblio->{'notes'});
-
+
$query = "Update biblio set
title = $biblio->{'title'},
author = $biblio->{'author'},
notes = $biblio->{'notes'}
where biblionumber = $biblio->{'biblionumber'}";
$sth = $dbh->prepare($query);
-
+
$sth->execute;
-
+
$sth->finish;
- $dbh->disconnect;
return($biblio->{'biblionumber'});
} # sub modbiblio
$sth->finish;
} # if
-
- $dbh->disconnect;
} # sub modaddauthor
and catalogueentry = '$subject[$i]'";
my $sth = $dbh->prepare($query);
$sth->execute;
-
+
if (my $data = $sth->fetchrow_hashref) {
} else {
if ($force eq $subject[$i]) {
$sth2->execute;
while (my $data = $sth2->fetchrow_hashref) {
- $error = $error."<br>$data->{'catalogueentry'}";
+ $error .= "<br>$data->{'catalogueentry'}";
} # while
$sth2->finish;
} # else
my $sth = $dbh->prepare($query);
my $data;
my $bibitemnum;
-
+
$biblioitem->{'volume'} = $dbh->quote($biblioitem->{'volume'});
$biblioitem->{'number'} = $dbh->quote($biblioitem->{'number'});
$biblioitem->{'classification'} = $dbh->quote($biblioitem->{'classification'});
$biblioitem->{'place'} = $dbh->quote($biblioitem->{'place'});
$biblioitem->{'lccn'} = $dbh->quote($biblioitem->{'lccn'});
$biblioitem->{'marc'} = $dbh->quote($biblioitem->{'marc'});
-
+
$sth->execute;
$data = $sth->fetchrow_arrayref;
$bibitemnum = $$data[0] + 1;
$data = $sth->fetchrow_hashref;
$itemnumber = $data->{'max(itemnumber)'} + 1;
$sth->finish;
-
+
$item->{'booksellerid'} = $dbh->quote($item->{'booksellerid'});
$item->{'homebranch'} = $dbh->quote($item->{'homebranch'});
$item->{'price'} = $dbh->quote($item->{'price'});
itemnotes='$item->{'notes'}',
homebranch='$item->{'homebranch'}',
itemlost='$item->{'lost'}',
- wthdrawn='$item->{'wthdrawn'}'
+ wthdrawn='$item->{'wthdrawn'}'
where itemnumber=$item->{'itemnum'}";
}
if ($item->{'replacement'} ne ''){
$sth->finish;
$query="Insert into deleteditems values (";
foreach my $temp (@data){
- $query=$query."'$temp',";
+ $query .= "'$temp',";
}
$query=~ s/\,$/\)/;
# print $query;
my @results;
$sth->execute;
-
+
if (@results = $sth->fetchrow_array) {
$query = "Insert into deletedbiblioitems values (";
foreach my $value (@results) {
$query="Insert into deletedbiblio values (";
foreach my $temp (@data){
$temp=~ s/\'/\\\'/g;
- $query=$query."'$temp',";
+ $query .= "'$temp',";
}
$query=~ s/\,$/\)/;
# print $query;
# FIXME - This is the same as &C4::Acquisitions::itemcount, but not
# the same as &C4::Search::itemcount
+# Since they're both exported, acqui/acquire.pl doesn't compile with -w.
sub itemcount{
my ($biblio)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
my $query="Select count(*) from items where biblionumber=$biblio";
# print $query;
my $sth=$dbh->prepare($query);
$sth->execute;
my $data=$sth->fetchrow_hashref;
$sth->finish;
- $dbh->disconnect;
return($data->{'count(*)'});
}
sub getorder{
my ($bi,$bib)=@_;
- my $dbh=C4Connect;
- my $query="Select ordernumber
- from aqorders
+ my $dbh = C4::Context->dbh;
+ my $query="Select ordernumber
+ from aqorders
where biblionumber=? and biblioitemnumber=?";
my $sth=$dbh->prepare($query);
$sth->execute($bib,$bi);
my $ordnum=$sth->fetchrow_hashref;
$sth->finish;
my $order=getsingleorder($ordnum->{'ordernumber'});
- $dbh->disconnect;
# print $query;
return ($order,$ordnum->{'ordernumber'});
}
# &C4::Acquisitions::getsingleorder and &C4::Catalogue::getsingleorder
sub getsingleorder {
my ($ordnum)=@_;
- my $dbh=C4Connect;
- my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
- where aqorders.ordernumber=?
+ my $dbh = C4::Context->dbh;
+ my $query="Select * from biblio,biblioitems,aqorders,aqorderbreakdown
+ where aqorders.ordernumber=?
and biblio.biblionumber=aqorders.biblionumber and
biblioitems.biblioitemnumber=aqorders.biblioitemnumber and
aqorders.ordernumber=aqorderbreakdown.ordernumber";
$sth->execute($ordnum);
my $data=$sth->fetchrow_hashref;
$sth->finish;
- $dbh->disconnect;
return($data);
}
+# FIXME - This is in effect identical to &C4::Acquisitions::newbiblio.
+# Pick one and stick with it.
sub newbiblio {
my ($biblio) = @_;
- my $dbh = &C4Connect;
+ my $dbh = C4::Context->dbh;
my $bibnum=OLDnewbiblio($dbh,$biblio);
# TODO : MARC add
- $dbh->disconnect;
return($bibnum);
}
+# FIXME - This is in effect the same as &C4::Acquisitions::modbiblio.
+# Pick one and stick with it.
+# FIXME - Get the POD from C4::Acquisitions
sub modbiblio {
my ($biblio) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $biblionumber=OLDmodbiblio($dbh,$biblio);
- $dbh->disconnect;
return($biblionumber);
} # sub modbiblio
+# FIXME - This is in effect identical to &C4::Acquisitions::modsubtitle.
+# Pick one and stick with it.
+# FIXME - Get the POD from C4::Acquisitions
sub modsubtitle {
my ($bibnum, $subtitle) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDmodsubtitle($dbh,$bibnum,$subtitle);
- $dbh->disconnect;
} # sub modsubtitle
# FIXME - This is functionally identical to
# &C4::Acquisitions::modaddauthor
+# Pick one and stick with it.
+# FIXME - Get the POD from C4::Acquisitions
sub modaddauthor {
my ($bibnum, $author) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDmodaddauthor($dbh,$bibnum,$author);
- $dbh->disconnect;
} # sub modaddauthor
+# FIXME - This is in effect identical to &C4::Acquisitions::modsubject.
+# Pick one and stick with it.
sub modsubject {
my ($bibnum, $force, @subject) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $error= &OLDmodsubject($dbh,$bibnum,$force, @subject);
return($error);
} # sub modsubject
+# FIXME - This is very similar to &C4::Acquisitions::modbibitem.
+# Pick one and stick with it.
sub modbibitem {
my ($biblioitem) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDmodbibitem($dbh,$biblioitem);
my $MARCbibitem = MARCkoha2marcBiblio($dbh,$biblioitem);
&MARCmodbiblio($dbh,$biblioitem->{biblionumber},0,$MARCbibitem);
- $dbh->disconnect;
} # sub modbibitem
+# FIXME - This is in effect identical to &C4::Acquisitions::modnote.
+# Pick one and stick with it.
sub modnote {
my ($bibitemnum,$note)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDmodnote($dbh,$bibitemnum,$note);
- $dbh->disconnect;
}
# FIXME - This is quite similar in effect to &C4::newbiblioitem,
-# except for the MARC stuff.
+# except for the MARC stuff. There's also a &newbiblioitem in
+# acqui.simple/addbookslccn.pl
sub newbiblioitem {
my ($biblioitem) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $bibitemnum = &OLDnewbiblioitem($dbh,$biblioitem);
# print STDERR "bibitemnum : $bibitemnum\n";
my $MARCbiblio= MARCkoha2marcBiblio($dbh,$biblioitem->{biblionumber},$bibitemnum);
return($bibitemnum);
}
+# FIXME - This is in effect identical to &C4::Acquisitions::newsubject.
+# Pick one and stick with it.
sub newsubject {
my ($bibnum)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDnewsubject($dbh,$bibnum);
- $dbh->disconnect;
}
# FIXME - This is just a wrapper around &OLDnewsubtitle
# FIXME - This is in effect the same as &C4::Acquisitions::newsubtitle
sub newsubtitle {
my ($bibnum, $subtitle) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDnewsubtitle($dbh,$bibnum,$subtitle);
- $dbh->disconnect;
}
+# FIXME - This is different from &C4::Acquisitions::newitems, though
+# both are exported.
sub newitems {
my ($item, @barcodes) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $errors;
my $itemnumber;
my $error;
&MARCadditem($dbh,$MARCitem,$item->{biblionumber});
# print STDERR "MARCmodbiblio called\n";
}
- $dbh->disconnect;
return($errors);
}
+# FIXME - This appears to be functionally equivalent to
+# &C4::Acquisitions::moditem.
+# Pick one and stick with it.
sub moditem {
my ($item) = @_;
# my ($loan,$itemnum,$bibitemnum,$barcode,$notes,$homebranch,$lost,$wthdrawn,$replacement)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDmoditem($dbh,$item);
warn "biblionumber : $item->{'biblionumber'} / $item->{'itemnum'}\n";
my $MARCitem = &MARCkoha2marcItem($dbh,$item->{'biblionumber'},$item->{'itemnum'});
# print STDERR "MARCitem ".$MARCitem->as_formatted()."\n";
my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$item->{biblionumber});
&MARCmoditem($dbh,$MARCitem,$bibid,$item->{itemnum},0);
- $dbh->disconnect;
}
+# FIXME - This is the same as &C4::Acquisitions::Checkitems.
+# Pick one and stick with it.
sub checkitems{
my ($count,@barcodes)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
my $error;
for (my $i=0;$i<$count;$i++){
$barcodes[$i]=uc $barcodes[$i];
}
$sth->finish;
}
- $dbh->disconnect;
return($error);
}
+# FIXME - This is identical to &C4::Acquisitions::countitems.
+# Pick one and stick with it.
sub countitems{
my ($bibitemnum)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
my $query="Select count(*) from items where biblioitemnumber='$bibitemnum'";
my $sth=$dbh->prepare($query);
$sth->execute;
my $data=$sth->fetchrow_hashref;
$sth->finish;
- $dbh->disconnect;
return($data->{'count(*)'});
}
# FIXME - This is just a wrapper around &OLDdelitem, and acts
# identically to &C4::Acquisitions::delitem
+# Pick one and stick with it.
sub delitem{
my ($itemnum)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDdelitem($dbh,$itemnum);
- $dbh->disconnect;
}
+# FIXME - This is functionally identical to
+# &C4::Acquisitions::deletebiblioitem.
+# Pick one and stick with it.
sub deletebiblioitem {
my ($biblioitemnumber) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDdeletebiblioitem($dbh,$biblioitemnumber);
- $dbh->disconnect;
} # sub deletebiblioitem
+# FIXME - This is functionally identical to &C4::Acquisitions::delbiblio.
+# Pick one and stick with it.
sub delbiblio {
my ($biblio)=@_;
- my $dbh=C4Connect;
+ my $dbh = C4::Context->dbh;
&OLDdelbiblio($dbh,$biblio);
- $dbh->disconnect;
}
+# FIXME - This is identical to &C4::Acquisitions::getitemtypes.
+# Pick one and stick with it.
sub getitemtypes {
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $query = "select * from itemtypes";
my $sth = $dbh->prepare($query);
# || die "Cannot prepare $query" . $dbh->errstr;
my $count = 0;
my @results;
-
+
$sth->execute;
# || die "Cannot execute $query\n" . $sth->errstr;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
$count++;
} # while
-
+
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub getitemtypes
sub getbiblio {
my ($biblionumber) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $query = "Select * from biblio where biblionumber = $biblionumber";
my $sth = $dbh->prepare($query);
# || die "Cannot prepare $query\n" . $dbh->errstr;
my $count = 0;
my @results;
-
+
$sth->execute;
# || die "Cannot execute $query\n" . $sth->errstr;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
$count++;
} # while
-
+
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub getbiblio
+# FIXME - This is identical to &C4::Acquisitions::getbiblioitem.
+# Pick one and stick with it.
sub getbiblioitem {
my ($biblioitemnum) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $query = "Select * from biblioitems where
biblioitemnumber = $biblioitemnum";
my $sth = $dbh->prepare($query);
} # while
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub getbiblioitem
+# FIXME - This is identical to
+# &C4::Acquisitions::getbiblioitembybiblionumber.
+# Pick one and stick with it.
sub getbiblioitembybiblionumber {
my ($biblionumber) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $query = "Select * from biblioitems where biblionumber =
$biblionumber";
my $sth = $dbh->prepare($query);
} # while
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub
+# FIXME - This is identical to
+# &C4::Acquisitions::getbiblioitembybiblionumber.
+# Pick one and stick with it.
sub getitemsbybiblioitem {
my ($biblioitemnum) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $query = "Select * from items, biblio where
biblio.biblionumber = items.biblionumber and biblioitemnumber
= $biblioitemnum";
# || die "Cannot prepare $query\n" . $dbh->errstr;
my $count = 0;
my @results;
-
+
$sth->execute;
# || die "Cannot execute $query\n" . $sth->errstr;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
$count++;
} # while
-
+
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub getitemsbybiblioitem
+# FIXME - This is identical to &C4::Acquisitions::isbnsearch.
+# Pick one and stick with it.
sub isbnsearch {
my ($isbn) = @_;
- my $dbh = C4Connect;
+ my $dbh = C4::Context->dbh;
my $count = 0;
my $query;
my $sth;
my @results;
-
+
$isbn = $dbh->quote($isbn);
$query = "Select biblio.* from biblio, biblioitems where
biblio.biblionumber = biblioitems.biblionumber
and isbn = $isbn";
$sth = $dbh->prepare($query);
-
+
$sth->execute;
while (my $data = $sth->fetchrow_hashref) {
$results[$count] = $data;
} # while
$sth->finish;
- $dbh->disconnect;
return($count, @results);
} # sub isbnsearch
# At the moment this is just a straight copy of the subject code. Needs heavy
# modification to work for additional authors, obviously.
# Check for additional author changes
-
+
# my $newadditionalauthor='';
# my $additionalauthors;
# foreach $newadditionalauthor (@{$biblio->{'additionalauthor'}}) {
# input params
my (
$dbh, # db handle
+ # FIXME - Unused argument
$biblio, # hash ref to fields
)=@_;
my $error;
#-----
- requireDBI($dbh,"getoraddbiblio");
+ $dbh = C4::Context->dbh;
print "<PRE>Looking for biblio </PRE>\n" if $debug;
$sth=$dbh->prepare("select biblionumber
from biblio
- where title=? and author=?
+ where title=? and author=?
and copyrightdate=? and seriestitle=?");
$sth->execute(
$biblio->{title}, $biblio->{author},
sub OLD_MAYBE_DELETED_newBiblioItem {
my ($env, $biblioitem) = @_;
- my $dbh=&C4Connect;
+ my $dbh = C4::Context->dbh;
my $biblionumber=$biblioitem->{'biblionumber'};
my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
my $volume=$biblioitem->{'volume'};
addTag($env, $Record_ID, $tag, ' ', ' ', $subfields);
}
$sth->finish;
- $dbh->disconnect;
return ($env, $Record_ID);
}
sub OLD_MAYBE_DELETED_newItem {
my ($env, $Record_ID, $item) = @_;
- my $dbh=&C4Connect;
+ my $dbh = C4::Context->dbh;
my $barcode=$item->{'barcode'};
my $q_barcode=$dbh->quote($barcode);
my $biblionumber=$item->{'biblionumber'};
my ($env, $biblio) = @_;
my $Record_ID;
my $biblionumber=$biblio->{'biblionumber'};
- my $dbh=&C4Connect;
+ my $dbh = C4::Context->dbh;
my $sth=$dbh->prepare("select * from biblio where biblionumber=$biblionumber");
$sth->execute;
my $origbiblio=$sth->fetchrow_hashref;
$origsubjects->{$subject}=1;
}
-
+
# Obtain a list of MARC Record_ID's that are tied to this biblio
$sth=$dbh->prepare("select bibid from marc_subfield_table where tag='090' and subfieldvalue=$biblionumber and subfieldcode='c'");
$sth->execute;
}
# Check for subject heading changes
-
+
my $newsubject='';
my $subjects;
foreach $newsubject (@{$biblio->{'subject'}}) {
# modified, and log all changes.
my ($env, $biblioitem) = @_;
- my $dbh=&C4Connect;
+ my $dbh = C4::Context->dbh;
my $biblioitemnumber=$biblioitem->{'biblioitemnumber'};
my $sth=$dbh->prepare("select * from biblioitems where biblioitemnumber=$biblioitemnumber");
changeSubfield($Record_ID, '010', 'a', $obi->{'lccn'}, $biblioitem->{'lccn'});
}
$sth->finish;
- $dbh->disconnect;
-
}
sub OLD_MAYBE_DELETED_updateItem {
# modified, and log all changes.
my ($env, $item) = @_;
- my $dbh=&C4Connect;
+ my $dbh = C4::Context->dbh;
my $itemnumber=$item->{'itemnumber'};
my $biblionumber=$item->{'biblionumber'};
my $biblioitemnumber=$item->{'biblioitemnumber'};
$sth=$dbh->prepare("select Subfield_ID from 8XX_Subfield_Table where Subfield_Mark=8 and Subfield_Value=$link and !(Subfield_ID=$Subfield876_ID)");
$sth->execute;
my ($Subfield852_ID) = $sth->fetchrow;
-
+
if ($item->{'barcode'} ne $olditem->{'barcode'}) {
logchange('kohadb', 'change', 'items', 'barcode', $olditem->{'barcode'}, $item->{'barcode'});
my $q_barcode=$dbh->quote($item->{'barcode'});
}
}
$sth->finish;
- $dbh->disconnect;
}
# Add a biblioitem and related data to Koha database
my (
$dbh, # DBI handle
+ # FIXME - Unused argument
$biblio, # hash ref to biblio record
$biblioitem, # hash ref to biblioitem record
$subjects, # list ref of subjects
my $additionalauthor;
#--------
- requireDBI($dbh,"newcompletebiblioitem");
+ $dbh = C4::Context->dbh;
print "<PRE>Trying to add biblio item Title=$biblio->{title} " .
"ISBN=$biblioitem->{isbn} </PRE>\n" if $debug;