Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * This is a part of CiviCRM extension management functionality. | |
30 | * | |
31 | * @package CRM | |
e7112fa7 | 32 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
33 | * $Id$ |
34 | * | |
35 | */ | |
36 | ||
37 | /** | |
38 | * This page displays the list of extensions registered in the system. | |
39 | */ | |
40 | class CRM_Admin_Page_Extensions extends CRM_Core_Page_Basic { | |
41 | ||
42 | /** | |
eceb18cc | 43 | * The action links that we need to display for the browse screen. |
6a488035 TO |
44 | * |
45 | * @var array | |
6a488035 TO |
46 | */ |
47 | static $_links = NULL; | |
48 | ||
49 | /** | |
50 | * Obtains the group name from url and sets the title. | |
51 | * | |
52 | * @return void | |
6a488035 | 53 | */ |
00be9182 | 54 | public function preProcess() { |
6a488035 | 55 | CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); |
481a74f4 | 56 | $destination = CRM_Utils_System::url('civicrm/admin/extensions', |
353ffa53 | 57 | 'reset=1'); |
8ef12e64 | 58 | |
481a74f4 TO |
59 | $destination = urlencode($destination); |
60 | $this->assign('destination', $destination); | |
6a488035 TO |
61 | } |
62 | ||
63 | /** | |
eceb18cc | 64 | * Get BAO Name. |
6a488035 | 65 | * |
a6c01b45 CW |
66 | * @return string |
67 | * Classname of BAO. | |
6a488035 | 68 | */ |
00be9182 | 69 | public function getBAOName() { |
6a488035 TO |
70 | return 'CRM_Core_BAO_Extension'; |
71 | } | |
72 | ||
73 | /** | |
eceb18cc | 74 | * Get action Links. |
6a488035 | 75 | * |
a6c01b45 CW |
76 | * @return array |
77 | * (reference) of action links | |
6a488035 | 78 | */ |
00be9182 | 79 | public function &links() { |
6a488035 TO |
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'), | |
87 | ), | |
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'), | |
94 | ), | |
95 | CRM_Core_Action::DISABLE => array( | |
96 | 'name' => ts('Disable'), | |
97 | 'url' => 'civicrm/admin/extensions', | |
98 | 'qs' => 'action=disable&id=%%id%%&key=%%key%%', | |
6a488035 TO |
99 | 'title' => ts('Disable'), |
100 | ), | |
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'), | |
106 | ), | |
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'), | |
112 | ), | |
113 | ); | |
114 | } | |
115 | return self::$_links; | |
116 | } | |
117 | ||
118 | /** | |
119 | * Run the basic page (run essentially starts execution for that page). | |
120 | * | |
121 | * @return void | |
122 | */ | |
00be9182 | 123 | public function run() { |
6a488035 TO |
124 | $this->preProcess(); |
125 | return parent::run(); | |
126 | } | |
127 | ||
128 | /** | |
eceb18cc | 129 | * Browse all options. |
6a488035 TO |
130 | * |
131 | * | |
132 | * @return void | |
6a488035 | 133 | */ |
00be9182 | 134 | public function browse() { |
6a488035 TO |
135 | $mapper = CRM_Extension_System::singleton()->getMapper(); |
136 | $manager = CRM_Extension_System::singleton()->getManager(); | |
137 | ||
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(); | |
141 | if (empty($reqs)) { | |
142 | $reqs = CRM_Extension_System::singleton()->getBrowser()->checkRequirements(); | |
143 | } | |
70d331a6 TO |
144 | if (empty($reqs)) { |
145 | $reqs = CRM_Extension_System::singleton()->getDefaultContainer()->checkRequirements(); | |
146 | } | |
6a488035 TO |
147 | $this->assign('extAddNewReqs', $reqs); |
148 | ||
149 | $this->assign('extDbUpgrades', CRM_Extension_Upgrades::hasPending()); | |
150 | $this->assign('extDbUpgradeUrl', CRM_Utils_System::url('civicrm/admin/extensions/upgrade', 'reset=1')); | |
151 | ||
152 | // TODO: Debate whether to immediately detect changes in underlying source tree | |
153 | // $manager->refresh(); | |
154 | ||
155 | // build list of local extensions | |
156 | $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info) | |
157 | $keys = array_keys($manager->getStatuses()); | |
158 | sort($keys); | |
22e263ad | 159 | foreach ($keys as $key) { |
6a488035 TO |
160 | try { |
161 | $obj = $mapper->keyToInfo($key); | |
0db6c3e1 TO |
162 | } |
163 | catch (CRM_Extension_Exception $ex) { | |
10a5be27 | 164 | CRM_Core_Session::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key))); |
6a488035 TO |
165 | continue; |
166 | } | |
167 | ||
168 | $row = self::createExtendedInfo($obj); | |
169 | $row['id'] = $obj->key; | |
170 | ||
171 | // assign actions | |
172 | $action = 0; | |
173 | switch ($row['status']) { | |
174 | case CRM_Extension_Manager::STATUS_UNINSTALLED: | |
175 | $action += CRM_Core_Action::ADD; | |
176 | break; | |
02fc859b | 177 | |
6a488035 TO |
178 | case CRM_Extension_Manager::STATUS_DISABLED: |
179 | $action += CRM_Core_Action::ENABLE; | |
180 | $action += CRM_Core_Action::DELETE; | |
181 | break; | |
02fc859b | 182 | |
6a488035 TO |
183 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: |
184 | $action += CRM_Core_Action::DELETE; | |
185 | break; | |
02fc859b | 186 | |
6a488035 TO |
187 | case CRM_Extension_Manager::STATUS_INSTALLED: |
188 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: | |
189 | $action += CRM_Core_Action::DISABLE; | |
190 | break; | |
02fc859b | 191 | |
6a488035 TO |
192 | default: |
193 | } | |
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(), | |
197 | $action, | |
198 | array( | |
199 | 'id' => $row['id'], | |
200 | 'key' => $obj->key, | |
87dab4a4 AH |
201 | ), |
202 | ts('more'), | |
203 | FALSE, | |
204 | 'extension.local.action', | |
205 | 'Extension', | |
206 | $row['id'] | |
6a488035 | 207 | ); |
87dab4a4 AH |
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 | |
6a488035 TO |
210 | |
211 | $localExtensionRows[$row['id']] = $row; | |
212 | } | |
213 | $this->assign('localExtensionRows', $localExtensionRows); | |
214 | ||
b44e3f84 | 215 | // build list of available downloads |
6a488035 TO |
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(), | |
222 | $action, | |
223 | array( | |
224 | 'id' => $row['id'], | |
225 | 'key' => $row['key'], | |
87dab4a4 AH |
226 | ), |
227 | ts('more'), | |
228 | FALSE, | |
229 | 'extension.remote.action', | |
230 | 'Extension', | |
231 | $row['id'] | |
6a488035 | 232 | ); |
46693baf TO |
233 | if (isset($localExtensionRows[$info->key])) { |
234 | if (version_compare($localExtensionRows[$info->key]['version'], $info->version, '<')) { | |
235 | $row['is_upgradeable'] = TRUE; | |
236 | } | |
237 | } | |
6a488035 TO |
238 | $remoteExtensionRows[$row['id']] = $row; |
239 | } | |
240 | $this->assign('remoteExtensionRows', $remoteExtensionRows); | |
241 | } | |
242 | ||
243 | /** | |
eceb18cc | 244 | * Get name of edit form. |
6a488035 | 245 | * |
a6c01b45 CW |
246 | * @return string |
247 | * Classname of edit form. | |
6a488035 | 248 | */ |
00be9182 | 249 | public function editForm() { |
6a488035 TO |
250 | return 'CRM_Admin_Form_Extensions'; |
251 | } | |
252 | ||
253 | /** | |
eceb18cc | 254 | * Get edit form name. |
6a488035 | 255 | * |
a6c01b45 CW |
256 | * @return string |
257 | * name of this page. | |
6a488035 | 258 | */ |
00be9182 | 259 | public function editName() { |
6a488035 TO |
260 | return 'CRM_Admin_Form_Extensions'; |
261 | } | |
262 | ||
263 | /** | |
264 | * Get user context. | |
265 | * | |
fd31fa4c EM |
266 | * @param null $mode |
267 | * | |
a6c01b45 CW |
268 | * @return string |
269 | * user context. | |
6a488035 | 270 | */ |
00be9182 | 271 | public function userContext($mode = NULL) { |
6a488035 TO |
272 | return 'civicrm/admin/extensions'; |
273 | } | |
274 | ||
275 | /** | |
eceb18cc | 276 | * Get userContext params. |
6a488035 | 277 | * |
5173bd95 TO |
278 | * @param int $mode |
279 | * Mode that we are in. | |
6a488035 TO |
280 | * |
281 | * @return string | |
6a488035 | 282 | */ |
00be9182 | 283 | public function userContextParams($mode = NULL) { |
6a488035 TO |
284 | return 'reset=1&action=browse'; |
285 | } | |
286 | ||
287 | /** | |
288 | * Take an extension's raw XML info and add information about the | |
289 | * extension's status on the local system. | |
290 | * | |
291 | * The result format resembles the old CRM_Core_Extensions_Extension. | |
292 | * | |
da6b46f4 EM |
293 | * @param CRM_Extension_Info $obj |
294 | * | |
6a488035 TO |
295 | * @return array |
296 | */ | |
297 | public static function createExtendedInfo(CRM_Extension_Info $obj) { | |
298 | $mapper = CRM_Extension_System::singleton()->getMapper(); | |
299 | $manager = CRM_Extension_System::singleton()->getManager(); | |
300 | ||
301 | $extensionRow = (array) $obj; | |
302 | try { | |
303 | $extensionRow['path'] = $mapper->keyToBasePath($obj->key); | |
0db6c3e1 TO |
304 | } |
305 | catch (CRM_Extension_Exception $e) { | |
6a488035 TO |
306 | $extensionRow['path'] = ''; |
307 | } | |
308 | $extensionRow['status'] = $manager->getStatus($obj->key); | |
309 | ||
310 | switch ($extensionRow['status']) { | |
311 | case CRM_Extension_Manager::STATUS_UNINSTALLED: | |
312 | $extensionRow['statusLabel'] = ''; // ts('Uninstalled'); | |
313 | break; | |
02fc859b | 314 | |
6a488035 TO |
315 | case CRM_Extension_Manager::STATUS_DISABLED: |
316 | $extensionRow['statusLabel'] = ts('Disabled'); | |
317 | break; | |
02fc859b | 318 | |
6a488035 TO |
319 | case CRM_Extension_Manager::STATUS_INSTALLED: |
320 | $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed'); | |
321 | break; | |
02fc859b | 322 | |
6a488035 TO |
323 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: |
324 | $extensionRow['statusLabel'] = ts('Disabled (Missing)'); | |
325 | break; | |
02fc859b | 326 | |
6a488035 TO |
327 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: |
328 | $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed'); | |
329 | break; | |
02fc859b | 330 | |
6a488035 TO |
331 | default: |
332 | $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')'; | |
333 | } | |
334 | return $extensionRow; | |
335 | } | |
96025800 | 336 | |
6a488035 | 337 | } |