3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Utils_Check_Component_Schema
extends CRM_Utils_Check_Component
{
20 * Check defined indices exist.
23 * @throws \CiviCRM_API3_Exception
25 public function checkIndices() {
28 // CRM-21298: The "Update Indices" tool that this check suggests is
29 // unreliable. Bypass this check until CRM-20817 and CRM-20533 are resolved.
32 $missingIndices = civicrm_api3('System', 'getmissingindices', [])['values'];
33 if ($missingIndices) {
35 foreach ($missingIndices as $tableName => $indices) {
36 foreach ($indices as $index) {
37 $fields = implode(', ', $index['field']);
38 $html .= "<tr><td>{$tableName}</td><td>{$index['name']}</td><td>$fields</td>";
41 $message = "<p>The following tables have missing indices. Click 'Update Indices' button to create them.<p>
42 <p><table><thead><tr><th>Table Name</th><th>Key Name</th><th>Expected Indices</th>
45 </tbody></table></p>";
46 $msg = new CRM_Utils_Check_Message(
49 ts('Performance warning: Missing indices'),
50 \Psr\Log\LogLevel
::WARNING
,
55 ts('Update all database indices now? This may take a few minutes and cause a noticeable performance lag for all users while running.'),
57 ['System', 'updateindexes']
67 public function checkMissingLogTables() {
69 $logging = new CRM_Logging_Schema();
70 $missingLogTables = $logging->getMissingLogTables();
72 if (Civi
::settings()->get('logging') && $missingLogTables) {
73 $msg = new CRM_Utils_Check_Message(
75 ts("You don't have logging enabled on some tables. This may cause errors on performing insert/update operation on them."),
76 ts('Missing Log Tables'),
77 \Psr\Log\LogLevel
::WARNING
,
81 ts('Create Missing Log Tables'),
82 ts('Create missing log tables now? This may take few minutes.'),
84 ['System', 'createmissinglogtables']
92 * Check that no smart groups exist that contain deleted custom fields.
96 public function checkSmartGroupCustomFieldCriteria() {
97 if (CRM_Core_BAO_Domain
::isDBUpdateRequired()) {
98 // Do not run this check when the db has not been updated as it might fail on non-updated schema issues.
101 $messages = $problematicSG = [];
102 $customFieldIds = array_keys(CRM_Core_BAO_CustomField
::getFields('ANY', FALSE, FALSE, NULL, NULL, FALSE, FALSE, FALSE));
104 $smartGroups = civicrm_api3('SavedSearch', 'get', [
106 'options' => ['limit' => 0],
109 catch (CiviCRM_API3_Exception
$e) {
110 $messages[] = new CRM_Utils_Check_Message(
112 ts('The smart group check was unable to run. This is likely to because a database upgrade is pending.'),
113 ts('Smart Group check did not run'),
114 \Psr\Log\LogLevel
::INFO
,
119 if (empty($smartGroups['values'])) {
122 foreach ($smartGroups['values'] as $group) {
123 if (empty($group['form_values'])) {
126 foreach ($group['form_values'] as $formValues) {
127 if (isset($formValues[0]) && (strpos($formValues[0], 'custom_') === 0)) {
128 list(, $customFieldID) = explode('_', $formValues[0]);
129 if (!in_array((int) $customFieldID, $customFieldIds, TRUE)) {
130 $problematicSG[CRM_Contact_BAO_SavedSearch
::getName($group['id'], 'id')] = [
131 'title' => CRM_Contact_BAO_SavedSearch
::getName($group['id'], 'title'),
132 'cfid' => $customFieldID,
133 'ssid' => $group['id'],
140 if (!empty($problematicSG)) {
142 foreach ($problematicSG as $id => $field) {
143 if (!empty($field['cfid'])) {
145 $customField = civicrm_api3('CustomField', 'getsingle', [
147 'id' => $field['cfid'],
149 $fieldName = ts('<a href="%1" title="Edit Custom Field"> %2 </a>', [
150 1 => CRM_Utils_System
::url('civicrm/admin/custom/group/field/update',
151 "action=update&reset=1&gid={$customField['custom_group_id']}&id={$field['cfid']}", TRUE
153 2 => $customField['label'],
156 catch (CiviCRM_API3_Exception
$e) {
157 $fieldName = ' <span style="color:red"> - Deleted - </span> ';
160 $groupEdit = '<a href="' . CRM_Utils_System
::url('civicrm/contact/search/advanced', "?reset=1&ssID={$field['ssid']}", TRUE) . '" title="' . ts('Edit search criteria') . '"> <i class="crm-i fa-pencil" aria-hidden="true"></i> </a>';
161 $groupConfig = '<a href="' . CRM_Utils_System
::url('civicrm/group', "?reset=1&action=update&id={$id}", TRUE) . '" title="' . ts('Group settings') . '"> <i class="crm-i fa-gear" aria-hidden="true"></i> </a>';
162 $html .= "<tr><td>{$id} - {$field['title']} </td><td>{$groupEdit} {$groupConfig}</td><td class='disabled'>{$fieldName}</td>";
165 $message = "<p>The following smart groups include custom fields which are disabled/deleted from the database. This may cause errors on group page.
166 You might need to edit their search criteria and update them to clean outdated fields from saved search OR disable them in order to fix the error.</p>
167 <p><table><thead><tr><th>Group</th><th></th><th>Custom Field</th>
173 $msg = new CRM_Utils_Check_Message(
176 ts('Disabled/Deleted fields on Smart Groups'),
177 \Psr\Log\LogLevel
::WARNING
,
185 public function checkMoneyValueFormatConfig() {
187 if (CRM_Core_Config
::singleton()->moneyvalueformat
!== '%!i') {
188 $msg = new CRM_Utils_Check_Message(
191 '<p>The Monetary Value Display format is a deprecated setting, and this site has a non-standard format. Please report your configuration on <a href="%1">this Gitlab issue</a>.',
192 [1 => 'https://lab.civicrm.org/dev/core/-/issues/1494']
194 ts('Deprecated monetary value display format configuration'),
195 \Psr\Log\LogLevel
::WARNING
,