From: Coleman Watts Date: Tue, 29 Dec 2015 15:09:30 +0000 (-0500) Subject: Add getfield specs to extension api X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=e5f24f02e222b394895ee7db4e97c9f6639d8dd5;p=civicrm-core.git Add getfield specs to extension api --- diff --git a/api/v3/Extension.php b/api/v3/Extension.php index 2fe2bd7258..9b02e8fc77 100644 --- a/api/v3/Extension.php +++ b/api/v3/Extension.php @@ -39,12 +39,12 @@ define('API_V3_EXTENSION_DELIMITER', ','); * * @param array $params * Input parameters. - * - key: string, eg "com.example.myextension" - * - keys: mixed; array of string, eg array("com.example.myextension1", "com.example.myextension2") or string with comma-delimited list - * Using 'keys' should be more performant than making multiple API calls with 'key'. + * - key: string, eg "com.example.myextension" + * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") + * + * Using 'keys' should be more performant than making multiple API calls with 'key' * * @return array - * API result */ function civicrm_api3_extension_install($params) { $keys = _civicrm_api3_getKeys($params); @@ -62,6 +62,20 @@ function civicrm_api3_extension_install($params) { return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_install_spec(&$fields) { + $fields['keys'] = array( + 'title' => 'Extension Key(s)', + 'api.required' => 1, + 'api.aliases' => array('key'), + 'type' => CRM_Utils_Type::T_STRING, + 'description' => 'Fully qualified name of one or more extensions', + ); +} + /** * Upgrade an extension - runs upgrade_N hooks and system.flush. * @@ -97,12 +111,12 @@ function civicrm_api3_extension_upgrade() { * * @param array $params * Input parameters. - * - key: string, eg "com.example.myextension" - * - keys: mixed; array of string, eg array("com.example.myextension1", "com.example.myextension2") or string with comma-delimited list - * using 'keys' should be more performant than making multiple API calls with 'key' + * - key: string, eg "com.example.myextension" + * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") + * + * Using 'keys' should be more performant than making multiple API calls with 'key' * * @return array - * API result */ function civicrm_api3_extension_enable($params) { $keys = _civicrm_api3_getKeys($params); @@ -114,17 +128,25 @@ function civicrm_api3_extension_enable($params) { return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_enable_spec(&$fields) { + _civicrm_api3_extension_install_spec($fields); +} + /** * Disable an extension. * * @param array $params * Input parameters. - * - key: string, eg "com.example.myextension" - * - keys: mixed; array of string, eg array("com.example.myextension1", "com.example.myextension2") or string with comma-delimited list - * using 'keys' should be more performant than making multiple API calls with 'key' + * - key: string, eg "com.example.myextension" + * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") + * + * Using 'keys' should be more performant than making multiple API calls with 'key' * * @return array - * API result */ function civicrm_api3_extension_disable($params) { $keys = _civicrm_api3_getKeys($params); @@ -136,18 +158,27 @@ function civicrm_api3_extension_disable($params) { return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_disable_spec(&$fields) { + _civicrm_api3_extension_install_spec($fields); +} + /** * Uninstall an extension. * * @param array $params * Input parameters. - * - key: string, eg "com.example.myextension" - * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") - * using 'keys' should be more performant than making multiple API calls with 'key' - * - removeFiles: bool, whether to remove source tree; default: FALSE + * - key: string, eg "com.example.myextension" + * - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2") + * + * Using 'keys' should be more performant than making multiple API calls with 'key' + * + * @todo: removeFiles as optional param * * @return array - * API result */ function civicrm_api3_extension_uninstall($params) { $keys = _civicrm_api3_getKeys($params); @@ -155,11 +186,23 @@ function civicrm_api3_extension_uninstall($params) { return civicrm_api3_create_success(); } - // TODO // $removeFiles = CRM_Utils_Array::value('removeFiles', $params, FALSE); CRM_Extension_System::singleton()->getManager()->uninstall($keys); return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_uninstall_spec(&$fields) { + _civicrm_api3_extension_install_spec($fields); + //$fields['removeFiles'] = array( + // 'title' => 'Remove files', + // 'description' => 'Whether to remove the source tree. Default FALSE.', + // 'type' => CRM_Utils_Type::T_BOOLEAN, + //); +} + /** * Download and install an extension. * @@ -173,13 +216,9 @@ function civicrm_api3_extension_uninstall($params) { * API result */ function civicrm_api3_extension_download($params) { - if (!array_key_exists('key', $params)) { - throw new API_Exception('Missing required parameter: key'); - } - if (!array_key_exists('url', $params)) { if (!CRM_Extension_System::singleton()->getBrowser()->isEnabled()) { - throw new API_Exception('Automatic downloading is diabled. Try adding parameter "url"'); + throw new API_Exception('Automatic downloading is disabled. Try adding parameter "url"'); } if ($reqs = CRM_Extension_System::singleton()->getBrowser()->checkRequirements()) { $first = array_shift($reqs); @@ -210,6 +249,24 @@ function civicrm_api3_extension_download($params) { return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_download_spec(&$fields) { + $fields['key'] = array( + 'title' => 'Extension Key', + 'api.required' => 1, + 'type' => CRM_Utils_Type::T_STRING, + 'description' => 'Fully qualified name of the extension', + ); + $fields['url'] = array( + 'title' => 'Download URL', + 'type' => CRM_Utils_Type::T_STRING, + 'description' => 'Optional as the system can determine the url automatically for public extensions', + ); +} + /** * Download and install an extension. * @@ -222,9 +279,6 @@ function civicrm_api3_extension_download($params) { * API result */ function civicrm_api3_extension_refresh($params) { - $defaults = array('local' => TRUE, 'remote' => TRUE); - $params = array_merge($defaults, $params); - $system = CRM_Extension_System::singleton(TRUE); if ($params['local']) { @@ -242,6 +296,25 @@ function civicrm_api3_extension_refresh($params) { return civicrm_api3_create_success(); } +/** + * Spec function for getfields + * @param $fields + */ +function _civicrm_api3_extension_refresh_spec(&$fields) { + $fields['local'] = array( + 'title' => 'Rescan Local', + 'api.default' => 1, + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'description' => 'Whether to rescan the local filesystem (default TRUE)', + ); + $fields['remote'] = array( + 'title' => 'Rescan Remote', + 'api.default' => 1, + 'type' => CRM_Utils_Type::T_BOOLEAN, + 'description' => 'Whether to rescan the remote repository (default TRUE)', + ); +} + /** * Get a list of available extensions. * @@ -252,7 +325,6 @@ function civicrm_api3_extension_refresh($params) { */ function civicrm_api3_extension_get($params) { $statuses = CRM_Extension_System::singleton()->getManager()->getStatuses(); - $mapper = CRM_Extension_System::singleton()->getMapper(); $result = array(); $id = 0; foreach ($statuses as $key => $status) {