Merge pull request #14192 from civicrm/5.14
[civicrm-core.git] / CRM / Extension / System.php
index 53965f2347d336c95bfbd58fb9d5c290ffbb1d23..6aeaa30baed776e5bfbf0f375e5bb05b30cc2735 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 5                                                  |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2018                                |
+ | Copyright CiviCRM LLC (c) 2004-2019                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -30,7 +30,7 @@
  * system.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2018
+ * @copyright CiviCRM LLC (c) 2004-2019
  */
 class CRM_Extension_System {
   private static $singleton;
@@ -93,7 +93,7 @@ class CRM_Extension_System {
    *   List of configuration values required by the extension system.
    *   Missing values will be guessed based on $config.
    */
-  public function __construct($parameters = array()) {
+  public function __construct($parameters = []) {
     $config = CRM_Core_Config::singleton();
     $parameters['extensionsDir'] = CRM_Utils_Array::value('extensionsDir', $parameters, $config->extensionsDir);
     $parameters['extensionsURL'] = CRM_Utils_Array::value('extensionsURL', $parameters, $config->extensionsURL);
@@ -109,7 +109,8 @@ class CRM_Extension_System {
     if (!array_key_exists('domain_id', $parameters)) {
       $parameters['domain_id'] = CRM_Core_Config::domainID();
     }
-    ksort($parameters); // guaranteed ordering - useful for md5(serialize($parameters))
+    // guaranteed ordering - useful for md5(serialize($parameters))
+    ksort($parameters);
 
     $this->parameters = $parameters;
   }
@@ -121,7 +122,7 @@ class CRM_Extension_System {
    */
   public function getFullContainer() {
     if ($this->fullContainer === NULL) {
-      $containers = array();
+      $containers = [];
 
       if ($this->getDefaultContainer()) {
         $containers['default'] = $this->getDefaultContainer();
@@ -205,12 +206,12 @@ class CRM_Extension_System {
    */
   public function getManager() {
     if ($this->manager === NULL) {
-      $typeManagers = array(
+      $typeManagers = [
         'payment' => new CRM_Extension_Manager_Payment($this->getMapper()),
         'report' => new CRM_Extension_Manager_Report(),
         'search' => new CRM_Extension_Manager_Search(),
         'module' => new CRM_Extension_Manager_Module($this->getMapper()),
-      );
+      ];
       $this->manager = new CRM_Extension_Manager($this->getFullContainer(), $this->getDefaultContainer(), $this->getMapper(), $typeManagers);
     }
     return $this->manager;
@@ -243,7 +244,8 @@ class CRM_Extension_System {
       $this->downloader = new CRM_Extension_Downloader(
         $this->getManager(),
         $basedir,
-        CRM_Utils_File::tempdir() // WAS: $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp';
+        // WAS: $config->extensionsDir . DIRECTORY_SEPARATOR . 'tmp';
+        CRM_Utils_File::tempdir()
       );
     }
     return $this->downloader;
@@ -254,13 +256,13 @@ class CRM_Extension_System {
    */
   public function getCache() {
     if ($this->cache === NULL) {
-      $cacheGroup = md5(serialize(array('ext', $this->parameters)));
+      $cacheGroup = md5(serialize(['ext', $this->parameters]));
       // Extension system starts before container. Manage our own cache.
-      $this->cache = CRM_Utils_Cache::create(array(
+      $this->cache = CRM_Utils_Cache::create([
         'name' => $cacheGroup,
-        'type' => array('*memory*', 'SqlGroup', 'ArrayCache'),
+        'type' => ['*memory*', 'SqlGroup', 'ArrayCache'],
         'prefetch' => TRUE,
-      ));
+      ]);
     }
     return $this->cache;
   }
@@ -286,6 +288,18 @@ class CRM_Extension_System {
     return $this->_repoUrl;
   }
 
+  /**
+   * Returns a list keyed by extension key
+   *
+   * @return array
+   */
+  public static function getCompatibilityInfo() {
+    if (!isset(Civi::$statics[__CLASS__]['compatibility'])) {
+      Civi::$statics[__CLASS__]['compatibility'] = json_decode(file_get_contents(Civi::paths()->getPath('[civicrm.root]/extension-compatibility.json')), TRUE);
+    }
+    return Civi::$statics[__CLASS__]['compatibility'];
+  }
+
   /**
    * Take an extension's raw XML info and add information about the
    * extension's status on the local system.
@@ -311,7 +325,8 @@ class CRM_Extension_System {
 
     switch ($extensionRow['status']) {
       case CRM_Extension_Manager::STATUS_UNINSTALLED:
-        $extensionRow['statusLabel'] = ''; // ts('Uninstalled');
+        // ts('Uninstalled');
+        $extensionRow['statusLabel'] = '';
         break;
 
       case CRM_Extension_Manager::STATUS_DISABLED:
@@ -319,7 +334,8 @@ class CRM_Extension_System {
         break;
 
       case CRM_Extension_Manager::STATUS_INSTALLED:
-        $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed');
+        // ts('Installed');
+        $extensionRow['statusLabel'] = ts('Enabled');
         break;
 
       case CRM_Extension_Manager::STATUS_DISABLED_MISSING:
@@ -327,7 +343,8 @@ class CRM_Extension_System {
         break;
 
       case CRM_Extension_Manager::STATUS_INSTALLED_MISSING:
-        $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed');
+        // ts('Installed');
+        $extensionRow['statusLabel'] = ts('Enabled (Missing)');
         break;
 
       default: