Split first time setup into multiple pages
authorTim Düsterhus <duesterhus@woltlab.com>
Mon, 6 Mar 2023 13:47:15 +0000 (14:47 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Mon, 17 Apr 2023 16:45:09 +0000 (18:45 +0200)
wcfsetup/install/files/acp/templates/firstTimeSetup.tpl [deleted file]
wcfsetup/install/files/acp/templates/firstTimeSetupCompleted.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/firstTimeSetupOptions.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/acp/action/FirstTimeSetupAction.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php [deleted file]
wcfsetup/install/files/lib/acp/form/FirstTimeSetupOptionsForm.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/acp/page/FirstTimeSetupCompletedPage.class.php [new file with mode: 0644]
wcfsetup/install/files/lib/acp/page/IndexPage.class.php
wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php

diff --git a/wcfsetup/install/files/acp/templates/firstTimeSetup.tpl b/wcfsetup/install/files/acp/templates/firstTimeSetup.tpl
deleted file mode 100644 (file)
index ee8fe1f..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-{include file='header' pageTitle='wcf.acp.option.firstTimeSetup'}
-
-{event name='javascriptInclude'}
-
-<script data-relocate="true">
-       $(function() {
-               new WCF.Option.Handler();
-       });
-       
-       {event name='javascriptInit'}
-</script>
-
-<header class="contentHeader">
-       <div class="contentHeaderTitle">
-               <h1 class="contentTitle">{lang}wcf.acp.option.firstTimeSetup{/lang}</h1>
-               <p class="contentHeaderDescription">{lang}wcf.acp.option.firstTimeSetup.description{/lang}</p>
-       </div>
-       
-       {hascontent}
-               <nav class="contentHeaderNavigation">
-                       <ul>
-                               {content}
-                                       <li><a href="{link}{/link}" class="button">{icon name='house'} <span>{lang}wcf.global.acp{/lang}</span></a></li>
-                                       
-                                       {event name='contentHeaderNavigation'}
-                               {/content}
-                       </ul>
-               </nav>
-       {/hascontent}
-</header>
-
-{if $success|isset}
-       <p class="success">{lang}wcf.global.success.edit{/lang}</p>
-{/if}
-
-{include file='formError'}
-
-<form method="post" action="{link controller='FirstTimeSetup'}{/link}" enctype="multipart/form-data">
-       {include file='optionFieldList' langPrefix='wcf.acp.option.'}
-       
-       <div class="formSubmit">
-               <input type="submit" value="{lang}wcf.global.button.submit{/lang}" name="__submit" accesskey="s">
-               {csrfToken}
-       </div>
-</form>
-
-{include file='footer'}
diff --git a/wcfsetup/install/files/acp/templates/firstTimeSetupCompleted.tpl b/wcfsetup/install/files/acp/templates/firstTimeSetupCompleted.tpl
new file mode 100644 (file)
index 0000000..6ffb55d
--- /dev/null
@@ -0,0 +1,21 @@
+{include file='header' pageTitle='wcf.acp.firstTimeSetup.completed'}
+
+<header class="contentHeader">
+       <div class="contentHeaderTitle">
+               <h1 class="contentTitle">{lang}wcf.acp.firstTimeSetup.completed{/lang}</h1>
+       </div>
+       
+       {hascontent}
+               <nav class="contentHeaderNavigation">
+                       <ul>
+                               {content}
+                                       <li><a href="{link}{/link}" class="button">{icon name='house'} <span>{lang}wcf.global.acp{/lang}</span></a></li>
+                                       
+                                       {event name='contentHeaderNavigation'}
+                               {/content}
+                       </ul>
+               </nav>
+       {/hascontent}
+</header>
+
+{include file='footer'}
diff --git a/wcfsetup/install/files/acp/templates/firstTimeSetupOptions.tpl b/wcfsetup/install/files/acp/templates/firstTimeSetupOptions.tpl
new file mode 100644 (file)
index 0000000..a252018
--- /dev/null
@@ -0,0 +1,47 @@
+{include file='header' pageTitle='wcf.acp.option.firstTimeSetup'}
+
+{event name='javascriptInclude'}
+
+<script data-relocate="true">
+       $(function() {
+               new WCF.Option.Handler();
+       });
+       
+       {event name='javascriptInit'}
+</script>
+
+<header class="contentHeader">
+       <div class="contentHeaderTitle">
+               <h1 class="contentTitle">{lang}wcf.acp.option.firstTimeSetup{/lang}</h1>
+               <p class="contentHeaderDescription">{lang}wcf.acp.option.firstTimeSetup.description{/lang}</p>
+       </div>
+       
+       {hascontent}
+               <nav class="contentHeaderNavigation">
+                       <ul>
+                               {content}
+                                       <li><a href="{link}{/link}" class="button">{icon name='house'} <span>{lang}wcf.global.acp{/lang}</span></a></li>
+                                       
+                                       {event name='contentHeaderNavigation'}
+                               {/content}
+                       </ul>
+               </nav>
+       {/hascontent}
+</header>
+
+{if $success|isset}
+       <p class="success">{lang}wcf.global.success.edit{/lang}</p>
+{/if}
+
+{include file='formError'}
+
+<form method="post" action="{link controller='FirstTimeSetupOptions'}{/link}" enctype="multipart/form-data">
+       {include file='optionFieldList' langPrefix='wcf.acp.option.'}
+       
+       <div class="formSubmit">
+               <input type="submit" value="{lang}wcf.global.button.submit{/lang}" name="__submit" accesskey="s">
+               {csrfToken}
+       </div>
+</form>
+
+{include file='footer'}
diff --git a/wcfsetup/install/files/lib/acp/action/FirstTimeSetupAction.class.php b/wcfsetup/install/files/lib/acp/action/FirstTimeSetupAction.class.php
new file mode 100644 (file)
index 0000000..b2fbb1b
--- /dev/null
@@ -0,0 +1,37 @@
+<?php
+
+namespace wcf\acp\action;
+
+use Laminas\Diactoros\Response\RedirectResponse;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Server\RequestHandlerInterface;
+use wcf\acp\form\FirstTimeSetupOptionsForm;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+
+/**
+ * Dispatches to the first time setup steps.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+final class FirstTimeSetupAction implements RequestHandlerInterface
+{
+    public function handle(ServerRequestInterface $request): ResponseInterface
+    {
+        WCF::getSession()->checkPermissions([
+            'admin.general.canUseAcp',
+        ]);
+
+        $controller = match (\FIRST_TIME_SETUP_STATE) {
+            0 => FirstTimeSetupOptionsForm::class,
+            default => FirstTimeSetupCompletedPage::class
+        };
+
+        return new RedirectResponse(LinkHandler::getInstance()->getControllerLink(
+            $controller
+        ), 303);
+    }
+}
diff --git a/wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php
deleted file mode 100644 (file)
index a61bfaf..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-<?php
-
-namespace wcf\acp\form;
-
-use wcf\data\option\Option;
-use wcf\data\option\OptionAction;
-use wcf\system\option\OptionHandler;
-use wcf\system\WCF;
-
-/**
- * Shows the option edit form.
- *
- * @author      Alexander Ebert
- * @copyright   2001-2019 WoltLab GmbH
- * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- *
- * @property OptionHandler $optionHandler
- */
-class FirstTimeSetupForm extends AbstractOptionListForm
-{
-    /**
-     * @inheritDoc
-     */
-    public $activeMenuItem = 'wcf.acp.menu.link.configuration';
-
-    /**
-     * @inheritDoc
-     */
-    public $neededPermissions = ['admin.configuration.canEditOption'];
-
-    /**
-     * list of options
-     * @var array
-     */
-    public $options = [];
-
-    /**
-     * @var string[]
-     */
-    public $optionNames = [
-        'page_title',
-        'timezone',
-        'mail_from_name',
-        'mail_from_address',
-        'mail_admin_address',
-        'module_contact_form',
-        'package_server_auth_code',
-    ];
-
-    /**
-     * @inheritDoc
-     */
-    protected function initOptionHandler()
-    {
-        parent::initOptionHandler();
-
-        $this->optionHandler->filterOptions($this->optionNames);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function readData()
-    {
-        parent::readData();
-
-        foreach ($this->optionNames as $optionName) {
-            $this->options[] = $this->optionHandler->getSingleOption($optionName);
-        }
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function save()
-    {
-        parent::save();
-
-        $saveOptions = $this->optionHandler->save('wcf.acp.option', 'wcf.acp.option.option');
-        $saveOptions[Option::getOptionByName('offline')->optionID] = 0;
-        $saveOptions[Option::getOptionByName('first_time_setup_state')->optionID] = 1;
-        $this->objectAction = new OptionAction([], 'updateAll', ['data' => $saveOptions]);
-        $this->objectAction->executeAction();
-        $this->saved();
-
-        WCF::getTPL()->assign('success', true);
-    }
-
-    /**
-     * @inheritDoc
-     */
-    public function assignVariables()
-    {
-        parent::assignVariables();
-
-        WCF::getTPL()->assign([
-            'options' => $this->options,
-            'optionNames' => $this->optionNames,
-        ]);
-    }
-}
diff --git a/wcfsetup/install/files/lib/acp/form/FirstTimeSetupOptionsForm.class.php b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupOptionsForm.class.php
new file mode 100644 (file)
index 0000000..8783463
--- /dev/null
@@ -0,0 +1,107 @@
+<?php
+
+namespace wcf\acp\form;
+
+use wcf\data\option\Option;
+use wcf\data\option\OptionAction;
+use wcf\system\option\OptionHandler;
+use wcf\system\request\LinkHandler;
+use wcf\system\WCF;
+use wcf\util\HeaderUtil;
+
+/**
+ * Shows the option edit form.
+ *
+ * @author      Alexander Ebert
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ *
+ * @property OptionHandler $optionHandler
+ */
+final class FirstTimeSetupOptionsForm extends AbstractOptionListForm
+{
+    /**
+     * @inheritDoc
+     */
+    public $activeMenuItem = 'wcf.acp.menu.link.configuration';
+
+    /**
+     * @inheritDoc
+     */
+    public $neededPermissions = ['admin.configuration.canEditOption'];
+
+    /**
+     * list of options
+     * @var array
+     */
+    public $options = [];
+
+    /**
+     * @var string[]
+     */
+    public $optionNames = [
+        'page_title',
+        'timezone',
+        'mail_from_name',
+        'mail_from_address',
+        'mail_admin_address',
+        'module_contact_form',
+        'package_server_auth_code',
+    ];
+
+    /**
+     * @inheritDoc
+     */
+    protected function initOptionHandler()
+    {
+        parent::initOptionHandler();
+
+        $this->optionHandler->filterOptions($this->optionNames);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function readData()
+    {
+        parent::readData();
+
+        foreach ($this->optionNames as $optionName) {
+            $this->options[] = $this->optionHandler->getSingleOption($optionName);
+        }
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function save()
+    {
+        parent::save();
+
+        $saveOptions = $this->optionHandler->save('wcf.acp.option', 'wcf.acp.option.option');
+        $saveOptions[Option::getOptionByName('first_time_setup_state')->optionID] = 1;
+        $this->objectAction = new OptionAction([], 'updateAll', ['data' => $saveOptions]);
+        $this->objectAction->executeAction();
+        $this->saved();
+
+        \http_response_code(303);
+        HeaderUtil::redirect(LinkHandler::getInstance()->getControllerLink(
+            FirstTimeSetupAction::class,
+        ));
+
+        exit;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public function assignVariables()
+    {
+        parent::assignVariables();
+
+        WCF::getTPL()->assign([
+            'options' => $this->options,
+            'optionNames' => $this->optionNames,
+        ]);
+    }
+}
diff --git a/wcfsetup/install/files/lib/acp/page/FirstTimeSetupCompletedPage.class.php b/wcfsetup/install/files/lib/acp/page/FirstTimeSetupCompletedPage.class.php
new file mode 100644 (file)
index 0000000..2c62a64
--- /dev/null
@@ -0,0 +1,41 @@
+<?php
+
+namespace wcf\acp\page;
+
+use wcf\data\option\Option;
+use wcf\data\option\OptionAction;
+use wcf\page\AbstractPage;
+
+/**
+ * Shows a success page for the completed first time setup.
+ *
+ * @author  Tim Duesterhus
+ * @copyright   2001-2023 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ */
+final class FirstTimeSetupCompletedPage extends AbstractPage
+{
+    /**
+     * @inheritDoc
+     */
+    public $neededPermissions = ['admin.general.canUseAcp'];
+
+    public function readData()
+    {
+        parent::readData();
+
+        if (\FIRST_TIME_SETUP_STATE != -1) {
+            $objectAction = new OptionAction(
+                [],
+                'updateAll',
+                [
+                    'data' => [
+                        Option::getOptionByName('offline')->optionID => 0,
+                        Option::getOptionByName('first_time_setup_state')->optionID => -1,
+                    ],
+                ]
+            );
+            $objectAction->executeAction();
+        }
+    }
+}
index 6a4d3f241a31c3420f1019d5379e9c2f7cc223b1..ece19d3b303cdab16b91096ddbb785cf06156424 100755 (executable)
@@ -2,7 +2,7 @@
 
 namespace wcf\acp\page;
 
-use wcf\acp\form\FirstTimeSetupForm;
+use wcf\acp\action\FirstTimeSetupAction;
 use wcf\data\devtools\missing\language\item\DevtoolsMissingLanguageItemList;
 use wcf\data\package\installation\queue\PackageInstallationQueue;
 use wcf\data\user\User;
@@ -219,9 +219,9 @@ class IndexPage extends AbstractPage
             exit;
         }
 
-        if (\FIRST_TIME_SETUP_STATE != 1) {
+        if (\FIRST_TIME_SETUP_STATE != -1) {
             HeaderUtil::redirect(LinkHandler::getInstance()->getControllerLink(
-                FirstTimeSetupForm::class,
+                FirstTimeSetupAction::class,
             ));
 
             exit;
index 49b3c17a6c753895e15e55c74590c080afe76696..8a68e6dddcd1e3cc4e841fe02760282a89373b89 100644 (file)
@@ -348,7 +348,7 @@ class PackageInstallationDispatcher
             'offline',
         ]);
         $statement->execute([
-            1,
+            -1,
             'first_time_setup_state',
         ]);