[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Koha-cvs] koha/C4 Biblio.pm [rel_2_2]
From: |
Joshua Ferraro |
Subject: |
[Koha-cvs] koha/C4 Biblio.pm [rel_2_2] |
Date: |
Sat, 14 Apr 2007 20:52:56 +0000 |
CVSROOT: /sources/koha
Module name: koha
Branch: rel_2_2
Changes by: Joshua Ferraro <kados> 07/04/14 20:52:56
Modified files:
C4 : Biblio.pm
Log message:
IMPORTANT: Major bug in addbiblio and additem, this fixes it.
Bug 1330
Previously, if you added a field to a biblio it would save it with the
same tagorder as one of the items, and then editing an item would result
in it being deleted.
This patch adds a 'reordering process' to the items data when editing
a biblio so that no item ever has the same tagorder as a field in the
biblio.
This is an important enough patch that it probably warrants a release
since data loss is caused by bug 1330.
It still needs some testing.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/koha/C4/Biblio.pm?cvsroot=koha&only_with_tag=rel_2_2&r1=1.115.2.66&r2=1.115.2.67
Patches:
Index: Biblio.pm
===================================================================
RCS file: /sources/koha/koha/C4/Biblio.pm,v
retrieving revision 1.115.2.66
retrieving revision 1.115.2.67
diff -u -b -r1.115.2.66 -r1.115.2.67
--- Biblio.pm 14 Apr 2007 16:25:12 -0000 1.115.2.66
+++ Biblio.pm 14 Apr 2007 20:52:56 -0000 1.115.2.67
@@ -26,7 +26,7 @@
use vars qw($VERSION @ISA @EXPORT);
# set the version for version checking
-$VERSION = do { my @v = '$Revision: 1.115.2.66 $' =~ /\d+/g;
+$VERSION = do { my @v = '$Revision: 1.115.2.67 $' =~ /\d+/g;
shift(@v) . "." . join("_", map {sprintf "%03d", $_ } @v);
};
@ISA = qw(Exporter);
@@ -324,39 +324,44 @@
}
sub MARCaddbiblio {
-
-# pass the MARC::Record to this function, and it will create the records in
the marc tables
+ # pass the MARC::Record to this function, and it will create the records
in the marc tables
my ($dbh,$record,$biblionumber,$frameworkcode,$bibid) = @_;
my @fields=$record->fields();
-# my $bibid;
-# adding main table, and retrieving bibid
-# if bibid is sent, then it's not a true add, it's only a re-add, after a
delete (ie, a mod)
+ # adding main table, and retrieving bibid
+ # if bibid is sent, then it's not a true add, it's only a re-add, after a
delete (ie, a mod)
# if bibid empty => true add, find a new bibid number
unless ($bibid) {
$dbh->do(
-"lock tables marc_biblio WRITE,marc_subfield_table WRITE, marc_word WRITE,
marc_blob_subfield WRITE, stopwords READ"
+ "LOCK TABLES marc_biblio WRITE,marc_subfield_table WRITE,
marc_word WRITE, marc_blob_subfield WRITE, stopwords READ"
);
my $sth =
$dbh->prepare(
-"insert into marc_biblio (datecreated,biblionumber,frameworkcode) values
(now(),?,?)"
+ "INSERT INTO marc_biblio (datecreated,biblionumber,frameworkcode)
VALUES (NOW(),?,?)"
);
$sth->execute( $biblionumber, $frameworkcode );
- $sth = $dbh->prepare("select max(bibid) from marc_biblio");
+ $sth = $dbh->prepare("SELECT MAX(bibid) FROM marc_biblio");
$sth->execute;
($bibid) = $sth->fetchrow;
$sth->finish;
}
- my $fieldcount = 0;
+ my $fieldcount = 1;
+
+ # save leader first
+ &MARCaddsubfield($dbh,$bibid,'000','',$fieldcount,'',1,$record->leader);
# now, add subfields...
foreach my $field (@fields) {
$fieldcount++;
# make sure we're dealing with valid MARC tags
if ($field->tag =~ /^[0-9A-Za-z]{3}$/) {
+
+ # save fixed fields
if ( $field->tag() < 10 ) {
&MARCaddsubfield( $dbh, $bibid, $field->tag(), '', $fieldcount, '',
1, $field->data() );
}
+
+ # save normal subfields
else {
my @subfields = $field->subfields();
foreach my $subfieldcount ( 0 .. $#subfields ) {
@@ -374,9 +379,24 @@
}
}
}
- # save leader
-
&MARCaddsubfield($dbh,$bibid,'000','',$fieldcount+1,'',1,$record->leader);
- $dbh->do("unlock tables");
+
+ # now we need to reorder the tagorder in marc_subfield_table for items data
+ #search item field code
+ my $sth = $dbh->prepare("SELECT tagfield FROM marc_subfield_structure
WHERE kohafield LIKE 'items.%'");
+ $sth->execute;
+ my $itemtag = $sth->fetchrow_hashref->{tagfield};
+ my $newsth = $dbh->prepare("SELECT distinct(tagorder) FROM
marc_subfield_table WHERE bibid=$bibid AND tag=$itemtag ORDER BY tagorder");
+ my $updatesth = $dbh->prepare("UPDATE marc_subfield_table SET tagorder=?
WHERE tagorder=? AND bibid=? AND tag=?");
+
+ $newsth->execute();
+
+ # for every item, update the tagorder
+ for my $tagorder ($newsth->fetchrow_array()) {
+ $fieldcount++;
+ $updatesth->execute($fieldcount,$tagorder,$bibid,$itemtag);
+ }
+
+ $dbh->do("UNLOCK TABLES");
return $bibid;
}
@@ -3011,8 +3031,25 @@
=cut
-# $Id: Biblio.pm,v 1.115.2.66 2007/04/14 16:25:12 kados Exp $
+# $Id: Biblio.pm,v 1.115.2.67 2007/04/14 20:52:56 kados Exp $
# $Log: Biblio.pm,v $
+# Revision 1.115.2.67 2007/04/14 20:52:56 kados
+# IMPORTANT: Major bug in addbiblio and additem, this fixes it.
+# Bug 1330
+#
+# Previously, if you added a field to a biblio it would save it with the
+# same tagorder as one of the items, and then editing an item would result
+# in it being deleted.
+#
+# This patch adds a 'reordering process' to the items data when editing
+# a biblio so that no item ever has the same tagorder as a field in the
+# biblio.
+#
+# This is an important enough patch that it probably warrants a release
+# since data loss is caused by bug 1330.
+#
+# It still needs some testing.
+#
# Revision 1.115.2.66 2007/04/14 16:25:12 kados
# minor spacing change, remove some unnecessary comments
#