3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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
48 static $_links = NULL;
51 * Obtains the group name from url and sets the title.
57 function preProcess() {
58 CRM_Utils_System
::setTitle(ts('CiviCRM Extensions'));
59 $destination = CRM_Utils_System
::url( 'civicrm/admin/extensions',
62 $destination = urlencode( $destination );
63 $this->assign( 'destination', $destination );
69 * @return string Classname of BAO.
71 function getBAOName() {
72 return 'CRM_Core_BAO_Extension';
78 * @return array (reference) of action links
81 if (!(self
::$_links)) {
82 self
::$_links = array(
83 CRM_Core_Action
::ADD
=> array(
84 'name' => ts('Install'),
85 'url' => 'civicrm/admin/extensions',
86 'qs' => 'action=add&id=%%id%%&key=%%key%%',
87 'title' => ts('Install'),
89 CRM_Core_Action
::ENABLE
=> array(
90 'name' => ts('Enable'),
91 'url' => 'civicrm/admin/extensions',
92 'qs' => 'action=enable&id=%%id%%&key=%%key%%',
93 'ref' => 'enable-action',
94 'title' => ts('Enable'),
96 CRM_Core_Action
::DISABLE
=> array(
97 'name' => ts('Disable'),
98 'url' => 'civicrm/admin/extensions',
99 'qs' => 'action=disable&id=%%id%%&key=%%key%%',
100 'ref' => 'disable-action',
101 'title' => ts('Disable'),
103 CRM_Core_Action
::DELETE
=> array(
104 'name' => ts('Uninstall'),
105 'url' => 'civicrm/admin/extensions',
106 'qs' => 'action=delete&id=%%id%%&key=%%key%%',
107 'title' => ts('Uninstall Extension'),
109 CRM_Core_Action
::UPDATE
=> array(
110 'name' => ts('Download'),
111 'url' => 'civicrm/admin/extensions',
112 'qs' => 'action=update&id=%%id%%&key=%%key%%',
113 'title' => ts('Download Extension'),
117 return self
::$_links;
121 * Run the basic page (run essentially starts execution for that page).
127 return parent
::run();
139 $mapper = CRM_Extension_System
::singleton()->getMapper();
140 $manager = CRM_Extension_System
::singleton()->getManager();
142 // build announcements at the top of the page
143 $this->assign('extAddNewEnabled', CRM_Extension_System
::singleton()->getBrowser()->isEnabled());
144 $reqs = CRM_Extension_System
::singleton()->getDownloader()->checkRequirements();
146 $reqs = CRM_Extension_System
::singleton()->getBrowser()->checkRequirements();
149 $reqs = CRM_Extension_System
::singleton()->getDefaultContainer()->checkRequirements();
151 $this->assign('extAddNewReqs', $reqs);
153 $this->assign('extDbUpgrades', CRM_Extension_Upgrades
::hasPending());
154 $this->assign('extDbUpgradeUrl', CRM_Utils_System
::url('civicrm/admin/extensions/upgrade', 'reset=1'));
156 // TODO: Debate whether to immediately detect changes in underlying source tree
157 // $manager->refresh();
159 // build list of local extensions
160 $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info)
161 $keys = array_keys($manager->getStatuses());
163 foreach($keys as $key) {
165 $obj = $mapper->keyToInfo($key);
166 } catch (CRM_Extension_Exception
$ex) {
167 CRM_Core_Session
::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(
173 $row = self
::createExtendedInfo($obj);
174 $row['id'] = $obj->key
;
178 switch ($row['status']) {
179 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
180 $action +
= CRM_Core_Action
::ADD
;
182 case CRM_Extension_Manager
::STATUS_DISABLED
:
183 $action +
= CRM_Core_Action
::ENABLE
;
184 $action +
= CRM_Core_Action
::DELETE
;
186 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
187 $action +
= CRM_Core_Action
::DELETE
;
189 case CRM_Extension_Manager
::STATUS_INSTALLED
:
190 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
191 $action +
= CRM_Core_Action
::DISABLE
;
195 // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
196 // then $action += CRM_Core_Action::UPDATE
197 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
205 $localExtensionRows[$row['id']] = $row;
207 $this->assign('localExtensionRows', $localExtensionRows);
209 // build list of availabe downloads
210 $remoteExtensionRows = array();
211 foreach (CRM_Extension_System
::singleton()->getBrowser()->getExtensions() as $info) {
212 $row = (array) $info;
213 $row['id'] = $info->key
;
214 $action = CRM_Core_Action
::UPDATE
;
215 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
219 'key' => $row['key'],
222 $remoteExtensionRows[$row['id']] = $row;
224 $this->assign('remoteExtensionRows', $remoteExtensionRows);
228 * Get name of edit form
230 * @return string Classname of edit form.
232 function editForm() {
233 return 'CRM_Admin_Form_Extensions';
239 * @return string name of this page.
241 function editName() {
242 return 'CRM_Admin_Form_Extensions';
248 * @return string user context.
250 function userContext($mode = NULL) {
251 return 'civicrm/admin/extensions';
255 * function to get userContext params
257 * @param int $mode mode that we are in
262 function userContextParams($mode = NULL) {
263 return 'reset=1&action=browse';
267 * Take an extension's raw XML info and add information about the
268 * extension's status on the local system.
270 * The result format resembles the old CRM_Core_Extensions_Extension.
274 public static function createExtendedInfo(CRM_Extension_Info
$obj) {
275 $mapper = CRM_Extension_System
::singleton()->getMapper();
276 $manager = CRM_Extension_System
::singleton()->getManager();
278 $extensionRow = (array) $obj;
280 $extensionRow['path'] = $mapper->keyToBasePath($obj->key
);
281 } catch (CRM_Extension_Exception
$e) {
282 $extensionRow['path'] = '';
284 $extensionRow['status'] = $manager->getStatus($obj->key
);
286 switch ($extensionRow['status']) {
287 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
288 $extensionRow['statusLabel'] = ''; // ts('Uninstalled');
290 case CRM_Extension_Manager
::STATUS_DISABLED
:
291 $extensionRow['statusLabel'] = ts('Disabled');
293 case CRM_Extension_Manager
::STATUS_INSTALLED
:
294 $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed');
296 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
297 $extensionRow['statusLabel'] = ts('Disabled (Missing)');
299 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
300 $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed');
303 $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')';
305 return $extensionRow;