From 4a98ec030d48abfccee2c442fdb623a4e1829091 Mon Sep 17 00:00:00 2001 From: Alex Arnaud Date: Fri, 10 Mar 2017 09:43:56 +0000 Subject: [PATCH] Bug 10382 - Course reserves: handle empty values DB changes: - remove course_items_ibfk_2, - set course_items.itype to VARCHAR(20), - set course_items.ccode to VARCHAR(20), - set course_items.holdingbranch to VARCHAR(20), https://bugs.koha-community.org/show_bug.cgi?id=10383 --- C4/CourseReserves.pm | 4 ++-- .../atomicupdate/bug_10382-changes-on-courseitems-table.sql | 4 ++++ installer/data/mysql/kohastructure.sql | 7 +++---- .../prog/en/modules/course_reserves/add_items-step2.tt | 8 ++++---- t/db_dependent/CourseReserves/CourseItems.t | 12 ++++++++---- 5 files changed, 21 insertions(+), 14 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_10382-changes-on-courseitems-table.sql diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm index 9fea72c..cfd11d7 100644 --- a/C4/CourseReserves.pm +++ b/C4/CourseReserves.pm @@ -642,7 +642,7 @@ sub _RevertFields { my @fields_to_null; foreach my $field (@fields) { foreach (@FIELDS) { - if ( $field eq $_ && $course_item->{$_} ) { + if ( $field eq $_ && $course_item->{$_} ne '' ) { $mod_item_params->{$_} = $course_item->{$_}; push( @fields_to_null, $_ ); } @@ -671,7 +671,7 @@ sub _SwapAllFields { my %course_item_fields; my %item_fields; foreach (@FIELDS) { - if ( defined( $course_item->{$_} ) ) { + if ( defined( $course_item->{$_} ) && $course_item->{$_} ne '' ) { $course_item_fields{$_} = $course_item->{$_}; $item_fields{$_} = $item->{$_} || q{}; } diff --git a/installer/data/mysql/atomicupdate/bug_10382-changes-on-courseitems-table.sql b/installer/data/mysql/atomicupdate/bug_10382-changes-on-courseitems-table.sql new file mode 100644 index 0000000..3aaacc0 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_10382-changes-on-courseitems-table.sql @@ -0,0 +1,4 @@ +ALTER TABLE course_items DROP FOREIGN KEY course_items_ibfk_2; +ALTER TABLE course_items MODIFY itype VARCHAR(20); +ALTER TABLE course_items MODIFY ccode VARCHAR(20); +ALTER TABLE course_items MODIFY holdingbranch VARCHAR(20); \ No newline at end of file diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index c293b79..a3b9d49 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3780,9 +3780,9 @@ DROP TABLE IF EXISTS course_items; CREATE TABLE `course_items` ( `ci_id` int(11) NOT NULL AUTO_INCREMENT, -- course item id `itemnumber` int(11) NOT NULL, -- items.itemnumber for the item on reserve - `itype` varchar(10) DEFAULT NULL, -- new itemtype for the item to have while on reserve (optional) - `ccode` varchar(10) DEFAULT NULL, -- new category code for the item to have while on reserve (optional) - `holdingbranch` varchar(10) DEFAULT NULL, -- new holding branch for the item to have while on reserve (optional) + `itype` varchar(20) DEFAULT NULL, -- new itemtype for the item to have while on reserve (optional) + `ccode` varchar(20) DEFAULT NULL, -- new category code for the item to have while on reserve (optional) + `holdingbranch` varchar(20) DEFAULT NULL, -- new holding branch for the item to have while on reserve (optional) `location` varchar(80) DEFAULT NULL, -- new shelving location for the item to have while on reseve (optional) `enabled` enum('yes','no') NOT NULL DEFAULT 'no', -- if at least one enabled course has this item on reseve, this field will be 'yes', otherwise it will be 'no' `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, @@ -3795,7 +3795,6 @@ CREATE TABLE `course_items` ( -- Constraints for table `course_items` -- ALTER TABLE `course_items` - ADD CONSTRAINT `course_items_ibfk_2` FOREIGN KEY (`holdingbranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE; -- diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt index ef22421..28a0563 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt @@ -35,7 +35,7 @@
  • - + [% FOREACH c IN ccodes %] [% IF course_item.ccode.defined && ( ( course.enabled == 'yes' && c.authorised_value == item.ccode ) || ( course.enabled == 'no' && c.authorised_value == course_item.ccode ) ) %] @@ -66,7 +66,7 @@
  • - + [% FOREACH b IN Branches.all() %] [% IF course_item.holdingbranch.defined && ( ( course.enabled == 'yes' && b.value == item.holdingbranch ) || ( course.enabled == 'no' && b.value == course_item.holdingbranch ) ) %] diff --git a/t/db_dependent/CourseReserves/CourseItems.t b/t/db_dependent/CourseReserves/CourseItems.t index c2bb237..00b561d 100644 --- a/t/db_dependent/CourseReserves/CourseItems.t +++ b/t/db_dependent/CourseReserves/CourseItems.t @@ -23,7 +23,7 @@ use C4::CourseReserves qw/ModCourseItem ModCourseReserve DelCourseReserve GetCou use C4::Context; use Koha::Items; -use Test::More tests => 17; +use Test::More tests => 21; BEGIN { require_ok('C4::CourseReserves'); @@ -83,10 +83,10 @@ is($item->ccode, '', 'Item ccode should be empty'); my $ci_id2 = ModCourseItem( itemnumber => $itemnumber, - itype => 'CD_foo', + itype => '', ccode => 'BOOK', - holdingbranch => 'B1', - location => 'HR', + holdingbranch => '', + location => '', ); my $cr_id2 = ModCourseReserve( @@ -97,10 +97,14 @@ my $cr_id2 = ModCourseReserve( ); $item = Koha::Items->find($itemnumber); +is($item->itype, 'CD_foo', 'Item type should be CD_foo'); is($item->ccode, 'BOOK', 'Item ccode should be BOOK'); my $course_item2 = GetCourseItem( ci_id => $ci_id2 ); +is($course_item2->{itype}, '', 'Course item ccode should be '); is($course_item2->{ccode}, '', 'Course item ccode should be empty'); +is($course_item2->{holdingbranch}, '', 'Course item holding branch should be '); +is($course_item2->{location}, '', 'Course item location should be '); DelCourseReserve( cr_id => $cr_id2 ); $item = Koha::Items->find($itemnumber); -- 2.7.4