[Koha-cvs] CVS: koha/C4 Biblio.pm,1.45,1.46
Paul POULAIN
tipaul at users.sourceforge.net
Mon May 19 15:45:22 CEST 2003
Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1:/tmp/cvs-serv32116/C4
Modified Files:
Biblio.pm
Log Message:
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.
Index: Biblio.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Biblio.pm,v
retrieving revision 1.45
retrieving revision 1.46
diff -C2 -r1.45 -r1.46
*** Biblio.pm 29 Apr 2003 16:50:49 -0000 1.45
--- Biblio.pm 19 May 2003 13:45:18 -0000 1.46
***************
*** 2,5 ****
--- 2,11 ----
# $Id$
# $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
# really proud of this commit :-)
***************
*** 413,420 ****
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
! otherwise, only data passed to MARCmodbiblio is managed.
! 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);
--- 419,424 ----
MARCmodbiblio changes a biblio for a biblio,MARC::Record passed as parameter
! It 1st delete the biblio, then recreates it.
! WARNING : the $delete parameter is not used anymore (too much unsolvable cases).
=item ($subfieldid,$subfieldvalue) = &MARCmodsubfield($dbh,$subfieldid,$subfieldvalue);
***************
*** 935,940 ****
}
}
return $record;
- # TODO : retrieve notes, additionalauthors
}
--- 939,959 ----
}
}
+ # 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;
}
***************
*** 964,968 ****
}
return $record;
- # TODO : retrieve notes, additionalauthors
}
--- 983,986 ----
***************
*** 1035,1039 ****
# the last has not been included inside the loop... do it now !
$record->add_fields($field);
! warn $record->as_formatted;
return $record;
}
--- 1053,1057 ----
# the last has not been included inside the loop... do it now !
$record->add_fields($field);
! # warn $record->as_formatted;
return $record;
}
***************
*** 1135,1192 ****
sub NEWnewbiblio {
! my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
! # note $oldbiblio and $oldbiblioitem are not mandatory.
! # if not present, they will be builded from $record with MARCmarc2koha function
! if (($oldbiblio) and not($oldbiblioitem)) {
! print STDERR "NEWnewbiblio : missing parameter\n";
! print "NEWnewbiblio : missing parameter : contact koha development team\n";
! die;
! }
! my $oldbibnum;
! my $oldbibitemnum;
! if ($oldbiblio) {
! $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
! $oldbiblioitem->{'biblionumber'} = $oldbibnum;
! $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
! } else {
! my $olddata = MARCmarc2koha($dbh,$record);
! $oldbibnum = OLDnewbiblio($dbh,$olddata);
! $olddata->{'biblionumber'} = $oldbibnum;
! $oldbibitemnum = OLDnewbiblioitem($dbh,$olddata);
! }
! # 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 {
! my ($dbh,$record,$bibid) =@_;
! &MARCmodbiblio($dbh,$bibid,$record,0);
! my $oldbiblio = MARCmarc2koha($dbh,$record);
! my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
! OLDmodbibitem($dbh,$oldbiblio);
! return 1;
}
--- 1153,1264 ----
sub NEWnewbiblio {
! my ($dbh, $record, $oldbiblio, $oldbiblioitem) = @_;
! # note $oldbiblio and $oldbiblioitem are not mandatory.
! # if not present, they will be builded from $record with MARCmarc2koha function
! if (($oldbiblio) and not($oldbiblioitem)) {
! print STDERR "NEWnewbiblio : missing parameter\n";
! print "NEWnewbiblio : missing parameter : contact koha development team\n";
! die;
! }
! my $oldbibnum;
! my $oldbibitemnum;
! if ($oldbiblio) {
! $oldbibnum = OLDnewbiblio($dbh,$oldbiblio);
! $oldbiblioitem->{'biblionumber'} = $oldbibnum;
! $oldbibitemnum = OLDnewbiblioitem($dbh,$oldbiblioitem);
! } else {
! my $olddata = MARCmarc2koha($dbh,$record);
! $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");
! 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");
! 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");
! 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,$oldbibnum,1, at 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 {
! my ($dbh,$record,$bibid) =@_;
! &MARCmodbiblio($dbh,$bibid,$record,0);
! my $oldbiblio = MARCmarc2koha($dbh,$record);
! my $oldbiblionumber = OLDmodbiblio($dbh,$oldbiblio);
! OLDmodbibitem($dbh,$oldbiblio);
! # 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, at subjects);
! }
! return 1;
}
***************
*** 1356,1418 ****
sub OLDmodsubject {
! my ($dbh,$bibnum, $force, @subject) = @_;
! # my $dbh = C4Connect;
! my $count = @subject;
! my $error;
! for (my $i = 0; $i < $count; $i++) {
! $subject[$i] =~ s/^ //g;
! $subject[$i] =~ s/ $//g;
! my $query = "select * from catalogueentry
! where entrytype = 's'
! and catalogueentry = '$subject[$i]'";
! my $sth = $dbh->prepare($query);
! $sth->execute;
! if (my $data = $sth->fetchrow_hashref) {
! } else {
! if ($force eq $subject[$i]) {
! # subject not in aut, chosen to force anway
! # so insert into cataloguentry so its in auth file
! $query = "Insert into catalogueentry
! (entrytype,catalogueentry)
! values ('s','$subject[$i]')";
! my $sth2 = $dbh->prepare($query);
!
! $sth2->execute;
! $sth2->finish;
! } else {
! $error = "$subject[$i]\n does not exist in the subject authority file";
! $query = "Select * from catalogueentry
! where entrytype = 's'
! and (catalogueentry like '$subject[$i] %'
! or catalogueentry like '% $subject[$i] %'
! or catalogueentry like '% $subject[$i]')";
! my $sth2 = $dbh->prepare($query);
!
! $sth2->execute;
! while (my $data = $sth2->fetchrow_hashref) {
! $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
--- 1428,1480 ----
sub OLDmodsubject {
! my ($dbh,$bibnum, $force, @subject) = @_;
! # my $dbh = C4Connect;
! my $count = @subject;
! my $error;
! for (my $i = 0; $i < $count; $i++) {
! $subject[$i] =~ s/^ //g;
! $subject[$i] =~ s/ $//g;
! my $query = "select * from catalogueentry where entrytype = 's' and catalogueentry = '$subject[$i]'";
! my $sth = $dbh->prepare($query);
! $sth->execute;
! if (my $data = $sth->fetchrow_hashref) {
! } else {
! if ($force eq $subject[$i]) {
! # subject not in aut, chosen to force anway
! # so insert into cataloguentry so its in auth file
! $query = "Insert into catalogueentry (entrytype,catalogueentry) values ('s','$subject[$i]')";
! my $sth2 = $dbh->prepare($query);
! $sth2->execute;
! $sth2->finish;
! } else {
! $error = "$subject[$i]\n does not exist in the subject authority file";
! $query = "Select * from catalogueentry where entrytype = 's' and (catalogueentry like '$subject[$i] %'
! or catalogueentry like '% $subject[$i] %' or catalogueentry like '% $subject[$i]')";
! my $sth2 = $dbh->prepare($query);
! $sth2->execute;
! while (my $data = $sth2->fetchrow_hashref) {
! $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
***************
*** 1514,1539 ****
sub OLDnewsubject {
my ($dbh,$bibnum)=@_;
! # my $dbh=C4Connect;
! my $query="insert into bibliosubject (biblionumber) values
! ($bibnum)";
my $sth=$dbh->prepare($query);
- # print $query;
$sth->execute;
$sth->finish;
- # $dbh->disconnect;
}
sub OLDnewsubtitle {
my ($dbh,$bibnum, $subtitle) = @_;
! # my $dbh = C4Connect;
! my $query = "insert into bibliosubtitle set
! biblionumber = ?,
! subtitle = ?";
my $sth = $dbh->prepare($query);
-
$sth->execute($bibnum,$subtitle);
-
$sth->finish;
- # $dbh->disconnect;
}
--- 1576,1591 ----
sub OLDnewsubject {
my ($dbh,$bibnum)=@_;
! my $query="insert into bibliosubject (biblionumber) values ($bibnum)";
my $sth=$dbh->prepare($query);
$sth->execute;
$sth->finish;
}
sub OLDnewsubtitle {
my ($dbh,$bibnum, $subtitle) = @_;
! my $query = "insert into bibliosubtitle set biblionumber = ?, subtitle = ?";
my $sth = $dbh->prepare($query);
$sth->execute($bibnum,$subtitle);
$sth->finish;
}
***************
*** 1779,1785 ****
sub newbiblio {
! my ($biblio) = @_;
! my $dbh = C4::Context->dbh;
! my $bibnum=OLDnewbiblio($dbh,$biblio);
# FIXME : MARC add
return($bibnum);
--- 1831,1841 ----
sub newbiblio {
! my ($biblio) = @_;
! my $dbh = C4::Context->dbh;
! 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
return($bibnum);
***************
*** 1805,1813 ****
sub modbiblio {
! my ($biblio) = @_;
! my $dbh = C4::Context->dbh;
! my $biblionumber=OLDmodbiblio($dbh,$biblio);
! return($biblionumber);
! # FIXME : MARC mod
} # sub modbiblio
--- 1861,1872 ----
sub modbiblio {
! my ($biblio) = @_;
! my $dbh = C4::Context->dbh;
! my $biblionumber=OLDmodbiblio($dbh,$biblio);
! my $record = MARCkoha2marcBiblio($dbh,$biblionumber);
! # finds new (MARC bibid
! my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$biblionumber);
! MARCmodbiblio($dbh,$bibid,$record,0);
! return($biblionumber);
} # sub modbiblio
More information about the Koha-cvs
mailing list