From c3c785e4ff196088c82df99273284c222342086f Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Fri, 2 Feb 2024 09:02:59 +0200 Subject: [PATCH] Bug 32132: Do not allow NULL value in column aqbudgets.budget_period_id If budget_period_id column is set as NULL, "Late orders" page dies on error 500. Logs read: Template process failed: undef error - DBIC result _type isn't of the _type Aqbudget at /home/koha/Koha/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/lateorders.tt line 157 This patch makes changes to column aqbudgets.budget_period_id so that it no longer allows NULL values. This is in line with aqbudgets tables foreign key "budget_period_id" which has ON DELETE CASCADE clause. To test: 1. Run prove t/db_dependent/Koha/Acquisition/Fund.t => Tests should fail 2. Run updatedatabase.pl and restart services if needed 3. Rerun prove t/db_dependent/Koha/Acquisition/Fund.t => Tests should now pass Sponsored-by: Koha-Suomi Oy Signed-off-by: Lucas Gass --- installer/data/mysql/atomicupdate/bug_32132.pl | 17 +++++++++++++++++ installer/data/mysql/kohastructure.sql | 2 +- t/db_dependent/Koha/Acquisition/Fund.t | 11 ++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_32132.pl diff --git a/installer/data/mysql/atomicupdate/bug_32132.pl b/installer/data/mysql/atomicupdate/bug_32132.pl new file mode 100755 index 0000000000..f85fb7e084 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_32132.pl @@ -0,0 +1,17 @@ +use Modern::Perl; + +return { + bug_number => "32132", + description => "Set aqbudgets.budget_period_id as NOT NULL", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + # Do you stuffs here + $dbh->do(q{ALTER TABLE aqbudgets MODIFY COLUMN `budget_period_id` INT(11) NOT NULL}); + + # Print useful stuff here + # tables + say $out "Change aqbudgets.budget_period_id to NOT accept NULL values."; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 16310f0f44..8834a5e273 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -559,7 +559,7 @@ CREATE TABLE `aqbudgets` ( `budget_expend` decimal(28,6) DEFAULT 0.000000 COMMENT 'budget warning at amount', `budget_notes` longtext DEFAULT NULL COMMENT 'notes related to this fund', `timestamp` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'date and time this fund was last touched (created or modified)', - `budget_period_id` int(11) DEFAULT NULL COMMENT 'id of the budget that this fund belongs to (aqbudgetperiods.budget_period_id)', + `budget_period_id` int(11) NOT NULL COMMENT 'id of the budget that this fund belongs to (aqbudgetperiods.budget_period_id)', `sort1_authcat` varchar(80) DEFAULT NULL COMMENT 'statistical category for this fund', `sort2_authcat` varchar(80) DEFAULT NULL COMMENT 'second statistical category for this fund', `budget_owner_id` int(11) DEFAULT NULL COMMENT 'borrowernumber of the person who owns this fund (borrowers.borrowernumber)', diff --git a/t/db_dependent/Koha/Acquisition/Fund.t b/t/db_dependent/Koha/Acquisition/Fund.t index 80c4e4e65a..fc21d0b38f 100755 --- a/t/db_dependent/Koha/Acquisition/Fund.t +++ b/t/db_dependent/Koha/Acquisition/Fund.t @@ -20,6 +20,7 @@ use Modern::Perl; use Test::More tests => 3; +use Test::Warn; use t::lib::TestBuilder; @@ -57,7 +58,7 @@ subtest 'budget ()' => sub { }; subtest 'budget' => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; my $f = $builder->build_object( @@ -70,5 +71,13 @@ subtest 'budget' => sub { is( ref( $fund->budget ), 'Koha::Acquisition::Budget', '->fund should return a Koha::Acquisition::Budget object' ); + + # Cannot set aqbudgets.budget_period_id as NULL + warning_like { + eval { $fund->budget_period_id(undef)->store } + } + qr{.*DBD::mysql::st execute failed: Column 'budget_period_id' cannot be null.*}, + 'DBD should have raised an error about budget_period_id that cannot be null'; + $schema->storage->txn_rollback; }; -- 2.30.2