Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | |
54 | * @access public | |
55 | * | |
56 | */ | |
57 | function preProcess() { | |
58 | CRM_Utils_System::setTitle(ts('CiviCRM Extensions')); | |
59 | $destination = CRM_Utils_System::url( 'civicrm/admin/extensions', | |
60 | 'reset=1' ); | |
61 | ||
62 | $destination = urlencode( $destination ); | |
63 | $this->assign( 'destination', $destination ); | |
64 | } | |
65 | ||
66 | /** | |
67 | * Get BAO Name | |
68 | * | |
69 | * @return string Classname of BAO. | |
70 | */ | |
71 | function getBAOName() { | |
72 | return 'CRM_Core_BAO_Extension'; | |
73 | } | |
74 | ||
75 | /** | |
76 | * Get action Links | |
77 | * | |
78 | * @return array (reference) of action links | |
79 | */ | |
80 | function &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'), | |
88 | ), | |
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'), | |
95 | ), | |
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'), | |
102 | ), | |
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'), | |
108 | ), | |
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'), | |
114 | ), | |
115 | ); | |
116 | } | |
117 | return self::$_links; | |
118 | } | |
119 | ||
120 | /** | |
121 | * Run the basic page (run essentially starts execution for that page). | |
122 | * | |
123 | * @return void | |
124 | */ | |
125 | function run() { | |
126 | $this->preProcess(); | |
127 | return parent::run(); | |
128 | } | |
129 | ||
130 | /** | |
131 | * Browse all options | |
132 | * | |
133 | * | |
134 | * @return void | |
135 | * @access public | |
136 | * @static | |
137 | */ | |
138 | function browse() { | |
139 | $mapper = CRM_Extension_System::singleton()->getMapper(); | |
140 | $manager = CRM_Extension_System::singleton()->getManager(); | |
141 | ||
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(); | |
145 | if (empty($reqs)) { | |
146 | $reqs = CRM_Extension_System::singleton()->getBrowser()->checkRequirements(); | |
147 | } | |
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) { | |
164 | CRM_Core_Session::setStatus(ts('Failed to read extension (%1). Please refresh the extension list.', array( | |
165 | 1 => $key, | |
166 | ))); | |
167 | continue; | |
168 | } | |
169 | ||
170 | $row = self::createExtendedInfo($obj); | |
171 | $row['id'] = $obj->key; | |
172 | ||
173 | // assign actions | |
174 | $action = 0; | |
175 | switch ($row['status']) { | |
176 | case CRM_Extension_Manager::STATUS_UNINSTALLED: | |
177 | $action += CRM_Core_Action::ADD; | |
178 | break; | |
179 | case CRM_Extension_Manager::STATUS_DISABLED: | |
180 | $action += CRM_Core_Action::ENABLE; | |
181 | $action += CRM_Core_Action::DELETE; | |
182 | break; | |
183 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: | |
184 | $action += CRM_Core_Action::DELETE; | |
185 | break; | |
186 | case CRM_Extension_Manager::STATUS_INSTALLED: | |
187 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: | |
188 | $action += CRM_Core_Action::DISABLE; | |
189 | break; | |
190 | default: | |
191 | } | |
192 | // TODO if extbrowser is enabled and extbrowser has newer version than extcontainer, | |
193 | // then $action += CRM_Core_Action::UPDATE | |
194 | $row['action'] = CRM_Core_Action::formLink(self::links(), | |
195 | $action, | |
196 | array( | |
197 | 'id' => $row['id'], | |
198 | 'key' => $obj->key, | |
199 | ) | |
200 | ); | |
201 | ||
202 | $localExtensionRows[$row['id']] = $row; | |
203 | } | |
204 | $this->assign('localExtensionRows', $localExtensionRows); | |
205 | ||
206 | // build list of availabe downloads | |
207 | $remoteExtensionRows = array(); | |
208 | foreach (CRM_Extension_System::singleton()->getBrowser()->getExtensions() as $info) { | |
209 | $row = (array) $info; | |
210 | $row['id'] = $info->key; | |
211 | $action = CRM_Core_Action::UPDATE; | |
212 | $row['action'] = CRM_Core_Action::formLink(self::links(), | |
213 | $action, | |
214 | array( | |
215 | 'id' => $row['id'], | |
216 | 'key' => $row['key'], | |
217 | ) | |
218 | ); | |
219 | $remoteExtensionRows[$row['id']] = $row; | |
220 | } | |
221 | $this->assign('remoteExtensionRows', $remoteExtensionRows); | |
222 | } | |
223 | ||
224 | /** | |
225 | * Get name of edit form | |
226 | * | |
227 | * @return string Classname of edit form. | |
228 | */ | |
229 | function editForm() { | |
230 | return 'CRM_Admin_Form_Extensions'; | |
231 | } | |
232 | ||
233 | /** | |
234 | * Get edit form name | |
235 | * | |
236 | * @return string name of this page. | |
237 | */ | |
238 | function editName() { | |
239 | return 'CRM_Admin_Form_Extensions'; | |
240 | } | |
241 | ||
242 | /** | |
243 | * Get user context. | |
244 | * | |
245 | * @return string user context. | |
246 | */ | |
247 | function userContext($mode = NULL) { | |
248 | return 'civicrm/admin/extensions'; | |
249 | } | |
250 | ||
251 | /** | |
252 | * function to get userContext params | |
253 | * | |
254 | * @param int $mode mode that we are in | |
255 | * | |
256 | * @return string | |
257 | * @access public | |
258 | */ | |
259 | function userContextParams($mode = NULL) { | |
260 | return 'reset=1&action=browse'; | |
261 | } | |
262 | ||
263 | /** | |
264 | * Take an extension's raw XML info and add information about the | |
265 | * extension's status on the local system. | |
266 | * | |
267 | * The result format resembles the old CRM_Core_Extensions_Extension. | |
268 | * | |
269 | * @return array | |
270 | */ | |
271 | public static function createExtendedInfo(CRM_Extension_Info $obj) { | |
272 | $mapper = CRM_Extension_System::singleton()->getMapper(); | |
273 | $manager = CRM_Extension_System::singleton()->getManager(); | |
274 | ||
275 | $extensionRow = (array) $obj; | |
276 | try { | |
277 | $extensionRow['path'] = $mapper->keyToBasePath($obj->key); | |
278 | } catch (CRM_Extension_Exception $e) { | |
279 | $extensionRow['path'] = ''; | |
280 | } | |
281 | $extensionRow['status'] = $manager->getStatus($obj->key); | |
282 | ||
283 | switch ($extensionRow['status']) { | |
284 | case CRM_Extension_Manager::STATUS_UNINSTALLED: | |
285 | $extensionRow['statusLabel'] = ''; // ts('Uninstalled'); | |
286 | break; | |
287 | case CRM_Extension_Manager::STATUS_DISABLED: | |
288 | $extensionRow['statusLabel'] = ts('Disabled'); | |
289 | break; | |
290 | case CRM_Extension_Manager::STATUS_INSTALLED: | |
291 | $extensionRow['statusLabel'] = ts('Enabled'); // ts('Installed'); | |
292 | break; | |
293 | case CRM_Extension_Manager::STATUS_DISABLED_MISSING: | |
294 | $extensionRow['statusLabel'] = ts('Disabled (Missing)'); | |
295 | break; | |
296 | case CRM_Extension_Manager::STATUS_INSTALLED_MISSING: | |
297 | $extensionRow['statusLabel'] = ts('Enabled (Missing)'); // ts('Installed'); | |
298 | break; | |
299 | default: | |
300 | $extensionRow['statusLabel'] = '(' . $extensionRow['status'] . ')'; | |
301 | } | |
302 | return $extensionRow; | |
303 | } | |
304 | } | |
305 |