From 417120fac6c62ad21a3cae50e0910a1b869fae58 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 --- C4/CourseReserves.pm | 4 ++-- .../atomicupdate/bug_10382-changes-on-courseitems-table.sql | 4 ++++ .../prog/en/modules/course_reserves/add_items-step2.tt | 8 ++++---- t/db_dependent/CourseReserves/CourseItems.t | 12 ++++++++---- 4 files changed, 18 insertions(+), 10 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/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 8c4c011..21e8461 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