kohabug 2380 Correcting serialitems table structure and fixing duplicate barcode check

The current serialitems table structure does not provide for a *:1 relationship with
the serial table. This causes a problem when attempting to add multiple items to a given
serial. The db throws an error when attempting to INSERT in  serialitems due to serialid.serialitems
being a unique key. A further side effect is that the marc record is updated with the
item inspite of the error. The mods to the serialitems table structure in this patch
drop serialid.serialitems as a key and make itemnumber.serialitems the primary key
creating a *:1 relationship with the serial table. This patch also makes serialid.serialitems
a foreign key referencing serialid.serial to maintain referential integrity.

Fix for duplicate barcode check

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
Signed-off-by: Joshua Ferraro <jmf@liblime.com>
This commit is contained in:
Chris Nighswonger 2008-07-25 10:44:30 -05:00 committed by Joshua Ferraro
parent 0d7265bd73
commit cdf93bffee
4 changed files with 21 additions and 10 deletions

View File

@ -2133,13 +2133,15 @@ CREATE TABLE `permissions` (
ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS serialitems;
CREATE TABLE serialitems (
serialid int(11) NOT NULL,
itemnumber int(11) NOT NULL,
UNIQUE KEY `serialididx` (`serialid`)
DROP TABLE IF EXISTS `serialitems`;
CREATE TABLE `serialitems` (
`itemnumber` int(11) NOT NULL,
`serialid` int(11) NOT NULL,
UNIQUE KEY `serialitemsidx` (`itemnumber`),
KEY `serialitems_sfk_1` (`serialid`),
CONSTRAINT `serialitems_sfk_1` FOREIGN KEY (`serialid`) REFERENCES `serial` (`serialid`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
DROP TABLE IF EXISTS `user_permissions`;
CREATE TABLE `user_permissions` (
`borrowernumber` int(11) NOT NULL DEFAULT 0,

View File

@ -1879,6 +1879,16 @@ if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
SetVersion($DBversion);
}
$DBversion = '3.00.00.102';
if ( C4::Context->preference('Version') < TransformToNum($DBversion) ) {
$dbh->do('ALTER TABLE serialitems MODIFY `serialid` int(11) NOT NULL AFTER itemnumber' );
$dbh->do('ALTER TABLE serialitems DROP KEY serialididx' );
$dbh->do('ALTER TABLE serialitems ADD CONSTRAINT UNIQUE KEY serialitemsidx (itemnumber)' );
$dbh->do('ALTER TABLE serialitems ADD CONSTRAINT serialitems_sfk_1 FOREIGN KEY (serialid) REFERENCES serial (serialid) ON DELETE CASCADE ON UPDATE CASCADE' );
print "Upgrade to $DBversion done (Updating serialitems table to allow for mulitple items per serial fixing kohabug 2380\n";
SetVersion($DBversion);
}
=item DropAllForeignKeys($table)
Drop all foreign keys of the table $table

View File

@ -10,7 +10,7 @@
use strict;
sub kohaversion {
our $VERSION = '3.00.00.101';
our $VERSION = '3.00.00.102';
# version needs to be set this way
# so that it can be picked up by Makefile.PL
# during install

View File

@ -225,11 +225,10 @@ if ($op eq 'serialchangestatus') {
if ($item=~/^N/){
#New Item
# if autoBarcode is ON, calculate barcode...
# if autoBarcode is set to 'incremental', calculate barcode...
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode");
if (C4::Context->preference("autoBarcode") eq 'incremental' ) {
eval { $record->field($tagfield)->subfield($tagsubfield) };
if ($@) {
if (!$record->field($tagfield)->subfield($tagsubfield)) {
my $sth_barcode = $dbh->prepare("select max(abs(barcode)) from items");
$sth_barcode->execute;
my ($newbarcode) = $sth_barcode->fetchrow;