Skip to content

Commit

Permalink
dev/core#1471 - Add system status alert for deleted custom fields in …
Browse files Browse the repository at this point in the history
…smart groups
  • Loading branch information
Jitendra Purohit committed Jan 10, 2020
1 parent c5f0aba commit 9dc1c01
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions CRM/Utils/Check/Component/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,54 @@ public function checkMissingLogTables() {
return $messages;
}

/**
* @return array
*/
public function checkSmartGroupCustomFieldCriteria() {
$messages = $problematicSG = [];
$customFieldIds = array_keys(CRM_Core_BAO_CustomField::getFields('ANY', FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE));
$smartGroups = civicrm_api3('SavedSearch', 'get', [
'sequential' => 1,
'options' => ['limit' => 0],
]);
if (empty($smartGroups['values'])) {
return;
}
foreach ($smartGroups['values'] as $group) {
if (empty($group['form_values'])) {
continue;
}
foreach ($group['form_values'] as $formValues) {
if (substr($formValues[0], 0, 7) == 'custom_') {
list(, $customFieldID) = explode('custom_', $formValues[0]);
if (!in_array($customFieldID, $customFieldIds)) {
$problematicSG[CRM_Contact_BAO_SavedSearch::getName($group['id'], 'id')] = CRM_Contact_BAO_SavedSearch::getName($group['id'], 'title');
}
}
}
}

if (!empty($problematicSG)) {
$html = '';
foreach ($problematicSG as $id => $groupName) {
$html .= "<tr><td>{$id}</td><td>{$groupName}</td>";
}
$message = "<p>The following smart groups include custom fields which are disabled/deleted from the database. This may cause errors on group page.<p>
<p><table><thead><tr><th>ID</th><th>Group Title</th>
</tr></thead><tbody>
$html
</tbody></table></p>
<p>You might need to revisit these groups and disable them in order to fix the error.</p>";
$msg = new CRM_Utils_Check_Message(
__FUNCTION__,
ts($message),
ts('Disabled/Deleted fields on Smart Groups'),
\Psr\Log\LogLevel::WARNING,
'fa-server'
);
$messages[] = $msg;
}
return $messages;
}

}

0 comments on commit 9dc1c01

Please sign in to comment.