From: Hypolite Petovan Date: Thu, 28 Jun 2018 03:05:38 +0000 (-0400) Subject: Add addon config hook X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=2e2930d770e9de39e14c8172fc8875041bcc00fd;p=friendica.git Add addon config hook --- diff --git a/index.php b/index.php index 16597fa62e..3a2067471e 100644 --- a/index.php +++ b/index.php @@ -36,10 +36,6 @@ $a->backend = false; require_once "include/dba.php"; if (!$a->mode == App::MODE_INSTALL) { - if (!dba::connected()) { - System::unavailable(); - } - /** * Load configs from db. Overwrite configs from config/local.ini.php */ diff --git a/mod/admin.php b/mod/admin.php index b308a2049b..d431fac2a2 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -845,6 +845,12 @@ function admin_page_summary(App $a) $warningtext[] = L10n::t('The last worker execution was on %s UTC. This is older than one hour. Please check your crontab settings.', $last_worker_call); } + // Legacy config file warning + if (file_exists('.htconfig.php')) { + $showwarning = true; + $warningtext[] = L10n::t('Friencia\'s configuration now is stored in config/local.ini.php, please copy config/local-sample.ini.php and move your config from .htconfig.php.'); + } + $r = q("SELECT `page-flags`, COUNT(`uid`) AS `count` FROM `user` GROUP BY `page-flags`"); $accounts = [ [L10n::t('Normal Account'), 0], diff --git a/src/App.php b/src/App.php index 17cfd3eefc..d35b497c2a 100644 --- a/src/App.php +++ b/src/App.php @@ -151,6 +151,12 @@ class App $this->determineMode(); + if ($this->mode === self::MODE_NORMAL) { + Core\Addon::loadHooks(); + + $this->loadAddonConfig(); + } + $this->loadDefaultTimezone(); $this->performance['start'] = microtime(true); @@ -295,6 +301,12 @@ class App $this->register_template_engine('Friendica\Render\FriendicaSmartyEngine'); } + /** + * Load the configuration files + * + * First loads the default value for all the configuration keys, then the legacy configuration files, then the + * expected local.ini.php + */ private function loadConfigFiles() { $this->loadConfigFile($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'defaults.ini.php'); @@ -328,6 +340,23 @@ class App } } + /** + * Tries to load the specified configuration file into the App->config array. + * Overwrites previously set values. + * + * The config format is INI and the template for configuration files is the following: + * + * getConfigValue('system', 'default_timezone')) { @@ -375,8 +417,7 @@ class App } /** - * Figure out if we are running at the top of a domain - * or in a sub-directory and adjust accordingly + * Figure out if we are running at the top of a domain or in a sub-directory and adjust accordingly */ private function determineUrlPath() { @@ -396,16 +437,31 @@ class App } } + /** + * Sets the App mode + * + * - App::MODE_INSTALL : Either the database connection can't be established or the config table doesn't exist + * - App::MODE_MAINTENANCE: The maintenance mode has been set + * - App::MODE_NORMAL : Normal run with all features enabled + * + * @return type + */ private function determineMode() { $this->mode = App::MODE_INSTALL; - // Missing DB connection - if (!\dba::connected()) { + // Missing local config files: MODE_INSTALL + if (!file_exists($this->basepath . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'local.ini.php') + && !file_exists($this->basepath . DIRECTORY_SEPARATOR . '.htconfig.php')) { return; } - // Working DB connection, missing tables + // Missing DB connection: ERROR + if (!\dba::connected()) { + System::unavailable(); + } + + // Working DB connection, missing tables: MODE_INSTALL if (\dba::fetch_first("SHOW TABLES LIKE 'config'") === false) { return; }