[Koha-cvs] CVS: koha/C4 Biblio.pm,1.129,1.130

Paul POULAIN tipaul at users.sourceforge.net
Fri Sep 2 16:34:16 CEST 2005


Update of /cvsroot/koha/koha/C4
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30775/C4

Modified Files:
	Biblio.pm 
Log Message:
continuing the work to move to zebra. Begin of work for MARC=OFF support.
IMPORTANT NOTE : the MARCkoha2marc sub API has been modified. Instead of biblionumber & biblioitemnumber, it now gets a hash.
The sub is used only in Biblio.pm, so the API change should be harmless (except for me, but i'm aware ;-) )

Index: Biblio.pm
===================================================================
RCS file: /cvsroot/koha/koha/C4/Biblio.pm,v
retrieving revision 1.129
retrieving revision 1.130
diff -C2 -r1.129 -r1.130
*** Biblio.pm	12 Aug 2005 13:50:31 -0000	1.129
--- Biblio.pm	2 Sep 2005 14:34:14 -0000	1.130
***************
*** 350,354 ****
  }
  
! =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$biblionumber,biblioitemnumber);
  
  =over 4
--- 350,354 ----
  }
  
! =head2 $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibliohash);
  
  =over 4
***************
*** 363,439 ****
  sub MARCkoha2marcBiblio {
  
!     # this function builds partial MARC::Record from the old koha-DB fields
!     my ( $dbh, $biblionumber, $biblioitemnumber ) = @_;
!     my $sth =
!       $dbh->prepare(
! "select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?"
!     );
!     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=?"
!         );
!         $sth2->execute($biblionumber);
!         my $row = $sth2->fetchrow_hashref;
!         my $code;
!         foreach $code ( keys %$row ) {
!             if ( $row->{$code} ) {
!                 &MARCkoha2marcOnefield( $sth, $record, "biblio." . $code,
!                     $row->{$code}, '');
!             }
!         }
!     }
! 
!     #--- if biblioitem, then retrieve old-style koha data
!     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 AS bnotes,size,place
! 					FROM biblioitems
! 					WHERE biblioitemnumber=?
! 					"
!         );
!         $sth2->execute($biblioitemnumber);
!         my $row = $sth2->fetchrow_hashref;
!         my $code;
!         foreach $code ( keys %$row ) {
!             if ( $row->{$code} ) {
!                 &MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $code,
!                     $row->{$code},'' );
!             }
!         }
!     }
! 
!     # 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'},'' );
!     }
!     $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'},'' );
!     }
!     $sth2 =
!       $dbh->prepare(
!         " SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
!     $sth2->execute($biblionumber);
!     while ( my $row = $sth2->fetchrow_hashref ) {
!         &MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle",
!             $row->{'subtitle'},'' );
!     }
!     return $record;
  }
  
--- 363,401 ----
  sub MARCkoha2marcBiblio {
  
! 	# this function builds partial MARC::Record from the old koha-DB fields
! 	my ( $dbh, $bibliohash ) = @_;
! 	# we don't have biblio entries in the hash, so we add them first
! 	my $sth = $dbh->prepare("select * from biblio where biblionumber=?");
! 	$sth->execute($bibliohash->{biblionumber});
! 	my $biblio = $sth->fetchrow_hashref;
! 	foreach (keys %$biblio) {
! 		$bibliohash->{$_}=$biblio->{$_};
! 	}
! 	my $sth = $dbh->prepare("select tagfield,tagsubfield from marc_subfield_structure where frameworkcode=? and kohafield=?");
! 	my $record = MARC::Record->new();
! 	foreach ( keys %$bibliohash ) {
! 		&MARCkoha2marcOnefield( $sth, $record, "biblio." . $_, $bibliohash->{$_}, '') if $bibliohash->{$_};
! 		&MARCkoha2marcOnefield( $sth, $record, "biblioitems." . $_, $bibliohash->{$_}, '') if $bibliohash->{$_};
! 	}
! 
! 	# other fields => additional authors, subjects, subtitles
! 	my $sth2 = $dbh->prepare(" SELECT author FROM additionalauthors WHERE biblionumber=?");
! 	$sth2->execute($bibliohash->{biblionumber});
! 	while ( my $row = $sth2->fetchrow_hashref ) {
! 		&MARCkoha2marcOnefield( $sth, $record, "additionalauthors.author", $bibliohash->{'author'},'' );
! 	}
! 	$sth2 = $dbh->prepare(" SELECT subject FROM bibliosubject WHERE biblionumber=?");
! 	$sth2->execute($bibliohash->{biblionumber});
! 	while ( my $row = $sth2->fetchrow_hashref ) {
! 		&MARCkoha2marcOnefield( $sth, $record, "bibliosubject.subject", $row->{'subject'},'' );
! 	}
! 	$sth2 = $dbh->prepare(" SELECT subtitle FROM bibliosubtitle WHERE biblionumber=?");
! 	$sth2->execute($bibliohash->{biblionumber});
! 	while ( my $row = $sth2->fetchrow_hashref ) {
! 		&MARCkoha2marcOnefield( $sth, $record, "bibliosubtitle.subtitle", $row->{'subtitle'},'' );
! 	}
! 	
! 	warn "RECORD : ".$record->as_formatted;
! 	return $record;
  }
  
