Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-20995 - API - Extension get - Filter by full_name #10796

Merged
merged 4 commits into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions api/v3/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,9 @@ function _civicrm_api3_extension_refresh_spec(&$fields) {
* API result
*/
function civicrm_api3_extension_get($params) {
$keys = isset($params['key']) ? (array) $params['key'] : NULL;
$full_names = _civicrm_api3_getKeys($params, 'full_name');
$keys = _civicrm_api3_getKeys($params, 'key');
$keys = array_merge($full_names, $keys);
$statuses = CRM_Extension_System::singleton()->getManager()->getStatuses();
$mapper = CRM_Extension_System::singleton()->getMapper();
$result = array();
Expand All @@ -347,7 +349,7 @@ function civicrm_api3_extension_get($params) {
}
$info = CRM_Extension_System::createExtendedInfo($obj);
$info['id'] = $id++; // backward compatibility with indexing scheme
if (!empty($params['key'])) {
if (!empty($keys)) {
if (in_array($key, $keys)) {
$result[] = $info;
}
Expand Down Expand Up @@ -386,16 +388,22 @@ function civicrm_api3_extension_getremote($params) {
* Determine the list of extension keys.
*
* @param array $params
* @param string $key
* API request params with 'keys'.
*
* @return array
*/
function _civicrm_api3_getKeys($params) {
if (is_array($params['keys'])) {
return $params['keys'];
function _civicrm_api3_getKeys($params, $key = 'keys') {
if (isset($params[$key])) {
if (is_array($params[$key])) {
return $params[$key];
}
if ($params[$key] == '') {
return array();
}
return explode(API_V3_EXTENSION_DELIMITER, $params[$key]);
}
if ($params['keys'] == '') {
else {
return array();
}
return explode(API_V3_EXTENSION_DELIMITER, $params['keys']);
}
8 changes: 8 additions & 0 deletions tests/phpunit/api/v3/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,12 @@ public function testGetMultipleExtensions() {
$this->assertEquals(2, $result['count']);
}

/**
* Test that extension get works with api request with parameter full_name as build by api explorer.
*/
public function testGetMultipleExtensionsApiExplorer() {
$result = $this->callAPISuccess('extension', 'get', array('full_name' => array('test.extension.manager.paymenttest', 'test.extension.manager.moduletest')));
$this->assertEquals(2, $result['count']);
}

}