3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class generates form components for Extensions
40 class CRM_Admin_Form_Extensions
extends CRM_Admin_Form
{
47 public function preProcess() {
50 $this->_key
= CRM_Utils_Request
::retrieve('key', 'String',
54 $session = CRM_Core_Session
::singleton();
55 $url = CRM_Utils_System
::url('civicrm/admin/extensions', 'reset=1&action=browse');
56 $session->pushUserContext($url);
57 $this->assign('id', $this->_id
);
58 $this->assign('key', $this->_key
);
61 switch ($this->_action
) {
62 case CRM_Core_Action
::ADD
:
63 case CRM_Core_Action
::DELETE
:
64 case CRM_Core_Action
::ENABLE
:
65 case CRM_Core_Action
::DISABLE
:
66 $info = CRM_Extension_System
::singleton()->getMapper()->keyToInfo($this->_key
);
67 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
68 $this->assign('extension', $extInfo);
71 case CRM_Core_Action
::UPDATE
:
72 if (! CRM_Extension_System
::singleton()->getBrowser()->isEnabled()) {
73 CRM_Core_Error
::fatal(ts('The system administrator has disabled this feature.'));
75 $info = CRM_Extension_System
::singleton()->getBrowser()->getExtension($this->_key
);
76 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
77 $this->assign('extension', $extInfo);
81 CRM_Core_Error
::fatal(ts('Unsupported action'));
87 * Set default values for the form.
88 * the default values are retrieved from the database
93 public function setDefaultValues() {
99 * Build the form object
103 public function buildQuickForm() {
105 $info = CRM_Extension_System
::singleton()->getMapper()->keyToInfo($this->_key
);
106 $extInfo = CRM_Admin_Page_Extensions
::createExtendedInfo($info);
107 $extName = $extInfo['name'];
109 switch ($this->_action
) {
110 case CRM_Core_Action
::ADD
:
111 $buttonName = ts('Install');
112 $title = ts('Install ' . $extName . '?');
115 case CRM_Core_Action
::UPDATE
:
116 $buttonName = ts('Download and Install');
117 $title = ts('Download and Install ' . $extName . '?');
120 case CRM_Core_Action
::DELETE
:
121 $buttonName = ts('Uninstall');
122 $title = ts('Uninstall ' . $extName . '?');
125 case CRM_Core_Action
::ENABLE
:
126 $buttonName = ts('Enable');
127 $title = ts('Enable ' . $extName . '?');
130 case CRM_Core_Action
::DISABLE
:
131 $buttonName = ts('Disable');
132 $title = ts('Disable ' . $extName . '?');
136 $this->assign('title', $title);
137 $this->addButtons(array(
140 'name' => $buttonName,
145 'name' => ts('Cancel'),
154 * @param array $fields
155 * The input form values.
156 * @param array $files
157 * The uploaded files if any.
161 * @return true if no errors, else an array of errors
164 public static function formRule($fields, $files, $self) {
167 return empty($errors) ?
TRUE : $errors;
171 * Process the form submission
176 public function postProcess() {
177 CRM_Utils_System
::flushCache();
179 if ($this->_action
& CRM_Core_Action
::DELETE
) {
181 CRM_Extension_System
::singleton()->getManager()->uninstall(array($this->_key
));
182 CRM_Core_Session
::setStatus("", ts('Extension Uninstalled'), "success");
183 } catch (CRM_Extension_Exception_DependencyException
$e) {
184 // currently only thrown for payment-processor dependencies
185 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');
189 if ($this->_action
& CRM_Core_Action
::ADD
) {
190 CRM_Extension_System
::singleton()->getManager()->install(array($this->_key
));
191 CRM_Core_Session
::setStatus("", ts('Extension Installed'), "success");
194 if ($this->_action
& CRM_Core_Action
::ENABLE
) {
195 CRM_Extension_System
::singleton()->getManager()->enable(array($this->_key
));
196 CRM_Core_Session
::setStatus("", ts('Extension Enabled'), "success");
199 if ($this->_action
& CRM_Core_Action
::DISABLE
) {
200 CRM_Extension_System
::singleton()->getManager()->disable(array($this->_key
));
201 CRM_Core_Session
::setStatus("", ts('Extension Disabled'), "success");
204 if ($this->_action
& CRM_Core_Action
::UPDATE
) {
205 $result = civicrm_api('Extension', 'download', array(
207 'key' => $this->_key
,
209 if (! CRM_Utils_Array
::value('is_error', $result, FALSE)) {
210 CRM_Core_Session
::setStatus("", ts('Extension Upgraded'), "success");
212 CRM_Core_Session
::setStatus($result['error_message'], ts('Extension Upgrade Failed'), "error");
216 CRM_Utils_System
::redirect(
217 CRM_Utils_System
::url(
218 'civicrm/admin/extensions',
219 'reset=1&action=browse'