3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2017 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2017
35 * This class generates form components for Extensions.
37 class CRM_Admin_Form_Extensions
extends CRM_Admin_Form
{
40 * Form pre-processing.
42 public function preProcess() {
45 $this->_key
= CRM_Utils_Request
::retrieve('key', 'String',
48 if (!CRM_Utils_Type
::validate($this->_key
, 'ExtensionKey')) {
49 throw new CRM_Core_Exception('Extension Key does not match expected standard');
51 $session = CRM_Core_Session
::singleton();
52 $url = CRM_Utils_System
::url('civicrm/admin/extensions', 'reset=1&action=browse');
53 $session->pushUserContext($url);
54 $this->assign('id', $this->_id
);
55 $this->assign('key', $this->_key
);
57 switch ($this->_action
) {
58 case CRM_Core_Action
::ADD
:
59 case CRM_Core_Action
::DELETE
:
60 case CRM_Core_Action
::ENABLE
:
61 case CRM_Core_Action
::DISABLE
:
62 $info = CRM_Extension_System
::singleton()->getMapper()->keyToInfo($this->_key
);
63 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
64 $this->assign('extension', $extInfo);
67 case CRM_Core_Action
::UPDATE
:
68 if (!CRM_Extension_System
::singleton()->getBrowser()->isEnabled()) {
69 CRM_Core_Error
::fatal(ts('The system administrator has disabled this feature.'));
71 $info = CRM_Extension_System
::singleton()->getBrowser()->getExtension($this->_key
);
72 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
73 $this->assign('extension', $extInfo);
77 CRM_Core_Error
::fatal(ts('Unsupported action'));
83 * Set default values for the form.
85 public function setDefaultValues() {
91 * Build the form object.
93 public function buildQuickForm() {
94 switch ($this->_action
) {
95 case CRM_Core_Action
::ADD
:
96 $buttonName = ts('Install');
97 $title = ts('Install "%1"?', array(
102 case CRM_Core_Action
::UPDATE
:
103 $buttonName = ts('Download and Install');
104 $title = ts('Download and Install "%1"?', array(
109 case CRM_Core_Action
::DELETE
:
110 $buttonName = ts('Uninstall');
111 $title = ts('Uninstall "%1"?', array(
116 case CRM_Core_Action
::ENABLE
:
117 $buttonName = ts('Enable');
118 $title = ts('Enable "%1"?', array(
123 case CRM_Core_Action
::DISABLE
:
124 $buttonName = ts('Disable');
125 $title = ts('Disable "%1"?', array(
131 $this->assign('title', $title);
132 $this->addButtons(array(
135 'name' => $buttonName,
140 'name' => ts('Cancel'),
149 * @param array $fields
150 * The input form values.
151 * @param array $files
152 * The uploaded files if any.
157 * true if no errors, else an array of errors
159 public static function formRule($fields, $files, $self) {
162 return empty($errors) ?
TRUE : $errors;
166 * Process the form submission.
168 public function postProcess() {
169 CRM_Utils_System
::flushCache();
171 if ($this->_action
& CRM_Core_Action
::DELETE
) {
173 CRM_Extension_System
::singleton()->getManager()->uninstall(array($this->_key
));
174 CRM_Core_Session
::setStatus("", ts('Extension Uninstalled'), "success");
176 catch (CRM_Extension_Exception_DependencyException
$e) {
177 // currently only thrown for payment-processor dependencies
178 CRM_Core_Session
::setStatus(ts('Cannot uninstall this extension - there is at least one payment processor using the payment processor type provided by it.'), ts('Uninstall Error'), 'error');
182 if ($this->_action
& CRM_Core_Action
::ADD
) {
183 civicrm_api3('Extension', 'install', array('keys' => $this->_key
));
184 CRM_Core_Session
::setStatus("", ts('Extension Installed'), "success");
187 if ($this->_action
& CRM_Core_Action
::ENABLE
) {
188 civicrm_api3('Extension', 'enable', array('keys' => $this->_key
));
189 CRM_Core_Session
::setStatus("", ts('Extension Enabled'), "success");
192 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
193 CRM_Extension_System
::singleton()->getManager()->disable(array($this->_key
));
194 CRM_Core_Session
::setStatus("", ts('Extension Disabled'), "success");
197 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
198 $result = civicrm_api('Extension', 'download', array(
200 'key' => $this->_key
,
202 if (!CRM_Utils_Array
::value('is_error', $result, FALSE)) {
203 CRM_Core_Session
::setStatus("", ts('Extension Upgraded'), "success");
206 CRM_Core_Session
::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error");
210 CRM_Utils_System
::redirect(
211 CRM_Utils_System
::url(
212 'civicrm/admin/extensions',
213 'reset=1&action=browse'