Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make financialacls require civi-contribute #28318

Merged
merged 2 commits into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions CRM/Core/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,44 @@ public static function isEnabled(string $component): bool {
}

/**
* Callback for the "enable_components" setting
* Callback for the "enable_components" setting (pre change)
*
* Before a component is disabled, disable reverse-dependencies (all extensions dependent on it).
*
* This is imperfect because it only goes one-level deep:
* it doesn't deal with any extensions that depend on the ones being disabled.
* The proper fix for that would probably be something like a CASCADE mode for
* disabling an extension with all its reverse dependencies (which would render this function moot).
*
* @param array $oldValue
* List of component names.
* @param array $newValue
* List of component names.
*
* @throws \CRM_Core_Exception.
*/
public static function preToggleComponents($oldValue, $newValue): void {
if (is_array($oldValue) && is_array($newValue)) {
$disabledComponents = array_diff($oldValue, $newValue);
}
if (empty($disabledComponents)) {
return;
}
$disabledExtensions = array_map(['CRM_Utils_String', 'convertStringToSnakeCase'], $disabledComponents);
$manager = CRM_Extension_System::singleton()->getManager();
$extensions = $manager->getStatuses();
foreach ($extensions as $extension => $status) {
if ($status === CRM_Extension_Manager::STATUS_INSTALLED) {
$info = $manager->mapper->keyToInfo($extension);
if (array_intersect($info->requires, $disabledExtensions)) {
$manager->disable($extension);
}
}
}
}

/**
* Callback for the "enable_components" setting (post change)
*
* When a component is enabled or disabled, ensure the corresponding module-extension is also enabled/disabled.
*
Expand All @@ -427,7 +464,7 @@ public static function isEnabled(string $component): bool {
*
* @throws \CRM_Core_Exception.
*/
public static function onToggleComponents($oldValue, $newValue): void {
public static function postToggleComponents($oldValue, $newValue): void {
if (CRM_Core_Config::isUpgradeMode()) {
return;
}
Expand Down
3 changes: 1 addition & 2 deletions CRM/Extension/Upgrader/Component.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php
use CRM_AfformAdmin_ExtensionUtil as E;

/**
* Upgrader base class ONLY for core component extensions (e.g. `civi_mail`, `civi_event`).
Expand All @@ -22,7 +21,7 @@ public function disable() {
}

/**
* Get of component (e.g. CiviMail)
* Get name of component corresponding to this extension (e.g. CiviMail)
*
* @return string
*/
Expand Down
3 changes: 3 additions & 0 deletions ext/financialacls/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
<mixins>
<mixin>setting-php@1.0.0</mixin>
</mixins>
<requires>
<ext>civi_contribute</ext>
</requires>
<civix>
<namespace>CRM/Financialacls</namespace>
<format>23.02.1</format>
Expand Down
3 changes: 2 additions & 1 deletion settings/Core.setting.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,9 +800,10 @@
'help_text' => NULL,
'on_change' => [
'CRM_Case_Info::onToggleComponents',
'CRM_Core_Component::preToggleComponents',
],
'post_change' => [
'CRM_Core_Component::onToggleComponents',
'CRM_Core_Component::postToggleComponents',
],
'pseudoconstant' => [
'callback' => 'CRM_Core_SelectValues::getComponentSelectValues',
Expand Down