@@ -, +, @@ different from the item's homebranch --- C4/CourseReserves.pm | 11 ++++- course_reserves/add_items.pl | 4 ++ .../data/mysql/atomicupdate/bug-22630.perl | 44 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 7 ++- .../course_reserves/add_items-step2.tt | 26 +++++++++++ .../modules/course_reserves/course-details.tt | 23 +++++++++- t/db_dependent/CourseReserves/CourseItems.t | 16 ++++++- 7 files changed, 127 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug-22630.perl --- a/C4/CourseReserves.pm +++ a/C4/CourseReserves.pm @@ -56,7 +56,7 @@ BEGIN { %EXPORT_TAGS = ( 'all' => \@EXPORT_OK ); $DEBUG = 0; - @FIELDS = ( 'itype', 'ccode', 'holdingbranch', 'location' ); + @FIELDS = ( 'itype', 'ccode', 'homebranch', 'holdingbranch', 'location' ); } =head1 NAME @@ -495,6 +495,7 @@ sub _AddCourseItem { my (%params) = @_; warn identify_myself(%params) if $DEBUG; + $params{homebranch} ||= undef; # Can't be empty string, FK constraint $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint my %data = map { $_ => $params{$_} } @FIELDS; @@ -524,6 +525,7 @@ sub _UpdateCourseItem { my $ci_id = $params{'ci_id'}; my $course_item = $params{'course_item'}; + $params{homebranch} ||= undef; # Can't be empty string, FK constraint $params{holdingbranch} ||= undef; # Can't be empty string, FK constraint return unless ( $ci_id || $course_item ); @@ -539,6 +541,7 @@ sub _UpdateCourseItem { $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled; $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled; $item_fields->{location} = $course_item->location if $course_item->location_enabled; + $item_fields->{homebranch} = $course_item->homebranch if $course_item->homebranch_enabled; $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled; Koha::Items->find( $course_item->itemnumber ) @@ -572,6 +575,7 @@ sub _RevertFields { $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled; $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled; $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled; + $item_fields->{homebranch} = $course_item->homebranch_storage if $course_item->homebranch_enabled; $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled; Koha::Items->find( $course_item->itemnumber ) @@ -582,6 +586,7 @@ sub _RevertFields { $course_item->itype_storage(undef); $course_item->ccode_storage(undef); $course_item->location_storage(undef); + $course_item->homebranch_storage(undef); $course_item->holdingbranch_storage(undef); $course_item->store(); } @@ -603,6 +608,7 @@ sub _SwapAllFields { $course_item->itype_storage( $item->effective_itemtype ) if $course_item->itype_enabled; $course_item->ccode_storage( $item->ccode ) if $course_item->ccode_enabled; $course_item->location_storage( $item->location ) if $course_item->location_enabled; + $course_item->homebranch_storage( $item->homebranch ) if $course_item->homebranch_enabled; $course_item->holdingbranch_storage( $item->holdingbranch ) if $course_item->holdingbranch_enabled; $course_item->store(); @@ -610,6 +616,7 @@ sub _SwapAllFields { $item_fields->{itype} = $course_item->itype if $course_item->itype_enabled; $item_fields->{ccode} = $course_item->ccode if $course_item->ccode_enabled; $item_fields->{location} = $course_item->location if $course_item->location_enabled; + $item_fields->{homebranch} = $course_item->homebranch if $course_item->homebranch_enabled; $item_fields->{holdingbranch} = $course_item->holdingbranch if $course_item->holdingbranch_enabled; Koha::Items->find( $course_item->itemnumber ) @@ -622,6 +629,7 @@ sub _SwapAllFields { $item_fields->{itype} = $course_item->itype_storage if $course_item->itype_enabled; $item_fields->{ccode} = $course_item->ccode_storage if $course_item->ccode_enabled; $item_fields->{location} = $course_item->location_storage if $course_item->location_enabled; + $item_fields->{homebranch} = $course_item->homebranch_storage if $course_item->homebranch_enabled; $item_fields->{holdingbranch} = $course_item->holdingbranch_storage if $course_item->holdingbranch_enabled; Koha::Items->find( $course_item->itemnumber ) @@ -632,6 +640,7 @@ sub _SwapAllFields { $course_item->itype_storage(undef); $course_item->ccode_storage(undef); $course_item->location_storage(undef); + $course_item->homebranch_storage(undef); $course_item->holdingbranch_storage(undef); $course_item->store(); } --- a/course_reserves/add_items.pl +++ a/course_reserves/add_items.pl @@ -93,11 +93,13 @@ if ( $action eq 'lookup' and $item ) { } elsif ( $action eq 'add' ) { my $itype = scalar $cgi->param('itype'); my $ccode = scalar $cgi->param('ccode'); + my $homebranch = $cgi->param('homebranch'); my $holdingbranch = scalar $cgi->param('holdingbranch'); my $location = scalar $cgi->param('location'); my $itype_enabled = scalar $cgi->param('itype_enabled') ? 1 : 0; my $ccode_enabled = scalar $cgi->param('ccode_enabled') ? 1 : 0; + my $homebranch_enabled = $cgi->param('homebranch_enabled') ? 1 : 0; my $holdingbranch_enabled = scalar $cgi->param('holdingbranch_enabled') ? 1 : 0; my $location_enabled = scalar $cgi->param('location_enabled') ? 1 : 0; @@ -105,10 +107,12 @@ if ( $action eq 'lookup' and $item ) { itemnumber => $itemnumber, itype => $itype, ccode => $ccode, + homebranch => $homebranch, holdingbranch => $holdingbranch, location => $location, itype_enabled => $itype_enabled, ccode_enabled => $ccode_enabled, + homebranch_enabled => $homebranch_enabled, holdingbranch_enabled => $holdingbranch_enabled, location_enabled => $location_enabled, ); --- a/installer/data/mysql/atomicupdate/bug-22630.perl +++ a/installer/data/mysql/atomicupdate/bug-22630.perl @@ -0,0 +1,44 @@ +$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_storage + }); + } + + if (!foreign_key_exists('course_items', 'fk_course_items_homebranch')) { + $dbh->do(q{ + ALTER TABLE course_items + ADD CONSTRAINT fk_course_items_homebranch + FOREIGN KEY (homebranch) REFERENCES branches (branchcode) + ON DELETE CASCADE ON UPDATE CASCADE + }); + } + + if (!column_exists('course_items', 'homebranch_enabled')) { + $dbh->do(q{ + ALTER TABLE course_items + ADD COLUMN homebranch_enabled tinyint(1) NOT NULL DEFAULT 0 AFTER homebranch + }); + } + + if (!column_exists('course_items', 'homebranch_storage')) { + $dbh->do(q{ + ALTER TABLE course_items + ADD COLUMN homebranch_storage VARCHAR(10) NULL DEFAULT NULL AFTER homebranch_enabled + }); + } + + if (!foreign_key_exists('course_items', 'fk_course_items_homebranch_storage')) { + $dbh->do(q{ + ALTER TABLE course_items + ADD CONSTRAINT fk_course_items_homebranch_storage + FOREIGN KEY (homebranch_storage) REFERENCES branches (branchcode) + ON DELETE CASCADE ON UPDATE CASCADE + }); + } + + SetVersion($DBversion); + print "Upgrade to $DBversion done (Bug 22630 - Add course_items.homebranch)\n"; +} --- a/installer/data/mysql/kohastructure.sql +++ a/installer/data/mysql/kohastructure.sql @@ -3823,6 +3823,9 @@ CREATE TABLE `course_items` ( `ccode` varchar(80) DEFAULT NULL, -- new category code for the item to have while on reserve (optional) `ccode_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if ccode should be changed while on course reserve `ccode_storage` varchar(80) DEFAULT NULL, -- a place to store the ccode when item is on course reserve + `homebranch` varchar(10) DEFAULT NULL, -- new home branch for the item to have while on reserve (optional) + `homebranch_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if homebranch should be changed while on course reserve + `homebranch_storage` varchar(10) DEFAULT NULL, -- a place to store the homebranch when item is on course reserve `holdingbranch` varchar(10) DEFAULT NULL, -- new holding branch for the item to have while on reserve (optional) `holdingbranch_enabled` tinyint(1) NOT NULL DEFAULT 0, -- indicates if itype should be changed while on course reserve `holdingbranch_storage` varchar(10) DEFAULT NULL, -- a place to store the holdingbranch when item is on course reserve @@ -3841,7 +3844,9 @@ CREATE 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; + ADD CONSTRAINT `course_items_ibfk_1` FOREIGN KEY (`itemnumber`) REFERENCES `items` (`itemnumber`) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT fk_course_items_homebranch FOREIGN KEY (homebranch) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE, + ADD CONSTRAINT fk_course_items_homebranch_storage FOREIGN KEY (homebranch_storage) REFERENCES branches (branchcode) ON DELETE CASCADE ON UPDATE CASCADE; -- -- Table structure for table `course_reserves` --- a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/course_reserves/add_items-step2.tt @@ -117,6 +117,32 @@ +