3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * This is a part of CiviCRM extension management functionality.
32 * @copyright CiviCRM LLC (c) 2004-2015
38 * This page displays the list of extensions registered in the system.
40 class CRM_Admin_Page_Extensions
extends CRM_Core_Page_Basic
{
43 * The action links that we need to display for the browse screen.
47 static $_links = NULL;
50 * Obtains the group name from url and sets the title.
54 public function preProcess() {
55 CRM_Utils_System
::setTitle(ts('CiviCRM Extensions'));
56 $destination = CRM_Utils_System
::url('civicrm/admin/extensions',
59 $destination = urlencode($destination);
60 $this->assign('destination', $destination);
69 public function getBAOName() {
70 return 'CRM_Core_BAO_Extension';
77 * (reference) of action links
79 public function &links() {
80 if (!(self
::$_links)) {
81 self
::$_links = array(
82 CRM_Core_Action
::ADD
=> array(
83 'name' => ts('Install'),
84 'url' => 'civicrm/admin/extensions',
85 'qs' => 'action=add&id=%%id%%&key=%%key%%',
86 'title' => ts('Install'),
88 CRM_Core_Action
::ENABLE
=> array(
89 'name' => ts('Enable'),
90 'url' => 'civicrm/admin/extensions',
91 'qs' => 'action=enable&id=%%id%%&key=%%key%%',
92 'ref' => 'enable-action',
93 'title' => ts('Enable'),
95 CRM_Core_Action
::DISABLE
=> array(
96 'name' => ts('Disable'),
97 'url' => 'civicrm/admin/extensions',
98 'qs' => 'action=disable&id=%%id%%&key=%%key%%',
99 'title' => ts('Disable'),
101 CRM_Core_Action
::DELETE
=> array(
102 'name' => ts('Uninstall'),
103 'url' => 'civicrm/admin/extensions',
104 'qs' => 'action=delete&id=%%id%%&key=%%key%%',
105 'title' => ts('Uninstall Extension'),
107 CRM_Core_Action
::UPDATE
=> array(
108 'name' => ts('Download'),
109 'url' => 'civicrm/admin/extensions',
110 'qs' => 'action=update&id=%%id%%&key=%%key%%',
111 'title' => ts('Download Extension'),
115 return self
::$_links;
119 * Run the basic page (run essentially starts execution for that page).
123 public function run() {
125 return parent
::run();
129 * Browse all options.
134 public function browse() {
135 $mapper = CRM_Extension_System
::singleton()->getMapper();
136 $manager = CRM_Extension_System
::singleton()->getManager();
138 // build announcements at the top of the page
139 $this->assign('extAddNewEnabled', CRM_Extension_System
::singleton()->getBrowser()->isEnabled());
140 $reqs = CRM_Extension_System
::singleton()->getDownloader()->checkRequirements();
142 $reqs = CRM_Extension_System
::singleton()->getBrowser()->checkRequirements();
145 $reqs = CRM_Extension_System
::singleton()->getDefaultContainer()->checkRequirements();
147 $this->assign('extAddNewReqs', $reqs);
149 $this->assign('extDbUpgrades', CRM_Extension_Upgrades
::hasPending());
150 $this->assign('extDbUpgradeUrl', CRM_Utils_System
::url('civicrm/admin/extensions/upgrade', 'reset=1'));
152 // TODO: Debate whether to immediately detect changes in underlying source tree
153 // $manager->refresh();
155 // build list of local extensions
156 $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info)
157 $keys = array_keys($manager->getStatuses());
159 foreach ($keys as $key) {
161 $obj = $mapper->keyToInfo($key);
163 catch (CRM_Extension_Exception
$ex) {
164 CRM_Core_Session
::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key)));
168 $row = self
::createExtendedInfo($obj);
169 $row['id'] = $obj->key
;
173 switch ($row['status']) {
174 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
175 $action +
= CRM_Core_Action
::ADD
;
178 case CRM_Extension_Manager
::STATUS_DISABLED
:
179 $action +
= CRM_Core_Action
::ENABLE
;
180 $action +
= CRM_Core_Action
::DELETE
;
183 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
184 $action +
= CRM_Core_Action
::DELETE
;
187 case CRM_Extension_Manager
::STATUS_INSTALLED
:
188 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
189 $action +
= CRM_Core_Action
::DISABLE
;
194 // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
195 // then $action += CRM_Core_Action::UPDATE
196 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
204 'extension.local.action',
208 // Key would be better to send, but it's not an integer. Moreover, sending the
209 // values to hook_civicrm_links means that you can still get at the key
211 $localExtensionRows[$row['id']] = $row;
213 $this->assign('localExtensionRows', $localExtensionRows);
215 // build list of available downloads
216 $remoteExtensionRows = array();
217 foreach (CRM_Extension_System
::singleton()->getBrowser()->getExtensions() as $info) {
218 $row = (array) $info;
219 $row['id'] = $info->key
;
220 $action = CRM_Core_Action
::UPDATE
;
221 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
225 'key' => $row['key'],
229 'extension.remote.action',
233 if (isset($localExtensionRows[$info->key
])) {
234 if (version_compare($localExtensionRows[$info->key
]['version'], $info->version
, '<')) {
235 $row['is_upgradeable'] = TRUE;
238 $remoteExtensionRows[$row['id']] = $row;
240 $this->assign('remoteExtensionRows', $remoteExtensionRows);
244 * Get name of edit form.
247 * Classname of edit form.
249 public function editForm() {
250 return 'CRM_Admin_Form_Extensions';
254 * Get edit form name.
259 public function editName() {
260 return 'CRM_Admin_Form_Extensions';
271 public function userContext($mode = NULL) {
272 return 'civicrm/admin/extensions';
276 * Get userContext params.
279 * Mode that we are in.
283 public function userContextParams($mode = NULL) {
284 return 'reset=1&action=browse';
288 * Take an extension's raw XML info and add information about the
289 * extension's status on the local system.
291 * The result format resembles the old CRM_Core_Extensions_Extension.
293 * @param CRM_Extension_Info $obj
297 public static function createExtendedInfo(CRM_Extension_Info
$obj) {
298 $mapper = CRM_Extension_System
::singleton()->getMapper();
299 $manager = CRM_Extension_System
::singleton()->getManager();
301 $extensionRow = (array) $obj;
303 $extensionRow['path'] = $mapper->keyToBasePath($obj->key
);
305 catch (CRM_Extension_Exception
$e) {
306 $extensionRow['path'] = '';
308 $extensionRow['status'] = $manager->getStatus($obj->key
);
310 switch ($extensionRow['status']) {
311 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
312 $extensionRow['statusLabel'] = ''; // ts('Uninstalled');
315 case CRM_Extension_Manager
::STATUS_DISABLED
:
316 $extensionRow['statusLabel'] = ts('Disabled');
319 case CRM_Extension_Manager
::STATUS_INSTALLED
:
320 $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed');
323 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
324 $extensionRow['statusLabel'] = ts('Disabled (Missing)');
327 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
328 $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed');
332 $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')';
334 return $extensionRow;