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>
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`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
+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,
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
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
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;