From cb7213564d0edee9dacf32802daf2940b290f566 Mon Sep 17 00:00:00 2001 From: Jitendra Purohit Date: Wed, 23 Aug 2017 15:06:22 +0530 Subject: [PATCH] add new api and unit test --- CRM/Utils/Check/Component/Schema.php | 8 ++++---- api/v3/System.php | 22 ++++++++++++++++------ tests/phpunit/api/v3/LoggingTest.php | 12 ++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/CRM/Utils/Check/Component/Schema.php b/CRM/Utils/Check/Component/Schema.php index 7d4d1353b6..41781473d6 100644 --- a/CRM/Utils/Check/Component/Schema.php +++ b/CRM/Utils/Check/Component/Schema.php @@ -87,16 +87,16 @@ class CRM_Utils_Check_Component_Schema extends CRM_Utils_Check_Component { 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("You don't have logging enabled on some tables. This may cause errors on performing insert/update operation 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.'), + ts('Create Missing Log Tables'), + ts('Create missing log tables now? This may take few minutes.'), 'api3', - array('System', 'updatelogtables') + array('System', 'createmissinglogtables') ); $messages[] = $msg; } diff --git a/api/v3/System.php b/api/v3/System.php index 8ab68c6512..83291c00cd 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -398,12 +398,6 @@ 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); } @@ -418,3 +412,19 @@ function civicrm_api3_system_updateindexes() { CRM_Core_BAO_SchemaHandler::createMissingIndices($missingIndices); return civicrm_api3_create_success(1); } + +/** + * Creates missing log tables. + * + * CRM-20838 - This adds any missing log tables into the database. + */ +function civicrm_api3_system_createmissinglogtables() { + $schema = new CRM_Logging_Schema(); + $missingLogTables = $schema->getMissingLogTables(); + if (!empty($missingLogTables)) { + foreach ($missingLogTables as $tableName) { + $schema->fixSchemaDifferencesFor($tableName, NULL, FALSE); + } + } + return civicrm_api3_create_success(1); +} diff --git a/tests/phpunit/api/v3/LoggingTest.php b/tests/phpunit/api/v3/LoggingTest.php index 27ff65e00b..15b8ec428b 100644 --- a/tests/phpunit/api/v3/LoggingTest.php +++ b/tests/phpunit/api/v3/LoggingTest.php @@ -127,6 +127,18 @@ class api_v3_LoggingTest extends CiviUnitTestCase { ); } + /** + * Check if we can create missing log tables using api. + */ + public function testCreateMissingLogTables() { + $this->callAPISuccess('Setting', 'create', array('logging' => TRUE)); + CRM_Core_DAO::executeQuery("DROP TABLE log_civicrm_contact"); + $this->callAPISuccess('System', 'createmissinglogtables', array()); + + //Assert if log_civicrm_contact is created. + $this->checkLogTableCreated(); + } + /** * Check we can update legacy log tables using the api function. */ -- 2.25.1