Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * This is a part of CiviCRM extension management functionality. | |
30 | * | |
31 | * @package CRM | |
06b69b18 | 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
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 | /** | |
43 | * The action links that we need to display for the browse screen | |
44 | * | |
45 | * @var array | |
46 | * @static | |
47 | */ | |
48 | static $_links = NULL; | |
49 | ||
50 | /** | |
51 | * Obtains the group name from url and sets the title. | |
52 | * | |
53 | * @return void | |
6a488035 TO |
54 | * |
55 | */ | |
00be9182 | 56 | public function preProcess() { |
6a488035 TO |
57 | CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); |
58 | $destination = CRM_Utils_System::url( 'civicrm/admin/extensions', | |
59 | 'reset=1' ); | |
8ef12e64 | 60 | |
6a488035 TO |
61 | $destination = urlencode( $destination ); |
62 | $this->assign( 'destination', $destination ); | |
63 | } | |
64 | ||
65 | /** | |
66 | * Get BAO Name | |
67 | * | |
68 | * @return string Classname of BAO. | |
69 | */ | |
00be9182 | 70 | public function getBAOName() { |
6a488035 TO |
71 | return 'CRM_Core_BAO_Extension'; |
72 | } | |
73 | ||
74 | /** | |
75 | * Get action Links | |
76 | * | |
77 | * @return array (reference) of action links | |
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 | /** | |
129 | * Browse all options | |
130 | * | |
131 | * | |
132 | * @return void | |
6a488035 TO |
133 | * @static |
134 | */ | |
00be9182 | 135 | public function browse() { |
6a488035 TO |
136 | $mapper = CRM_Extension_System::singleton()->getMapper(); |
137 | $manager = CRM_Extension_System::singleton()->getManager(); | |
138 | ||
139 | // build announcements at the top of the page | |
140 | $this->assign('extAddNewEnabled', CRM_Extension_System::singleton()->getBrowser()->isEnabled()); | |
141 | $reqs = CRM_Extension_System::singleton()->getDownloader()->checkRequirements(); | |
142 | if (empty($reqs)) { | |
143 | $reqs = CRM_Extension_System::singleton()->getBrowser()->checkRequirements(); | |
144 | } | |
70d331a6 TO |
145 | if (empty($reqs)) { |
146 | $reqs = CRM_Extension_System::singleton()->getDefaultContainer()->checkRequirements(); | |
147 | } | |
6a488035 TO |
148 | $this->assign('extAddNewReqs', $reqs); |
149 | ||
150 | $this->assign('extDbUpgrades', CRM_Extension_Upgrades::hasPending()); | |
151 | $this->assign('extDbUpgradeUrl', CRM_Utils_System::url('civicrm/admin/extensions/upgrade', 'reset=1')); | |
152 | ||
153 | // TODO: Debate whether to immediately detect changes in underlying source tree | |
154 | // $manager->refresh(); | |
155 | ||
156 | // build list of local extensions | |
157 | $localExtensionRows = array(); // array($pseudo_id => extended_CRM_Extension_Info) | |
158 | $keys = array_keys($manager->getStatuses()); | |
159 | sort($keys); | |
160 | foreach($keys as $key) { | |
161 | try { | |
162 | $obj = $mapper->keyToInfo($key); | |
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; | |
177 | case CRM_Extension_Manager::STATUS_DISABLED: | |
178 | $action += CRM_Core_Action::ENABLE; | |
179 | $action += CRM_Core_Action::DELETE; | |
180 | break; | |
181 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: | |
182 | $action += CRM_Core_Action::DELETE; | |
183 | break; | |
184 | case CRM_Extension_Manager::STATUS_INSTALLED: | |
185 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: | |
186 | $action += CRM_Core_Action::DISABLE; | |
187 | break; | |
188 | default: | |
189 | } | |
190 | // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer, | |
191 | // then $action += CRM_Core_Action::UPDATE | |
192 | $row['action'] = CRM_Core_Action::formLink(self::links(), | |
193 | $action, | |
194 | array( | |
195 | 'id' => $row['id'], | |
196 | 'key' => $obj->key, | |
87dab4a4 AH |
197 | ), |
198 | ts('more'), | |
199 | FALSE, | |
200 | 'extension.local.action', | |
201 | 'Extension', | |
202 | $row['id'] | |
6a488035 | 203 | ); |
87dab4a4 AH |
204 | // Key would be better to send, but it's not an integer. Moreover, sending the |
205 | // values to hook_civicrm_links means that you can still get at the key | |
6a488035 TO |
206 | |
207 | $localExtensionRows[$row['id']] = $row; | |
208 | } | |
209 | $this->assign('localExtensionRows', $localExtensionRows); | |
210 | ||
211 | // build list of availabe downloads | |
212 | $remoteExtensionRows = array(); | |
213 | foreach (CRM_Extension_System::singleton()->getBrowser()->getExtensions() as $info) { | |
214 | $row = (array) $info; | |
215 | $row['id'] = $info->key; | |
216 | $action = CRM_Core_Action::UPDATE; | |
217 | $row['action'] = CRM_Core_Action::formLink(self::links(), | |
218 | $action, | |
219 | array( | |
220 | 'id' => $row['id'], | |
221 | 'key' => $row['key'], | |
87dab4a4 AH |
222 | ), |
223 | ts('more'), | |
224 | FALSE, | |
225 | 'extension.remote.action', | |
226 | 'Extension', | |
227 | $row['id'] | |
6a488035 | 228 | ); |
46693baf TO |
229 | if (isset($localExtensionRows[$info->key])) { |
230 | if (version_compare($localExtensionRows[$info->key]['version'], $info->version, '<')) { | |
231 | $row['is_upgradeable'] = TRUE; | |
232 | } | |
233 | } | |
6a488035 TO |
234 | $remoteExtensionRows[$row['id']] = $row; |
235 | } | |
236 | $this->assign('remoteExtensionRows', $remoteExtensionRows); | |
237 | } | |
238 | ||
239 | /** | |
240 | * Get name of edit form | |
241 | * | |
242 | * @return string Classname of edit form. | |
243 | */ | |
00be9182 | 244 | public function editForm() { |
6a488035 TO |
245 | return 'CRM_Admin_Form_Extensions'; |
246 | } | |
247 | ||
248 | /** | |
249 | * Get edit form name | |
250 | * | |
251 | * @return string name of this page. | |
252 | */ | |
00be9182 | 253 | public function editName() { |
6a488035 TO |
254 | return 'CRM_Admin_Form_Extensions'; |
255 | } | |
256 | ||
257 | /** | |
258 | * Get user context. | |
259 | * | |
fd31fa4c EM |
260 | * @param null $mode |
261 | * | |
6a488035 TO |
262 | * @return string user context. |
263 | */ | |
00be9182 | 264 | public function userContext($mode = NULL) { |
6a488035 TO |
265 | return 'civicrm/admin/extensions'; |
266 | } | |
267 | ||
268 | /** | |
100fef9d | 269 | * Get userContext params |
6a488035 | 270 | * |
5173bd95 TO |
271 | * @param int $mode |
272 | * Mode that we are in. | |
6a488035 TO |
273 | * |
274 | * @return string | |
6a488035 | 275 | */ |
00be9182 | 276 | public function userContextParams($mode = NULL) { |
6a488035 TO |
277 | return 'reset=1&action=browse'; |
278 | } | |
279 | ||
280 | /** | |
281 | * Take an extension's raw XML info and add information about the | |
282 | * extension's status on the local system. | |
283 | * | |
284 | * The result format resembles the old CRM_Core_Extensions_Extension. | |
285 | * | |
da6b46f4 EM |
286 | * @param CRM_Extension_Info $obj |
287 | * | |
6a488035 TO |
288 | * @return array |
289 | */ | |
290 | public static function createExtendedInfo(CRM_Extension_Info $obj) { | |
291 | $mapper = CRM_Extension_System::singleton()->getMapper(); | |
292 | $manager = CRM_Extension_System::singleton()->getManager(); | |
293 | ||
294 | $extensionRow = (array) $obj; | |
295 | try { | |
296 | $extensionRow['path'] = $mapper->keyToBasePath($obj->key); | |
297 | } catch (CRM_Extension_Exception $e) { | |
298 | $extensionRow['path'] = ''; | |
299 | } | |
300 | $extensionRow['status'] = $manager->getStatus($obj->key); | |
301 | ||
302 | switch ($extensionRow['status']) { | |
303 | case CRM_Extension_Manager::STATUS_UNINSTALLED: | |
304 | $extensionRow['statusLabel'] = ''; // ts('Uninstalled'); | |
305 | break; | |
306 | case CRM_Extension_Manager::STATUS_DISABLED: | |
307 | $extensionRow['statusLabel'] = ts('Disabled'); | |
308 | break; | |
309 | case CRM_Extension_Manager::STATUS_INSTALLED: | |
310 | $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed'); | |
311 | break; | |
312 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: | |
313 | $extensionRow['statusLabel'] = ts('Disabled (Missing)'); | |
314 | break; | |
315 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: | |
316 | $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed'); | |
317 | break; | |
318 | default: | |
319 | $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')'; | |
320 | } | |
321 | return $extensionRow; | |
322 | } | |
323 | } |