Preserve the package server credentials when upgrading from 5.2 -> 5.3
authorAlexander Ebert <ebert@woltlab.com>
Mon, 21 Dec 2020 16:41:54 +0000 (17:41 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 21 Dec 2020 16:41:54 +0000 (17:41 +0100)
Fixes #3805

com.woltlab.wcf/package.xml
com.woltlab.wcf/update_5.3.sql
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.3_packageServer.php [new file with mode: 0644]

index 235d02156dafae8c17b1137cb835fb1896c11614..a6732adcc42c6659dd3fd995ee14fecbc3804429 100644 (file)
                <!-- This SQL step purges the legacy package servers, this must come last to make sure that an early
                     abort of the core upgrade does not brick the installation. -->
                <instruction type="sql">update_5.3.sql</instruction>
+               
+               <instruction type="script">acp/update_com.woltlab.wcf_5.3_packageServer.php</instruction>
        </instructions>
        
        <!-- Run update_com.woltlab.wcf_5.3.2_style.php for 5.3.1 -> 5.3.2 -->
index fb603493e7733ef7ed9024c21b11aa25b5231ed9..852fab855912b934bcae11db387a419230daf35f 100644 (file)
@@ -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 (file)
index 0000000..d762d69
--- /dev/null
@@ -0,0 +1,56 @@
+<?php
+namespace wcf\acp;
+use wcf\data\package\update\server\PackageUpdateServerEditor;
+use wcf\system\WCF;
+
+// Do not use the `PackageUpdateServer` classes because we need to access
+// the raw server URL that is implicitly rewritten in 5.3.
+$sql = "SELECT  *
+       FROM    wcf1_package_update_server
+       WHERE   LOWER(serverURL) REGEXP 'https?://(store|update)\.woltlab\.com/.*'";
+$statement = WCF::getDB()->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"],
+       ]);
+}