Merge pull request #4283 from WoltLab/devtools_package_server
authorMatthias Schmidt <gravatronics@live.com>
Mon, 14 Jun 2021 09:25:28 +0000 (11:25 +0200)
committerGitHub <noreply@github.com>
Mon, 14 Jun 2021 09:25:28 +0000 (11:25 +0200)
Support adding WoltLab package server login credentials to dev config file

extra/examples/wsc-dev-config-54.json [deleted file]
extra/examples/wsc-dev-config-55.json [new file with mode: 0644]
wcfsetup/install/files/lib/system/devtools/DevtoolsSetup.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

diff --git a/extra/examples/wsc-dev-config-54.json b/extra/examples/wsc-dev-config-54.json
deleted file mode 100644 (file)
index 605aa81..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-{
-    "setup": {
-        "database": {
-            "auto": true,
-            "host": "localhost",
-            "password": "root",
-            "username": "root",
-            "dbNumber": "2"
-        },
-        "useDefaultInstallPath": true,
-        "forceStaticCookiePrefix": true
-    },
-    "configuration": {
-        "option": {
-            "captcha_type": "",
-            "module_cookie_policy_page": "0"
-        },
-        "devtools": {
-            "importFromPath": "C:/inetpub/wwwroot/wcf/"
-        }
-    },
-    "user": [
-        {
-            "username": "test",
-            "password": "test",
-            "email": "test@example.com"
-        },
-        {
-            "username": "test2",
-            "password": "test",
-            "email": "test2@example.com"
-        }
-    ]
-}
diff --git a/extra/examples/wsc-dev-config-55.json b/extra/examples/wsc-dev-config-55.json
new file mode 100644 (file)
index 0000000..605aa81
--- /dev/null
@@ -0,0 +1,34 @@
+{
+    "setup": {
+        "database": {
+            "auto": true,
+            "host": "localhost",
+            "password": "root",
+            "username": "root",
+            "dbNumber": "2"
+        },
+        "useDefaultInstallPath": true,
+        "forceStaticCookiePrefix": true
+    },
+    "configuration": {
+        "option": {
+            "captcha_type": "",
+            "module_cookie_policy_page": "0"
+        },
+        "devtools": {
+            "importFromPath": "C:/inetpub/wwwroot/wcf/"
+        }
+    },
+    "user": [
+        {
+            "username": "test",
+            "password": "test",
+            "email": "test@example.com"
+        },
+        {
+            "username": "test2",
+            "password": "test",
+            "email": "test2@example.com"
+        }
+    ]
+}
index 893dfc3054bf0ac61b4072958f6d6a646bdbdca2..ba35890fdf76fe314fb3e84dbe154bc5dad376b2 100644 (file)
@@ -22,7 +22,7 @@ class DevtoolsSetup extends SingletonFactory
      * configuration file in the server's document root
      * @var string
      */
