support for subtitles, additional authors, subject.

This supports is only for MARC <-> OLD-DB link. It worked previously, but values entered as MARC were not reported to OLD-DB, neither values entered as OLD-DB were reported to MARC.
Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
For example it seems impossible to have more that 1 addi author and 1 subtitle. In MARC it's not the case. So, if you enter more than one, I'm afraid only the LAST will be stored.
This commit is contained in:
tipaul 2003-05-19 13:45:18 +00:00
parent e862f505e0
commit 7a95c1d809

View file

@ -1,6 +1,12 @@
package C4::Biblio; package C4::Biblio;
# $Id$ # $Id$
# $Log$ # $Log$
# Revision 1.46 2003/05/19 13:45:18 tipaul
# support for subtitles, additional authors, subject.
# This supports is only for MARC <-> OLD-DB link. It worked previously, but values entered as MARC were not reported to OLD-DB, neither values entered as OLD-DB were reported to MARC.
# Note that some OLD-DB subs are strange (dummy ?) see OLDmodsubject, OLDmodsubtitle, OLDmodaddiauthor in C4/Biblio.pm
# For example it seems impossible to have more that 1 addi author and 1 subtitle. In MARC it's not the case. So, if you enter more than one, I'm afraid only the LAST will be stored.
#
# Revision 1.45 2003/04/29 16:50:49 tipaul # Revision 1.45 2003/04/29 16:50:49 tipaul
# really proud of this commit :-) # really proud of this commit :-)
# z3950 search and import seems to works fine. # z3950 search and import seems to works fine.
@ -412,10 +418,8 @@ Returns a MARC::Record for the biblio $bibid.
=item &MARCmodbiblio($dbh,$bibid,$record,$delete); =item &MARCmodbiblio($dbh,$bibid,$record,$delete);
MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
if $delete == 1, every field/subfield not found is deleted in the biblio It 1st delete the biblio, then recreates it.
otherwise, only data passed to MARCmodbiblio is managed. WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
thus, you can change only a small part of a biblio (like an item, or a subtitle, or a additionalauthor...)
=item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue); =item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
MARCmodsubfield changes the value of a given subfield MARCmodsubfield changes the value of a given subfield
@ -934,8 +938,23 @@ sub MARCkoha2marcBiblio {
} }
} }
} }
# other fields => additional authors, subjects, subtitles
my $sth2=$dbh->prepare(" SELECT author FROM additionalauthors WHERE biblionumber=?");
$sth2->execute($biblionumber);
while (my $row=$sth2->fetchrow_hashref) {
&MARCkoha2marcOnefield($sth,$record,"additionalauthors.author",$row->{'author'});
}
my $sth2=$dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
$sth2->execute($biblionumber);
while (my $row=$sth2->fetchrow_hashref) {
&MARCkoha2marcOnefield($sth,$record,"bibliosubject.subject",$row->{'subject'});
}
my $sth2=$dbh->prepare(" SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
$sth2->execute($biblionumber);
while (my $row=$sth2->fetchrow_hashref) {
&MARCkoha2marcOnefield($sth,$record,"bibliosubtitle.title",$row->{'subtitle'});
}
return $record; return $record;
# TODO : retrieve notes, additionalauthors
} }
sub MARCkoha2marcItem { sub MARCkoha2marcItem {
@ -963,7 +982,6 @@ sub MARCkoha2marcItem {
} }
} }
return $record; return $record;
# TODO : retrieve notes, additionalauthors
} }
sub MARCkoha2marcSubtitle { sub MARCkoha2marcSubtitle {
@ -1034,7 +1052,7 @@ sub MARChtml2marc {
} }
# the last has not been included inside the loop... do it now ! # the last has not been included inside the loop... do it now !
$record->add_fields($field); $record->add_fields($field);
warn $record->as_formatted; # warn $record->as_formatted;
return $record; return $record;
} }
@ -1134,60 +1152,114 @@ adds an item in the db.
=cut =cut
sub NEWnewbiblio { sub NEWnewbiblio {
my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_; my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
# note $oldbiblio and $oldbiblioitem are not mandatory. # note $oldbiblio and $oldbiblioitem are not mandatory.
# if not present, they will be builded from $record with MARCmarc2koha function # if not present, they will be builded from $record with MARCmarc2koha function
if (($oldbiblio) and not($oldbiblioitem)) { if (($oldbiblio) and not($oldbiblioitem)) {
print STDERR "NEWnewbiblio : missing parameter\n"; print STDERR "NEWnewbiblio : missing parameter\n";
print "NEWnewbiblio : missing parameter : contact koha development team\n"; print "NEWnewbiblio : missing parameter : contact koha development team\n";
die; die;
} }
my $oldbibnum; my $oldbibnum;
my $oldbibitemnum; my $oldbibitemnum;
if ($oldbiblio) { if ($oldbiblio) {
$oldbibnum = OLDnewbiblio($dbh,$oldbiblio); $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
$oldbiblioitem->{'biblionumber'} = $oldbibnum; $oldbiblioitem->{'biblionumber'} = $oldbibnum;
$oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem); $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
} else { } else {
my $olddata = MARCmarc2koha($dbh,$record); my $olddata = MARCmarc2koha($dbh,$record);
$oldbibnum = OLDnewbiblio($dbh,$olddata); $oldbibnum = OLDnewbiblio($dbh,$olddata);
$olddata->{'biblionumber'} = $oldbibnum; $olddata->{'biblionumber'} = $oldbibnum;
$oldbibitemnum = OLDnewbiblioitem($dbh,$olddata); $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
} }
# we must add bibnum and bibitemnum in MARC::Record... # search subtiles, addiauthors and subjects
# we build the new field with biblionumber and biblioitemnumber my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author");
# we drop the original field my @addiauthfields = $record->field($tagfield);
# we add the new builded field. foreach my $addiauthfield (@addiauthfields) {
# NOTE : Works only if the field is ONLY for biblionumber and biblioitemnumber my @addiauthsubfields = $addiauthfield->subfield($tagsubfield);
# (steve and paul : thinks 090 is a good choice) foreach my $subfieldcount (0..$#addiauthsubfields) {
my $sth=$dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where kohafield=?"); OLDmodaddauthor($dbh,$oldbibnum,$addiauthsubfields[$subfieldcount]);
$sth->execute("biblio.biblionumber"); }
(my $tagfield1, my $tagsubfield1) = $sth->fetchrow; }
$sth->execute("biblioitems.biblioitemnumber"); ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubtitle.subtitle");
(my $tagfield2, my $tagsubfield2) = $sth->fetchrow; my @subtitlefields = $record->field($tagfield);
if ($tagfield1 != $tagfield2) { foreach my $subtitlefield (@subtitlefields) {
warn "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number"; my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number"; foreach my $subfieldcount (0..$#subtitlesubfields) {
die; OLDnewsubtitle($dbh,$oldbibnum,$subtitlesubfields[$subfieldcount]);
} }
my $newfield = MARC::Field->new( $tagfield1,'','', }
"$tagsubfield1" => $oldbibnum, ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject");
"$tagsubfield2" => $oldbibitemnum); my @subj = $record->field($tagfield);
# drop old field and create new one... foreach my $subject (@subj) {
my $old_field = $record->field($tagfield1); my @subjsubfield = $subject->subfield($tagsubfield);
$record->delete_field($old_field); my @subjects;
$record->add_fields($newfield); foreach my $subfieldcount (0..$#subjsubfield) {
my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum); push @subjects,$subjsubfield[$subfieldcount];
return ($bibid,$oldbibnum,$oldbibitemnum ); }
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;
if ($tagfield1 != $tagfield2) {
warn "Error in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
print "Content-Type: text/html\n\nError in NEWnewbiblio : biblio.biblionumber and biblioitems.biblioitemnumber MUST have the same field number";
die;
}
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);
my $bibid = MARCaddbiblio($dbh,$record,$oldbibnum);
return ($bibid,$oldbibnum,$oldbibitemnum );
} }
sub NEWmodbiblio { sub NEWmodbiblio {
my ($dbh,$record,$bibid) =@_; my ($dbh,$record,$bibid) =@_;
&MARCmodbiblio($dbh,$bibid,$record,0); &MARCmodbiblio($dbh,$bibid,$record,0);
my $oldbiblio = MARCmarc2koha($dbh,$record); my $oldbiblio = MARCmarc2koha($dbh,$record);
my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio); my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
OLDmodbibitem($dbh,$oldbiblio); OLDmodbibitem($dbh,$oldbiblio);
return 1; # now, modify addi authors, subject, addititles.
my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"additionalauthors.author");
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");
my @subtitlefields = $record->field($tagfield);
foreach my $subtitlefield (@subtitlefields) {
my @subtitlesubfields = $subtitlefield->subfield($tagsubfield);
foreach my $subfieldcount (0..$#subtitlesubfields) {
OLDmodsubtitle($dbh,$oldbiblionumber,$subtitlesubfields[$subfieldcount]);
}
}
($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,"bibliosubject.subject");
my @subj = $record->field($tagfield);
foreach my $subject (@subj) {
my @subjsubfield = $subject->subfield($tagsubfield);
my @subjects;
foreach my $subfieldcount (0..$#subjsubfield) {
push @subjects,$subjsubfield[$subfieldcount];
}
OLDmodsubject($dbh,$oldbiblionumber,1,@subjects);
}
return 1;
} }
@ -1355,65 +1427,55 @@ sub OLDmodaddauthor {
sub OLDmodsubject { sub OLDmodsubject {
my ($dbh,$bibnum, $force, @subject) = @_; my ($dbh,$bibnum, $force, @subject) = @_;
# my $dbh = C4Connect; # my $dbh = C4Connect;
my $count = @subject; my $count = @subject;
my $error; my $error;
for (my $i = 0; $i < $count; $i++) { for (my $i = 0; $i < $count; $i++) {
$subject[$i] =~ s/^ //g; $subject[$i] =~ s/^ //g;
$subject[$i] =~ s/ $//g; $subject[$i] =~ s/ $//g;
my $query = "select * from catalogueentry my $query = "select * from catalogueentry where entrytype = 's' and catalogueentry = '$subject[$i]'";
where entrytype = 's' my $sth = $dbh->prepare($query);
and catalogueentry = '$subject[$i]'"; $sth->execute;
my $sth = $dbh->prepare($query);
$sth->execute;
if (my $data = $sth->fetchrow_hashref) { if (my $data = $sth->fetchrow_hashref) {
} else { } else {
if ($force eq $subject[$i]) { if ($force eq $subject[$i]) {
# subject not in aut, chosen to force anway # subject not in aut, chosen to force anway
# so insert into cataloguentry so its in auth file # so insert into cataloguentry so its in auth file
$query = "Insert into catalogueentry $query = "Insert into catalogueentry (entrytype,catalogueentry) values ('s','$subject[$i]')";
(entrytype,catalogueentry) my $sth2 = $dbh->prepare($query);
values ('s','$subject[$i]')";
my $sth2 = $dbh->prepare($query);
$sth2->execute; $sth2->execute;
$sth2->finish; $sth2->finish;
} else { } else {
$error = "$subject[$i]\n does not exist in the subject authority file"; $error = "$subject[$i]\n does not exist in the subject authority file";
$query = "Select * from catalogueentry $query = "Select * from catalogueentry where entrytype = 's' and (catalogueentry like '$subject[$i] %'
where entrytype = 's' or catalogueentry like '% $subject[$i] %' or catalogueentry like '% $subject[$i]')";
and (catalogueentry like '$subject[$i] %' my $sth2 = $dbh->prepare($query);
or catalogueentry like '% $subject[$i] %' $sth2->execute;
or catalogueentry like '% $subject[$i]')"; while (my $data = $sth2->fetchrow_hashref) {
my $sth2 = $dbh->prepare($query); $error .= "<br>$data->{'catalogueentry'}";
} # while
$sth2->finish;
} # else
} # else
$sth->finish;
} # else
if ($error eq '') {
my $query = "Delete from bibliosubject where biblionumber = $bibnum";
my $sth = $dbh->prepare($query);
$sth->execute;
$sth->finish;
for (my $i = 0; $i < $count; $i++) {
$sth = $dbh->prepare("Insert into bibliosubject values ('$subject[$i]', $bibnum)");
$sth->execute;
$sth->finish;
} # for
} # if
$sth2->execute; # $dbh->disconnect;
while (my $data = $sth2->fetchrow_hashref) { return($error);
$error .= "<br>$data->{'catalogueentry'}";
} # while
$sth2->finish;
} # else
} # else
$sth->finish;
} # else
if ($error eq '') {
my $query = "Delete from bibliosubject where biblionumber = $bibnum";
my $sth = $dbh->prepare($query);
$sth->execute;
$sth->finish;
for (my $i = 0; $i < $count; $i++) {
$sth = $dbh->prepare("Insert into bibliosubject
values ('$subject[$i]', $bibnum)");
$sth->execute;
$sth->finish;
} # for
} # if
# $dbh->disconnect;
return($error);
} # sub modsubject } # sub modsubject
sub OLDmodbibitem { sub OLDmodbibitem {
@ -1513,28 +1575,18 @@ sub OLDnewbiblioitem {
sub OLDnewsubject { sub OLDnewsubject {
my ($dbh,$bibnum)=@_; my ($dbh,$bibnum)=@_;
# my $dbh=C4Connect; my $query="insert into bibliosubject (biblionumber) values ($bibnum)";
my $query="insert into bibliosubject (biblionumber) values
($bibnum)";
my $sth=$dbh->prepare($query); my $sth=$dbh->prepare($query);
# print $query;
$sth->execute; $sth->execute;
$sth->finish; $sth->finish;
# $dbh->disconnect;
} }
sub OLDnewsubtitle { sub OLDnewsubtitle {
my ($dbh,$bibnum, $subtitle) = @_; my ($dbh,$bibnum, $subtitle) = @_;
# my $dbh = C4Connect; my $query = "insert into bibliosubtitle set biblionumber = ?, subtitle = ?";
my $query = "insert into bibliosubtitle set
biblionumber = ?,
subtitle = ?";
my $sth = $dbh->prepare($query); my $sth = $dbh->prepare($query);
$sth->execute($bibnum,$subtitle); $sth->execute($bibnum,$subtitle);
$sth->finish; $sth->finish;
# $dbh->disconnect;
} }
@ -1778,9 +1830,13 @@ sub getsingleorder {
} }
sub newbiblio { sub newbiblio {
my ($biblio) = @_; my ($biblio) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $bibnum=OLDnewbiblio($dbh,$biblio); my $bibnum=OLDnewbiblio($dbh,$biblio);
# finds new (MARC bibid
my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
my $record = &MARCkoha2marcBiblio($dbh,$bibnum);
MARCaddbiblio($dbh,$record,$bibnum);
# FIXME : MARC add # FIXME : MARC add
return($bibnum); return($bibnum);
} }
@ -1804,11 +1860,14 @@ successful or not.
=cut =cut
sub modbiblio { sub modbiblio {
my ($biblio) = @_; my ($biblio) = @_;
my $dbh = C4::Context->dbh; my $dbh = C4::Context->dbh;
my $biblionumber=OLDmodbiblio($dbh,$biblio); my $biblionumber=OLDmodbiblio($dbh,$biblio);
return($biblionumber); my $record = MARCkoha2marcBiblio($dbh,$biblionumber);
# FIXME : MARC mod # finds new (MARC bibid
my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
MARCmodbiblio($dbh,$bibid,$record,0);
return($biblionumber);
} # sub modbiblio } # sub modbiblio
=item modsubtitle =item modsubtitle