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 3 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
30 changes: 19 additions & 11 deletions api/v3/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
* @return array
*/
function civicrm_api3_extension_install($params) {
$keys = _civicrm_api3_getKeys($params);
$keys = _civicrm_api3_getKeys($params, 'keys');
if (!$keys) {
return civicrm_api3_create_success();
}
Expand Down Expand Up @@ -119,7 +119,7 @@ function civicrm_api3_extension_upgrade() {
* @return array
*/
function civicrm_api3_extension_enable($params) {
$keys = _civicrm_api3_getKeys($params);
$keys = _civicrm_api3_getKeys($params, 'keys');
if (count($keys) == 0) {
return civicrm_api3_create_success();
}
Expand Down Expand Up @@ -149,7 +149,7 @@ function _civicrm_api3_extension_enable_spec(&$fields) {
* @return array
*/
function civicrm_api3_extension_disable($params) {
$keys = _civicrm_api3_getKeys($params);
$keys = _civicrm_api3_getKeys($params, 'keys');
if (count($keys) == 0) {
return civicrm_api3_create_success();
}
Expand Down Expand Up @@ -181,7 +181,7 @@ function _civicrm_api3_extension_disable_spec(&$fields) {
* @return array
*/
function civicrm_api3_extension_uninstall($params) {
$keys = _civicrm_api3_getKeys($params);
$keys = _civicrm_api3_getKeys($params, 'keys');
if (count($keys) == 0) {
return civicrm_api3_create_success();
}
Expand Down 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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest giving the default value 'keys' to the 2nd param in this function signature, to better guerantee backward compatibility. Then you won't have to change the function call everywhere and as a side benefit this PR will be smaller/simpler.

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']);
}

}