Update copyright date for 2020
[civicrm-core.git] / CRM / Utils / Check / Component / Schema.php
CommitLineData
49186f94
AS
1<?php
2/*
3 +--------------------------------------------------------------------+
fee14197 4 | CiviCRM version 5 |
49186f94 5 +--------------------------------------------------------------------+
f299f7db 6 | Copyright CiviCRM LLC (c) 2004-2020 |
49186f94
AS
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28/**
29 *
30 * @package CRM
f299f7db 31 * @copyright CiviCRM LLC (c) 2004-2020
49186f94
AS
32 */
33class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component {
34
35 /**
36 * @return array
37 */
38 public function checkIndices() {
be2fb01f 39 $messages = [];
bb90f230
AH
40
41 // CRM-21298: The "Update Indices" tool that this check suggests is
42 // unreliable. Bypass this check until CRM-20817 and CRM-20533 are resolved.
43 return $messages;
44
3d4602c3
JP
45 $missingIndices = CRM_Core_BAO_SchemaHandler::getMissingIndices();
46 if ($missingIndices) {
f4f835ed 47 $html = '';
3d4602c3 48 foreach ($missingIndices as $tableName => $indices) {
f4f835ed
JP
49 foreach ($indices as $index) {
50 $fields = implode(', ', $index['field']);
51 $html .= "<tr><td>{$tableName}</td><td>{$index['name']}</td><td>$fields</td>";
52 }
53 }
3d4602c3
JP
54 $message = "<p>The following tables have missing indices. Click 'Update Indices' button to create them.<p>
55 <p><table><thead><tr><th>Table Name</th><th>Key Name</th><th>Expected Indices</th>
f4f835ed
JP
56 </tr></thead><tbody>
57 $html
58 </tbody></table></p>";
531b0c6c 59 $msg = new CRM_Utils_Check_Message(
49186f94 60 __FUNCTION__,
f4f835ed 61 ts($message),
63809327 62 ts('Performance warning: Missing indices'),
49186f94
AS
63 \Psr\Log\LogLevel::WARNING,
64 'fa-server'
65 );
531b0c6c 66 $msg->addAction(
d758aa97 67 ts('Update Indices'),
531b0c6c
CW
68 ts('Update all database indices now? This may take a few minutes and cause a noticeable performance lag for all users while running.'),
69 'api3',
be2fb01f 70 ['System', 'updateindexes']
531b0c6c
CW
71 );
72 $messages[] = $msg;
49186f94
AS
73 }
74 return $messages;
75 }
76
74044663
JP
77 /**
78 * @return array
79 */
80 public function checkMissingLogTables() {
be2fb01f 81 $messages = [];
74044663
JP
82 $logging = new CRM_Logging_Schema();
83 $missingLogTables = $logging->getMissingLogTables();
84
26943048 85 if (Civi::settings()->get('logging') && $missingLogTables) {
74044663
JP
86 $msg = new CRM_Utils_Check_Message(
87 __FUNCTION__,
cb721356 88 ts("You don't have logging enabled on some tables. This may cause errors on performing insert/update operation on them."),
74044663
JP
89 ts('Missing Log Tables'),
90 \Psr\Log\LogLevel::WARNING,
91 'fa-server'
92 );
93 $msg->addAction(
cb721356
JP
94 ts('Create Missing Log Tables'),
95 ts('Create missing log tables now? This may take few minutes.'),
74044663 96 'api3',
be2fb01f 97 ['System', 'createmissinglogtables']
74044663
JP
98 );
99 $messages[] = $msg;
100 }
101 return $messages;
102 }
103
49186f94 104}