From: Tim Otten Date: Thu, 9 Jul 2020 01:22:50 +0000 (-0700) Subject: Setup API - Fail more gracefully if 'components' list is empty/missing X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=eb7547e0ecb1e9d7145e45cf84a89b4254c1e681;p=civicrm-core.git 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). --- 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));