Skip to content

Commit

Permalink
Merge pull request #22687 from colemanw/cleanupComponentCheck
Browse files Browse the repository at this point in the history
REF - Switch to using new `CRM_Core_Component::isEnabled()`
  • Loading branch information
colemanw authored Feb 6, 2022
2 parents d7a3e0f + e46f73c commit 654b491
Show file tree
Hide file tree
Showing 36 changed files with 48 additions and 100 deletions.
3 changes: 1 addition & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2067,8 +2067,7 @@ public static function getProfileFields() {
'is_current_revision',
'activity_is_deleted',
];
$config = CRM_Core_Config::singleton();
if (!in_array('CiviCampaign', $config->enableComponents)) {
if (!CRM_Core_Component::isEnabled('CiviCampaign')) {
$skipFields[] = 'activity_engagement_level';
}

Expand Down
3 changes: 1 addition & 2 deletions CRM/Activity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ public static function tasks() {
],
];

$config = CRM_Core_Config::singleton();
if (in_array('CiviCase', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviCase')) {
if (CRM_Core_Permission::check('access all cases and activities') ||
CRM_Core_Permission::check('access my cases and activities')
) {
Expand Down
3 changes: 1 addition & 2 deletions CRM/Admin/Form/Options.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,7 @@ public function buildQuickForm() {

// If CiviCase enabled AND "Add" mode OR "edit" mode for non-reserved activities, only allow user to pick Core or CiviCase component.
// FIXME: Each component should define whether adding new activity types is allowed.
$config = CRM_Core_Config::singleton();
if ($this->_gName == 'activity_type' && in_array("CiviCase", $config->enableComponents) &&
if ($this->_gName == 'activity_type' && CRM_Core_Component::isEnabled("CiviCase") &&
(($this->_action & CRM_Core_Action::ADD) || !$isReserved)
) {
$caseID = CRM_Core_Component::getComponentID('CiviCase');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/BAO/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public static function getPermissionedCampaigns(
* @return bool
*/
public static function isCampaignEnable(): bool {
return in_array('CiviCampaign', CRM_Core_Config::singleton()->enableComponents, TRUE);
return CRM_Core_Component::isEnabled('CiviCampaign');
}

/**
Expand Down
3 changes: 1 addition & 2 deletions CRM/Case/BAO/Case.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class CRM_Case_BAO_Case extends CRM_Case_DAO_Case {
* @return bool
*/
public static function enabled() {
$config = CRM_Core_Config::singleton();
return in_array('CiviCase', $config->enableComponents);
return CRM_Core_Component::isEnabled('CiviCase');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -3268,7 +3268,7 @@ public static function checkUserMenuPermissions($aclPermissionedTasks, $corePerm
$componentName = $menuOptions['component'] ?? NULL;

// if component action - make sure component is enable.
if ($componentName && !in_array($componentName, CRM_Core_Config::singleton()->enableComponents)) {
if ($componentName && !CRM_Core_Component::isEnabled($componentName)) {
return FALSE;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public function preProcess() {

$this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();

if (in_array('CiviPledge', CRM_Core_Config::singleton()->enableComponents) && !$this->_formType) {
if (CRM_Core_Component::isEnabled('CiviPledge') && !$this->_formType) {
$this->preProcessPledge();
}

Expand Down
3 changes: 1 addition & 2 deletions CRM/Contribute/Form/Contribution/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ public function buildQuickForm() {
$this->set('productID', $productID);
$this->set('option', $option);
}
$config = CRM_Core_Config::singleton();
if (in_array('CiviMember', $config->enableComponents) && empty($this->_ccid)) {
if (CRM_Core_Component::isEnabled('CiviMember') && empty($this->_ccid)) {
if (isset($params['selectMembership']) &&
$params['selectMembership'] !== 'no_thanks'
) {
Expand Down
3 changes: 1 addition & 2 deletions CRM/Contribute/Form/Contribution/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -426,8 +426,7 @@ public function buildQuickForm() {

//don't build pledge block when mid is passed
if (!$this->_mid && empty($this->_ccid)) {
$config = CRM_Core_Config::singleton();
if (in_array('CiviPledge', $config->enableComponents) && !empty($this->_values['pledge_block_id'])) {
if (CRM_Core_Component::isEnabled('CiviPledge') && !empty($this->_values['pledge_block_id'])) {
CRM_Pledge_BAO_PledgeBlock::buildPledgeBlock($this);
}
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,6 @@ public function assignToTemplate() {
'amount_level',
];

$config = CRM_Core_Config::singleton();
if (isset($this->_values['is_recur']) && !empty($this->_paymentProcessor['is_recur'])) {
$this->assign('is_recur_enabled', 1);
$vars = array_merge($vars, [
Expand All @@ -537,9 +536,10 @@ public function assignToTemplate() {
]);
}

if (in_array('CiviPledge', $config->enableComponents) &&
CRM_Utils_Array::value('is_pledge', $this->_params) == 1
if (CRM_Core_Component::isEnabled('CiviPledge') &&
!empty($this->_params['is_pledge'])
) {
// TODO: Assigned variable appears to be unused
$this->assign('pledge_enabled', 1);

$vars = array_merge($vars, [
Expand Down
3 changes: 1 addition & 2 deletions CRM/Contribute/Form/ContributionPage/Amount.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ public function buildQuickForm() {
]);

//CiviPledge fields.
$config = CRM_Core_Config::singleton();
if (in_array('CiviPledge', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviPledge')) {
$this->assign('civiPledge', TRUE);
$this->addElement('checkbox', 'is_pledge_active', ts('Pledges'),
NULL, ['onclick' => "showHideAmountBlock( this, 'is_pledge_active' ); return showHideByValue('is_pledge_active',true,'pledgeFields','table-row','radio',false);"]
Expand Down
6 changes: 1 addition & 5 deletions CRM/Contribute/Page/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,11 @@ public function run() {
return $controller->run();
}
elseif ($action & CRM_Core_Action::UPDATE) {
$config = CRM_Core_Config::singleton();

// assign vars to templates
$this->assign('id', $id);
$this->assign('title', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'title'));
$this->assign('is_active', CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $id, 'is_active'));
if (in_array('CiviMember', $config->enableComponents)) {
$this->assign('CiviMember', TRUE);
}
$this->assign('CiviMember', CRM_Core_Component::isEnabled('CiviMember'));
}
elseif ($action & CRM_Core_Action::COPY) {
// @todo Unused local variable can be safely removed.
Expand Down
4 changes: 1 addition & 3 deletions CRM/Contribute/StateMachine/ContributionPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public function __construct($controller, $action = CRM_Core_Action::NONE) {
$session = CRM_Core_Session::singleton();
$session->set('singleForm', FALSE);

$config = CRM_Core_Config::singleton();

$this->_pages = [
'CRM_Contribute_Form_ContributionPage_Settings' => NULL,
'CRM_Contribute_Form_ContributionPage_Amount' => NULL,
Expand All @@ -48,7 +46,7 @@ public function __construct($controller, $action = CRM_Core_Action::NONE) {
'CRM_Contribute_Form_ContributionPage_Widget' => NULL,
];

if (!in_array("CiviMember", $config->enableComponents)) {
if (!CRM_Core_Component::isEnabled('CiviMember')) {
unset($this->_pages['CRM_Member_Form_MembershipBlock']);
}

Expand Down
6 changes: 1 addition & 5 deletions CRM/Core/BAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ public static function initializeDashlets() {
*/
public static function checkPermission($permissions, $operator) {
if ($permissions) {
$config = CRM_Core_Config::singleton();

static $allComponents;
if (!$allComponents) {
$allComponents = CRM_Core_Component::getNames();
Expand All @@ -170,9 +168,7 @@ public static function checkPermission($permissions, $operator) {

//hack to determine if it's a component related permission
if ($componentName) {
if (!in_array($componentName, $config->enableComponents) ||
!CRM_Core_Permission::check($key)
) {
if (!CRM_Core_Component::isEnabled($componentName) || !CRM_Core_Permission::check($key)) {
$showDashlet = FALSE;
if ($operator == 'AND') {
return $showDashlet;
Expand Down
4 changes: 1 addition & 3 deletions CRM/Core/BAO/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,9 +368,7 @@ public static function checkPermission($item) {
$componentName = CRM_Core_Permission::getComponentName($key);

if ($componentName) {
if (!in_array($componentName, CRM_Core_Config::singleton()->enableComponents) ||
!CRM_Core_Permission::check($key)
) {
if (!CRM_Core_Component::isEnabled($componentName) || !CRM_Core_Permission::check($key)) {
$showItem = FALSE;
if ($operator == 'AND') {
return FALSE;
Expand Down
6 changes: 2 additions & 4 deletions CRM/Core/BAO/UFGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -3455,8 +3455,7 @@ public static function groupTypeValues($profileId, $groupType = NULL) {
*/
public static function isProfileDoubleOptin() {
// check for double optin
$config = CRM_Core_Config::singleton();
if (in_array('CiviMail', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviMail')) {
return Civi::settings()->get('profile_double_optin');
}
return FALSE;
Expand All @@ -3467,8 +3466,7 @@ public static function isProfileDoubleOptin() {
*/
public static function isProfileAddToGroupDoubleOptin() {
// check for add to group double optin
$config = CRM_Core_Config::singleton();
if (in_array('CiviMail', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviMail')) {
return Civi::settings()->get('profile_add_to_group_double_optin');
}
return FALSE;
Expand Down
10 changes: 3 additions & 7 deletions CRM/Core/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,6 @@ private static function setTemplateValues($id) {
* Create the list of options to create New objects for the application and format is as a block.
*/
private static function setTemplateShortcutValues() {
$config = CRM_Core_Config::singleton();

static $shortCuts = [];

if (!($shortCuts)) {
Expand All @@ -349,14 +347,12 @@ private static function setTemplateShortcutValues() {

$components = CRM_Core_Component::getEnabledComponents();

if (!empty($config->enableComponents)) {
if ($components) {
// check if we can process credit card contribs
$newCredit = CRM_Core_Config::isEnabledBackOfficeCreditCardPayments();

foreach ($components as $componentName => $obj) {
if (in_array($componentName, $config->enableComponents)) {
$obj->creatNewShortcut($shortCuts, $newCredit);
}
foreach ($components as $obj) {
$obj->creatNewShortcut($shortCuts, $newCredit);
}
}

Expand Down
3 changes: 1 addition & 2 deletions CRM/Core/Component/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,7 @@ abstract public function getActivityTypes();
* true if component is enabled, false if not
*/
public function isEnabled() {
$config = CRM_Core_Config::singleton();
return in_array($this->info['name'], $config->enableComponents, TRUE);
return CRM_Core_Component::isEnabled($this->info['name']);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions CRM/Core/Form/ShortCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class CRM_Core_Form_ShortCode extends CRM_Core_Form {
* Build form data. Can be modified via hook_civicrm_preProcess.
*/
public function preProcess() {
$config = CRM_Core_Config::singleton();

$this->components['user-dashboard'] = [
'label' => ts("User Dashboard"),
'select' => NULL,
Expand All @@ -73,7 +71,7 @@ public function preProcess() {
],
];

if (in_array('CiviContribute', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviContribute')) {
$this->components['contribution'] = [
'label' => ts("Contribution Page"),
'select' => [
Expand All @@ -92,7 +90,7 @@ public function preProcess() {
];
}

if (in_array('CiviEvent', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviEvent')) {
$this->components['event'] = [
'label' => ts("Event Page"),
'select' => [
Expand All @@ -103,7 +101,7 @@ public function preProcess() {
];
}

if (in_array('CiviCampaign', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviCampaign')) {
$this->components['petition'] = [
'label' => ts("Petition"),
'select' => [
Expand Down
4 changes: 1 addition & 3 deletions CRM/Core/Permission.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,7 @@ public static function eventClause($type = CRM_Core_Permission::VIEW, $prefix =
* Access to specified $module is granted.
*/
public static function access($module, $checkPermission = TRUE, $requireAllCasesPermOnCiviCase = FALSE) {
$config = CRM_Core_Config::singleton();

if (!in_array($module, $config->enableComponents)) {
if (!CRM_Core_Component::isEnabled($module)) {
return FALSE;
}

Expand Down
8 changes: 2 additions & 6 deletions CRM/Event/Form/ManageEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,7 @@ public function getDefaultContext() {
* Set variables up before form is built.
*/
public function preProcess() {
$config = CRM_Core_Config::singleton();
if (in_array('CiviEvent', $config->enableComponents)) {
$this->assign('CiviEvent', TRUE);
}
$this->assign('CiviEvent', CRM_Core_Component::isEnabled('CiviEvent'));
CRM_Core_Form_RecurringEntity::preProcess('civicrm_event');

$this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add', 'REQUEST');
Expand Down Expand Up @@ -354,8 +351,7 @@ public function endPostProcess() {
[1 => CRM_Utils_Array::value('title', CRM_Utils_Array::value($subPage, $this->get('tabHeader')), $className)]
), $this->getTitle(), 'success');

$config = CRM_Core_Config::singleton();
if (in_array('CiviCampaign', $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviCampaign')) {
$values = $this->controller->exportValues($this->_name);
$newCampaignID = $values['campaign_id'] ?? NULL;
$eventID = $values['id'] ?? NULL;
Expand Down
3 changes: 1 addition & 2 deletions CRM/Mailing/Info.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public static function createAngularSettings():array {
}
}

$config = CRM_Core_Config::singleton();
$session = CRM_Core_Session::singleton();
$contactID = $session->get('userID');

Expand Down Expand Up @@ -95,7 +94,7 @@ public static function createAngularSettings():array {
$crmMailingSettings = [
'templateTypes' => CRM_Mailing_BAO_Mailing::getTemplateTypes(),
'civiMails' => [],
'campaignEnabled' => in_array('CiviCampaign', $config->enableComponents),
'campaignEnabled' => CRM_Core_Component::isEnabled('CiviCampaign'),
'groupNames' => [],
// @todo this is not used in core. Remove once Mosaico no longer depends on it.
'testGroupNames' => $groupNames['values'],
Expand Down
4 changes: 1 addition & 3 deletions CRM/Report/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -4399,9 +4399,7 @@ public function selectedTables() {
*/
public function addCampaignFields($entityTable = 'civicrm_contribution', $groupBy = FALSE, $orderBy = FALSE, $filters = TRUE) {
// Check if CiviCampaign is a) enabled and b) has active campaigns
$config = CRM_Core_Config::singleton();
$campaignEnabled = in_array('CiviCampaign', $config->enableComponents);
if ($campaignEnabled) {
if (CRM_Core_Component::isEnabled('CiviCampaign')) {
$getCampaigns = CRM_Campaign_BAO_Campaign::getPermissionedCampaigns(NULL, NULL, FALSE, FALSE, TRUE);
// If we have a campaign, build out the relevant elements
if (!empty($getCampaigns['campaigns'])) {
Expand Down
3 changes: 1 addition & 2 deletions CRM/Report/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,7 @@ public function add2group($groupID) {
*/
public static function formRule($fields, $files, $self) {
$errors = [];
$config = CRM_Core_Config::singleton();
if (in_array("CiviCase", $config->enableComponents)) {
if (CRM_Core_Component::isEnabled('CiviCase')) {
$componentId = CRM_Core_Component::getComponentID('CiviCase');
$caseActivityTypes = CRM_Core_OptionGroup::values('activity_type', TRUE, FALSE, FALSE, " AND v.component_id={$componentId}");
if (!empty($fields['activity_type_id_value']) && is_array($fields['activity_type_id_value']) && empty($fields['include_case_activities_value'])) {
Expand Down
3 changes: 1 addition & 2 deletions CRM/Report/Page/InstanceList.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ public function info() {

$dao = CRM_Core_DAO::executeQuery($sql, $queryParams);

$config = CRM_Core_Config::singleton();
$rows = [];
$url = 'civicrm/report/instance';
$my_reports_grouping = 'My';
Expand All @@ -143,7 +142,7 @@ public function info() {
continue;
}

$enabled = in_array("Civi{$dao->compName}", $config->enableComponents);
$enabled = CRM_Core_Component::isEnabled("Civi{$dao->compName}");
if ($dao->compName == 'Contact' || $dao->compName == $dao->grouping) {
$enabled = TRUE;
}
Expand Down
3 changes: 1 addition & 2 deletions CRM/Report/Page/TemplateList.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,9 @@ public static function &info($compID = NULL, $grouping = NULL) {

$dao = CRM_Core_DAO::executeQuery($sql);
$rows = [];
$config = CRM_Core_Config::singleton();
while ($dao->fetch()) {
if ($dao->component_name != 'Contact' && $dao->component_name != $dao->grouping &&
!in_array("Civi{$dao->component_name}", $config->enableComponents)
!CRM_Core_Component::isEnabled("Civi{$dao->component_name}")
) {
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Upgrade/Incremental/php/FiveFortySeven.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function updateRelationshipDates(CRM_Queue_TaskContext $ctx): bool
* @throws \Civi\API\Exception\NotImplementedException
*/
public static function migrateCiviGrant(CRM_Queue_TaskContext $ctx): bool {
$civiGrantEnabled = in_array('CiviGrant', Civi::settings()->get('enable_components'), TRUE);
$civiGrantEnabled = CRM_Core_Component::isEnabled('CiviGrant');
if ($civiGrantEnabled) {
CRM_Core_BAO_ConfigSetting::disableComponent('CiviGrant');
}
Expand Down
4 changes: 1 addition & 3 deletions CRM/Upgrade/Incremental/php/FiveThirteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ class CRM_Upgrade_Incremental_php_FiveThirteen extends CRM_Upgrade_Incremental_B
* an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs.
*/
public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) {
$config = CRM_Core_Config::singleton();
$campaignEnabled = in_array("CiviCampaign", $config->enableComponents);
if ($rev == '5.13.alpha1' && $campaignEnabled) {
if ($rev == '5.13.alpha1' && CRM_Core_Component::isEnabled('CiviCampaign')) {
$postUpgradeMessage .= '<br /><br />' . ts("If you have created a report based on the Mailing Summary Report template and it outputs or filters on campaigns, You will need to go back to that report and re-save the report after selecting and or setting the campaign filters up again");
}
}
Expand Down
Loading

0 comments on commit 654b491

Please sign in to comment.