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 +--------------------------------------------------------------------+
29 * This is a part of CiviCRM extension management functionality.
32 * @copyright CiviCRM LLC (c) 2004-2017
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 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
53 CRM_Utils_System
::setTitle(ts('CiviCRM Extensions'));
54 $destination = CRM_Utils_System
::url('civicrm/admin/extensions',
57 $destination = urlencode($destination);
58 $this->assign('destination', $destination);
67 public function getBAOName() {
68 return 'CRM_Core_BAO_Extension';
75 * (reference) of action links
77 public function &links() {
78 if (!(self
::$_links)) {
79 self
::$_links = array(
80 CRM_Core_Action
::ADD
=> array(
81 'name' => ts('Install'),
82 'url' => 'civicrm/admin/extensions',
83 'qs' => 'action=add&id=%%id%%&key=%%key%%',
84 'title' => ts('Install'),
86 CRM_Core_Action
::ENABLE
=> array(
87 'name' => ts('Enable'),
88 'url' => 'civicrm/admin/extensions',
89 'qs' => 'action=enable&id=%%id%%&key=%%key%%',
90 'ref' => 'enable-action',
91 'title' => ts('Enable'),
93 CRM_Core_Action
::DISABLE
=> array(
94 'name' => ts('Disable'),
95 'url' => 'civicrm/admin/extensions',
96 'qs' => 'action=disable&id=%%id%%&key=%%key%%',
97 'title' => ts('Disable'),
99 CRM_Core_Action
::DELETE
=> array(
100 'name' => ts('Uninstall'),
101 'url' => 'civicrm/admin/extensions',
102 'qs' => 'action=delete&id=%%id%%&key=%%key%%',
103 'title' => ts('Uninstall Extension'),
105 CRM_Core_Action
::UPDATE
=> array(
106 'name' => ts('Download'),
107 'url' => 'civicrm/admin/extensions',
108 'qs' => 'action=update&id=%%id%%&key=%%key%%',
109 'title' => ts('Download Extension'),
113 return self
::$_links;
117 * Run the basic page (run essentially starts execution for that page).
119 public function run() {
121 return parent
::run();
125 * Browse all options.
127 public function browse() {
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 $localExtensionRows = $this->formatLocalExtensionRows();
147 $this->assign('localExtensionRows', $localExtensionRows);
149 $remoteExtensionRows = $this->formatRemoteExtensionRows($localExtensionRows);
150 $this->assign('remoteExtensionRows', $remoteExtensionRows);
154 * Get the list of local extensions and format them as a table with
155 * status and action data.
159 public function formatLocalExtensionRows() {
160 $mapper = CRM_Extension_System
::singleton()->getMapper();
161 $manager = CRM_Extension_System
::singleton()->getManager();
163 $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info)
164 $keys = array_keys($manager->getStatuses());
166 foreach ($keys as $key) {
168 $obj = $mapper->keyToInfo($key);
170 catch (CRM_Extension_Exception
$ex) {
171 CRM_Core_Session
::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key)));
175 $row = self
::createExtendedInfo($obj);
176 $row['id'] = $obj->key
;
180 switch ($row['status']) {
181 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
182 $action +
= CRM_Core_Action
::ADD
;
185 case CRM_Extension_Manager
::STATUS_DISABLED
:
186 $action +
= CRM_Core_Action
::ENABLE
;
187 $action +
= CRM_Core_Action
::DELETE
;
190 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
191 $action +
= CRM_Core_Action
::DELETE
;
194 case CRM_Extension_Manager
::STATUS_INSTALLED
:
195 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
196 $action +
= CRM_Core_Action
::DISABLE
;
201 // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
202 // then $action += CRM_Core_Action::UPDATE
203 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
211 'extension.local.action',
215 // Key would be better to send, but it's not an integer. Moreover, sending the
216 // values to hook_civicrm_links means that you can still get at the key
218 $localExtensionRows[$row['id']] = $row;
220 return $localExtensionRows;
224 * Get the list of local extensions and format them as a table with
225 * status and action data.
227 * @param array $localExtensionRows
230 public function formatRemoteExtensionRows($localExtensionRows) {
232 $remoteExtensions = CRM_Extension_System
::singleton()->getBrowser()->getExtensions();
234 catch (CRM_Extension_Exception
$e) {
235 $remoteExtensions = array();
236 CRM_Core_Session
::setStatus($e->getMessage(), ts('Extension download error'), 'error');
239 // build list of available downloads
240 $remoteExtensionRows = array();
241 foreach ($remoteExtensions as $info) {
242 $row = (array) $info;
243 $row['id'] = $info->key
;
244 $action = CRM_Core_Action
::UPDATE
;
245 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
249 'key' => $row['key'],
253 'extension.remote.action',
257 if (isset($localExtensionRows[$info->key
])) {
258 if (array_key_exists('version', $localExtensionRows[$info->key
])) {
259 if (version_compare($localExtensionRows[$info->key
]['version'], $info->version
, '<')) {
260 $row['is_upgradeable'] = TRUE;
264 $remoteExtensionRows[$row['id']] = $row;
267 return $remoteExtensionRows;
271 * Get name of edit form.
274 * Classname of edit form.
276 public function editForm() {
277 return 'CRM_Admin_Form_Extensions';
281 * Get edit form name.
286 public function editName() {
287 return 'CRM_Admin_Form_Extensions';
298 public function userContext($mode = NULL) {
299 return 'civicrm/admin/extensions';
303 * Get userContext params.
306 * Mode that we are in.
310 public function userContextParams($mode = NULL) {
311 return 'reset=1&action=browse';
315 * Take an extension's raw XML info and add information about the
316 * extension's status on the local system.
318 * The result format resembles the old CRM_Core_Extensions_Extension.
320 * @param CRM_Extension_Info $obj
324 public static function createExtendedInfo(CRM_Extension_Info
$obj) {
325 return CRM_Extension_System
::createExtendedInfo($obj);