3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
13 * This is a part of CiviCRM extension management functionality.
16 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 * This page displays the list of extensions registered in the system.
22 class CRM_Admin_Page_Extensions
extends CRM_Core_Page_Basic
{
25 * The action links that we need to display for the browse screen.
29 public static $_links = NULL;
32 * Obtains the group name from url and sets the title.
34 public function preProcess() {
35 Civi
::resources()->addStyleFile('civicrm', 'css/admin.css');
37 CRM_Utils_System
::setTitle(ts('CiviCRM Extensions'));
38 $destination = CRM_Utils_System
::url('civicrm/admin/extensions',
41 $destination = urlencode($destination);
42 $this->assign('destination', $destination);
51 public function getBAOName() {
52 return 'CRM_Core_BAO_Extension';
59 * (reference) of action links
61 public function &links() {
62 if (!(self
::$_links)) {
64 CRM_Core_Action
::ADD
=> [
65 'name' => ts('Install'),
66 'url' => 'civicrm/admin/extensions',
67 'qs' => 'action=add&id=%%id%%&key=%%key%%',
68 'title' => ts('Install'),
70 CRM_Core_Action
::ENABLE
=> [
71 'name' => ts('Enable'),
72 'url' => 'civicrm/admin/extensions',
73 'qs' => 'action=enable&id=%%id%%&key=%%key%%',
74 'ref' => 'enable-action',
75 'title' => ts('Enable'),
77 CRM_Core_Action
::DISABLE
=> [
78 'name' => ts('Disable'),
79 'url' => 'civicrm/admin/extensions',
80 'qs' => 'action=disable&id=%%id%%&key=%%key%%',
81 'title' => ts('Disable'),
83 CRM_Core_Action
::DELETE
=> [
84 'name' => ts('Uninstall'),
85 'url' => 'civicrm/admin/extensions',
86 'qs' => 'action=delete&id=%%id%%&key=%%key%%',
87 'title' => ts('Uninstall Extension'),
89 CRM_Core_Action
::UPDATE
=> [
90 'name' => ts('Download'),
91 'url' => 'civicrm/admin/extensions',
92 'qs' => 'action=update&id=%%id%%&key=%%key%%',
93 'title' => ts('Download Extension'),
101 * Run the basic page (run essentially starts execution for that page).
103 public function run() {
105 return parent
::run();
109 * Browse all options.
111 public function browse() {
113 // build announcements at the top of the page
114 $this->assign('extAddNewEnabled', CRM_Extension_System
::singleton()->getBrowser()->isEnabled());
115 $reqs = CRM_Extension_System
::singleton()->getDownloader()->checkRequirements();
117 $reqs = CRM_Extension_System
::singleton()->getBrowser()->checkRequirements();
120 $reqs = CRM_Extension_System
::singleton()->getDefaultContainer()->checkRequirements();
122 $this->assign('extAddNewReqs', $reqs);
124 $this->assign('extDbUpgrades', CRM_Extension_Upgrades
::hasPending());
125 $this->assign('extDbUpgradeUrl', CRM_Utils_System
::url('civicrm/admin/extensions/upgrade', 'reset=1'));
127 // TODO: Debate whether to immediately detect changes in underlying source tree
128 // $manager->refresh();
130 $localExtensionRows = $this->formatLocalExtensionRows();
131 $this->assign('localExtensionRows', $localExtensionRows);
133 $remoteExtensionRows = $this->formatRemoteExtensionRows($localExtensionRows);
134 $this->assign('remoteExtensionRows', $remoteExtensionRows);
137 ->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
139 'tabSettings' => ['active' => $_GET['selectedChild'] ??
NULL],
144 * Get the list of local extensions and format them as a table with
145 * status and action data.
149 public function formatLocalExtensionRows() {
150 $mapper = CRM_Extension_System
::singleton()->getMapper();
151 $manager = CRM_Extension_System
::singleton()->getManager();
153 // array($pseudo_id => extended_CRM_Extension_Info)
154 $localExtensionRows = [];
155 $keys = array_keys($manager->getStatuses());
157 $hiddenExtensions = $mapper->getKeysByTag('mgmt:hidden');
158 foreach ($keys as $key) {
159 if (in_array($key, $hiddenExtensions)) {
163 $obj = $mapper->keyToInfo($key);
165 catch (CRM_Extension_Exception
$ex) {
166 CRM_Core_Session
::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', [1 => $key]));
170 $mapper = CRM_Extension_System
::singleton()->getMapper();
172 $row = self
::createExtendedInfo($obj);
173 $row['id'] = $obj->key
;
178 switch ($row['status']) {
179 case CRM_Extension_Manager
::STATUS_UNINSTALLED
:
180 if (!$manager->isIncompatible($row['id'])) {
181 $action +
= CRM_Core_Action
::ADD
;
185 case CRM_Extension_Manager
::STATUS_DISABLED
:
186 if (!$manager->isIncompatible($row['id'])) {
187 $action +
= CRM_Core_Action
::ENABLE
;
189 $action +
= CRM_Core_Action
::DELETE
;
192 case CRM_Extension_Manager
::STATUS_DISABLED_MISSING
:
193 $action +
= CRM_Core_Action
::DELETE
;
196 case CRM_Extension_Manager
::STATUS_INSTALLED
:
197 case CRM_Extension_Manager
::STATUS_INSTALLED_MISSING
:
198 $action +
= CRM_Core_Action
::DISABLE
;
203 // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer,
204 // then $action += CRM_Core_Action::UPDATE
206 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
208 ['id' => $row['id'], 'key' => $obj->key
],
211 'extension.local.action',
216 // Key would be better to send, but it's not an integer. Moreover, sending the
217 // values to hook_civicrm_links means that you can still get at the key
219 $localExtensionRows[$row['id']] = $row;
221 return $localExtensionRows;
225 * Get the list of remote extensions and format them as a table with
226 * status and action data.
228 * @param array $localExtensionRows
231 public function formatRemoteExtensionRows($localExtensionRows) {
233 $remoteExtensions = CRM_Extension_System
::singleton()->getBrowser()->getExtensions();
235 catch (CRM_Extension_Exception
$e) {
236 $remoteExtensions = [];
237 CRM_Core_Session
::setStatus($e->getMessage(), ts('Extension download error'), 'error');
240 // build list of available downloads
241 $remoteExtensionRows = [];
242 $compat = CRM_Extension_System
::getCompatibilityInfo();
243 $mapper = CRM_Extension_System
::singleton()->getMapper();
245 foreach ($remoteExtensions as $info) {
246 if (!empty($compat[$info->key
]['obsolete'])) {
249 $row = (array) $info;
250 $row['id'] = $info->key
;
251 $action = CRM_Core_Action
::UPDATE
;
252 $row['action'] = CRM_Core_Action
::formLink(self
::links(),
256 'key' => $row['key'],
260 'extension.remote.action',
264 if (isset($localExtensionRows[$info->key
])) {
265 if (array_key_exists('version', $localExtensionRows[$info->key
])) {
266 if (version_compare($localExtensionRows[$info->key
]['version'], $info->version
, '<')) {
267 $row['upgradelink'] = $mapper->getUpgradeLink($remoteExtensions[$info->key
], $localExtensionRows[$info->key
]);
271 $remoteExtensionRows[$row['id']] = $row;
274 return $remoteExtensionRows;
278 * Get name of edit form.
281 * Classname of edit form.
283 public function editForm() {
284 return 'CRM_Admin_Form_Extensions';
288 * Get edit form name.
293 public function editName() {
294 return 'CRM_Admin_Form_Extensions';
305 public function userContext($mode = NULL) {
306 return 'civicrm/admin/extensions';
310 * Get userContext params.
313 * Mode that we are in.
317 public function userContextParams($mode = NULL) {
318 return 'reset=1&action=browse';
322 * Take an extension's raw XML info and add information about the
323 * extension's status on the local system.
325 * The result format resembles the old CRM_Core_Extensions_Extension.
327 * @param CRM_Extension_Info $obj
331 public static function createExtendedInfo(CRM_Extension_Info
$obj) {
332 return CRM_Extension_System
::createExtendedInfo($obj);