CRM-14798 - CiviCase - Fix max_instances check
[civicrm-core.git] / CRM / Extension / Manager.php
index 8c89a7a4a788b3ae244aa0820a368656dfcf6e0a..1d3da982f439df289dd0afb331e5a99ccd7e4efc 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -30,7 +30,7 @@
  * uninstalling extensions.
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
@@ -101,7 +101,10 @@ class CRM_Extension_Manager {
   public $statuses;
 
   /**
+   * @param CRM_Extension_Container_Interface $fullContainer
    * @param CRM_Extension_Container_Basic|FALSE $defaultContainer
+   * @param CRM_Extension_Mapper $mapper
+   * @param $typeManagers
    */
   function __construct(CRM_Extension_Container_Interface $fullContainer, $defaultContainer, CRM_Extension_Mapper $mapper, $typeManagers) {
     $this->fullContainer = $fullContainer;
@@ -138,6 +141,7 @@ class CRM_Extension_Manager {
         $tgtPath = $this->fullContainer->getPath($newInfo->key);
         if (! CRM_Utils_File::isChildPath($this->defaultContainer->getBaseDir(), $tgtPath)) {
           // force installation in the default-container
+          $oldPath = $tgtPath;
           $tgtPath = $this->defaultContainer->getBaseDir() . DIRECTORY_SEPARATOR . $newInfo->key;
           CRM_Core_Session::setStatus(ts('A copy of the extension (%1) is in a system folder (%2). The system copy will be preserved, but the new copy will be used.', array(
             1 => $newInfo->key,
@@ -157,7 +161,7 @@ class CRM_Extension_Manager {
         $oldInfo = $typeManager = NULL;
         break;
       default:
-        throw new CRM_Extension_Exception("Cannot install or enable extension: $key");
+        throw new CRM_Extension_Exception("Cannot install or enable extension: {$newInfo->key}");
     }
 
     // move the code!
@@ -182,7 +186,7 @@ class CRM_Extension_Manager {
         $typeManager->onPostReplace($oldInfo, $newInfo);
         break;
       default:
-        throw new CRM_Extension_Exception("Cannot install or enable extension: $key");
+        throw new CRM_Extension_Exception("Cannot install or enable extension: {$newInfo->key}");
     }
 
     $this->refresh();
@@ -357,6 +361,8 @@ class CRM_Extension_Manager {
   /**
    * Determine the status of an extension
    *
+   * @param $key
+   *
    * @return string constant (STATUS_INSTALLED, STATUS_DISABLED, STATUS_UNINSTALLED, STATUS_UNKNOWN)
    */
   public function getStatus($key) {
@@ -414,8 +420,10 @@ class CRM_Extension_Manager {
   /**
    * Find the $info and $typeManager for a $key
    *
-   * @return array (0 => CRM_Extension_Info, 1 => CRM_Extension_Manager_Interface)
+   * @param $key
+   *
    * @throws CRM_Extension_Exception
+   * @return array (0 => CRM_Extension_Info, 1 => CRM_Extension_Manager_Interface)
    */
   private function _getInfoTypeHandler($key) {
     $info = $this->mapper->keyToInfo($key); // throws Exception
@@ -429,8 +437,10 @@ class CRM_Extension_Manager {
   /**
    * Find the $info and $typeManager for a $key
    *
-   * @return array (0 => CRM_Extension_Info, 1 => CRM_Extension_Manager_Interface)
+   * @param $key
+   *
    * @throws CRM_Extension_Exception
+   * @return array (0 => CRM_Extension_Info, 1 => CRM_Extension_Manager_Interface)
    */
   private function _getMissingInfoTypeHandler($key) {
     $info = $this->createInfoFromDB($key);
@@ -445,6 +455,11 @@ class CRM_Extension_Manager {
     }
   }
 
+  /**
+   * @param CRM_Extension_Info $info
+   *
+   * @return bool
+   */
   private function _createExtensionEntry(CRM_Extension_Info $info) {
     $dao = new CRM_Core_DAO_Extension();
     $dao->label = $info->label;
@@ -456,6 +471,11 @@ class CRM_Extension_Manager {
     return (bool) ($dao->insert());
   }
 
+  /**
+   * @param CRM_Extension_Info $info
+   *
+   * @return bool
+   */
   private function _updateExtensionEntry(CRM_Extension_Info $info) {
     $dao = new CRM_Core_DAO_Extension();
     $dao->full_name = $info->key;
@@ -472,6 +492,11 @@ class CRM_Extension_Manager {
     }
   }
 
+  /**
+   * @param CRM_Extension_Info $info
+   *
+   * @throws CRM_Extension_Exception
+   */
   private function _removeExtensionEntry(CRM_Extension_Info $info) {
     $dao = new CRM_Core_DAO_Extension();
     $dao->full_name = $info->key;
@@ -484,6 +509,10 @@ class CRM_Extension_Manager {
     } // else: post-condition already satisified
   }
 
+  /**
+   * @param CRM_Extension_Info $info
+   * @param $isActive
+   */
   private function _setExtensionActive(CRM_Extension_Info $info, $isActive) {
     CRM_Core_DAO::executeQuery('UPDATE civicrm_extension SET is_active = %1 where full_name = %2', array(
       1 => array($isActive, 'Integer'),
@@ -495,6 +524,7 @@ class CRM_Extension_Manager {
    * Auto-generate a place-holder for a missing extension using info from
    * database.
    *
+   * @param $key
    * @return CRM_Extension_Info|NULL
    */
   public function createInfoFromDB($key) {