/**
 * 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
 *
 */
function civicrm_api3_extension_install($params)
{
    $keys = _civicrm_api3_getKeys($params);
    if (count($keys) == 0) {
        return civicrm_api3_create_success();
    }
    $ext = new CRM_Core_Extensions();
    $exts = $ext->getExtensions();
    foreach ($keys as $key) {
        if (!$ext->isEnabled()) {
            return civicrm_api3_create_error('Extension support is not enabled');
        } elseif (!$ext->isExtensionKey($key) || !array_key_exists($key, $exts)) {
            return civicrm_api3_create_error('Invalid extension key: ' . $key);
        } elseif ($exts[$key]->status == 'installed' && $exts[$key]->is_active == TRUE) {
            // already installed
        } elseif (!in_array($exts[$key]->status, array('remote', 'local'))) {
            return civicrm_api3_create_error('Can only install extensions with status "Available (Local)" or "Available (Remote)"');
        } else {
            // pre-condition: not installed
            $ext->install(NULL, $key);
            // FIXME: only rebuild cache one time
        }
    }
    return civicrm_api3_create_success();
}
Esempio n. 2
0
 /**
  * Function to process the form
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         require_once 'CRM/Core/Extensions.php';
         $ext = new CRM_Core_Extensions();
         $ext->uninstall($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been uninstalled.'));
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         require_once 'CRM/Core/Extensions.php';
         $ext = new CRM_Core_Extensions();
         $ext->install($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been installed.'));
     }
 }
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         $ext = new CRM_Core_Extensions();
         if ($ext->uninstall($this->_id, $this->_key)) {
             CRM_Core_Session::setStatus(ts('Extension has been uninstalled.'));
         }
     }
     if ($this->_action & CRM_Core_Action::ADD) {
         $ext = new CRM_Core_Extensions();
         $ext->install($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been installed.'));
     }
     if ($this->_action & CRM_Core_Action::ENABLE) {
         $ext = new CRM_Core_Extensions();
         $ext->enable($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been enabled.'));
     }
     if ($this->_action & CRM_Core_Action::DISABLE) {
         $ext = new CRM_Core_Extensions();
         $ext->disable($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been disabled.'));
     }
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $ext = new CRM_Core_Extensions();
         $ext->upgrade($this->_id, $this->_key);
         CRM_Core_Session::setStatus(ts('Extension has been upgraded.'));
     }
     CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse'));
 }