Add order_reference to spec
[civicrm-core.git] / api / v3 / Extension.php
index c7302892aaf3a950e9cd6e0a56f10ac994e74dd4..ce46a5dfb4c7e2bc65a22194a8f33ca9617964f0 100644 (file)
@@ -1,27 +1,11 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 5                                                  |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2017                                |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM.                                    |
- |                                                                    |
- | CiviCRM is free software; you can copy, modify, and distribute it  |
- | under the terms of the GNU Affero General Public License           |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ | Copyright CiviCRM LLC. All rights reserved.                        |
  |                                                                    |
- | CiviCRM is distributed in the hope that it will be useful, but     |
- | WITHOUT ANY WARRANTY; without even the implied warranty of         |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
- | See the GNU Affero General Public License for more details.        |
- |                                                                    |
- | You should have received a copy of the GNU Affero General Public   |
- | License and the CiviCRM Licensing Exception along                  |
- | with this program; if not, contact CiviCRM LLC                     |
- | at info[AT]civicrm[DOT]org. If you have questions about the        |
- | GNU Affero General Public License or the licensing of CiviCRM,     |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ | This work is published under the GNU AGPLv3 license with some      |
+ | permitted exceptions and without any warranty. For full license    |
+ | and copyright information, see https://civicrm.org/licensing       |
  +--------------------------------------------------------------------+
  */
 
