From bc9e8f68f1eb8d4093a3eab8e64617703d91bbe8 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Tue, 22 Jan 2019 21:49:42 +0100 Subject: [PATCH] Move default settings to install step The various installation "frontends" (such as GUI and console) can now provide custom overrides, if they want to. --- src/Install/Console/DefaultsDataProvider.php | 20 +---------- src/Install/Console/FileDataProvider.php | 2 +- src/Install/Console/UserDataProvider.php | 14 -------- src/Install/Controller/InstallController.php | 14 -------- src/Install/Installation.php | 6 ++-- src/Install/Steps/WriteSettings.php | 36 +++++++++++++++++--- tests/Install/DefaultInstallationTest.php | 14 -------- 7 files changed, 37 insertions(+), 69 deletions(-) diff --git a/src/Install/Console/DefaultsDataProvider.php b/src/Install/Console/DefaultsDataProvider.php index 62841faea..119e657a4 100644 --- a/src/Install/Console/DefaultsDataProvider.php +++ b/src/Install/Console/DefaultsDataProvider.php @@ -37,25 +37,7 @@ class DefaultsDataProvider implements DataProviderInterface 'email' => 'admin@example.com', ]; - protected $settings = [ - 'allow_post_editing' => 'reply', - 'allow_renaming' => '10', - 'allow_sign_up' => '1', - 'custom_less' => '', - 'default_locale' => 'en', - 'default_route' => '/all', - 'extensions_enabled' => '[]', - 'forum_title' => 'Development Forum', - 'forum_description' => '', - 'mail_driver' => 'mail', - 'mail_from' => 'noreply@flarum.dev', - 'theme_colored_header' => '0', - 'theme_dark_mode' => '0', - 'theme_primary_color' => '#4D698E', - 'theme_secondary_color' => '#4D698E', - 'welcome_message' => 'This is beta software and you should not use it in production.', - 'welcome_title' => 'Welcome to Development Forum', - ]; + protected $settings = []; public function getDatabaseConfiguration() { diff --git a/src/Install/Console/FileDataProvider.php b/src/Install/Console/FileDataProvider.php index 0eb8886f0..7e4a00d0a 100644 --- a/src/Install/Console/FileDataProvider.php +++ b/src/Install/Console/FileDataProvider.php @@ -72,7 +72,7 @@ class FileDataProvider implements DataProviderInterface public function getSettings() { - return $this->settings + $this->default->getSettings(); + return $this->settings; } public function isDebugMode(): bool diff --git a/src/Install/Console/UserDataProvider.php b/src/Install/Console/UserDataProvider.php index eb10ef5ba..2de2a2677 100644 --- a/src/Install/Console/UserDataProvider.php +++ b/src/Install/Console/UserDataProvider.php @@ -77,22 +77,8 @@ class UserDataProvider implements DataProviderInterface $baseUrl = $this->baseUrl ?: 'http://localhost'; return [ - 'allow_post_editing' => 'reply', - 'allow_renaming' => '10', - 'allow_sign_up' => '1', - 'custom_less' => '', - 'default_locale' => 'en', - 'default_route' => '/all', - 'extensions_enabled' => '[]', 'forum_title' => $title, - 'forum_description' => '', - 'mail_driver' => 'mail', 'mail_from' => 'noreply@'.preg_replace('/^www\./i', '', parse_url($baseUrl, PHP_URL_HOST)), - 'theme_colored_header' => '0', - 'theme_dark_mode' => '0', - 'theme_primary_color' => '#4D698E', - 'theme_secondary_color' => '#4D698E', - 'welcome_message' => 'This is beta software and you should not use it in production.', 'welcome_title' => 'Welcome to '.$title, ]; } diff --git a/src/Install/Controller/InstallController.php b/src/Install/Controller/InstallController.php index d86db5caa..8dd46e9a3 100644 --- a/src/Install/Controller/InstallController.php +++ b/src/Install/Controller/InstallController.php @@ -80,22 +80,8 @@ class InstallController implements RequestHandlerInterface 'email' => array_get($input, 'adminEmail'), ]) ->settings([ - 'allow_post_editing' => 'reply', - 'allow_renaming' => '10', - 'allow_sign_up' => '1', - 'custom_less' => '', - 'default_locale' => 'en', - 'default_route' => '/all', - 'extensions_enabled' => '[]', 'forum_title' => array_get($input, 'forumTitle'), - 'forum_description' => '', - 'mail_driver' => 'mail', 'mail_from' => 'noreply@'.preg_replace('/^www\./i', '', parse_url($baseUrl, PHP_URL_HOST)), - 'theme_colored_header' => '0', - 'theme_dark_mode' => '0', - 'theme_primary_color' => '#4D698E', - 'theme_secondary_color' => '#4D698E', - 'welcome_message' => 'This is beta software and you should not use it in production.', 'welcome_title' => 'Welcome to '.array_get($input, 'forumTitle'), ]) ->build(); diff --git a/src/Install/Installation.php b/src/Install/Installation.php index e6dba3414..bc703db7c 100644 --- a/src/Install/Installation.php +++ b/src/Install/Installation.php @@ -21,7 +21,7 @@ class Installation private $debug = false; private $dbConfig = []; private $baseUrl; - private $defaultSettings = []; + private $customSettings = []; private $adminUser = []; public function __construct($basePath, $publicPath, $storagePath) @@ -61,7 +61,7 @@ class Installation public function settings($settings) { - $this->defaultSettings = $settings; + $this->customSettings = $settings; return $this; } @@ -129,7 +129,7 @@ class Installation }); $pipeline->pipe(function () { - return new Steps\WriteSettings($this->tmp['db'], $this->defaultSettings); + return new Steps\WriteSettings($this->tmp['db'], $this->customSettings); }); $pipeline->pipe(function () { diff --git a/src/Install/Steps/WriteSettings.php b/src/Install/Steps/WriteSettings.php index 657e838d9..366fc3696 100644 --- a/src/Install/Steps/WriteSettings.php +++ b/src/Install/Steps/WriteSettings.php @@ -26,12 +26,12 @@ class WriteSettings implements Step /** * @var array */ - private $defaults; + private $custom; - public function __construct(ConnectionInterface $database, array $defaults) + public function __construct(ConnectionInterface $database, array $custom) { $this->database = $database; - $this->defaults = $defaults; + $this->custom = $custom; } public function getMessage() @@ -45,8 +45,36 @@ class WriteSettings implements Step $repo->set('version', Application::VERSION); - foreach ($this->defaults as $key => $value) { + foreach ($this->getSettings() as $key => $value) { $repo->set($key, $value); } } + + private function getSettings() + { + return $this->custom + $this->getDefaults(); + } + + private function getDefaults() + { + return [ + 'allow_post_editing' => 'reply', + 'allow_renaming' => '10', + 'allow_sign_up' => '1', + 'custom_less' => '', + 'default_locale' => 'en', + 'default_route' => '/all', + 'extensions_enabled' => '[]', + 'forum_title' => 'A new Flarum forum', + 'forum_description' => '', + 'mail_driver' => 'mail', + 'mail_from' => 'noreply@localhost', + 'theme_colored_header' => '0', + 'theme_dark_mode' => '0', + 'theme_primary_color' => '#4D698E', + 'theme_secondary_color' => '#4D698E', + 'welcome_message' => 'This is beta software and you should not use it in production.', + 'welcome_title' => 'Welcome to Flarum', + ]; + } } diff --git a/tests/Install/DefaultInstallationTest.php b/tests/Install/DefaultInstallationTest.php index b7507ea7b..02eaf4d2a 100644 --- a/tests/Install/DefaultInstallationTest.php +++ b/tests/Install/DefaultInstallationTest.php @@ -69,22 +69,8 @@ class DefaultInstallationTest extends TestCase private function getSettings() { return [ - 'allow_post_editing' => 'reply', - 'allow_renaming' => '10', - 'allow_sign_up' => '1', - 'custom_less' => '', - 'default_locale' => 'en', - 'default_route' => '/all', - 'extensions_enabled' => '[]', 'forum_title' => 'Development Forum', - 'forum_description' => '', 'mail_driver' => 'log', - 'mail_from' => 'noreply@flarum.dev', - 'theme_colored_header' => '0', - 'theme_dark_mode' => '0', - 'theme_primary_color' => '#4D698E', - 'theme_secondary_color' => '#4D698E', - 'welcome_message' => 'This is beta software and you should not use it in production.', 'welcome_title' => 'Welcome to Development Forum', ]; }