From cf93de9416d5cd1508bb8bafff5eee6dad4ba392 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 11 Jan 2019 13:41:48 +0100 Subject: [PATCH] Implemented the 'First Time Setup' page See #2797 --- .../files/acp/templates/firstTimeSetup.tpl | 47 +++++++++ .../acp/action/InstallPackageAction.class.php | 11 ++- .../lib/acp/form/FirstTimeSetupForm.class.php | 95 +++++++++++++++++++ .../lib/system/option/OptionHandler.class.php | 35 +++++-- .../PackageInstallationDispatcher.class.php | 2 + wcfsetup/install/lang/de.xml | 2 + wcfsetup/install/lang/en.xml | 2 + 7 files changed, 186 insertions(+), 8 deletions(-) create mode 100644 wcfsetup/install/files/acp/templates/firstTimeSetup.tpl create mode 100644 wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php diff --git a/wcfsetup/install/files/acp/templates/firstTimeSetup.tpl b/wcfsetup/install/files/acp/templates/firstTimeSetup.tpl new file mode 100644 index 0000000000..1281194bee --- /dev/null +++ b/wcfsetup/install/files/acp/templates/firstTimeSetup.tpl @@ -0,0 +1,47 @@ +{include file='header' pageTitle='wcf.acp.option.firstTimeSetup'} + +{event name='javascriptInclude'} + + + +
+
+

{lang}wcf.acp.option.firstTimeSetup{/lang}

+

{lang}wcf.acp.option.firstTimeSetup.description{/lang}

+
+ + {hascontent} + + {/hascontent} +
+ +{if $success|isset} +

{lang}wcf.global.success.edit{/lang}

+{/if} + +{include file='formError'} + +
+ {include file='optionFieldList' langPrefix='wcf.acp.option.'} + +
+ + {@SECURITY_TOKEN_INPUT_TAG} +
+
+ +{include file='footer'} diff --git a/wcfsetup/install/files/lib/acp/action/InstallPackageAction.class.php b/wcfsetup/install/files/lib/acp/action/InstallPackageAction.class.php index ea54f4033c..30b8877607 100755 --- a/wcfsetup/install/files/lib/acp/action/InstallPackageAction.class.php +++ b/wcfsetup/install/files/lib/acp/action/InstallPackageAction.class.php @@ -132,8 +132,15 @@ class InstallPackageAction extends AbstractDialogAction { /** @var Application $application */ $application = $statement->fetchObject(Application::class); - // do not use the LinkHandler here as it is sort of unreliable during WCFSetup - return $application->getPageURL() . 'acp/index.php?package-list/'; + $controller = 'package-list'; + if (WCF::getSession()->getVar('__wcfSetup_completed')) { + $controller = 'first-time-setup'; + + WCF::getSession()->unregister('__wcfSetup_completed'); + } + + // Do not use the LinkHandler here as it is sort of unreliable during WCFSetup. + return $application->getPageURL() . "acp/index.php?{$controller}/"; } /** diff --git a/wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php new file mode 100644 index 0000000000..f0a6e9878c --- /dev/null +++ b/wcfsetup/install/files/lib/acp/form/FirstTimeSetupForm.class.php @@ -0,0 +1,95 @@ + + * @package WoltLabSuite\Core\Acp\Form + * + * @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', + 'image_allow_external_source', + 'module_contact_form', + 'log_ip_address', + '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'); + $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/system/option/OptionHandler.class.php b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php index 5319887824..dc951fb0b6 100644 --- a/wcfsetup/install/files/lib/system/option/OptionHandler.class.php +++ b/wcfsetup/install/files/lib/system/option/OptionHandler.class.php @@ -15,7 +15,7 @@ use wcf\util\StringUtil; * Handles options. * * @author Alexander Ebert - * @copyright 2001-2018 WoltLab GmbH + * @copyright 2001-2019 WoltLab GmbH * @license GNU Lesser General Public License * @package WoltLabSuite\Core\System\Option */ @@ -24,7 +24,7 @@ class OptionHandler implements IOptionHandler { * list of application abbreviations * @var string[] */ - protected $abbreviations = null; + protected $abbreviations; /** * cache class name @@ -36,25 +36,25 @@ class OptionHandler implements IOptionHandler { * list of all option categories * @var OptionCategory[] */ - public $cachedCategories = null; + public $cachedCategories; /** * list of all options * @var Option[] */ - public $cachedOptions = null; + public $cachedOptions; /** * category structure * @var array */ - public $cachedCategoryStructure = null; + public $cachedCategoryStructure; /** * option structure * @var array */ - public $cachedOptionToCategories = null; + public $cachedOptionToCategories; /** * name of the active option category @@ -284,6 +284,17 @@ class OptionHandler implements IOptionHandler { ]; } + /** + * Wrapper function to preserve backwards compatibility with the visibility of `getOption()`. + * + * @param string $optionName + * @return array + * @since 3.2 + */ + public function getSingleOption($optionName) { + return $this->getOption($optionName); + } + /** * Validates an option. * @@ -415,6 +426,18 @@ class OptionHandler implements IOptionHandler { } } + /** + * Removes any option that is not listed in the provided list. + * + * @param string[] $optionNames + * @since 5.2 + */ + public function filterOptions(array $optionNames) { + $this->options = array_filter($this->options, function (Option $option) use ($optionNames) { + return in_array($option->optionName, $optionNames); + }); + } + /** * Creates a list of all active options. * diff --git a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php index e96d535711..c6603db270 100644 --- a/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php +++ b/wcfsetup/install/files/lib/system/package/PackageInstallationDispatcher.class.php @@ -297,6 +297,8 @@ class PackageInstallationDispatcher { // update options.inc.php OptionEditor::resetCache(); + + WCF::getSession()->register('__wcfSetup_completed', true); } // rebuild application paths diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 723139b71f..6c74ece735 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -1665,6 +1665,8 @@ Als Benachrichtigungs-URL in der Konfiguration der sofortigen Zahlungsbestätigu + + diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 0bfc3c11b8..031d653b9d 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -1650,6 +1650,8 @@ When prompted for the notification URL for the instant payment notifications, pl + + -- 2.20.1