/**
  * Obtains the group name from url and sets the title.
  *
  * @return void
  * @access public
  *
  */
 function preProcess()
 {
     $ext = new CRM_Core_Extensions();
     if ($ext->enabled === TRUE) {
         self::$_extensions = $ext->getExtensions();
     }
     CRM_Utils_System::setTitle(ts('CiviCRM Extensions'));
     $destination = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1');
     $destination = urlencode($destination);
     $this->assign('destination', $destination);
 }
 /**
  * Function to for pre-processing
  *
  * @return None
  * @access public
  */
 public function preProcess()
 {
     parent::preProcess();
     $this->_key = CRM_Utils_Request::retrieve('key', 'String', $this, FALSE, 0);
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1&action=browse');
     $session->pushUserContext($url);
     $this->assign('id', $this->_id);
     $this->assign('key', $this->_key);
     $ext = new CRM_Core_Extensions();
     $extension = $ext->getExtensions();
     $this->assign('extension', get_object_vars($extension[$this->_key]));
 }
/**
 * 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();
}