From daa62c36e752cf7ff9fd80f06b9043fd0062e0e2 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 24 Nov 2017 13:56:04 +0100 Subject: [sysconfig] Simplify installer, add constraint to location table --- modules-available/sysconfig/install.inc.php | 37 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'modules-available/sysconfig') diff --git a/modules-available/sysconfig/install.inc.php b/modules-available/sysconfig/install.inc.php index 91f282dd..251b3de9 100644 --- a/modules-available/sysconfig/install.inc.php +++ b/modules-available/sysconfig/install.inc.php @@ -39,21 +39,29 @@ $res[] = tableCreate('configtgz_location', " // Constraints if (in_array(UPDATE_DONE, $res)) { - $ret = Database::exec("ALTER TABLE `configtgz_x_module` - ADD CONSTRAINT `configtgz_x_module_ibfk_1` FOREIGN KEY (`configid`) REFERENCES `configtgz` (`configid`) - ON DELETE CASCADE"); - $ret = Database::exec("ALTER TABLE `configtgz_x_module` - ADD CONSTRAINT `configtgz_x_module_ibfk_2` FOREIGN KEY (`moduleid`) REFERENCES `configtgz_module` (`moduleid`)") || $ret; - $ret = Database::exec("ALTER TABLE `configtgz_location` - ADD CONSTRAINT `configtgz_location_fk_configid` FOREIGN KEY ( `configid` ) REFERENCES `openslx`.`configtgz` (`configid`) - ON DELETE CASCADE ON UPDATE CASCADE") || $ret; - if ($ret) { - $res[] = UPDATE_DONE; - } + // To self + $res[] = tableAddConstraint('configtgz_x_module', 'configid', 'configtgz', 'configid', + ''); + $res[] = tableAddConstraint('configtgz_x_module', 'moduleid', 'configtgz_module', 'moduleid', + ''); + $res[] = tableAddConstraint('configtgz_location', 'configid', 'configtgz', 'configid', + 'ON DELETE CASCADE ON UPDATE CASCADE'); +} +// To location +if (tableExists('location')) { + // Cleanup from when we didn't have the constraint + Database::exec("DELETE c FROM configtgz_location c + LEFT JOIN location l USING (locationid) + WHERE l.locationid IS NULL"); + $res[] = tableAddConstraint('configtgz_location', 'locationid', 'location', 'locationid', + 'ON UPDATE CASCADE ON DELETE CASCADE'); +} elseif (Module::get('locations') !== false) { + $res[] = UPDATE_RETRY; } // Update path +// ####################### // ##### 2014-12-12 // Rename config modules Database::exec("UPDATE configtgz_module SET moduletype = 'Branding' WHERE moduletype = 'BRANDING'"); @@ -98,9 +106,4 @@ if ($list === false) { } // Create response for browser - -if (in_array(UPDATE_DONE, $res)) { - finalResponse(UPDATE_DONE, 'Tables created successfully'); -} - -finalResponse(UPDATE_NOOP, 'Everything already up to date'); +responseFromArray($res); -- cgit v1.2.3-55-g7522