diff --git a/CHANGELOG.md b/CHANGELOG.md index 688ba5d..c5dc3be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ and this project follows the which is based on the major version of Backdrop CMS with a semantic version system for each contributed module, theme and layout. -## [Unreleased] - 2024-09-25 +## [Unreleased] - 2024-10-09 ### Added - An option for the `db-import` command to allow import from newer MariaDB @@ -20,6 +20,10 @@ database or client does not support it. - Unhandled errors and warnings if commands run outside Backdrop root and/or before installing Backdrop. +### Changed +- Bee will now notify the user of additional modules that will be enabled or disabled +based on module dependencies when using the enable and disable commands. + ## [1.x-1.1.0] - 2024-09-07 ### Added diff --git a/bee.php b/bee.php index df2742f..5cea220 100755 --- a/bee.php +++ b/bee.php @@ -23,6 +23,7 @@ require_once __DIR__ . '/includes/input.inc'; require_once __DIR__ . '/includes/globals.inc'; require_once __DIR__ . '/includes/telemetry.inc'; +require_once __DIR__ . '/includes/dependencies.inc'; // Main execution code. bee_initialize_server(); diff --git a/commands/projects.bee.inc b/commands/projects.bee.inc index fc3fb5a..487185e 100644 --- a/commands/projects.bee.inc +++ b/commands/projects.bee.inc @@ -229,7 +229,7 @@ function enable_bee_callback($arguments, $options) { foreach ($dependencies as $key => $dependency) { if (!in_array($dependency, $unique_dependencies)) { // Report info on dependencies to be enabled. - bee_message(bt("The '!dependency' module will also be enabled, as it is required by the '!current' module.", [ + bee_instant_message(bt("The '!dependency' module will also be enabled, as it is required by the '!current' module or one of the modules it requires.", [ '!dependency' => $modules[$dependency]->info['name'], '!current' => $module->info['name'], ]), 'info'); @@ -367,7 +367,7 @@ function disable_bee_callback($arguments, $options) { foreach ($dependencies as $key => $dependency) { if (!in_array($dependency, $unique_dependencies)) { // Report info on dependencies to be disabled. - bee_message(bt("The '!dependency' module will also be disabled, as it depends on the '!current' module.", [ + bee_instant_message(bt("The '!dependency' module will also be disabled, as it depends on the '!current' module or one of the modules it requires.", [ '!dependency' => $modules[$dependency]->info['name'], '!current' => $module->info['name'], ]), 'info'); diff --git a/includes/dependencies.inc b/includes/dependencies.inc new file mode 100644 index 0000000..656bfcb --- /dev/null +++ b/includes/dependencies.inc @@ -0,0 +1,100 @@ +status) { + // This module doesn't exist or is already disabled, skip it. + unset($module_list[$module]); + continue; + } + $module_list[$module] = $module_data[$module]->sort; + + // Add dependent modules to the list, with a placeholder weight. + // The new modules will be processed as the while loop continues. + foreach ($module_data[$module]->required_by as $dependent => $dependent_data) { + if (!isset($module_list[$dependent]) && $dependent != $profile) { + $module_list[$dependent] = 0; + } + } + } + // Sort the module list by pre-calculated weights. + asort($module_list); + $module_list = array_keys($module_list); + + return $module_list; +} + +/** + * Builds the full list of module requirements based on input. + * This function is copied from Backdrop Core module_enable() + * until its functionality can be broken out for contrib access. + * + * @param array $module_data + * A list of all installed modules. + * @param array $module_list + * A list of modules for which to check requirements. + * + * @return array $module_list + * A list of modules and their required modules. + */ +function bee_get_required_modules(array $module_data, array $module_list) { + // Create an associative array with weights as values. + $module_list = array_flip(array_values($module_list)); + + // The array is iterated over manually (instead of using a foreach) because + // modules may be added to the list within the loop and we need to process + // them. + while ($module = key($module_list)) { + next($module_list); + if (!isset($module_data[$module])) { + // This module is not found in the filesystem, abort. + return FALSE; + } + if ($module_data[$module]->status) { + // Skip already enabled modules. + unset($module_list[$module]); + continue; + } + $module_list[$module] = $module_data[$module]->sort; + + // Add dependencies to the list, with a placeholder weight. + // The new modules will be processed as the while loop continues. + foreach (array_keys($module_data[$module]->requires) as $dependency) { + if (!isset($module_list[$dependency])) { + $module_list[$dependency] = 0; + } + } + } + + // Sort the module list by pre-calculated weights. + arsort($module_list); + $module_list = array_keys($module_list); + + return $module_list; +} diff --git a/includes/miscellaneous.inc b/includes/miscellaneous.inc index 212c294..1cd84ef 100644 --- a/includes/miscellaneous.inc +++ b/includes/miscellaneous.inc @@ -206,98 +206,3 @@ function bee_format_date($timestamp, $format = 'Y-m-d H:i:s T', $timezone = NULL } return $date->format($format); } - -/** - * Builds the full list of dependent modules based on input. - * This function is copied from Backdrop Core module_disable() - * until its functionality can be broken out for contrib access. - * - * @param array $module_data - * A list of all installed modules. - * @param array $module_list - * A list of modules for which to check dependencies. - * - * @return array $module_list - * A list of modules and their dependent modules. - */ -function bee_get_dependent_modules(array $module_data, array $module_list) { - // Create an associative array with weights as values. - $module_list = array_flip(array_values($module_list)); - - $profile = backdrop_get_profile(); - // The array is iterated over manually (instead of using a foreach) because - // modules may be added to the list within the loop and we need to process - // them. - while ($module = key($module_list)) { - next($module_list); - if (!isset($module_data[$module]) || !$module_data[$module]->status) { - // This module doesn't exist or is already disabled, skip it. - unset($module_list[$module]); - continue; - } - $module_list[$module] = $module_data[$module]->sort; - - // Add dependent modules to the list, with a placeholder weight. - // The new modules will be processed as the while loop continues. - foreach ($module_data[$module]->required_by as $dependent => $dependent_data) { - if (!isset($module_list[$dependent]) && $dependent != $profile) { - $module_list[$dependent] = 0; - } - } - } - - // Sort the module list by pre-calculated weights. - asort($module_list); - $module_list = array_keys($module_list); - - return $module_list; -} - -/** - * Builds the full list of module requirements based on input. - * This function is copied from Backdrop Core module_able() - * until its functionality can be broken out for contrib access. - * - * @param array $module_data - * A list of all installed modules. - * @param array $module_list - * A list of modules for which to check requirements. - * - * @return array $module_list - * A list of modules and their required modules. - */ -function bee_get_required_modules(array $module_data, array $module_list) { - // Create an associative array with weights as values. - $module_list = array_flip(array_values($module_list)); - - // The array is iterated over manually (instead of using a foreach) because - // modules may be added to the list within the loop and we need to process - // them. - while ($module = key($module_list)) { - next($module_list); - if (!isset($module_data[$module])) { - // This module is not found in the filesystem, abort. - return FALSE; - } - if ($module_data[$module]->status) { - // Skip already enabled modules. - unset($module_list[$module]); - continue; - } - $module_list[$module] = $module_data[$module]->sort; - - // Add dependencies to the list, with a placeholder weight. - // The new modules will be processed as the while loop continues. - foreach (array_keys($module_data[$module]->requires) as $dependency) { - if (!isset($module_list[$dependency])) { - $module_list[$dependency] = 0; - } - } - } - - // Sort the module list by pre-calculated weights. - arsort($module_list); - $module_list = array_keys($module_list); - - return $module_list; -}