From eb7547e0ecb1e9d7145e45cf84a89b4254c1e681 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Wed, 8 Jul 2020 18:22:50 -0700 Subject: [PATCH] Setup API - Fail more gracefully if 'components' list is empty/missing 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). --- .../installDatabase/InstallComponents.civi-setup.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/setup/plugins/installDatabase/InstallComponents.civi-setup.php b/setup/plugins/installDatabase/InstallComponents.civi-setup.php index e5a6b0b5d6..88170571b5 100644 --- a/setup/plugins/installDatabase/InstallComponents.civi-setup.php +++ b/setup/plugins/installDatabase/InstallComponents.civi-setup.php @@ -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)); -- 2.25.1