Skip to content

Commit

Permalink
add new api and unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
Jitendra Purohit committed Aug 23, 2017
1 parent 7404466 commit 0dca860
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
8 changes: 4 additions & 4 deletions CRM/Utils/Check/Component/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ public function checkMissingLogTables() {
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;
}
Expand Down
22 changes: 16 additions & 6 deletions api/v3/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,12 +398,6 @@ function ($k) {
*/
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);
}
Expand All @@ -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);
}
12 changes: 12 additions & 0 deletions tests/phpunit/api/v3/LoggingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,18 @@ public function testUpdateLegacyLogTable() {
);
}

/**
* 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.
*/
Expand Down

0 comments on commit 0dca860

Please sign in to comment.