]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/layouts.php
Release 6.5.0
[Github/sugarcrm.git] / modules / UpgradeWizard / layouts.php
1 <?php
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.
7  * 
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.
14  * 
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
18  * details.
19  * 
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
23  * 02110-1301 USA.
24  * 
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.
27  * 
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.
31  * 
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  ********************************************************************************/
38
39 /*********************************************************************************
40
41  * Description:
42  * Portions created by SugarCRM are Copyright(C) SugarCRM, Inc. All Rights
43  * Reserved. Contributor(s): ______________________________________..
44  * *******************************************************************************/
45
46
47 logThis('Upgrade Wizard At Layout Commits');
48
49 global $mod_strings;
50 $curr_lang = 'en_us';
51 if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null))
52         $curr_lang = $GLOBALS['current_language'];
53
54 return_module_language($curr_lang, 'UpgradeWizard');
55 error_reporting(E_ERROR);
56 set_time_limit(0);
57 set_upgrade_progress('layouts','in_progress');
58
59 //If the user has seleceted which modules they want to merge, perform the filtering and 
60 //execute the merge.
61 if( isset($_POST['layoutSelectedModules']) )
62 {
63     logThis('Layout Commits examining modules to revert');
64     
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();
70     
71     foreach ( $mergedModules as $moduleKey => $layouts)
72     {
73         if( ! in_array($moduleKey , $selectedModules) )
74         {
75             logThis("Adding $moduleKey module to rollback list.");
76             $rollBackList[$moduleKey] = $layouts;
77         }
78         else 
79         {
80             $actualMergedList[$moduleKey] = $layouts;
81         }
82     }
83     
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));
86     
87     $layoutMergeData = $actualMergedList;
88     
89     rollBackMergedModules($rollBackList);
90     
91     $stepBack = $_REQUEST['step'] - 1;
92     $stepNext = $_REQUEST['step'] + 1;
93     $stepCancel = -1;
94     $stepRecheck = $_REQUEST['step'];
95     $_SESSION['step'][$steps['files'][$_REQUEST['step']]] = 'success';
96     
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>";
102 }
103 else 
104 {
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>";
113 }
114
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');
122     
123 $showBack = FALSE;
124 $showCancel = FALSE;
125 $showRecheck = FALSE;
126 $showNext = TRUE;
127
128 set_upgrade_progress('layouts','done');
129
130 /**
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.
133  *
134  * @param array $data
135  * @return array
136  */
137 function cleanMergeData($data)
138 {
139     $results = array();
140     foreach ($data as $m => $layouts)
141     {
142         if(count($layouts) > 0)
143         {
144             $results[$m] = $layouts;
145         }
146     }
147     
148     return $results;
149 }
150 /**
151  * Rollback metadata files for each module provided in the list.
152  *
153  * @param array $data
154  */
155 function rollBackMergedModules($data)
156 {
157     logThis('Layout Commits, starting rollback');
158     $backupFileSufix = '.suback.php';
159     foreach ($data as $moduleName => $layouts)
160     {
161         logThis('Layout Commits, iterating over module:' . $moduleName);
162         foreach ($layouts as $fileName => $wasMerged)
163         {
164             if($wasMerged)
165             {
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) )
171                 {
172                     if( file_exists($srcFile) )
173                     {
174                         logThis('Layout Commits, rollBackMergedModules is removing file: ' . $srcFile);
175                         @unlink($srcFile);
176                     }
177                     $copyResult = @copy($srcBackupFile, $srcFile);
178                     if($copyResult === TRUE)
179                     {
180                         @unlink($srcBackupFile);
181                         logThis("Layout Commits, rollBackMergedModules successfully reverted file $srcFile");
182                     }
183                     else 
184                     {
185                         logThis("Layout Commits, rollBackMergedModules was unable to copy file: $srcBackupFile, to $srcFile.");
186                     }
187                 }
188                 else 
189                 {
190                     logThis("Layout Commits, rollBackMergedModules is unable to find backup file $srcBackupFile , nothing to do.");
191                 }
192             }
193         }
194     }
195 }
196
197 /**
198  * Format results from SugarMerge output to be used in the selection table.
199  *
200  * @param array $layoutMergeData
201  * @return array
202  */
203 function formatLayoutMergeDataForDisplay($layoutMergeData)
204 {
205     global $mod_strings,$app_list_strings;
206     
207     $curr_lang = 'en_us';
208     if(isset($GLOBALS['current_language']) && ($GLOBALS['current_language'] != null))
209         $curr_lang = $GLOBALS['current_language'];
210
211     $module_builder_language = return_module_language($curr_lang, 'ModuleBuilder');
212
213     $results = array();
214     foreach ($layoutMergeData as $k => $v)
215     {
216         $layouts = array();
217         foreach ($v as $layoutPath => $isMerge)
218         {
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'];
229             else 
230                 continue;
231
232             $layouts[] = array('path' => $layoutPath, 'label' => $label);
233         }
234
235         $results[$k]['layouts'] = $layouts; 
236         $results[$k]['moduleName'] = $app_list_strings['moduleList'][$k]; 
237     }
238
239     return $results;
240 }