From e37d349dd1844909138730d0e5f409ac426525f2 Mon Sep 17 00:00:00 2001 From: Julian Maurice Date: Wed, 3 Apr 2019 14:49:00 +0200 Subject: [PATCH] Bug 22630: Allow to change homebranch in course reserves Test plan: 1. Create a course (disabled) 2. Add a reserve to this course for an item and set a homebranch different from the item's homebranch 3. Enable the course 4. Verify that the item's homebranch has changed 5. Disable the course 6. Verify that the item's homebranch was reset to its initial value 7. prove t/db_dependent/CourseReserves/CourseItems.t Signed-off-by: Liz Rea --- C4/CourseReserves.pm | 2 +- course_reserves/add_items.pl | 1 + .../data/mysql/atomicupdate/bug-22630.perl | 13 +++++++++++ installer/data/mysql/kohastructure.sql | 2 ++ .../course_reserves/add_items-step2.tt | 14 +++++++++++ .../modules/course_reserves/course-details.tt | 23 ++++++++++++++++++- t/db_dependent/CourseReserves/CourseItems.t | 11 ++++++++- 7 files changed, 63 insertions(+), 3 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-22630.perl diff --git a/C4/CourseReserves.pm b/C4/CourseReserves.pm index 428d7e9d33..0488dd40c0 100644 --- a/C4/CourseReserves.pm +++ b/C4/CourseReserves.pm @@ -52,7 +52,7 @@ BEGIN { %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); $DEBUG = 0; - @FIELDS = ( 'itype', 'ccode', 'holdingbranch', 'location' ); + @FIELDS = ( 'itype', 'ccode', 'homebranch', 'holdingbranch', 'location' ); } =head1 NAME diff --git a/course_reserves/add_items.pl b/course_reserves/add_items.pl index 42416b3a63..f7133b3592 100755 --- a/course_reserves/add_items.pl +++ b/course_reserves/add_items.pl @@ -93,6 +93,7 @@ if ( $action eq 'lookup' and $item ) { itemnumber => scalar $cgi->param('itemnumber'), itype => scalar $cgi->param('itype'), ccode => scalar $cgi->param('ccode'), + homebranch => scalar $cgi->param('homebranch'), holdingbranch => scalar $cgi->param('holdingbranch'), location => scalar $cgi->param('location'), ); diff --git a/installer/data/mysql/atomicupdate/bug-22630.perl b/installer/data/mysql/atomicupdate/bug-22630.perl new file mode 100644 index 0000000000..02b7fab10b --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug-22630.perl @@ -0,0 +1,13 @@ +$DBversion = 'XXX'; +if (CheckVersion($DBversion)) { + if (!column_exists('course_items', 'homebranch')) { + $dbh->do(q{ + ALTER TABLE course_items + ADD COLUMN homebranch VARCHAR(10) NULL DEFAULT NULL AFTER ccode, + ADD CONSTRAINT course_items_ibfk_3 FOREIGN KEY (homebranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE + }); + } + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 22630 - Add course_items.homebranch)\n"; +} diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index d5864d18d5..cd221a8cd6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3811,6 +3811,7 @@ CREATE TABLE `course_items` ( `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(80) DEFAULT NULL, -- new category code for the item to have while on reserve (optional) + `homebranch` varchar(10) DEFAULT NULL, -- new home branch 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) `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' @@ -3824,6 +3825,7 @@ CREATE TABLE `course_items` ( -- Constraints for table `course_items` -- ALTER TABLE `course_items` + ADD CONSTRAINT `course_items_ibfk_3` FOREIGN KEY (`homebranch`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE ON UPDATE CASCADE, 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 919c7d57c6..b59af815dd 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 @@ -83,6 +83,20 @@ +
  • + + +
  • +