From c2aa47f3cfbfb994439328dd7c045645d08ce4b0 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 11 Sep 2020 14:38:30 +0200 Subject: [locations] install: Make openingtime migration a bit more robust This decouples column creation in location table from checking existence of the old column in locationinfo_locationconfig. In case import fails the first time, this will simply "resume" the update in case it is triggered a second time. --- modules-available/locations/install.inc.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'modules-available') diff --git a/modules-available/locations/install.inc.php b/modules-available/locations/install.inc.php index 9a232829..5664c7ed 100644 --- a/modules-available/locations/install.inc.php +++ b/modules-available/locations/install.inc.php @@ -15,6 +15,7 @@ $res[] = tableCreate('location', ' `locationid` INT(11) NOT NULL AUTO_INCREMENT, `parentlocationid` INT(11) NOT NULL, `locationname` VARCHAR(100) NOT NULL, + `openingtime` BLOB, PRIMARY KEY (`locationid`), KEY `locationname` (`locationname`), KEY `parentlocationid` (`parentlocationid`) @@ -38,24 +39,25 @@ $res[] = tableAddConstraint('setting_location', 'locationid', 'location', 'locat // Update // 2020-07-14 Add openingtime column to location table, then migrate data and delete the column from locationinfo - if (!tableHasColumn('location', 'openingtime')) { if (Database::exec("ALTER TABLE location ADD openingtime BLOB") === false) { finalResponse(UPDATE_FAILED, 'Could not create openingtime column'); - } else { - if (Module::get('locationinfo') !== false) { - if (Database::exec( - "UPDATE location, locationinfo_locationconfig + } + $res[] = UPDATE_DONE; +} +if (tableHasColumn('locationinfo_locationconfig', 'openingtime')) { + if (Database::exec( + "UPDATE location, locationinfo_locationconfig SET location.openingtime = locationinfo_locationconfig.openingtime - WHERE location.locationid = locationinfo_locationconfig.locationid") === false) { - finalResponse(UPDATE_FAILED, 'Could not migrate openingtime data from table to table'); - } - if (Database::exec("ALTER TABLE locationinfo_locationconfig DROP COLUMN openingtime") === false) { - finalResponse(UPDATE_FAILED, 'Could not delete openingtime column'); - } - $res[] = UPDATE_DONE; - } + WHERE location.locationid = locationinfo_locationconfig.locationid + AND Length(location.openingtime) < 5 + AND Length(locationinfo_locationconfig.openingtime) > 5") === false) { + finalResponse(UPDATE_FAILED, 'Could not migrate openingtime data from table to table'); + } + if (Database::exec("ALTER TABLE locationinfo_locationconfig DROP COLUMN openingtime") === false) { + finalResponse(UPDATE_FAILED, 'Could not delete old openingtime column'); } + $res[] = UPDATE_DONE; } // Create response for browser -- cgit v1.2.3-55-g7522