Standalone: add setup plugin so that we can install
authorMathieu Lutfy <mathieu@symbiotic.coop>
Fri, 24 Jun 2022 23:22:23 +0000 (19:22 -0400)
committerbgm <bgm@bagdad.bidon.ca>
Wed, 29 Jun 2022 15:07:56 +0000 (11:07 -0400)
setup/plugins/init/Standalone.civi-setup.php [new file with mode: 0644]
setup/res/finished.Standalone.php [new file with mode: 0644]

diff --git a/setup/plugins/init/Standalone.civi-setup.php b/setup/plugins/init/Standalone.civi-setup.php
new file mode 100644 (file)
index 0000000..8b47333
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * @file
+ *
+ * Determine default settings for Standalone.
+ */
+
+if (!defined('CIVI_SETUP')) {
+  exit("Installation plugins must only be loaded by the installer.\n");
+}
+
+\Civi\Setup::dispatcher()
+  ->addListener('civi.setup.checkAuthorized', function (\Civi\Setup\Event\CheckAuthorizedEvent $e) {
+    $model = $e->getModel();
+    if ($model->cms !== 'Standalone') {
+      return;
+    }
+
+    \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkAuthorized'));
+    $e->setAuthorized(TRUE);
+  });
+
+
+\Civi\Setup::dispatcher()
+  ->addListener('civi.setup.init', function (\Civi\Setup\Event\InitEvent $e) {
+    $model = $e->getModel();
+    if ($model->cms !== 'Standalone') {
+      return;
+    }
+    \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'init'));
+
+    // Compute settingsPath.
+    // We use this structure: /var/www/standalone/data/{civicrm.settings.php,templates_c}
+    // to reduce the number of directories that admins have to chmod
+    $model->settingsPath = implode(DIRECTORY_SEPARATOR, [$model->webroot, 'data', 'civicrm.settings.php']);
+    $model->templateCompilePath = implode(DIRECTORY_SEPARATOR, [$model->webroot, 'data', 'templates_c']);
+
+    // Compute DSN.
+    $model->db = $model->cmsDb = [
+      'server' => 'localhost',
+      'username' => '',
+      'password' => '',
+      'database' => '',
+    ];
+
+    // Compute URLs (@todo?)
+    $model->cmsBaseUrl = $_SERVER['HTTP_ORIGIN'] ?: $_SERVER['HTTP_REFERER'];
+    $model->mandatorySettings['userFrameworkResourceURL'] = $model->cmsBaseUrl . '/assets/civicrm/core';
+
+    // Compute default locale.
+    $model->lang = $_REQUEST['lang'] ?? 'en_US';
+  });
diff --git a/setup/res/finished.Standalone.php b/setup/res/finished.Standalone.php
new file mode 100644 (file)
index 0000000..65002c8
--- /dev/null
@@ -0,0 +1,16 @@
+<?php \Civi\Setup::assertRunning(); ?>
+<h1><?php echo ts('CiviCRM Installed'); ?></h1>
+<div style="padding: 1em;">
+  <p style="background-color: #0C0; border: 1px #070 solid; color: white;">
+    <?php echo ts("CiviCRM has been successfully installed"); ?>
+  </p>
+  <ul>
+    <li><?php
+    $cmsURL = '/civicrm/admin/configtask&reset=1';
+    echo ts("Use the <a %1>Configuration Checklist</a> to review and configure settings for your new site", [1 => "target='_blank' href='$cmsURL'"]);
+    ?></li>
+    <?php include 'finished.Common.php'; ?>
+  </ul>
+
+  <p><a href="/"><?php echo ts("Continue to the CiviCRM Dashboard"); ?></a></p>
+</div>