Merge pull request #6500 from LevityNL/master
[civicrm-core.git] / api / v3 / Extension.php
index 4bf680fc60b4ef15385a210984411bc099edaa66..2fe2bd7258f67b8e99f5ace29ef651de1efe5209 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.6                                                |
+ | CiviCRM version 4.7                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -29,24 +29,19 @@ define('API_V3_EXTENSION_DELIMITER', ',');
 
 
 /**
- * File for the CiviCRM APIv3 extension functions
+ * This provides an api interface for CiviCRM extension management.
  *
  * @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'
+ *   - 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
@@ -68,7 +63,7 @@ function civicrm_api3_extension_install($params) {
 }
 
 /**
- * Upgrade an extension - runs upgrade_N hooks and system.flush
+ * Upgrade an extension - runs upgrade_N hooks and system.flush.
  *
  * @return array
  *   API result
@@ -98,13 +93,13 @@ function civicrm_api3_extension_upgrade() {
 }
 
 /**
- * Enable an extension
+ * Enable 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: 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
@@ -120,7 +115,7 @@ function civicrm_api3_extension_enable($params) {
 }
 
 /**
- * Disable an extension
+ * Disable an extension.
  *
  * @param array $params
  *   Input parameters.
@@ -130,7 +125,6 @@ function civicrm_api3_extension_enable($params) {
  *
  * @return array
  *   API result
- * @example ExtensionDisable.php
  */
 function civicrm_api3_extension_disable($params) {
   $keys = _civicrm_api3_getKeys($params);
@@ -143,7 +137,7 @@ function civicrm_api3_extension_disable($params) {
 }
 
 /**
- * Uninstall an extension
+ * Uninstall an extension.
  *
  * @param array $params
  *   Input parameters.
@@ -167,25 +161,24 @@ function civicrm_api3_extension_uninstall($params) {
 }
 
 /**
- * Download and install an extension
+ * Download and install an extension.
  *
  * @param array $params
  *   Input parameters.
- *                          - key: string, eg "com.example.myextension"
- *                          - url: string eg "http://repo.com/myextension-1.0.zip"
+ *   - key: string, eg "com.example.myextension"
+ *   - url: string eg "http://repo.com/myextension-1.0.zip"
  *
  * @throws API_Exception
  * @return array
  *   API result
- * @example ExtensionDownload.php
  */
 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()) {
@@ -199,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"');
   }
 
@@ -207,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();
@@ -218,17 +211,15 @@ function civicrm_api3_extension_download($params) {
 }
 
 /**
- * Download and install an extension
+ * Download and install an extension.
  *
  * @param array $params
  *   Input parameters.
- *                          - local: bool, whether to rescan local filesystem (default: TRUE)
- *                          - remote: bool, whether to rescan remote repository (default: TRUE)
+ *   - local: bool, whether to rescan local filesystem (default: TRUE)
+ *   - remote: bool, whether to rescan remote repository (default: TRUE)
  *
  * @return array
  *   API result
- * @example ExtensionRefresh.php
- *
  */
 function civicrm_api3_extension_refresh($params) {
   $defaults = array('local' => TRUE, 'remote' => TRUE);
@@ -252,36 +243,38 @@ 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
- * @example ExtensionGet.php
  */
 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) {
     //try {
     //  $info = (array) $mapper->keyToInfo($key);
     //} catch (CRM_Extension_Exception $e) {
     $info = array();
+    $info['id'] = $id++; // backward compatibility with indexing scheme
     $info['key'] = $key;
     //}
     $info['status'] = $status;
     $result[] = $info;
   }
-  return civicrm_api3_create_success($result);
+  return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', array('id', 'key', 'status'));
 }
 
 /**
- * Determine the list of extension keys
+ * Determine the list of extension keys.
  *
  * @param array $params
  *   API request params with 'key' or 'keys'.
+ *
  * @return array
  *   Array of extension keys
  * @throws API_Exception