2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM Community Edition is a customer relationship management program developed by
5 * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
7 * This program is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Affero General Public License version 3 as published by the
9 * Free Software Foundation with the addition of the following permission added
10 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
11 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
12 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
19 * You should have received a copy of the GNU Affero General Public License along with
20 * this program; if not, see http://www.gnu.org/licenses or write to the Free
21 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
25 * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
27 * The interactive user interfaces in modified source and object code versions
28 * of this program must display Appropriate Legal Notices, as required under
29 * Section 5 of the GNU Affero General Public License version 3.
31 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
32 * these Appropriate Legal Notices must retain the display of the "Powered by
33 * SugarCRM" logo. If the display of the logo is not reasonably feasible for
34 * technical reasons, the Appropriate Legal Notices must display the words
35 * "Powered by SugarCRM".
36 ********************************************************************************/
38 /*********************************************************************************
40 * Description: Defines the English language pack for the base application.
41 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
42 * All Rights Reserved.
43 * Contributor(s): ______________________________________..
44 ********************************************************************************/
46 require_once('modules/UpgradeWizard/SugarMerge/EditViewMerge.php');
47 require_once('modules/UpgradeWizard/SugarMerge/DetailViewMerge.php');
48 require_once('modules/UpgradeWizard/SugarMerge/SearchMerge.php');
49 require_once('modules/UpgradeWizard/SugarMerge/ListViewMerge.php');
50 require_once('modules/UpgradeWizard/SugarMerge/QuickCreateMerge.php');
51 require_once('modules/ModuleBuilder/parsers/views/History.php');
54 * SugarMerge wraps around all the merge functionality of Sugar given a module name and the path to an unzipped patch
58 private $mergeMapping = array();
59 private $new_path = '';
60 private $custom_path = 'custom';
61 private $original_path = '';
62 private $merged = array();
65 function SugarMerge($new_path='', $original_path='', $custom_path='custom') {
67 $this->new_path = empty($new_path) || preg_match('/[\/]$/', $new_path) ? $new_path : $new_path . '/';
68 $this->original_path = empty($original_path) || preg_match('/[\/]$/', $original_path) ? $original_path : $original_path . '/';
69 $this->custom_path = empty($custom_path) || preg_match('/[\/]$/', $custom_path) ? $custom_path : $custom_path . '/';
71 $this->mergeMapping = array(
72 'editviewdefs.php'=> new EditViewMerge(),
73 'detailviewdefs.php'=>new DetailViewMerge(),
74 'listviewdefs.php'=>new ListViewMerge(),
75 'searchdefs.php'=>new SearchMerge(),
76 'quickcreatedefs.php'=>new QuickCreateMerge(),
80 function setLogFilePointer($fp){
87 * This will run through all the modules that may need merging and determine if there is anything to merge
88 * if $merge is set to true it will perform the merge
89 * if $merge and $save are set to true it will perform the merge and save the results in the custom directory
91 * @param BOOLEAN|ARRAY $merge - do we wish to perform the merge if false it will just return a list of files that can be merged. If an array is passed, only those modules present in the array will be merged.
92 * @param BOOLEAN $save - do we wish to save the merged files to true - $merge must be true for this to apply - otherwise it will simulate merging so you can view the log files of the merge
93 * @param BOOLEAN $logHistory - do we wish to create history entries for any of the merges
94 * @return ARRAY - an associative array of module names to files that were either merged or have the potential to be merged depeneding if $merge and $save are set to true
96 function mergeAll($merge=true, $save=true, $logHistory=true){
97 $this->merged = array();
98 $searchDirectory = $this->custom_path;
99 if(!preg_match('/[\/]modules$/si', $searchDirectory)) {
100 $searchDirectory .= preg_match('/[\/]$/', $this->custom_path) ? 'modules' : '/modules';
103 if(file_exists($searchDirectory)){
104 $dir = dir($searchDirectory);
105 while($e = $dir->read()){
106 if(substr($e , 0, 1) != '.') {
107 if(is_dir("{$searchDirectory}/{$e}/metadata")){
108 if( is_array($merge) )
110 if ( in_array($e,$merge) )
111 $this->merged[$e] = $this->mergeModule($e, TRUE, $save,$logHistory );
114 $GLOBALS['log']->debug("SugarMerge is skipping $e module as filter array passed in but module not specified for merge.");
119 $this->merged[$e] = $this->mergeModule($e, $merge, $save,$logHistory );
124 return $this->merged;
131 * This will merge any files that need merging for a given module
132 * if $merge is set to true it will perform the merge
133 * if $merge and $save are set to true it will perform the merge and save the results in the custom directory
135 * @param STRING $module - the name of the module to merge files for
136 * @param BOOLEAN $merge - do we wish to perform the merge if false it will just return a list of files that can be merged
137 * @param BOOLEAN $save - do we wish to save the merged files to true - $merge must be true for this to apply - otherwise it will simulate merging so you can view the log files of the merge
138 * @param BOOLEAN $logHistory - do we wish to create history entries for any of the merges
139 * @return ARRAY - an associative array of files that were either merged or have the potential to be merged depeneding if $merge and $save are set to true
141 function mergeModule($module, $merge = true, $save=true,$logHistory=true){
143 $path = $this->original_path . 'modules/' . $module . '/metadata/';
144 $custom_path = $this->custom_path . 'modules/' . $module . '/metadata/';
145 $new_path = $this->new_path . 'modules/' . $module . '/metadata/';
146 foreach($this->mergeMapping as $file=>&$object){
147 if(file_exists("{$custom_path}{$file}") && file_exists("{$new_path}{$file}")){
149 $merged[$file] = $this->mergeFile($module, $file, $save, $logHistory);
151 $merged[$file] = true;
161 * This function will merge a single file for a module
163 * @param STRING $module - name of the module
164 * @param STRING $file - name of the file
165 * @param STRING $save - should the merged file be saved to the custom directory
166 * @return BOOLEAN - success or failure of the merge
168 function mergeFile($module, $file, $save=true,$logHistory=true){
169 $path = $this->original_path . 'modules/' . $module . '/metadata/';
170 $custom_path = $this->custom_path . 'modules/' . $module . '/metadata/';
171 $new_path = $this->new_path . 'modules/' . $module . '/metadata/';
172 if($this->fp) $this->mergeMapping[$file]->setLogFilePointer($this->fp);
173 if(isset($this->mergeMapping[$file]) && file_exists("{$path}{$file}") && file_exists("{$custom_path}{$file}") && file_exists("{$new_path}{$file}")){
174 //Create a log entry of the custom file before it is merged
175 if($logHistory && $save)
176 $this->createHistoryLog($module, "{$custom_path}{$file}",$file);
177 return $this->mergeMapping[$file]->merge($module, "{$path}{$file}", "{$new_path}{$file}", "{$custom_path}{$file}", $save);
184 * Create a history copy of the custom file that will be merged so that it can be access through
185 * studio if admins wish to revert at a later date.
187 * @param STRING $module - name of the module
188 * @param STRING $file - name of the file
189 * @param STRING $customFile - Path to the custom file that will be merged
191 protected function createHistoryLog($module,$customFile,$file)
193 $historyPath = 'custom/' . MB_HISTORYMETADATALOCATION . "/modules/$module/metadata/$file";
194 $history = new History($historyPath);
195 $timeStamp = $history->append($customFile);
196 $GLOBALS['log']->debug("Created history file after merge with new file: " . $historyPath .'_'.$timeStamp);
200 * Return the custom modules path
202 * @return STRING directory where custom module files are located
204 function getCustomPath() {
205 return $this->custom_path;
210 * Return the new upgrade modules path
212 * @return STRING directory where new module files are located
214 function getNewPath() {
215 return $this->new_path;
220 * Return the original modules path
222 * @return STRING directory where new module files are located
224 function getOriginalPath() {
225 return $this->original_path;