[TikiWiki-commits] [Git][tikiwiki/tiki][27.x] [BP][MOD] Support multiple system configuration (INI) files with precedence and legacy fallback

"John Livingston \(@JohnXLivingston\) via TikiWiki-cvs" <[email protected]>
Newsgroups gmane.comp.cms.tiki.cvs
Message-ID <6a7311b9cc4eb_38dfd4a091680@gitlab-sidekiq-low-urgency-cpu-bound-v2-56bbddd49d-pfw75.mail>

John Livingston pushed to branch 27.x at Tiki Wiki CMS Groupware / Tiki


Commits:
f0bc168c by Moïse Nturubika at 2026-08-05T12:27:54+02:00
[BP][MOD] Support multiple system configuration (INI) files with precedence and legacy fallback
---


See merge request tikiwiki/tiki!10181 and tikiwiki/tiki!10024

See merge request tikiwiki/tiki!10237

(cherry picked from commit c2a907d802bba81ea2a6302479301d41212776a4)

See merge request tikiwiki/tiki!10840

- - - - -


8 changed files:

- db/preconfiguration.php
- db/tiki-db.php
- installer/installlib.php
- lib/admin/adminlib.php
- lib/core/Tiki/Command/ConfigureCommand.php
- lib/core/Tiki/Command/PreferencesSetCommand.php
- lib/core/Tiki/Config/Ini.php
- tiki-admin.php


Changes:

=====================================
db/preconfiguration.php
=====================================
@@ -9,4 +9,5 @@
 // $dbs_tiki_preconfig='tiki_db';
 
 // Want configurations managed at the system level or restrict some preferences? http://doc.tiki.org/System+Configuration
-// $system_configuration_file = 'db/tiki.ini.php';
+// Multiple configuration files (files listed later override earlier ones):
+// $system_configuration_files = ['db/local.ini', 'db/system_local.ini'];


