@@ -, +, @@ subscription.aqbooksellerid --- C4/Serials.pm | 4 ++++ installer/data/mysql/atomicupdate/bug_18745.perl | 11 +++++++++++ installer/data/mysql/kohastructure.sql | 5 +++-- serials/subscription-add.pl | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) --- a/C4/Serials.pm +++ a/C4/Serials.pm @@ -1311,6 +1311,8 @@ sub ModSubscription { $itemtype, $previousitemtype, $mana_id ) = @_; + $aqbooksellerid ||= undef; + my $dbh = C4::Context->dbh; my $query = "UPDATE subscription SET librarian=?, branchcode=?, aqbooksellerid=?, cost=?, aqbudgetid=?, @@ -1373,6 +1375,8 @@ sub NewSubscription { ) = @_; my $dbh = C4::Context->dbh; + $aqbooksellerid ||= undef; + #save subscription (insert into database) my $query = qq| INSERT INTO subscription --- a/installer/data/mysql/atomicupdate/bug_18745.perl +++ a/installer/data/mysql/atomicupdate/bug_18745.perl @@ -1,5 +1,16 @@ $DBversion = 'XXX'; if( CheckVersion( $DBversion ) ) { + $dbh->do(q{ + UPDATE subscription + SET aqbooksellerid = NULL + WHERE aqbooksellerid = 0 + }); + $dbh->do(q{ + ALTER TABLE subscription + MODIFY COLUMN aqbooksellerid int(11) NULL DEFAULT NULL, + ADD CONSTRAINT subscription_ibfk_aqbooksellerid FOREIGN KEY (aqbooksellerid) REFERENCES aqbooksellers (id) ON DELETE RESTRICT ON UPDATE CASCADE + }); + if (!column_exists('serial', 'aqbooksellerid')) { $dbh->do(q{ ALTER TABLE `serial` --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -2095,7 +2095,7 @@ CREATE TABLE `subscription` ( -- information related to the subscription `subscriptionid` int(11) NOT NULL auto_increment, -- unique key for this subscription `librarian` varchar(100) default '', -- the librarian's username from borrowers.userid `startdate` date default NULL, -- start date for this subscription - `aqbooksellerid` int(11) default 0, -- foreign key for aqbooksellers.id to link to the vendor + `aqbooksellerid` int(11) NULL DEFAULT NULL, -- foreign key for aqbooksellers.id to link to the vendor `cost` int(11) default 0, `aqbudgetid` int(11) default 0, `weeklength` int(11) default 0, -- subscription length in weeks (will not be filled in if monthlength or numberlength is set) @@ -2137,7 +2137,8 @@ CREATE TABLE `subscription` ( -- information related to the subscription PRIMARY KEY (`subscriptionid`), KEY `by_biblionumber` (`biblionumber`), CONSTRAINT subscription_ibfk_1 FOREIGN KEY (periodicity) REFERENCES subscription_frequencies (id) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT subscription_ibfk_2 FOREIGN KEY (numberpattern) REFERENCES subscription_numberpatterns (id) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT subscription_ibfk_aqbooksellerid FOREIGN KEY (aqbooksellerid) REFERENCES aqbooksellers (id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- --- a/serials/subscription-add.pl +++ a/serials/subscription-add.pl @@ -317,7 +317,7 @@ sub redirect_add_subscription { my $auser = $query->param('user'); my $branchcode = $query->param('branchcode'); - my $aqbooksellerid = $query->param('aqbooksellerid'); + my $aqbooksellerid = $query->param('aqbooksellerid') || undef; my $cost = $query->param('cost'); my $aqbudgetid = $query->param('aqbudgetid'); my @irregularity = $query->multi_param('irregularity'); @@ -411,7 +411,7 @@ sub redirect_mod_subscription { my $librarian => scalar $query->param('librarian'), my $branchcode = $query->param('branchcode'); my $cost = $query->param('cost'); - my $aqbooksellerid = $query->param('aqbooksellerid'); + my $aqbooksellerid = $query->param('aqbooksellerid') || undef; my $biblionumber = $query->param('biblionumber'); my $aqbudgetid = $query->param('aqbudgetid'); --