X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=api%2Fv3%2FExtension.php;h=2dfbe7728aa3b99e67ea6b1013f84ac4e241cd3a;hb=0b2bdd13e190523e68f8ee762b825eaa0a801e4b;hp=18e52ec3540902209e704c839f9ededcf6c7ac39;hpb=1024e1784fb68b8529a77143f5191a60d70837cf;p=civicrm-core.git diff --git a/api/v3/Extension.php b/api/v3/Extension.php index 18e52ec354..2dfbe7728a 100644 --- a/api/v3/Extension.php +++ b/api/v3/Extension.php @@ -29,29 +29,22 @@ define('API_V3_EXTENSION_DELIMITER', ','); /** - * File for the CiviCRM APIv3 extension functions + * This api exposes CiviCRM extension. * * @package CiviCRM_APIv3 - * @subpackage API_Extension - * - * @copyright CiviCRM LLC (c) 2004-2014 - * @version $Id$ - * */ /** - * Install an extension + * Install 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' - * - * @return array API result - * @static void - * @access public - * @example ExtensionInstall.php + * @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'. * + * @return array + * API result */ function civicrm_api3_extension_install($params) { $keys = _civicrm_api3_getKeys($params); @@ -61,7 +54,8 @@ function civicrm_api3_extension_install($params) { try { CRM_Extension_System::singleton()->getManager()->install($keys); - } catch (CRM_Extension_Exception $e) { + } + catch (CRM_Extension_Exception $e) { return civicrm_api3_create_error($e->getMessage()); } @@ -69,12 +63,10 @@ function civicrm_api3_extension_install($params) { } /** - * Upgrade an extension - runs upgrade_N hooks and system.flush - * - * @return array API result - * @static void - * @access public + * Upgrade an extension - runs upgrade_N hooks and system.flush. * + * @return array + * API result */ function civicrm_api3_extension_upgrade() { CRM_Core_Invoke::rebuildMenuAndCaches(TRUE); @@ -87,30 +79,30 @@ function civicrm_api3_extension_upgrade() { try { $result = $runner->runAll(); - } catch (CRM_Extension_Exception $e) { + } + catch (CRM_Extension_Exception $e) { return civicrm_api3_create_error($e->getMessage()); } if ($result === TRUE) { return civicrm_api3_create_success(); - } else { + } + else { return $result; } } /** - * Enable an extension + * Enable an extension. * - * @param array $params input parameters + * @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' * - * @return array API result - * @static void - * @access public - * @example ExtensionEnable.php - * + * @return array + * API result */ function civicrm_api3_extension_enable($params) { $keys = _civicrm_api3_getKeys($params); @@ -123,18 +115,16 @@ function civicrm_api3_extension_enable($params) { } /** - * Disable an extension + * Disable an extension. * - * @param array $params input parameters + * @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' * - * @return array API result - * @static void - * @access public - * @example ExtensionDisable.php - * + * @return array + * API result */ function civicrm_api3_extension_disable($params) { $keys = _civicrm_api3_getKeys($params); @@ -147,19 +137,17 @@ function civicrm_api3_extension_disable($params) { } /** - * Uninstall an extension + * Uninstall an extension. * - * @param array $params input parameters + * @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 * - * @return array API result - * @static void - * @access public - * @example ExtensionUninstall.php - * + * @return array + * API result */ function civicrm_api3_extension_uninstall($params) { $keys = _civicrm_api3_getKeys($params); @@ -173,25 +161,24 @@ function civicrm_api3_extension_uninstall($params) { } /** - * Download and install an extension + * Download and install an extension. * - * @param array $params input parameters + * @param array $params + * Input parameters. * - key: string, eg "com.example.myextension" * - url: string eg "http://repo.com/myextension-1.0.zip" * * @throws API_Exception - * @return array API result - * @static void - * @access public - * @example ExtensionDownload.php + * @return array + * API result */ function civicrm_api3_extension_download($params) { - if (! array_key_exists('key', $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()) { + 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"'); } if ($reqs = CRM_Extension_System::singleton()->getBrowser()->checkRequirements()) { @@ -205,7 +192,7 @@ function civicrm_api3_extension_download($params) { } } - if (! array_key_exists('url', $params)) { + if (!array_key_exists('url', $params)) { throw new API_Exception('Cannot resolve download url for extension. Try adding parameter "url"'); } @@ -213,7 +200,7 @@ function civicrm_api3_extension_download($params) { return civicrm_api3_create_error($requirement['message']); } - if (! CRM_Extension_System::singleton()->getDownloader()->download($params['key'], $params['url'])) { + if (!CRM_Extension_System::singleton()->getDownloader()->download($params['key'], $params['url'])) { return civicrm_api3_create_error('Download failed - ZIP file is unavailable or malformed'); } CRM_Extension_System::singleton()->getCache()->flush(); @@ -224,17 +211,15 @@ function civicrm_api3_extension_download($params) { } /** - * Download and install an extension + * Download and install an extension. * - * @param array $params input parameters + * @param array $params + * Input parameters. * - local: bool, whether to rescan local filesystem (default: TRUE) * - remote: bool, whether to rescan remote repository (default: TRUE) * - * @return array API result - * @static void - * @access public - * @example ExtensionRefresh.php - * + * @return array + * API result */ function civicrm_api3_extension_refresh($params) { $defaults = array('local' => TRUE, 'remote' => TRUE); @@ -258,14 +243,12 @@ function civicrm_api3_extension_refresh($params) { } /** - * Get a list of available extensions + * Get a list of available extensions. * * @param array $params * - * @return array API result - * @static void - * @access public - * @example ExtensionGet.php + * @return array + * API result */ function civicrm_api3_extension_get($params) { $statuses = CRM_Extension_System::singleton()->getManager()->getStatuses(); @@ -275,8 +258,8 @@ function civicrm_api3_extension_get($params) { //try { // $info = (array) $mapper->keyToInfo($key); //} catch (CRM_Extension_Exception $e) { - $info = array(); - $info['key'] = $key; + $info = array(); + $info['key'] = $key; //} $info['status'] = $status; $result[] = $info; @@ -285,24 +268,31 @@ function civicrm_api3_extension_get($params) { } /** - * Determine the list of extension keys + * Determine the list of extension keys. * - * @param array $params API request params with 'key' or 'keys' - * @return array of extension keys + * @param array $params + * API request params with 'key' or 'keys'. + * + * @return array + * Array of extension keys * @throws API_Exception */ function _civicrm_api3_getKeys($params) { if (array_key_exists('keys', $params) && is_array($params['keys'])) { return $params['keys']; - } elseif (array_key_exists('keys', $params) && is_string($params['keys'])) { + } + elseif (array_key_exists('keys', $params) && is_string($params['keys'])) { if ($params['keys'] == '') { return array(); - } else { + } + else { return explode(API_V3_EXTENSION_DELIMITER, $params['keys']); } - } elseif (array_key_exists('key', $params)) { + } + elseif (array_key_exists('key', $params)) { return array($params['key']); - } else { + } + else { throw new API_Exception('Missing required parameter: key or keys'); } }