2 if(!defined('sugarEntry') || !sugarEntry)
3 die('Not A Valid Entry Point');
4 /*********************************************************************************
5 * SugarCRM Community Edition is a customer relationship management program developed by
6 * SugarCRM, Inc. Copyright (C) 2004-2012 SugarCRM Inc.
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU Affero General Public License version 3 as published by the
10 * Free Software Foundation with the addition of the following permission added
11 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
12 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
13 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15 * This program is distributed in the hope that it will be useful, but WITHOUT
16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
20 * You should have received a copy of the GNU Affero General Public License along with
21 * this program; if not, see http://www.gnu.org/licenses or write to the Free
22 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
26 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
28 * The interactive user interfaces in modified source and object code versions
29 * of this program must display Appropriate Legal Notices, as required under
30 * Section 5 of the GNU Affero General Public License version 3.
32 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
33 * these Appropriate Legal Notices must retain the display of the "Powered by
34 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
35 * technical reasons, the Appropriate Legal Notices must display the words
36 * "Powered by SugarCRM".
37 ********************************************************************************/
39 /*********************************************************************************
42 * Portions created by SugarCRM are Copyright(C) SugarCRM, Inc. All Rights
43 * Reserved. Contributor(s): ______________________________________..
44 * *******************************************************************************/
47 logThis('Upgrade Wizard At Layout Commits');
51 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null))
52 $curr_lang = $GLOBALS['current_language'];
54 return_module_language($curr_lang, 'UpgradeWizard');
55 error_reporting(E_ERROR);
57 set_upgrade_progress('layouts','in_progress');
59 //If the user has seleceted which modules they want to merge, perform the filtering and
61 if( isset($_POST['layoutSelectedModules']) )
63 logThis('Layout Commits examining modules to revert');
65 $mergedModules = $_SESSION['sugarMergeRunResults'];
66 $selectedModules = explode("^,^",$_POST['layoutSelectedModules']);
67 logThis('Layout Commits, selected modules by user: ' . print_r($selectedModules, TRUE));
68 $rollBackList = array();
69 $actualMergedList = array();
71 foreach ( $mergedModules as $moduleKey => $layouts)
73 if( ! in_array($moduleKey , $selectedModules) )
75 logThis("Adding $moduleKey module to rollback list.");
76 $rollBackList[$moduleKey] = $layouts;
80 $actualMergedList[$moduleKey] = $layouts;
84 logThis('Layout Commits will rollback the following modules: ' . print_r($rollBackList, TRUE));
85 logThis('Layout Commits merged the following modules: ' . print_r($actualMergedList, TRUE));
87 $layoutMergeData = $actualMergedList;
89 rollBackMergedModules($rollBackList);
91 $stepBack = $_REQUEST['step'] - 1;
92 $stepNext = $_REQUEST['step'] + 1;
94 $stepRecheck = $_REQUEST['step'];
95 $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = 'success';
97 logThis('Layout Commits completed successfully');
98 $smarty->assign("CONFIRM_LAYOUT_HEADER", $mod_strings['LBL_UW_CONFIRM_LAYOUT_RESULTS']);
99 $smarty->assign("CONFIRM_LAYOUT_DESC", $mod_strings['LBL_UW_CONFIRM_LAYOUT_RESULTS_DESC']);
100 $showCheckBoxes = FALSE;
101 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_LAYOUT_MERGE_TITLE2']}</b>";
105 //Fist visit to the commit layout page. Display the selection table to the user.
106 logThis('Layout Commits about to show selection table');
107 $smarty->assign("CONFIRM_LAYOUT_HEADER", $mod_strings['LBL_UW_CONFIRM_LAYOUTS']);
108 $smarty->assign("CONFIRM_LAYOUT_DESC", $mod_strings['LBL_LAYOUT_MERGE_DESC']);
109 $layoutMergeData = cleanMergeData($_SESSION['sugarMergeRunResults']);
110 $stepNext = $_REQUEST['step'];
111 $showCheckBoxes = TRUE;
112 $GLOBALS['top_message'] = "<b>{$mod_strings['LBL_LAYOUT_MERGE_TITLE']}</b>";
115 $smarty->assign("APP", $app_strings);
116 $smarty->assign("APP_LIST", $app_list_strings);
117 $smarty->assign("MOD", $mod_strings);
118 $smarty->assign("showCheckboxes", $showCheckBoxes);
119 $layoutMergeData = formatLayoutMergeDataForDisplay($layoutMergeData);
120 $smarty->assign("METADATA_DATA", $layoutMergeData);
121 $uwMain = $smarty->fetch('modules/UpgradeWizard/tpls/layoutsMerge.tpl');
125 $showRecheck = FALSE;
128 set_upgrade_progress('layouts','done');
131 * Clean the merge data results, removing any emptys or blanks that should not be displayed
132 * to the user on the confirm layout screen.
137 function cleanMergeData($data)
140 foreach ($data as $m => $layouts)
142 if(count($layouts) > 0)
144 $results[$m] = $layouts;
151 * Rollback metadata files for each module provided in the list.
155 function rollBackMergedModules($data)
157 logThis('Layout Commits, starting rollback');
158 $backupFileSufix = '.suback.php';
159 foreach ($data as $moduleName => $layouts)
161 logThis('Layout Commits, iterating over module:' . $moduleName);
162 foreach ($layouts as $fileName => $wasMerged)
166 $srcFile = 'custom' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR . 'metadata'. DIRECTORY_SEPARATOR . $fileName;
167 $srcBackupFile = $srcFile . $backupFileSufix;
168 logThis('Layout Commits, rollBackMergedModules source file: ' . $srcDirectory);
169 logThis('Layout Commits, rollBackMergedModules backup file: ' . $srcBackupFile);
170 if( file_exists($srcBackupFile) )
172 if( file_exists($srcFile) )
174 logThis('Layout Commits, rollBackMergedModules is removing file: ' . $srcFile);
177 $copyResult = @copy($srcBackupFile, $srcFile);
178 if($copyResult === TRUE)
180 @unlink($srcBackupFile);
181 logThis("Layout Commits, rollBackMergedModules successfully reverted file $srcFile");
185 logThis("Layout Commits, rollBackMergedModules was unable to copy file: $srcBackupFile, to $srcFile.");
190 logThis("Layout Commits, rollBackMergedModules is unable to find backup file $srcBackupFile , nothing to do.");
198 * Format results from SugarMerge output to be used in the selection table.
200 * @param array $layoutMergeData
203 function formatLayoutMergeDataForDisplay($layoutMergeData)
205 global $mod_strings,$app_list_strings;
207 $curr_lang = 'en_us';
208 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null))
209 $curr_lang = $GLOBALS['current_language'];
211 $module_builder_language = return_module_language($curr_lang, 'ModuleBuilder');
214 foreach ($layoutMergeData as $k => $v)
217 foreach ($v as $layoutPath => $isMerge)
219 if( preg_match('/listviewdefs.php/i', $layoutPath) )
220 $label = $module_builder_language['LBL_LISTVIEW'];
221 else if( preg_match('/detailviewdefs.php/i', $layoutPath) )
222 $label = $module_builder_language['LBL_DETAILVIEW'];
223 else if( preg_match('/editviewdefs.php/i', $layoutPath) )
224 $label = $module_builder_language['LBL_EDITVIEW'];
225 else if( preg_match('/quickcreatedefs.php/i', $layoutPath) )
226 $label = $module_builder_language['LBL_QUICKCREATE'];
227 else if( preg_match('/searchdefs.php/i', $layoutPath) )
228 $label = $module_builder_language['LBL_SEARCH'];
232 $layouts[] = array('path' => $layoutPath, 'label' => $label);
235 $results[$k]['layouts'] = $layouts;
236 $results[$k]['moduleName'] = $app_list_strings['moduleList'][$k];