}
}
- // 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],
+ ]);
+
+ // 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)';
+
+ // 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);
}
/**