2 /*********************************************************************************
3 * SugarCRM Community Edition is a customer relationship management program developed by
4 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
6 * This program is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Affero General Public License version 3 as published by the
8 * Free Software Foundation with the addition of the following permission added
9 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
18 * You should have received a copy of the GNU Affero General Public License along with
19 * this program; if not, see http://www.gnu.org/licenses or write to the Free
20 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
26 * The interactive user interfaces in modified source and object code versions
27 * of this program must display Appropriate Legal Notices, as required under
28 * Section 5 of the GNU Affero General Public License version 3.
30 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31 * these Appropriate Legal Notices must retain the display of the "Powered by
32 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33 * technical reasons, the Appropriate Legal Notices must display the words
34 * "Powered by SugarCRM".
35 ********************************************************************************/
37 require_once('ModuleInstall/PackageManager/PackageManagerDisplay.php');
38 require_once('ModuleInstall/PackageManager/PackageManager.php');
39 class PackageController{
43 * Constructor: this class is called from the the ajax call and handles invoking the correct
44 * functionality on the server.
46 function PackageController(){
47 $this->_pm = new PackageManager();
50 function performBasicSearch(){
54 if(isset($_REQUEST['search_term'])) {
55 $search_term = nl2br($_REQUEST['search_term']);
57 if(isset($_REQUEST['node_id'])) {
58 $node_id = nl2br($_REQUEST['node_id']);
60 $xml = PackageManager::getPackages($node_id);
61 echo 'result = ' . $json->encode(array('packages' => $xml));
65 * Retrieve a list of packages which belong to the corresponding category
67 * @param category_id this is passed via POST and is the category id of packages
69 * @return packages xml string consisting of the packages and releases which belong to
72 function getPackages(){
76 if(isset($_REQUEST['category_id'])) {
77 $category_id = nl2br($_REQUEST['category_id']);
79 $xml = PackageManager::getPackages($category_id);
80 echo 'result = ' . $json->encode(array('package_output' => $xml));
84 * Obtain a list of releases from the server. This function is currently used for generating the patches/langpacks for upgrade wizard
85 * as well as during installation
87 function getReleases(){
92 if(isset($_REQUEST['category_id'])) {
93 $category_id = nl2br($_REQUEST['category_id']);
95 if(isset($_REQUEST['package_id'])) {
96 $package_id = nl2br($_REQUEST['package_id']);
98 if(isset($_REQUEST['types'])) {
99 $types = nl2br($_REQUEST['types']);
101 $types = explode(',', $types);
104 $count = count($types);
107 foreach($types as $type){
108 $type_str .= "'".$type."'";
114 $filter = array('type' => $type_str);
115 $filter = PackageManager::toNameValueList($filter);
116 $releases = PackageManager::getReleases($category_id, $package_id, $filter);
118 $release_map = array();
119 foreach($releases['packages'] as $release){
120 $release = PackageManager::fromNameValueList($release);
121 $nodes[] = array('description' => $release['description'], 'version' => $release['version'], 'build_number' => $release['build_number'], 'id' => $release['id']);
122 $release_map[$release['id']] = array('package_id' => $release['package_id'], 'category_id' => $release['category_id']);
124 $_SESSION['ML_PATCHES'] = $release_map;
125 echo 'result = ' . $json->encode(array('releases' => $nodes));
129 * Obtain a promotion from the depot
131 function getPromotion(){
132 $json = getJSONobj();
134 $header = PackageManager::getPromotion();
136 echo 'result = ' . $json->encode(array('promotion' => $header));
140 * Download the given release
142 * @param category_id this is passed via POST and is the category id of the release we wish to download
143 * @param package_id this is passed via POST and is the package id of the release we wish to download
144 * @param release_id this is passed via POST and is the release id of the release we wish to download
145 * @return bool true is successful in downloading, false otherwise
148 global $sugar_config;
149 $json = getJSONobj();
153 if(isset($_REQUEST['package_id'])) {
154 $package_id = nl2br($_REQUEST['package_id']);
156 if(isset($_REQUEST['category_id'])) {
157 $category_id = nl2br($_REQUEST['category_id']);
159 if(isset($_REQUEST['release_id'])) {
160 $release_id = nl2br($_REQUEST['release_id']);
162 $GLOBALS['log']->debug("PACKAGE ID: ".$package_id);
163 $GLOBALS['log']->debug("CATEGORY ID: ".$category_id);
164 $GLOBALS['log']->debug("RELEASE ID: ".$release_id);
165 $result = $this->_pm->download($category_id, $package_id, $release_id);
166 $GLOBALS['log']->debug("RESULT: ".print_r($result,true));
169 $GLOBALS['log']->debug("Performing Setup");
170 $this->_pm->performSetup($result, 'module', false);
171 $GLOBALS['log']->debug("Complete Setup");
174 echo 'result = ' . $json->encode(array('success' => $success));
178 * Retrieve a list of categories that are subcategories to the selected category
180 * @param id - the id of the parent_category, -1 if this is the root
181 * @return array - a list of categories/nodes which are underneath this node
183 function getCategories(){
184 $json = getJSONobj();
186 if(isset($_REQUEST['category_id'])) {
187 $node_id = nl2br($_REQUEST['category_id']);
189 $GLOBALS['log']->debug("NODE ID: ".$node_id);
190 $nodes = PackageManager::getCategories($node_id);
191 echo 'result = ' . $json->encode(array('nodes' => $nodes));
195 $json = getJSONobj();
197 if(isset($_REQUEST['category_id'])) {
198 $category_id = nl2br($_REQUEST['category_id']);
200 $GLOBALS['log']->debug("CATEGORY ID: ".$category_id);
201 $nodes = PackageManager::getModuleLoaderCategoryPackages($category_id);
202 $GLOBALS['log']->debug(var_export($nodes, true));
203 echo 'result = ' . $json->encode(array('nodes' => $nodes));
207 * Check the SugarDepot for updates for the given type as passed in via POST
208 * @param type the type to check for
209 * @return array return an array of releases for each given installed object if an update is found
211 function checkForUpdates(){
212 $json = getJSONobj();
214 if(isset($_REQUEST['type'])) {
215 $type = nl2br($_REQUEST['type']);
217 $pm = new PackageManager();
218 $updates = $pm->checkForUpdates();
220 $release_map = array();
221 if(!empty($updates)){
222 foreach($updates as $update){
223 $update = PackageManager::fromNameValueList($update);
224 $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
225 $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
229 $filter = array(array('name' => 'type', 'value' => "'patch'"));
230 $releases = $pm->getReleases('', '', $filter);
231 if(!empty($releases['packages'])){
232 foreach($releases['packages'] as $update){
233 $update = PackageManager::fromNameValueList($update);
234 $nodes[] = array('label' => $update['name'], 'description' => $update['description'], 'version' => $update['version'], 'build_number' => $update['build_number'], 'id' => $update['id'], 'type' => $update['type']);
235 $release_map[$update['id']] = array('package_id' => $update['package_id'], 'category_id' => $update['category_id'], 'type' => $update['type']);
238 $_SESSION['ML_PATCHES'] = $release_map;
239 echo 'result = ' . $json->encode(array('updates' => $nodes));
242 function getLicenseText(){
243 $json = getJSONobj();
245 if(isset($_REQUEST['file'])) {
246 $file = hashToFile($_REQUEST['file']);
248 $GLOBALS['log']->debug("FILE : ".$file);
249 echo 'result = ' . $json->encode(array('license_display' => PackageManagerDisplay::buildLicenseOutput($file)));
253 * build the list of modules that are currently in the staging area waiting to be installed
255 function getPackagesInStaging(){
256 $packages = $this->_pm->getPackagesInStaging('module');
257 $json = getJSONobj();
259 echo 'result = ' . $json->encode(array('packages' => $packages));
263 * build the list of modules that are currently in the staging area waiting to be installed
265 function performInstall(){
267 if(isset($_REQUEST['file'])) {
268 $file = hashToFile($_REQUEST['file']);
271 $this->_pm->performInstall($file);
273 $json = getJSONobj();
275 echo 'result = ' . $json->encode(array('result' => 'success'));
278 function authenticate(){
279 $json = getJSONobj();
284 if(isset($_REQUEST['username'])) {
285 $username = nl2br($_REQUEST['username']);
287 if(isset($_REQUEST['password'])) {
288 $password = nl2br($_REQUEST['password']);
290 if(isset($_REQUEST['servername'])) {
291 $servername = $_REQUEST['servername'];
293 if(isset($_REQUEST['terms_checked'])) {
294 $terms_checked = $_REQUEST['terms_checked'];
295 if($terms_checked == 'on')
296 $terms_checked = true;
299 if(!empty($username) && !empty($password)){
300 $password = md5($password);
301 $result = PackageManager::authenticate($username, $password, $servername, $terms_checked);
302 if(!is_array($result) && $result == true)
305 $status = $result['faultstring'];
310 echo 'result = ' . $json->encode(array('status' => $status));
313 function getDocumentation(){
314 $json = getJSONobj();
318 if(isset($_REQUEST['package_id'])) {
319 $package_id = nl2br($_REQUEST['package_id']);
321 if(isset($_REQUEST['release_id'])) {
322 $release_id = nl2br($_REQUEST['release_id']);
325 $documents = PackageManager::getDocumentation($package_id, $release_id);
326 $GLOBALS['log']->debug("DOCUMENTS: ".var_export($documents, true));
327 echo 'result = ' . $json->encode(array('documents' => $documents));
330 function downloadedDocumentation(){
331 $json = getJSONobj();
334 if(isset($_REQUEST['document_id'])) {
335 $document_id = nl2br($_REQUEST['document_id']);
337 $GLOBALS['log']->debug("Downloading Document: ".$document_id);
338 PackageManagerComm::downloadedDocumentation($document_id);
339 echo 'result = ' . $json->encode(array('result' => 'true'));
343 * Remove metadata files such as foo-manifest
344 * Enter description here ...
345 * @param unknown_type $file
346 * @param unknown_type $meta
348 protected function rmMetaFile($file, $meta)
350 $metafile = pathinfo($file, PATHINFO_DIRNAME)."/". pathinfo($file, PATHINFO_FILENAME)."-$meta.php";
351 if(file_exists($metafile)) {
357 $json = getJSONobj();
360 if(isset($_REQUEST['file'])) {
361 $file = urldecode(hashToFile($_REQUEST['file']));
363 $GLOBALS['log']->debug("FILE TO REMOVE: ".$file);
366 foreach(array("manifest", "icon") as $meta) {
367 $this->rmMetaFile($file, $meta);
370 echo 'result = ' . $json->encode(array('result' => 'true'));