コード例 #1
0
/**
 * Uninstall an extension
 *
 * @param  array   	  $params input parameters
 *                          - key: string, eg "com.example.myextension"
 *                          - keys: array of string, eg array("com.example.myextension1", "com.example.myextension2")
 *                            using 'keys' should be more performant than making multiple API calls with 'key'
 *                          - removeFiles: bool, whether to remove source tree; default: FALSE
 *
 * @return array API result
 * @static void
 * @access public
 * @example ExtensionUninstall.php
 *
 */
function civicrm_api3_extension_uninstall($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)) {
            // FIXME: is this necesary? if $key is not in $exts, can't we assume it's uninstalled
            return civicrm_api3_create_error('Invalid extension key: ' . $key);
        } elseif ($exts[$key]->status != 'installed') {
            return civicrm_api3_create_error('Can only uninstall extensions which have been previously installed');
        } elseif ($exts[$key]->is_active == TRUE) {
            return civicrm_api3_create_error('Extension must be disabled before uninstalling');
        } else {
            // pre-condition: installed and inactive
            $removeFiles = CRM_Utils_Array::value('removeFiles', $params, FALSE);
            $ext->uninstall(NULL, $key, $removeFiles);
            // FIXME: only rebuild cache one time
        }
    }
    return civicrm_api3_create_success();
}
コード例 #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.'));
     }
 }
コード例 #3
0
 /**
  * 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'));
 }