=====================================
db/tiki-db.php
=====================================
@@ -83,7 +83,7 @@ $systemConfiguration = new Config(
 );
 if (isset($_SERVER['TIKI_INI_FILE'])) {
     if (! is_readable($_SERVER['TIKI_INI_FILE'])) {
-        $error = $_SERVER['TIKI_INI_FILE'] . ' could not be read' . PHP_EOL ;
+        $error = $_SERVER['TIKI_INI_FILE'] . ' could not be read' . PHP_EOL;
         if (defined('TIKI_CONSOLE')) {
             throw new ConsoleSetupException($error, 1001);
         }
@@ -94,40 +94,53 @@ if (isset($_SERVER['TIKI_INI_FILE'])) {
     $configReader = new Tiki_Config_Ini();
     $configReader->setFilterSection(isset($_SERVER['TIKI_INI_IDENTIFIER']) ? $_SERVER['TIKI_INI_IDENTIFIER'] : null);
     $configData = $configReader->fromFile($_SERVER['TIKI_INI_FILE']);
-    $systemConfiguration = $systemConfiguration->merge(new Laminas\Config\Config($configData));
+    $systemConfiguration = $systemConfiguration->merge(new Config($configData));
+}
+
+// Normalize to array: support both legacy $system_configuration_file (string)
+// and the newer $system_configuration_files (array of file paths).
+// When using the array form, files listed later override keys from earlier files.
+if (isset($system_configuration_files)) {
+    if (! is_array($system_configuration_files)) {
+        // Safety: should be an array
+        $system_configuration_files = [];
+    }
+} else {
+    $system_configuration_files = ! empty($system_configuration_file) ? [$system_configuration_file] : [];
 }
-if (isset($system_configuration_file)) {
-    if (! is_readable($system_configuration_file)) {
-        $error = $system_configuration_file . ' could not be read' . PHP_EOL ;
+
+foreach ($system_configuration_files as $configFile) {
+    if (! empty($configFile) && ! is_readable($configFile)) {
+        $error = $configFile . ' could not be read' . PHP_EOL;
         if (defined('TIKI_CONSOLE')) {
             throw new ConsoleSetupException($error, 1001);
         }
         echo $error;
         exit(1);
     }
-    if (! isset($system_configuration_identifier)) {
-        $system_configuration_identifier = null;
-    }
-    $configReader = new Tiki_Config_Ini();
-    $configReader->setFilterSection($system_configuration_identifier);
-
-    if (preg_match('/\.ini.php$/', $system_configuration_file)) {
-        $retrieveIniContent = function ($system_configuration_file) {
-            ob_start();
-            include($system_configuration_file);
-            $system_configuration_file_content = ob_get_contents();
-            ob_end_clean();
-
-            return $system_configuration_file_content;
-        };
-
-        $system_configuration_content = $retrieveIniContent($system_configuration_file);
-        $configData = $configReader->fromString($system_configuration_content);
-    } else {
-        $configData = $configReader->fromFile($system_configuration_file);
-    }
 
-    $systemConfiguration = $systemConfiguration->merge(new Config($configData));
+    if (! empty($configFile) && is_readable($configFile)) {
+        if (! isset($system_configuration_identifier)) {
+            $system_configuration_identifier = null;
+        }
+        $configReader = new Tiki_Config_Ini();
+        $configReader->setFilterSection($system_configuration_identifier);
+
+        if (preg_match('/\.ini.php$/', $configFile)) {
+            $retrieveIniContent = function ($configFile) {
+                ob_start();
+                include($configFile);
+                $content = ob_get_contents();
+                ob_end_clean();
+                return $content;
+            };
+            $configData = $configReader->fromString($retrieveIniContent($configFile));
+        } else {
+            $configData = $configReader->fromFile($configFile);
+        }
+
+        $systemConfiguration = $systemConfiguration->merge(new Config($configData));
+    }
 }
 
 if ($re === false) {


=====================================
installer/installlib.php
=====================================
@@ -69,7 +69,9 @@ function write_local_php($host_tiki, $user_tiki, $pass_tiki, $dbs_tiki, $client_
         $filetowrite .= "// If your php installation does not not have pdo extension\n";
         $filetowrite .= "// \$api_tiki = 'adodb';\n\n";
         $filetowrite .= "// Want configurations managed at the system level or restrict some preferences? http://doc.tiki.org/System+Configuration\n";
-        $filetowrite .= "// \$system_configuration_file = '/etc/tiki.ini.php';\n";
+        $filetowrite .= "// Multiple configuration files (files listed later override earlier ones):\n";
+        $filetowrite .= "// \$system_configuration_files = ['db/local.ini', 'db/system_local.ini'];\n";
+        $filetowrite .= "// If \$system_configuration_identifier is present, it MUST match one of the top sections in your ini file(s). That section will be the active configuration.\n";
         $filetowrite .= "// \$system_configuration_identifier = 'example.com';\n\n";
         fwrite($fw, $filetowrite);
         fclose($fw);


=====================================
lib/admin/adminlib.php
=====================================
@@ -4,6 +4,8 @@
 //
 // All Rights Reserved. See copyright.txt for details and a complete list of authors.
 // Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
+
+
 /**
  *
  */
@@ -569,20 +571,23 @@ class AdminLib extends TikiLib
      */
     public function checkSystemConfigurationFile()
     {
-        global $system_configuration_file;
+        global $system_configuration_files;
         $show_warning = false;
 
         $db_file = TIKI_CONFIG_FILE_PATH;
         if (file_exists($db_file)) {
             include($db_file);
 
-            if (isset($system_configuration_file) && file_exists($system_configuration_file)) {
-                $tikiPath = realpath(TIKI_PATH);
-                $configPath = realpath($system_configuration_file);
-                if (strncmp($tikiPath, $configPath, strlen($tikiPath)) == 0) {
-                    $file_extension = pathinfo($system_configuration_file, PATHINFO_EXTENSION);
-                    if ($file_extension == 'ini') {
-                        $show_warning = true;
+            foreach ($system_configuration_files as $configFile) {
+                if (isset($configFile) && file_exists($configFile)) {
+                    $tikiPath = realpath(TIKI_PATH);
+                    $configPath = realpath($configFile);
+                    if (strncmp($tikiPath, $configPath, strlen($tikiPath)) == 0) {
+                        $file_extension = pathinfo($configFile, PATHINFO_EXTENSION);
+                        if ($file_extension == 'ini') {
+                            $show_warning = true;
+                            break;
+                        }
                     }
                 }
             }
@@ -653,33 +658,44 @@ class AdminLib extends TikiLib
      */
     public function retrieveConfigFileData($retrieve_all_data = false)
     {
-        global $system_configuration_identifier, $system_configuration_file;
+        global $system_configuration_identifier, $system_configuration_files;
 
-        if (! is_readable($system_configuration_file)) {
-            throw new Exception(tr('%0 configuration file could not be read', $system_configuration_file));
-        }
-        $configData = [];
-        if ($retrieve_all_data || ! isset($system_configuration_identifier)) {
-            $system_configuration_identifier = null;
-        }
-        $configReader = new Tiki_Config_Ini();
-        $configReader->setFilterSection($system_configuration_identifier);
+        $mergedConfigData = [];
 
-        if (preg_match('/\.ini.php$/', $system_configuration_file)) {
-            $retrieveIniContent = function ($system_configuration_file) {
-                ob_start();
-                include($system_configuration_file);
-                $system_configuration_file_content = ob_get_contents();
-                ob_end_clean();
+        foreach ($system_configuration_files as $configFilePath) {
+            if (! is_readable($configFilePath)) {
+                throw new Exception(tr('%0 configuration file could not be read', $configFilePath));
+            }
 
-                return $system_configuration_file_content;
-            };
+            $configData = [];
+            $identifier = ($retrieve_all_data || ! isset($system_configuration_identifier))
+                ? null
+                : $system_configuration_identifier;
 
-            $system_configuration_content = $retrieveIniContent($system_configuration_file);
-            $configData = $configReader->fromString($system_configuration_content);
-        } else {
-            $configData = $configReader->fromFile($system_configuration_file);
+            $configReader = new Tiki_Config_Ini();
+            $configReader->setFilterSection($identifier);
+
+            if (preg_match('/\.ini.php$/', $configFilePath)) {
+                $retrieveIniContent = function ($file) {
+                    ob_start();
+                    include($file);
+                    $content = ob_get_contents();
+                    ob_end_clean();
+
+                    return $content;
+                };
+
+                $iniContent = $retrieveIniContent($configFilePath);
+                $configData = $configReader->fromString($iniContent);
+            } else {
+                $configData = $configReader->fromFile($configFilePath);
+            }
+
+            // Merge: later files override earlier files (array_replace_recursive)
+            $mergedConfigData = array_replace_recursive($mergedConfigData, $configData);
         }
-        return $configData;
+
+
+        return $mergedConfigData;
     }
 }


=====================================
lib/core/Tiki/Command/ConfigureCommand.php
=====================================
@@ -81,8 +81,8 @@ class ConfigureCommand extends Command
 // \$api_tiki = 'adodb';
 
 // Want configurations managed at the system level or restrict some preferences? http://doc.tiki.org/System+Configuration
-// \$system_configuration_file = 'db/tiki.ini.php';
-// \$system_configuration_file = '/etc/tiki.ini';
+// Multiple configuration files (files listed later override earlier ones):
+// \$system_configuration_files = ['db/local.ini', 'db/system_local.ini'];
 // \$system_configuration_identifier = 'example.com';
 
 LOCALPHP;


=====================================
lib/core/Tiki/Command/PreferencesSetCommand.php
=====================================
@@ -36,7 +36,7 @@ class PreferencesSetCommand extends Command
 
     protected function execute(InputInterface $input, OutputInterface $output): int
     {
-        global $system_configuration_file;
+        global $system_configuration_files;
 
         $logslib = TikiLib::lib('logs');
         $preference = $input->getArgument('name');
@@ -71,7 +71,11 @@ class PreferencesSetCommand extends Command
                 $output->writeln(sprintf('Preference %s was successfully set to %s in the database.', $preference, $userValue));
                 if ($result['forced_by_config']) {
                     $configValue = $result['config_value'];
-                    $configFile = $system_configuration_file ?? 'unknown configuration file';
+                    if (! empty($system_configuration_files)) {
+                        $configFile = implode(', ', $system_configuration_files);
+                    } else {
+                        $configFile = 'unknown configuration file';
+                    }
                     if ($userValue === $configValue) {
                         $output->writeln(sprintf(
                             '<comment>Note: The preference is overridden by ini file %s to effective value %s, which matches the set value.</comment>',


=====================================
lib/core/Tiki/Config/Ini.php
=====================================
@@ -22,7 +22,7 @@ class Tiki_Config_Ini extends Laminas\Config\Reader\Ini
      * @param  array $data
      * @return array
      */
-    protected function process(array $data)
+    protected function process(array $data): array
     {
         $data = $this->preProcessSectionInheritance($data);
         $config = parent::process($data);


=====================================
tiki-admin.php
=====================================
@@ -419,7 +419,7 @@ $smarty->assign('admin_icons', $admin_icons);
 $show_warning = $adminlib->checkSystemConfigurationFile();
 $smarty->assign('show_system_configuration_warning', $show_warning);
 
-if (isset($system_configuration_file)) {
+if (! empty($system_configuration_files)) {
     $config_file_errors = $adminlib->checkConfigurationFileErrors();
     $smarty->assign('config_file_errors', $config_file_errors);
 }



View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/f0bc168c69e3f633955870dbfc1d38f78eafa1c5

-- 
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/f0bc168c69e3f633955870dbfc1d38f78eafa1c5
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help

_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.