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

Restrict inactive Dashlet query to Dashlets in the current domain #15283

Merged
merged 4 commits into from
Oct 9, 2019
Merged
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
34 changes: 30 additions & 4 deletions CRM/Core/BAO/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,39 @@ public static function saveDashletChanges($columns, $contactID = NULL) {
}
}

// Disable inactive widgets
$dashletClause = $dashletIDs ? "dashboard_id NOT IN (" . implode(',', $dashletIDs) . ")" : '(1)';
// Find dashlets in this domain.
$domainDashlets = civicrm_api3('Dashboard', 'get', [
'return' => array('id'),
'domain_id' => CRM_Core_Config::domainID(),
'options' => ['limit' => 0],
]);
christianwach marked this conversation as resolved.
Show resolved Hide resolved

// Get the array of IDs.
$domainDashletIDs = [];
if ($domainDashlets['is_error'] == 0) {
$domainDashletIDs = CRM_Utils_Array::collect('id', $domainDashlets['values']);
}

// Restrict query to Dashlets in this domain.
$domainDashletClause = !empty($domainDashletIDs) ? "dashboard_id IN (" . implode(',', $domainDashletIDs) . ")" : '(1)';
christianwach marked this conversation as resolved.
Show resolved Hide resolved

// Target only those Dashlets which are inactive.
$dashletClause = $dashletIDs ? "dashboard_id NOT IN (" . implode(',', $dashletIDs) . ")" : '(1)';

// Build params.
$params = [
1 => [$contactID, 'Integer'],
];

// Build query.
$updateQuery = "UPDATE civicrm_dashboard_contact
SET is_active = 0
WHERE $dashletClause AND contact_id = {$contactID}";
WHERE $domainDashletClause
AND $dashletClause
AND contact_id = %1";

CRM_Core_DAO::executeQuery($updateQuery);
// Disable inactive widgets.
CRM_Core_DAO::executeQuery($updateQuery, $params);
}

/**
Expand Down