3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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
36 * This page displays the list of extensions registered in the system.
38 class CRM_Admin_Page_Extensions
extends CRM_Core_Page_Basic
{
41 * The action links that we need to display for the browse screen.
45 static $_links = NULL;
48 * Obtains the group name from url and sets the title.
50 public function preProcess() {
51 CRM_Utils_System
::setTitle(ts('CiviCRM Extensions'));
52 $destination = CRM_Utils_System
::url('civicrm/admin/extensions',
55 $destination = urlencode($destination);
56 $this->assign('destination', $destination);
65 public function getBAOName() {
66 return 'CRM_Core_BAO_Extension';
73 * (reference) of action links
75 public function &links() {
76 if (!(self
::$_links)) {
77 self
::$_links = array(
78 CRM_Core_Action
::ADD
=> array(
79 'name' => ts('Install'),
80 'url' => 'civicrm/admin/extensions',
81 'qs' => 'action=add&id=%%id%%&key=%%key%%',
82 'title' => ts('Install'),
84 CRM_Core_Action
::ENABLE
=> array(
85 'name' => ts('Enable'),
86 'url' => 'civicrm/admin/extensions',
87 'qs' => 'action=enable&id=%%id%%&key=%%key%%',
88 'ref' => 'enable-action',
89 'title' => ts('Enable'),
91 CRM_Core_Action
::DISABLE
=> array(
92 'name' => ts('Disable'),
93 'url' => 'civicrm/admin/extensions',
94 'qs' => 'action=disable&id=%%id%%&key=%%key%%',
95 'title' => ts('Disable'),
97 CRM_Core_Action
::DELETE
=> array(
98 'name' => ts('Uninstall'),
99 'url' => 'civicrm/admin/extensions',
100 'qs' => 'action=delete&id=%%id%%&key=%%key%%',
101 'title' => ts('Uninstall Extension'),
103 CRM_Core_Action
::UPDATE
=> array(
104 'name' => ts('Download'),
105 'url' => 'civicrm/admin/extensions',
106 'qs' => 'action=update&id=%%id%%&key=%%key%%',
107 'title' => ts('Download Extension'),
111 return self
::$_links;
115 * Run the basic page (run essentially starts execution for that page).
117 public function run() {
119 return parent
::run();
123 * Browse all options.
125 public function browse() {
126 $mapper = CRM_Extension_System
::singleton()->getMapper();
127 $manager = CRM_Extension_System
::singleton()->getManager();
129 // build announcements at the top of the page
130 $this->assign('extAddNewEnabled', CRM_Extension_System
::singleton()->getBrowser()->isEnabled());
131 $reqs = CRM_Extension_System
::singleton()->getDownloader()->checkRequirements();
133 $reqs = CRM_Extension_System
::singleton()->getBrowser()->checkRequirements();
136 $reqs = CRM_Extension_System
::singleton()->getDefaultContainer()->checkRequirements();
138 $this->assign('extAddNewReqs', $reqs);
140 $this->assign('extDbUpgrades', CRM_Extension_Upgrades
::hasPending());
141 $this->assign('extDbUpgradeUrl', CRM_Utils_System
::url('civicrm/admin/extensions/upgrade', 'reset=1'));
143 // TODO: Debate whether to immediately detect changes in underlying source tree
144 // $manager->refresh();
146 // build list of local extensions
147 $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info)
148 $keys = array_keys($manager->getStatuses());
150 foreach ($keys as $key) {
152 $obj = $mapper->keyToInfo($key);
154 catch (CRM_Extension_Exception
$ex) {
155 CRM_Core_Session
::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key)));
159 $row = self
::createExtendedInfo($obj);
160 $row['id'] = $obj->key
;
164 switch ($row['status']) {
165 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
166 $action +
= CRM_Core_Action
::ADD
;
169 case CRM_Extension_Manager
::STATUS_DISABLED
:
170 $action +
= CRM_Core_Action
::ENABLE
;
171 $action +
= CRM_Core_Action
::DELETE
;
174 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
175 $action +
= CRM_Core_Action
::DELETE
;
178 case CRM_Extension_Manager
::STATUS_INSTALLED
:
179 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
180 $action +
= CRM_Core_Action
::DISABLE
;
185 // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
186 // then $action += CRM_Core_Action::UPDATE
187 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
195 'extension.local.action',
199 // Key would be better to send, but it's not an integer. Moreover, sending the
200 // values to hook_civicrm_links means that you can still get at the key
202 $localExtensionRows[$row['id']] = $row;
204 $this->assign('localExtensionRows', $localExtensionRows);
206 // build list of available downloads
207 $remoteExtensionRows = array();
208 foreach (CRM_Extension_System
::singleton()->getBrowser()->getExtensions() as $info) {
209 $row = (array) $info;
210 $row['id'] = $info->key
;
211 $action = CRM_Core_Action
::UPDATE
;
212 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
216 'key' => $row['key'],
220 'extension.remote.action',
224 if (isset($localExtensionRows[$info->key
])) {
225 if (version_compare($localExtensionRows[$info->key
]['version'], $info->version
, '<')) {
226 $row['is_upgradeable'] = TRUE;
229 $remoteExtensionRows[$row['id']] = $row;
231 $this->assign('remoteExtensionRows', $remoteExtensionRows);
235 * Get name of edit form.
238 * Classname of edit form.
240 public function editForm() {
241 return 'CRM_Admin_Form_Extensions';
245 * Get edit form name.
250 public function editName() {
251 return 'CRM_Admin_Form_Extensions';
262 public function userContext($mode = NULL) {
263 return 'civicrm/admin/extensions';
267 * Get userContext params.
270 * Mode that we are in.
274 public function userContextParams($mode = NULL) {
275 return 'reset=1&action=browse';
279 * Take an extension's raw XML info and add information about the
280 * extension's status on the local system.
282 * The result format resembles the old CRM_Core_Extensions_Extension.
284 * @param CRM_Extension_Info $obj
288 public static function createExtendedInfo(CRM_Extension_Info
$obj) {
289 $mapper = CRM_Extension_System
::singleton()->getMapper();
290 $manager = CRM_Extension_System
::singleton()->getManager();
292 $extensionRow = (array) $obj;
294 $extensionRow['path'] = $mapper->keyToBasePath($obj->key
);
296 catch (CRM_Extension_Exception
$e) {
297 $extensionRow['path'] = '';
299 $extensionRow['status'] = $manager->getStatus($obj->key
);
301 switch ($extensionRow['status']) {
302 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
303 $extensionRow['statusLabel'] = ''; // ts('Uninstalled');
306 case CRM_Extension_Manager
::STATUS_DISABLED
:
307 $extensionRow['statusLabel'] = ts('Disabled');
310 case CRM_Extension_Manager
::STATUS_INSTALLED
:
311 $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed');
314 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
315 $extensionRow['statusLabel'] = ts('Disabled (Missing)');
318 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
319 $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed');
323 $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')';
325 return $extensionRow;