Setup UI - Use separate "Database" section (on standalone)
authorTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 06:12:18 +0000 (23:12 -0700)
committerTim Otten <totten@civicrm.org>
Sun, 16 Jul 2023 06:14:17 +0000 (23:14 -0700)
setup/plugins/blocks/advanced.tpl.php
setup/plugins/blocks/database.civi-setup.php [new file with mode: 0644]
setup/plugins/blocks/database.tpl.php [new file with mode: 0644]

index 12531bed4b810b0a1a347b87f3a2965b6ecd61b9..e130a6a8b47371177a56dd081ce2b5d1d5d2e9d0 100644 (file)
@@ -9,6 +9,7 @@ endif; ?>
 <div style="">
   <table class="settingsTable">
     <tbody>
+    <?php if ($model->cms !== 'Standalone'): ?>
     <tr>
       <th><?php echo ts('CMS Database'); ?></th>
       <td>
@@ -44,6 +45,7 @@ endif; ?>
         </div>
       </td>
     </tr>
+    <?php endif; ?>
     <tr>
       <th><?php echo ts('CiviCRM Settings File'); ?></th>
       <td><code><?php echo htmlentities($model->settingsPath); ?></code></td>
diff --git a/setup/plugins/blocks/database.civi-setup.php b/setup/plugins/blocks/database.civi-setup.php
new file mode 100644 (file)
index 0000000..c642416
--- /dev/null
@@ -0,0 +1,38 @@
+<?php
+if (!defined('CIVI_SETUP')) {
+  exit("Installation plugins must only be loaded by the installer.\n");
+}
+
+\Civi\Setup::dispatcher()
+  ->addListener('civi.setupui.boot', function (\Civi\Setup\UI\Event\UIBootEvent $e) {
+    \Civi\Setup::log()->info(sprintf('[%s] Register blocks', basename(__FILE__)));
+
+    /**
+     * @var \Civi\Setup\UI\SetupController $ctrl
+     */
+    $ctrl = $e->getCtrl();
+
+    $ctrl->blocks['database'] = [
+      'is_active' => ($e->getModel()->cms === 'Standalone'),
+      'file' => __DIR__ . DIRECTORY_SEPARATOR . 'database.tpl.php',
+      'class' => '',
+      'weight' => 15,
+    ];
+    if (empty($ctrl->blocks['database']['is_active'])) {
+      return;
+    }
+
+    $webDefault = ['server' => '127.0.0.1:3306', 'database' => 'civicrm', 'username' => '', 'password' => ''];
+
+    if ($e->getMethod() === 'GET') {
+      $e->getModel()->db = $webDefault;
+    }
+    elseif ($e->getMethod() === 'POST') {
+      $db = $e->getField('db', $webDefault);
+
+      foreach (['server', 'database', 'username', 'password'] as $field) {
+        $e->getModel()->db[$field] = $db[$field];
+      }
+    }
+
+  }, \Civi\Setup::PRIORITY_PREPARE);
diff --git a/setup/plugins/blocks/database.tpl.php b/setup/plugins/blocks/database.tpl.php
new file mode 100644 (file)
index 0000000..b6f75b8
--- /dev/null
@@ -0,0 +1,24 @@
+<?php if (!defined('CIVI_SETUP')): exit("Installation plugins must only be loaded by the installer.\n");
+endif; ?>
+
+<h2><?php echo ts('Database'); ?></h2>
+
+<p style="margin-left: 2em">
+  <label for="server"><span><?php echo ts('Server:'); ?></span></label>
+  <input type="text" id="dbServer" name="civisetup[db][server]" value="<?php echo htmlentities($model->db['server'] ?? '') ?>">
+</p>
+
+<p style="margin-left: 2em">
+  <label for="database"><span><?php echo ts('Database:'); ?></span></label>
+  <input type="text" id="dbDatabase" name="civisetup[db][database]" value="<?php echo htmlentities($model->db['database'] ?? '') ?>">
+</p>
+
+<p style="margin-left: 2em">
+  <label for="username"><span><?php echo ts('Username:'); ?></span></label>
+  <input type="text" id="dbUsername" name="civisetup[db][username]" value="<?php echo htmlentities($model->db['username'] ?? '') ?>">
+</p>
+
+<p style="margin-left: 2em">
+  <label for="password"><span><?php echo ts('Password:'); ?></span></label>
+  <input type="password" id="dbPassword" name="civisetup[db][password]" value="<?php echo htmlentities($model->db['password'] ?? '') ?>">
+</p>