From: Alexander Ebert Date: Mon, 21 Dec 2020 16:41:54 +0000 (+0100) Subject: Preserve the package server credentials when upgrading from 5.2 -> 5.3 X-Git-Tag: 5.3.2~13^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=849248532d22a13da4aa93191292637c67baaef0;p=GitHub%2FWoltLab%2FWCF.git Preserve the package server credentials when upgrading from 5.2 -> 5.3 Fixes #3805 --- diff --git a/com.woltlab.wcf/package.xml b/com.woltlab.wcf/package.xml index 235d02156d..a6732adcc4 100644 --- a/com.woltlab.wcf/package.xml +++ b/com.woltlab.wcf/package.xml @@ -102,6 +102,8 @@ update_5.3.sql + + acp/update_com.woltlab.wcf_5.3_packageServer.php diff --git a/com.woltlab.wcf/update_5.3.sql b/com.woltlab.wcf/update_5.3.sql index fb603493e7..852fab8559 100644 --- a/com.woltlab.wcf/update_5.3.sql +++ b/com.woltlab.wcf/update_5.3.sql @@ -1,7 +1 @@ DELETE FROM wcf1_style_variable WHERE variableName = 'useGoogleFont'; - --- Purge the existing official package servers to clean up any mess. -DELETE FROM wcf1_package_update_server WHERE LOWER(serverURL) REGEXP 'https?://(store|update)\.woltlab\.com/.*'; - --- Insert the default official package servers that will be dynamically adjusted. -INSERT INTO wcf1_package_update_server (serverURL) VALUES ('http://update.woltlab.com/5.3/'), ('http://store.woltlab.com/5.3/'); diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3_packageServer.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3_packageServer.php new file mode 100644 index 0000000000..d762d69760 --- /dev/null +++ b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3_packageServer.php @@ -0,0 +1,56 @@ +prepareStatement($sql); +$statement->execute(); + +// Try to extract authentication credentials from the previous package servers. +$newServers = [ + "update" => [ + "loginUsername" => "", + "loginPassword" => "", + ], + "store" => [ + "loginUsername" => "", + "loginPassword" => "", + ], +]; + +$deleteServerIDs = []; +while ($row = $statement->fetchArray()) { + $deleteServerIDs[] = $row["packageUpdateServerID"]; + + // Only use values from the "2019" servers to avoid dealing with outdated + // credentials that have never been updated. + $serverURL = $row["serverURL"]; + if (preg_match("~^https?://update\.woltlab\.com/2019/~", $serverURL)) { + $newServers["update"]["loginUsername"] = $row["loginUsername"]; + $newServers["update"]["loginPassword"] = $row["loginPassword"]; + } + else if (preg_match("~^https?://store\.woltlab\.com/2019/~", $serverURL)) { + $newServers["store"]["loginUsername"] = $row["loginUsername"]; + $newServers["store"]["loginPassword"] = $row["loginPassword"]; + } +} + +if (!empty($deleteServerIDs)) { + PackageUpdateServerEditor::deleteAll($deleteServerIDs); +} + +// Add the new package servers. +$sql = "INSERT INTO wcf" . WCF_N . "_package_update_server (serverURL, loginUsername, loginPassword) VALUES (?, ?, ?)"; +$statement = WCF::getDB()->prepareStatement($sql); +foreach ($newServers as $server => $authData) { + $statement->execute([ + "https://{$server}.woltlab.com/5.3/", + $authData["loginUsername"], + $authData["loginPassword"], + ]); +}