From 1acd5c7d229baeff73f3790614a4a98de704343c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 16 Mar 2019 20:04:11 +0100 Subject: [PATCH 1/3] - Adding additional legacy .htconfig information --- src/Core/Config/Cache/ConfigCacheLoader.php | 42 ++++++++++++------- tests/datasets/config/.htconfig.test.php | 6 +++ .../Config/Cache/ConfigCacheLoaderTest.php | 6 +++ 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/src/Core/Config/Cache/ConfigCacheLoader.php b/src/Core/Config/Cache/ConfigCacheLoader.php index b043bf27cb..95d6041d46 100644 --- a/src/Core/Config/Cache/ConfigCacheLoader.php +++ b/src/Core/Config/Cache/ConfigCacheLoader.php @@ -103,47 +103,61 @@ class ConfigCacheLoader { $filePath = $this->baseDir . DIRECTORY_SEPARATOR . '.' . $name . '.php'; + $config = []; + if (file_exists($filePath)) { - $a = new \stdClass(); - $a->config = []; include $filePath; if (isset($db_host)) { - $a->config['database']['hostname'] = $db_host; + $config['database']['hostname'] = $db_host; unset($db_host); } if (isset($db_user)) { - $a->config['database']['username'] = $db_user; + $config['database']['username'] = $db_user; unset($db_user); } if (isset($db_pass)) { - $a->config['database']['password'] = $db_pass; + $config['database']['password'] = $db_pass; unset($db_pass); } if (isset($db_data)) { - $a->config['database']['database'] = $db_data; + $config['database']['database'] = $db_data; unset($db_data); } if (isset($a->config['system']['db_charset'])) { - $a->config['database']['charset'] = $a->config['system']['charset']; + $a->config['database']['charset'] = $config['system']['charset']; } if (isset($pidfile)) { - $a->config['system']['pidfile'] = $pidfile; + $config['system']['pidfile'] = $pidfile; unset($pidfile); } if (isset($default_timezone)) { - $a->config['system']['default_timezone'] = $default_timezone; + $config['system']['default_timezone'] = $default_timezone; unset($default_timezone); } if (isset($lang)) { - $a->config['system']['language'] = $lang; + $config['system']['language'] = $lang; unset($lang); } - - return $a->config; - } else { - return []; + if (isset($admin_email)) { + $config['config']['admin_email'] = $admin_email; + unset($admin_email); + } + if (isset($admin_nickname)) { + $config['config']['admin_nickname'] = $admin_nickname; + unset($admin_nickname); + } + if (isset($php_path)) { + $config['config']['php_path'] = $php_path; + unset($php_path); + } + if (isset($max_import_size)) { + $config['config']['max_import_size'] = $max_import_size; + unset($max_import_size); + } } + + return $config; } /** diff --git a/tests/datasets/config/.htconfig.test.php b/tests/datasets/config/.htconfig.test.php index 88ba4e3ef3..78bb6bcdae 100644 --- a/tests/datasets/config/.htconfig.test.php +++ b/tests/datasets/config/.htconfig.test.php @@ -8,6 +8,12 @@ $db_user = 'testuser'; $db_pass = 'testpw'; $db_data = 'testdb'; +$admin_email = 'admin@friendica.local'; +$admin_nickname = 'Friendly admin'; + $pidfile = '/var/run/friendica.pid'; $default_timezone = 'Europe/Berlin'; $lang = 'fr'; + +$php_path = '/another/php'; +$max_import_size = 999; \ No newline at end of file diff --git a/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php b/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php index d473aec00c..4fd0b46509 100644 --- a/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php +++ b/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php @@ -135,6 +135,12 @@ class ConfigCacheLoaderTest extends MockedTest $this->assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile')); $this->assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone')); $this->assertEquals('fr', $configCache->get('system', 'language')); + + $this->assertEquals('admin@friendica.local', $configCache->get('config', 'admin_email')); + $this->assertEquals('Friendly admin', $configCache->get('config', 'admin_nickname')); + + $this->assertEquals('/another/php', $configCache->get('config', 'php_path')); + $this->assertEquals('999', $configCache->get('config', 'max_import_size')); } public function testLoadAddonConfig() From 8c6e6b5dea571e603205af9bbb251619b189c12c Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 16 Mar 2019 20:31:10 +0100 Subject: [PATCH 2/3] Fixing .htconfig --- src/Core/Config/Cache/ConfigCacheLoader.php | 39 +++++++------- tests/datasets/config/.htconfig.test.php | 54 +++++++++++++++++-- .../Config/Cache/ConfigCacheLoaderTest.php | 5 ++ 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/src/Core/Config/Cache/ConfigCacheLoader.php b/src/Core/Config/Cache/ConfigCacheLoader.php index 95d6041d46..8a2dc2b1e2 100644 --- a/src/Core/Config/Cache/ConfigCacheLoader.php +++ b/src/Core/Config/Cache/ConfigCacheLoader.php @@ -106,8 +106,27 @@ class ConfigCacheLoader $config = []; if (file_exists($filePath)) { + $a = new \stdClass(); + $a->config = []; include $filePath; + $htconfigAr = array_keys($a->config); + + // map the legacy configuration structure to the current structure + foreach ($htconfigAr as $htconfig) { + if (isset($a->config[$htconfig]) && is_array($a->config[$htconfig])) { + $keys = array_keys($a->config[$htconfig]); + + foreach ($keys as $key) { + $config[$htconfig][$key] = $a->config[$htconfig][$key]; + } + } else { + $config['config'][$htconfig] = $a->config[$htconfig]; + } + } + + unset($a); + if (isset($db_host)) { $config['database']['hostname'] = $db_host; unset($db_host); @@ -124,8 +143,8 @@ class ConfigCacheLoader $config['database']['database'] = $db_data; unset($db_data); } - if (isset($a->config['system']['db_charset'])) { - $a->config['database']['charset'] = $config['system']['charset']; + if (isset($config['system']['db_charset'])) { + $config['database']['charset'] = $config['system']['db_charset']; } if (isset($pidfile)) { $config['system']['pidfile'] = $pidfile; @@ -139,22 +158,6 @@ class ConfigCacheLoader $config['system']['language'] = $lang; unset($lang); } - if (isset($admin_email)) { - $config['config']['admin_email'] = $admin_email; - unset($admin_email); - } - if (isset($admin_nickname)) { - $config['config']['admin_nickname'] = $admin_nickname; - unset($admin_nickname); - } - if (isset($php_path)) { - $config['config']['php_path'] = $php_path; - unset($php_path); - } - if (isset($max_import_size)) { - $config['config']['max_import_size'] = $max_import_size; - unset($max_import_size); - } } return $config; diff --git a/tests/datasets/config/.htconfig.test.php b/tests/datasets/config/.htconfig.test.php index 78bb6bcdae..193142c49c 100644 --- a/tests/datasets/config/.htconfig.test.php +++ b/tests/datasets/config/.htconfig.test.php @@ -8,12 +8,56 @@ $db_user = 'testuser'; $db_pass = 'testpw'; $db_data = 'testdb'; -$admin_email = 'admin@friendica.local'; -$admin_nickname = 'Friendly admin'; - $pidfile = '/var/run/friendica.pid'; + +// Set the database connection charset to UTF8. +// Changing this value will likely corrupt the special characters. +// You have been warned. +$a->config['system']['db_charset'] = "anotherCharset"; + +// Choose a legal default timezone. If you are unsure, use "America/Los_Angeles". +// It can be changed later and only applies to timestamps for anonymous viewers. $default_timezone = 'Europe/Berlin'; $lang = 'fr'; -$php_path = '/another/php'; -$max_import_size = 999; \ No newline at end of file +// What is your site name? +$a->config['sitename'] = "Friendica My Network"; + +// Your choices are REGISTER_OPEN, REGISTER_APPROVE, or REGISTER_CLOSED. +// Be certain to create your own personal account before setting +// REGISTER_CLOSED. 'register_text' (if set) will be displayed prominently on +// the registration page. REGISTER_APPROVE requires you set 'admin_email' +// to the email address of an already registered person who can authorise +// and/or approve/deny the request. +// In order to perform system administration via the admin panel, admin_email +// must precisely match the email address of the person logged in. +$a->config['register_policy'] = REGISTER_OPEN; +$a->config['register_text'] = 'A register text'; +$a->config['admin_email'] = 'admin@friendica.local'; +$a->config['admin_nickname'] = 'Friendly admin'; + +// Maximum size of an imported message, 0 is unlimited +$a->config['max_import_size'] = 999; + +// maximum size of uploaded photos +$a->config['system']['maximagesize'] = 666; + +// Location of PHP command line processor +$a->config['php_path'] = '/another/php'; + +// PuSH - aka pubsubhubbub URL. This makes delivery of public posts as fast as private posts +$a->config['system']['huburl'] = '[internal]'; + +// allowed themes (change this from admin panel after installation) +$a->config['system']['allowed_themes'] = 'quattro,vier,duepuntozero'; + +// default system theme +$a->config['system']['theme'] = 'duepuntozero'; + +// By default allow pseudonyms +$a->config['system']['no_regfullname'] = true; + +//Deny public access to the local directory +//$a->config['system']['block_local_dir'] = false; +// Location of the global directory +$a->config['system']['directory'] = 'http://another.url'; diff --git a/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php b/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php index 4fd0b46509..c9acdfff36 100644 --- a/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php +++ b/tests/src/Core/Config/Cache/ConfigCacheLoaderTest.php @@ -131,6 +131,7 @@ class ConfigCacheLoaderTest extends MockedTest $this->assertEquals('testuser', $configCache->get('database', 'username')); $this->assertEquals('testpw', $configCache->get('database', 'password')); $this->assertEquals('testdb', $configCache->get('database', 'database')); + $this->assertEquals('anotherCharset', $configCache->get('database', 'charset')); $this->assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile')); $this->assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone')); @@ -141,6 +142,10 @@ class ConfigCacheLoaderTest extends MockedTest $this->assertEquals('/another/php', $configCache->get('config', 'php_path')); $this->assertEquals('999', $configCache->get('config', 'max_import_size')); + $this->assertEquals('666', $configCache->get('system', 'maximagesize')); + + $this->assertEquals('quattro,vier,duepuntozero', $configCache->get('system', 'allowed_themes')); + $this->assertEquals('1', $configCache->get('system', 'no_regfullname')); } public function testLoadAddonConfig() From b22ff7419eedbf8247fe08c154b5ae352aca7a07 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sun, 17 Mar 2019 09:57:34 +0100 Subject: [PATCH 3/3] refactor naming & superfluous check --- src/Core/Config/Cache/ConfigCache.php | 2 +- src/Core/Config/Cache/ConfigCacheLoader.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Core/Config/Cache/ConfigCache.php b/src/Core/Config/Cache/ConfigCache.php index cf50b43d4f..cb299eb330 100644 --- a/src/Core/Config/Cache/ConfigCache.php +++ b/src/Core/Config/Cache/ConfigCache.php @@ -30,7 +30,7 @@ class ConfigCache implements IConfigCache, IPConfigCache $categories = array_keys($config); foreach ($categories as $category) { - if (isset($config[$category]) && is_array($config[$category])) { + if (is_array($config[$category])) { $keys = array_keys($config[$category]); foreach ($keys as $key) { diff --git a/src/Core/Config/Cache/ConfigCacheLoader.php b/src/Core/Config/Cache/ConfigCacheLoader.php index 8a2dc2b1e2..55f18681ce 100644 --- a/src/Core/Config/Cache/ConfigCacheLoader.php +++ b/src/Core/Config/Cache/ConfigCacheLoader.php @@ -110,18 +110,18 @@ class ConfigCacheLoader $a->config = []; include $filePath; - $htconfigAr = array_keys($a->config); + $htConfigCategories = array_keys($a->config); // map the legacy configuration structure to the current structure - foreach ($htconfigAr as $htconfig) { - if (isset($a->config[$htconfig]) && is_array($a->config[$htconfig])) { - $keys = array_keys($a->config[$htconfig]); + foreach ($htConfigCategories as $htConfigCategory) { + if (is_array($a->config[$htConfigCategory])) { + $keys = array_keys($a->config[$htConfigCategory]); foreach ($keys as $key) { - $config[$htconfig][$key] = $a->config[$htconfig][$key]; + $config[$htConfigCategory][$key] = $a->config[$htConfigCategory][$key]; } } else { - $config['config'][$htconfig] = $a->config[$htconfig]; + $config['config'][$htConfigCategory] = $a->config[$htConfigCategory]; } }