コード例 #1
0
/**
 * Enable 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 ExtensionEnable.php
 *
 */
function civicrm_api3_extension_enable($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 enabled
        } elseif ($exts[$key]->status != 'installed') {
            return civicrm_api3_create_error('Can only enable extensions which have been previously installed');
        } elseif ($exts[$key]->is_active == TRUE) {
            return civicrm_api3_create_error('Can only enable extensions which are currently inactive');
        } else {
            // pre-condition: installed and inactive
            $ext->enable(NULL, $key);
            // 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) {
         $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'));
 }