[Koha-cvs] koha/C4 Biblio.pm

Tumer Garip tgarip at neu.edu.tr
Mon Apr 10 22:39:49 CEST 2006


CVSROOT:	/sources/koha
Module name:	koha
Branch: 	
Changes by:	Tumer Garip <tgarip1957 at savannah.gnu.org>	06/04/10 20:39:49

Modified files:
	C4             : Biblio.pm 

Log message:
	New sub to use by Circ2.pm . Allows one subfield of MARC holdings fields to be updated to use with branch transfer(holdingbranch) and onloan flag when set

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/koha/C4/Biblio.pm.diff?tr1=1.168&tr2=1.169&r1=text&r2=text

Patches:
Index: koha/C4/Biblio.pm
diff -u koha/C4/Biblio.pm:1.168 koha/C4/Biblio.pm:1.169
--- koha/C4/Biblio.pm:1.168	Mon Apr  3 04:00:02 2006
+++ koha/C4/Biblio.pm	Mon Apr 10 20:39:49 2006
@@ -32,7 +32,7 @@
 use vars qw($VERSION @ISA @EXPORT);
 
 # set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.168 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.169 $' =~ /\d+/g;
                 shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v); };
 
 @ISA = qw(Exporter);
@@ -70,7 +70,7 @@
   &MARCkoha2marcBiblio &MARCmarc2koha
   &MARCkoha2marcItem &MARChtml2marc &MARChtml2xml
   &MARCgetbiblio &MARCgetitem
-  MARCfind_MARCbibid_from_oldbiblionumber
+  &MARCmoditemonefield
   &XMLgetbiblio
   
   &FindDuplicate