-    const CONFIGURATION_FILE = 'wsc-dev-config-54.json';
+    const CONFIGURATION_FILE = 'wsc-dev-config-55.json';
 
     /**
      * configuration data
@@ -157,6 +157,18 @@ class DevtoolsSetup extends SingletonFactory
         return (isset($this->configuration['configuration']['devtools']) && !empty($this->configuration['configuration']['devtools']['importFromPath'])) ? $this->configuration['configuration']['devtools']['importFromPath'] : '';
     }
 
+    /**
+     * Returns the login data for the WoltLab package servers.
+     */
+    public function getPackageServerLogin(): array
+    {
+        if (isset($this->configuration['packageServerLogin']['username']) && $this->configuration['packageServerLogin']['password']) {
+            return $this->configuration['packageServerLogin'];
+        }
+
+        return [];
+    }
+
     /**
      * Returns the raw configuration data.
      *
index ee98ad09be42fdd1ef27de02a9ab36700c4efc10..6e628956fa7bc928be9a00c5ba3f3f10122c22b5 100644 (file)
@@ -261,58 +261,7 @@ class PackageInstallationDispatcher
                     );
 
                     if (WCF::getSession()->getVar('__wcfSetup_developerMode')) {
-                        $statement->execute([
-                            1,
-                            'enable_debug_mode',
-                        ]);
-                        $statement->execute([
-                            'public',
-                            'exception_privacy',
-                        ]);
-                        $statement->execute([
-                            'debugFolder',
-                            'mail_send_method',
-                        ]);
-                        $statement->execute([
-                            1,
-                            'enable_developer_tools',
-                        ]);
-                        $statement->execute([
-                            1,
-                            'log_missing_language_items',
-                        ]);
-
-                        foreach (DevtoolsSetup::getInstance()->getOptionOverrides() as $optionName => $optionValue) {
-                            $statement->execute([
-                                $optionValue,
-                                $optionName,
-                            ]);
-                        }
-
-                        foreach (DevtoolsSetup::getInstance()->getUsers() as $newUser) {
-                            try {
-                                (new UserAction([], 'create', [
-                                    'data' => [
-                                        'email' => $newUser['email'],
-                                        'password' => $newUser['password'],
-                                        'username' => $newUser['username'],
-                                    ],
-                                    'groups' => [
-                                        1,
-                                        3,
-                                    ],
-                                ]))->executeAction();
-                            } catch (SystemException $e) {
-                                // ignore errors due to event listeners missing at this
-                                // point during installation
-                            }
-                        }
-
-                        if (($importPath = DevtoolsSetup::getInstance()->getDevtoolsImportPath()) !== '') {
-                            (new DevtoolsProjectAction([], 'quickSetup', [
-                                'path' => $importPath,
-                            ]))->executeAction();
-                        }
+                        $this->setupDeveloperMode();
                     }
 
                     if (WCF::getSession()->getVar('__wcfSetup_imagick')) {
@@ -385,6 +334,85 @@ class PackageInstallationDispatcher
         return $step;
     }
 
+    /**
+     * @since   5.5
+     */
+    protected function setupDeveloperMode(): void
+    {
+        $sql = "UPDATE  wcf" . WCF_N . "_option
+                SET     optionValue = ?
+                WHERE   optionName = ?";
+        $statement = WCF::getDB()->prepareStatement($sql);
+
+        $statement->execute([
+            1,
+            'enable_debug_mode',
+        ]);
+        $statement->execute([
+            'public',
+            'exception_privacy',
+        ]);
+        $statement->execute([
+            'debugFolder',
+            'mail_send_method',
+        ]);
+        $statement->execute([
+            1,
+            'enable_developer_tools',
+        ]);
+        $statement->execute([
+            1,
+            'log_missing_language_items',
+        ]);
+
+        foreach (DevtoolsSetup::getInstance()->getOptionOverrides() as $optionName => $optionValue) {
+            $statement->execute([
+                $optionValue,
+                $optionName,
+            ]);
+        }
+
+        foreach (DevtoolsSetup::getInstance()->getUsers() as $newUser) {
+            try {
+                (new UserAction([], 'create', [
+                    'data' => [
+                        'email' => $newUser['email'],
+                        'password' => $newUser['password'],
+                        'username' => $newUser['username'],
+                    ],
+                    'groups' => [
+                        1,
+                        3,
+                    ],
+                ]))->executeAction();
+            } catch (SystemException $e) {
+                // ignore errors due to event listeners missing at this
+                // point during installation
+            }
+        }
+
+        $importPath = DevtoolsSetup::getInstance()->getDevtoolsImportPath();
+        if ($importPath !== '') {
+            (new DevtoolsProjectAction([], 'quickSetup', [
+                'path' => $importPath,
+            ]))->executeAction();
+        }
+
+        $packageServerLogin = DevtoolsSetup::getInstance()->getPackageServerLogin();
+        if (!empty($packageServerLogin)) {
+            // All update servers installed at this point are only our own servers for which the same
+            // login data can be used.
+            $sql = "UPDATE  wcf1_package_update_server
+                    SET     loginUsername = ?,
+                            loginPassword = ?";
+            $statement = WCF::getDB()->prepare($sql);
+            $statement->execute([
+                $packageServerLogin['username'],
+                $packageServerLogin['password'],
+            ]);
+        }
+    }
+
     /**
      * Logs an installation step.
      *