@@ -69,17 +53,17 @@ function civicrm_api3_extension_install($params) {
  * @param $fields
  */
 function _civicrm_api3_extension_install_spec(&$fields) {
-  $fields['keys'] = array(
+  $fields['keys'] = [
     'title' => 'Extension Key(s)',
-    'api.aliases' => array('key'),
+    'api.aliases' => ['key'],
     'type' => CRM_Utils_Type::T_STRING,
     'description' => 'Fully qualified name of one or more extensions',
-  );
-  $fields['path'] = array(
+  ];
+  $fields['path'] = [
     'title' => 'Extension Path',
     'type' => CRM_Utils_Type::T_STRING,
     'description' => 'The path to the extension. May use wildcard ("*").',
-  );
+  ];
 }
 
 /**
@@ -91,11 +75,11 @@ function _civicrm_api3_extension_install_spec(&$fields) {
 function civicrm_api3_extension_upgrade() {
   CRM_Core_Invoke::rebuildMenuAndCaches(TRUE);
   $queue = CRM_Extension_Upgrades::createQueue();
-  $runner = new CRM_Queue_Runner(array(
+  $runner = new CRM_Queue_Runner([
     'title' => 'Extension Upgrades',
     'queue' => $queue,
     'errorMode' => CRM_Queue_Runner::ERROR_ABORT,
-  ));
+  ]);
 
   try {
     $result = $runner->runAll();
@@ -245,7 +229,10 @@ function civicrm_api3_extension_download($params) {
     throw new API_Exception('Cannot resolve download url for extension. Try adding parameter "url"');
   }
 
-  foreach (CRM_Extension_System::singleton()->getDownloader()->checkRequirements() as $requirement) {
+  if (!isset($info)) {
+    $info = NULL;
+  }
+  foreach (CRM_Extension_System::singleton()->getDownloader()->checkRequirements($info) as $requirement) {
     return civicrm_api3_create_error($requirement['message']);
   }
 
@@ -255,7 +242,7 @@ function civicrm_api3_extension_download($params) {
   CRM_Extension_System::singleton()->getCache()->flush();
   CRM_Extension_System::singleton(TRUE);
   if (CRM_Utils_Array::value('install', $params, TRUE)) {
-    CRM_Extension_System::singleton()->getManager()->install(array($params['key']));
+    CRM_Extension_System::singleton()->getManager()->install([$params['key']]);
   }
 
   return civicrm_api3_create_success();
@@ -266,23 +253,23 @@ function civicrm_api3_extension_download($params) {
  * @param $fields
  */
 function _civicrm_api3_extension_download_spec(&$fields) {
-  $fields['key'] = array(
+  $fields['key'] = [
     'title' => 'Extension Key',
     'api.required' => 1,
     'type' => CRM_Utils_Type::T_STRING,
     'description' => 'Fully qualified name of the extension',
-  );
-  $fields['url'] = array(
+  ];
+  $fields['url'] = [
     'title' => 'Download URL',
     'type' => CRM_Utils_Type::T_STRING,
     'description' => 'Optional as the system can determine the url automatically for public extensions',
-  );
-  $fields['install'] = array(
+  ];
+  $fields['install'] = [
     'title' => 'Auto-install',
     'type' => CRM_Utils_Type::T_STRING,
     'description' => 'Automatically install the downloaded extension',
     'api.default' => TRUE,
-  );
+  ];
 }
 
 /**
@@ -301,13 +288,15 @@ function civicrm_api3_extension_refresh($params) {
 
   if ($params['local']) {
     $system->getManager()->refresh();
-    $system->getManager()->getStatuses(); // force immediate scan
+    // force immediate scan
+    $system->getManager()->getStatuses();
   }
 
   if ($params['remote']) {
     if ($system->getBrowser()->isEnabled() && empty($system->getBrowser()->checkRequirements)) {
       $system->getBrowser()->refresh();
-      $system->getBrowser()->getExtensions(); // force immediate download
+      // force immediate download
+      $system->getBrowser()->getExtensions();
     }
   }
 
@@ -319,18 +308,18 @@ function civicrm_api3_extension_refresh($params) {
  * @param $fields
  */
 function _civicrm_api3_extension_refresh_spec(&$fields) {
-  $fields['local'] = array(
+  $fields['local'] = [
     'title' => 'Rescan Local',
     'api.default' => 1,
     'type' => CRM_Utils_Type::T_BOOLEAN,
     'description' => 'Whether to rescan the local filesystem (default TRUE)',
-  );
-  $fields['remote'] = array(
+  ];
+  $fields['remote'] = [
     'title' => 'Rescan Remote',
     'api.default' => 1,
     'type' => CRM_Utils_Type::T_BOOLEAN,
     'description' => 'Whether to rescan the remote repository (default TRUE)',
-  );
+  ];
 }
 
 /**
@@ -347,18 +336,19 @@ function civicrm_api3_extension_get($params) {
   $keys = array_merge($full_names, $keys);
   $statuses = CRM_Extension_System::singleton()->getManager()->getStatuses();
   $mapper = CRM_Extension_System::singleton()->getMapper();
-  $result = array();
+  $result = [];
   $id = 0;
   foreach ($statuses as $key => $status) {
     try {
       $obj = $mapper->keyToInfo($key);
     }
     catch (CRM_Extension_Exception $ex) {
-      CRM_Core_Session::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key)));
+      CRM_Core_Session::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', [1 => $key]));
       continue;
     }
     $info = CRM_Extension_System::createExtendedInfo($obj);
-    $info['id'] = $id++; // backward compatibility with indexing scheme
+    // backward compatibility with indexing scheme
+    $info['id'] = $id++;
     if (!empty($keys)) {
       if (in_array($key, $keys)) {
         $result[] = $info;
@@ -374,7 +364,7 @@ function civicrm_api3_extension_get($params) {
   unset($params['keys']);
   unset($params['full_name']);
 
-  $filterableFields = array('id', 'type', 'status', 'path');
+  $filterableFields = ['id', 'type', 'status', 'path'];
   return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', $filterableFields);
 }
 
@@ -388,15 +378,16 @@ function civicrm_api3_extension_get($params) {
  */
 function civicrm_api3_extension_getremote($params) {
   $extensions = CRM_Extension_System::singleton()->getBrowser()->getExtensions();
-  $result = array();
+  $result = [];
   $id = 0;
   foreach ($extensions as $key => $obj) {
-    $info = array();
-    $info['id'] = $id++; // backward compatibility with indexing scheme
+    $info = [];
+    // backward compatibility with indexing scheme
+    $info['id'] = $id++;
     $info = array_merge($info, (array) $obj);
     $result[] = $info;
   }
-  return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', CRM_Utils_Array::value('return', $params, array()));
+  return _civicrm_api3_basic_array_get('Extension', $params, $result, 'id', CRM_Utils_Array::value('return', $params, []));
 }
 
 /**
@@ -419,11 +410,11 @@ function _civicrm_api3_getKeys($params, $key = 'keys') {
       return $params[$key];
     }
     if ($params[$key] == '') {
-      return array();
+      return [];
     }
     return explode(API_V3_EXTENSION_DELIMITER, $params[$key]);
   }
   else {
-    return array();
+    return [];
   }
 }