@@ -, +, @@ 3.20.x to 3.22.x --- installer/data/mysql/updatedatabase.pl | 36 +++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) --- a/installer/data/mysql/updatedatabase.pl +++ a/installer/data/mysql/updatedatabase.pl @@ -10801,12 +10801,34 @@ if ( CheckVersion($DBversion) ) { LEFT JOIN course_items USING(ci_id) WHERE course_items.ci_id IS NULL }); - $dbh->do(q{ - ALTER IGNORE TABLE course_reserves - add CONSTRAINT course_reserves_ibfk_2 - FOREIGN KEY (ci_id) REFERENCES course_items (ci_id) - ON DELETE CASCADE ON UPDATE CASCADE - }); + my $dbconfigured = C4::Context->config("database"); + my $count_course_reserves_ibfk_2 = $dbh->selectrow_arrayref(qq| + SELECT COUNT(*) + FROM information_schema.table_constraints + WHERE table_schema = '$dbconfigured' + AND table_name = 'course_reserves' + AND CONSTRAINT_NAME = 'course_reserves_ibfk_2' + |); + #Add fk only if not present + if ( $count_course_reserves_ibfk_2-->[0] == 0) { + $dbh->do(q{ + ALTER IGNORE TABLE course_reserves + add CONSTRAINT course_reserves_ibfk_2 + FOREIGN KEY (ci_id) REFERENCES course_items (ci_id) + ON DELETE CASCADE ON UPDATE CASCADE + }); + }else{ + $dbh->do(q{ + ALTER IGNORE TABLE course_reserves + DROP FOREIGN KEY course_reserves_ibfk_2; + }); + $dbh->do(q{ + ALTER IGNORE TABLE course_reserves + add CONSTRAINT course_reserves_ibfk_2 + FOREIGN KEY (ci_id) REFERENCES course_items (ci_id) + ON DELETE CASCADE ON UPDATE CASCADE + }); + }; print "Upgrade to $DBversion done (Bug 14205: Deleting an Item/Record does not remove link to course reserve)\n"; SetVersion($DBversion); } @@ -10869,7 +10891,7 @@ if ( CheckVersion($DBversion) ) { $DBversion = "3.21.00.027"; if ( CheckVersion($DBversion) ) { $dbh->do(q| - INSERT INTO permissions (module_bit, code, description) + INSERT IGNORE INTO permissions (module_bit, code, description) VALUES (1, 'self_checkout', 'Perform self checkout at the OPAC. It should be used for the patron matching the AutoSelfCheckID') |); --