Skip to content

Commit

Permalink
Add filter 'tables' on System.updateindexes function
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Dec 23, 2019
1 parent 8c25ce7 commit c1a7d35
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
22 changes: 20 additions & 2 deletions api/v3/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -411,12 +411,30 @@ function _civicrm_api3_system_updatelogtables_spec(&$params) {
* Update indexes.
*
* This adds any indexes that exist in the schema but not the database.
*
* @param array $params
*
* @return array
*/
function civicrm_api3_system_updateindexes() {
CRM_Core_BAO_SchemaHandler::createMissingIndices(CRM_Core_BAO_SchemaHandler::getMissingIndices(TRUE));
function civicrm_api3_system_updateindexes(array $params):array {
$tables = empty($params['tables']) ? FALSE : (array) $params['tables'];
CRM_Core_BAO_SchemaHandler::createMissingIndices(CRM_Core_BAO_SchemaHandler::getMissingIndices(TRUE, $tables));
return civicrm_api3_create_success(1);
}

/**
* Declare metadata for api System.getmissingindices
*
* @param array $params
*/
function _civicrm_api3_system_updateindexes_spec(array &$params) {
$params['tables'] = [
'type' => CRM_Utils_Type::T_STRING,
'api.default' => FALSE,
'title' => ts('Optional tables filter'),
];
}

/**
* Get an array of indices that should be defined but are not.
*
Expand Down
3 changes: 3 additions & 0 deletions tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ public function testGetMissingIndicesWithTableFilter() {
$this->assertEquals($expected, $missingIndices);
$missingIndices = $this->callAPISuccess('System', 'getmissingindices', ['tables' => ['civicrm_contact']])['values'];
$this->assertEquals(['civicrm_contact' => $expected['civicrm_contact']], $missingIndices);
$this->callAPISuccess('System', 'updateindexes', ['tables' => 'civicrm_contribution']);
$missingIndices = $this->callAPISuccess('System', 'getmissingindices', [])['values'];
$this->assertEquals(['civicrm_contact' => $expected['civicrm_contact']], $missingIndices);
}

/**
Expand Down

0 comments on commit c1a7d35

Please sign in to comment.