InstallSettingsFile - Split out separate rules for Joomla settings files
authorTim Otten <totten@civicrm.org>
Wed, 28 Jun 2023 08:41:01 +0000 (01:41 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 28 Jun 2023 10:42:25 +0000 (03:42 -0700)
setup/plugins/installFiles/InstallJoomlaSettingsFile.civi-setup.php [new file with mode: 0644]
setup/plugins/installFiles/InstallSettingsFile.civi-setup.php

diff --git a/setup/plugins/installFiles/InstallJoomlaSettingsFile.civi-setup.php b/setup/plugins/installFiles/InstallJoomlaSettingsFile.civi-setup.php
new file mode 100644 (file)
index 0000000..cbe3e42
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**
+ * @file
+ *
+ * Generate the civicrm.settings.php file.
+ *
+ * The Joomla setup is unusual because it has two copies of the file, and they're
+ * slightly different.
+ */
+
+if (!defined('CIVI_SETUP')) {
+  exit("Installation plugins must only be loaded by the installer.\n");
+}
+
+/**
+ * Read the $model and create the "civicrm.settings.php" files for Joomla.
+ */
+\Civi\Setup::dispatcher()
+  ->addListener('civi.setup.installFiles', function (\Civi\Setup\Event\InstallFilesEvent $e) {
+    if ($e->getModel()->cms !== 'Joomla') {
+      return;
+    }
+
+    \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'installFiles'));
+
+    $liveSite = substr_replace(JURI::root(), '', -1, 1);
+
+    /**
+     * @var \Civi\Setup\Model $m
+     */
+    $m = $e->getModel();
+    $params = \Civi\Setup\SettingsUtil::createParams($m);
+    $files = [
+      'backend' => [
+        'file' => $m->settingsPath,
+        'params' => ['baseURL' => $liveSite . '/administrator/'] + $params,
+      ],
+      'frontend' => [
+        'file' => implode(DIRECTORY_SEPARATOR, [JPATH_SITE, 'components', 'com_civicrm', 'civicrm.settings.php']),
+        'params' => ['baseURL' => $liveSite . '/'] + $params,
+      ],
+    ];
+
+    $tplPath = implode(DIRECTORY_SEPARATOR,
+      [$m->srcPath, 'templates', 'CRM', 'common', 'civicrm.settings.php.template']
+    );
+
+    foreach ($files as $fileSpec) {
+      $str = \Civi\Setup\SettingsUtil::evaluate($tplPath, $fileSpec['params']);
+      JFile::write($fileSpec['file'], $str);
+    }
+
+  }, \Civi\Setup::PRIORITY_LATE);
index 735909d643684dd89d8a22f4c22f4b26c5db37a4..7eab4536de5cfe6af542d7c2295851374ac2da0b 100644 (file)
@@ -60,6 +60,11 @@ if (!defined('CIVI_SETUP')) {
  */
 \Civi\Setup::dispatcher()
   ->addListener('civi.setup.installFiles', function (\Civi\Setup\Event\InstallFilesEvent $e) {
+    if ($e->getModel()->cms === 'Joomla') {
+      // Complicated. Another plugin will do it.
+      return;
+    }
+
     \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'installFiles'));
 
     /**