Setup API - Fail more gracefully if 'components' list is empty/missing
authorTim Otten <totten@civicrm.org>
Thu, 9 Jul 2020 01:22:50 +0000 (18:22 -0700)
committerTim Otten <totten@civicrm.org>
Thu, 16 Jul 2020 10:05:57 +0000 (03:05 -0700)
Use-case: You run the installer with an empty list of `components`

Before: The installer begins running - but then crashes half way through

After: The installer doesn't even begin - because the requirement-check fails.

Comment: There are guards in both `checkRequirements` and `installDatabase`.  They're slightly redundant, but not
strictly redundant (e.g.  in cases of installer bugs or wonky plugins).

setup/plugins/installDatabase/InstallComponents.civi-setup.php

index e5a6b0b5d64341e4487ce3cc5b44ad800104d2bd..88170571b5dc05283476e6b6ea6522c5c936fc93 100644 (file)
@@ -9,6 +9,17 @@ if (!defined('CIVI_SETUP')) {
   exit("Installation plugins must only be loaded by the installer.\n");
 }
 
+Civi\Setup::dispatcher()
+  ->addListener('civi.setup.checkRequirements', function (\Civi\Setup\Event\CheckRequirementsEvent $e) {
+    \Civi\Setup::log()->info(sprintf('[%s] Handle %s', basename(__FILE__), 'checkRequirements'));
+    $model = $e->getModel();
+
+    if (empty($model->components)) {
+      $e->addError('system', 'components', "System must have at least one active component.");
+      return;
+    }
+  });
+
 \Civi\Setup::dispatcher()
   ->addListener('civi.setup.installDatabase', function (\Civi\Setup\Event\InstallDatabaseEvent $e) {
     \Civi\Setup::log()->info('[InstallComponents.civi-setup.php] Activate components: ' . implode(" ", $e->getModel()->components));