@@ -275,7 +275,7 @@
 sub marc2xml {
 	my ($record) = @_;
 	my $xmlrecord;
-	eval { $xmlrecord=$record->as_xml() };
+	eval { $xmlrecord=$record->as_xml_record() };
 	#TODO: better error handling here
 	if ($@){
 		warn "ERROR: I suspect a badly formatted MARC record";
@@ -476,7 +476,7 @@
 	$sth->execute($biblionumber);
 	my ($rawmarc) = $sth->fetchrow;
 	my $record = C4::Search::get_record($biblionumber);
-	warn "ITEMRECORD".$record->as_formatted;
+#	warn "ITEMRECORD".$record->as_formatted;
 	# now, find the relevant itemnumber
 	my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber',$frameworkcode);
 	# prepare the new item record
@@ -484,19 +484,53 @@
 	# parse all fields fields from the complete record
 	foreach ($record->field($itemnumberfield)) {
 		# when the item field is found, save it
-		warn "Itenumberfield = $itemnumberfield";
+#		warn "Itenumberfield = $itemnumberfield";
 		if ($_->subfield($itemnumbersubfield) == $itemnumber) {
-			warn "Inside if subfield=$itemnumbersubfield";
+#			warn "Inside if subfield=$itemnumbersubfield";
 			$itemrecord->append_fields($_);
 		} else {
 			warn "No match subfield=$itemnumbersubfield and
 			               itemnumber=$itemnumber";
 		}
 	}
-	warn "ITEMS".$itemrecord->as_formatted;
+#	warn "ITEMS".$itemrecord->as_formatted;
     return $itemrecord;
 }
 
+
+##Changes only field or subfield from the holdings fields of MARC record used for branch transfers or onloan flag -TG
+
+
+sub MARCmoditemonefield{
+my ($dbh,$biblionumber,$itemnumber,$itemfield,$newvalue)=@_;
+
+my $frameworkcode=MARCfind_frameworkcode($dbh,$biblionumber);
+	# get the complete MARC record
+	my $sth = $dbh->prepare("select marc from biblioitems where biblionumber=?");
+	$sth->execute($biblionumber);
+	my ($rawmarc) = $sth->fetchrow;
+my $bibliorecord=MARC::File::USMARC::decode($rawmarc);
+	# now, find the relevant itemnumber
+	my ($itemnumberfield,$itemnumbersubfield) = MARCfind_marc_from_kohafield($dbh,'items.itemnumber',$frameworkcode);
+	my ($tagfield,$tagsubfield) = MARCfind_marc_from_kohafield($dbh,$itemfield,$frameworkcode);
+	
+	# parse all fields fields from the complete record
+	foreach ($bibliorecord->field($itemnumberfield)) {
+		# when the item field is found, update it
+		if ($_->subfield($itemnumbersubfield) == $itemnumber) {
+			$_->update($tagsubfield =>$newvalue);
+		} 
+	}
+
+ # save the record into biblioitem
+$dbh->do('lock tables biblioitems WRITE');
+	$sth=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
+	$sth->execute($bibliorecord->as_usmarc(),$bibliorecord->as_xml_record(),$biblionumber);
+	z3950_extended_services('update',set_service_options('update'),$bibliorecord);
+        z3950_extended_services('commit');
+  	$dbh->do('unlock tables');
+}
+
 =head2 find_biblioitemnumber
 
 my $biblioitemnumber = find_biblioitemnumber($dbh,$biblionumber);
@@ -867,7 +901,7 @@
 
 	#create the marc entry, that stores the rax marc record in Koha 3.0
 	$olddata->{marc} = $record->as_usmarc();
-	$olddata->{marcxml} = $record->as_xml();
+	$olddata->{marcxml} = $record->as_xml_record();
 	# and create biblioitem, that's all folks !
     $biblioitemnumber = REALnewbiblioitem( $dbh, $olddata );
 
@@ -947,7 +981,7 @@
 	#create the marc entry, that stores the rax marc record in Koha 3.0
 	$oldbiblio->{biblionumber} = $biblionumber unless $oldbiblio->{biblionumber};
 	$oldbiblio->{marc} = $record->as_usmarc();
-	$oldbiblio->{marcxml} = $record->as_xml();
+	$oldbiblio->{marcxml} = $record->as_xml_record();
 	warn "dans NEWmodbiblio $biblionumber = ".$oldbiblio->{biblionumber}." = ".$oldbiblio->{marcxml};
 	REALmodbiblio($dbh,$oldbiblio);
 	REALmodbiblioitem($dbh,$oldbiblio);
@@ -1376,7 +1410,7 @@
 	my $field=$record->field($biblioitemnumberfield);
 	$field->update($biblioitemnumbersubfield => "$biblioitemnumber");
 	$biblioitem->{marc} = $record->as_usmarc();
-	$biblioitem->{marcxml} = $record->as_xml();
+	$biblioitem->{marcxml} = $record->as_xml_record();
 
 	$sth = $dbh->prepare( "insert into biblioitems set
 									biblioitemnumber = ?,		biblionumber 	 = ?,
@@ -1552,7 +1586,7 @@
 	$record->insert_grouped_field($itemfield);
 	# save the record into biblioitem
 	$sth=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=?");
-	$sth->execute($record->as_usmarc(),$record->as_xml(),$item->{biblionumber});
+	$sth->execute($record->as_usmarc(),$record->as_xml_record(),$item->{biblionumber});
     if ( defined $sth->errstr ) {
         $error .= $sth->errstr;
     }
@@ -1651,7 +1685,7 @@
 # 	$record->insert_grouped_field($itemfield);
 	# save the record into biblioitem
 	$sth=$dbh->prepare("update biblioitems set marc=?,marcxml=? where biblionumber=? and biblioitemnumber=?");
-	$sth->execute($record->as_usmarc(),$record->as_xml(),$item->{biblionumber},$item->{biblioitemnumber});
+	$sth->execute($record->as_usmarc(),$record->as_xml_record(),$item->{biblionumber},$item->{biblioitemnumber});
 	z3950_extended_services('update',set_service_options('update'),$record);
         z3950_extended_services('commit');
     if ( defined $sth->errstr ) {
@@ -3027,8 +3061,11 @@
 
 =cut
 
-# $Id: Biblio.pm,v 1.168 2006/04/03 04:00:02 rangi Exp $
+# $Id: Biblio.pm,v 1.169 2006/04/10 20:39:49 tgarip1957 Exp $
 # $Log: Biblio.pm,v $
+# Revision 1.169  2006/04/10 20:39:49  tgarip1957
+# New sub to use by Circ2.pm . Allows one subfield of MARC holdings fields to be updated to use with branch transfer(holdingbranch) and onloan flag when set
+#
 # Revision 1.168  2006/04/03 04:00:02  rangi
 # Modify item now works
 #





More information about the Koha-cvs mailing list