From c1a7d35bccb785c25f4ff3312fd30c9888ffaeda Mon Sep 17 00:00:00 2001 From: eileen Date: Mon, 23 Dec 2019 12:53:41 +1300 Subject: [PATCH] Add filter 'tables' on System.updateindexes function --- api/v3/System.php | 22 +++++++++++++++++-- .../CRM/Core/BAO/SchemaHandlerTest.php | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/api/v3/System.php b/api/v3/System.php index 7bf1d3f4015a..2abbdf4bc44c 100644 --- a/api/v3/System.php +++ b/api/v3/System.php @@ -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. * diff --git a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php index 811e8c4c8d67..ae788ba64f72 100644 --- a/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php +++ b/tests/phpunit/CRM/Core/BAO/SchemaHandlerTest.php @@ -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); } /**