From 74044663c96aefee2aba7e355a3009db0b022fc1 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Mon, 10 Jul 2017 13:18:54 +0530 Subject: [PATCH] CRM-20388 - Add check for missing log tables on system status --- CRM/Logging/Schema.php | 12 ++++++++++++ CRM/Utils/Check/Component/Schema.php | 27 +++++++++++++++++++++++++++ api/v3/System.php | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/CRM/Logging/Schema.php b/CRM/Logging/Schema.php index b34806019f..4551b89a64 100644 --- a/CRM/Logging/Schema.php +++ b/CRM/Logging/Schema.php @@ -934,4 +934,16 @@ COLS; return array_intersect($tables, $this->tables); } + /** + * Retrieve missing log tables. + * + * @return array + */ + public function getMissingLogTables() { + if ($this->tablesExist()) { + return array_diff($this->tables, array_keys($this->logs)); + } + return array(); + } + } diff --git a/CRM/Utils/Check/Component/Schema.php b/CRM/Utils/Check/Component/Schema.php index 72cfd636a6..7d4d1353b6 100644 --- a/CRM/Utils/Check/Component/Schema.php +++ b/CRM/Utils/Check/Component/Schema.php @@ -76,4 +76,31 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component { return $messages; } + /** + * @return array + */ + public function checkMissingLogTables() { + $messages = array(); + $logging = new CRM_Logging_Schema(); + $missingLogTables = $logging->getMissingLogTables(); + + if ($missingLogTables) { + $msg = new CRM_Utils_Check_Message( + __FUNCTION__, + ts("You don't have logging enabled for some tables. This may cause errors on performing insert/update actions on them."), + ts('Missing Log Tables'), + \Psr\Log\LogLevel::WARNING, + 'fa-server' + ); + $msg->addAction( + ts('Update Log Tables'), + ts('Update logging now? This may take few minutes.'), + 'api3', + array('System', 'updatelogtables') + ); + $messages[] = $msg; + } + return $messages; + } + } diff --git a/api/v3/System.php b/api/v3/System.php index b4b4974bf0..8ab68c6512 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -398,6 +398,12 @@ function _civicrm_api3_system_get_whitelist($whitelistFile) { */ function civicrm_api3_system_updatelogtables() { $schema = new CRM_Logging_Schema(); + $missingLogTables = $schema->getMissingLogTables(); + if (!empty($missingLogTables)) { + foreach ($missingLogTables as $tableName) { + $schema->fixSchemaDifferencesFor($tableName, NULL, FALSE); + } + } $schema->updateLogTableSchema(); return civicrm_api3_create_success(1); } -- 2.25.1