***************
*** 1158,1162 ****
  	my ( $dbh, $biblioitem ) = @_;
  
! 	$dbh->do("lock tables biblioitems WRITE, biblio WRITE");
  	my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
  	my $data;
--- 1120,1124 ----
  	my ( $dbh, $biblioitem ) = @_;
  
! 	$dbh->do("lock tables biblioitems WRITE, biblio WRITE, marc_subfield_structure READ");
  	my $sth = $dbh->prepare("Select max(biblioitemnumber) from biblioitems");
  	my $data;
***************
*** 1626,1631 ****
      # finds new (MARC bibid
      # 	my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
!     my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
!     MARCaddbiblio( $dbh, $record, $bibnum,'' );
      return ($bibnum);
  }
--- 1588,1593 ----
      # finds new (MARC bibid
      # 	my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
! #     my $record = &MARCkoha2marcBiblio( $dbh, $bibnum );
! #     MARCaddbiblio( $dbh, $record, $bibnum,'' );
      return ($bibnum);
  }
***************
*** 1655,1658 ****
--- 1617,1621 ----
  	my $dbh  = C4::Context->dbh;
  	my $biblionumber=REALmodbiblio($dbh,$biblio);
+ 	warn "in MODBIBLIO";
  	my $record = MARCkoha2marcBiblio($dbh,$biblionumber,$biblionumber);
  	# finds new (MARC bibid
***************
*** 1719,1727 ****
  		# subjects, of course, it deletes the biblio in marc, and then recreates.
  		# This check is to ensure that no MARC data exists to lose.
! 		if (C4::Context->preference("MARC") eq '0'){
! 			my $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibnum);
! 			my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
! 			&MARCmodbiblio($dbh,$bibid, $MARCRecord);
! 		}
  	}
  	return ($error);
--- 1682,1691 ----
  		# subjects, of course, it deletes the biblio in marc, and then recreates.
  		# This check is to ensure that no MARC data exists to lose.
! # 		if (C4::Context->preference("MARC") eq '0'){
! # 		warn "in modSUBJECT";
! # 			my $MARCRecord = &MARCkoha2marcBiblio($dbh,$bibnum);
! # 			my $bibid = &MARCfind_MARCbibid_from_oldbiblionumber($dbh,$bibnum);
! # 			&MARCmodbiblio($dbh,$bibid, $MARCRecord);
! # 		}
  	}
  	return ($error);
***************
*** 1757,1769 ****
      my ($biblioitem) = @_;
      my $dbh        = C4::Context->dbh;
      my $bibitemnum = &REALnewbiblioitem( $dbh, $biblioitem );
- 
-     my $MARCbiblio =
-       MARCkoha2marcBiblio( $dbh, 0, $bibitemnum )
-       ; # the 0 means "do NOT retrieve biblio, only biblioitem, in the MARC record
-     my $bibid =
-       &MARCfind_MARCbibid_from_oldbiblionumber( $dbh,
-         $biblioitem->{biblionumber} );
-     &MARCaddbiblio( $dbh, $MARCbiblio, $biblioitem->{biblionumber}, '',$bibid );
      return ($bibitemnum);
  }
--- 1721,1728 ----
      my ($biblioitem) = @_;
      my $dbh        = C4::Context->dbh;
+ 	# add biblio information to the hash
+     my $MARCbiblio = MARCkoha2marcBiblio( $dbh, $biblioitem );
+ 	$biblioitem->{marc} = $MARCbiblio->as_usmarc();
      my $bibitemnum = &REALnewbiblioitem( $dbh, $biblioitem );
      return ($bibitemnum);
  }
***************
*** 2340,2343 ****
--- 2299,2307 ----
  # $Id$
  # $Log$
+ # Revision 1.130  2005/09/02 14:34:14  tipaul
+ # continuing the work to move to zebra. Begin of work for MARC=OFF support.
+ # IMPORTANT NOTE : the MARCkoha2marc sub API has been modified. Instead of biblionumber & biblioitemnumber, it now gets a hash.
+ # The sub is used only in Biblio.pm, so the API change should be harmless (except for me, but i'm aware ;-) )
+ #
  # Revision 1.129  2005/08/12 13:50:31  tipaul
  # removing useless sub declarations





More information about the Koha-cvs mailing list