]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - modules/UpgradeWizard/SugarMerge/SearchMerge.php
Release 6.5.0
[Github/sugarcrm.git] / modules / UpgradeWizard / SugarMerge / SearchMerge.php
1 <?php
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-2012 SugarCRM Inc.
6  * 
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.
13  * 
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
17  * details.
18  * 
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
22  * 02110-1301 USA.
23  * 
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.
26  * 
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.
30  * 
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  ********************************************************************************/
37
38 /*********************************************************************************
39
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  ********************************************************************************/
45
46 require_once('modules/UpgradeWizard/SugarMerge/ListViewMerge.php');
47 /**
48  * SearchMerge is a class for merging search meta data together. This search meta-data has a listing of fields similar to ListViews
49  *
50  */
51 class SearchMerge extends ListViewMerge{
52         protected $varName = 'searchdefs';
53         protected $viewDefs = 'Search';
54         protected $panelName = 'layout';
55         
56         /**
57          * Loads the meta data of the original, new, and custom file into the variables originalData, newData, and customData respectively it then transforms them into a structure that EditView Merge would understand
58          *
59          * @param STRING $module - name of the module's files that are to be merged
60          * @param STRING $original_file - path to the file that originally shipped with sugar
61          * @param STRING $new_file - path to the new file that is shipping with the patch 
62          * @param STRING $custom_file - path to the custom file
63          */
64         protected function loadData($module, $original_file, $new_file, $custom_file){
65                 EditViewMerge::loadData($module, $original_file, $new_file, $custom_file);
66                 $this->originalData = array($module=>array( $this->viewDefs=>$this->originalData[$module]));
67                 $this->customData = array($module=>array( $this->viewDefs=>$this->customData[$module]));
68                 $this->newData = array($module=>array( $this->viewDefs=>$this->newData[$module]));
69         
70         }
71         /**
72          * This takes in a  list of panels and returns an associative array of field names to the meta-data of the field as well as the locations of that field
73          * Since searchdefs have the concept of basic and advanced those act as panels for merging
74          * @param ARRAY $panels - this is the 'panel' section of the meta-data for list views all the meta data is one panel since it is just a list of fields
75          * @return ARRAY $fields - an associate array of fields and their meta-data as well as their location
76          */
77         
78         protected function getFields(&$panels, $multiple = true){
79                 $fields = array();
80                 if(!$multiple)$panels = array($panels);
81                 
82                 foreach($panels as $panel_id=>$panel){
83                                 foreach($panel as $col_id=>$col){
84                                         if(is_array($col)){
85                                                 $field_name = $col['name'];
86                                         }else{
87                                                 $field_name = $col;
88                                         }
89                                         $fields[$field_name . $panel_id] = array('data'=>$col, 'loc'=>array('row'=>$col_id, 'panel'=>$panel_id));
90                                 }
91                         }
92                         
93                         return $fields;
94                 }
95         
96         /**
97          * This builds the array of fields from the merged fields in the right order
98          * when building the panels for a list view the most important thing is order 
99          * so we ensure the fields that came from the custom file keep 
100          * their order then we add any new fields at the end
101          *
102          * @return ARRAY
103          */
104         protected function buildPanels(){
105                 $panels  = array();
106                 
107                 //first only deal with ones that have their location coming from the custom source
108                 foreach($this->mergedFields as $id =>$field){
109                         if($field['loc']['source'] == 'custom'){
110                                 $panels[$field['loc']['panel']][] = $field['data'];
111                                 unset($this->mergedFields[$id]);
112                         }
113                 }
114
115                 return $panels;
116         }
117         
118         /**
119          * Sets the panel section for the meta-data after it has been merged
120          *
121          */
122         protected function setPanels(){
123                 $this->newData[$this->module][$this->viewDefs][$this->panelName] = $this->buildPanels();
124                 $this->newData[$this->module] = $this->newData[$this->module][$this->viewDefs];
125                 
126         }
127         public function save($to){
128                 return write_array_to_file("$this->varName['$this->module']", $this->newData[$this->module], $to);
129         }
130         
131         /**
132          * public function that will merge meta data from an original sugar file that shipped with the product, a customized file, and a new file shipped with an upgrade
133          *
134          * @param STRING $module - name of the module's files that are to be merged
135          * @param STRING $original_file - path to the file that originally shipped with sugar
136          * @param STRING $new_file - path to the new file that is shipping with the patch 
137          * @param STRING $custom_file - path to the custom file
138          * @param BOOLEAN $save - boolean on if it should save the results to the custom file or not
139          * @return BOOLEAN - if the merged file was saved if false is passed in for the save parameter it always returns true
140          */
141         public function merge($module, $original_file, $new_file, $custom_file=false, $save=true){
142                 //Bug 37207
143                 if($module == 'Connectors') {
144                    return false;
145                 }                       
146                 
147                 $this->clear();
148                 $this->log("\n\n". 'Starting a merge in ' . get_class($this));
149                 $this->log('merging the following files');
150                 $this->log('original file:'  . $original_file);
151                 $this->log('new file:'  . $new_file);
152                 $this->log('custom file:'  . $custom_file);     
153                 if(empty($custom_file) && $save){
154                         return true;
155                 }else{                  
156                         $this->loadData($module, $original_file, $new_file, $custom_file);
157                                                 
158                         if(!isset($this->originalData[$module])) {
159                            return false;
160                         }
161                         
162                         $this->mergeMetaData();
163                         if($save && !empty($this->newData) && !empty($custom_file)){
164                                 //backup the file
165                                 copy($custom_file, $custom_file . '.suback.php');
166                                 return $this->save($custom_file);
167                         }
168                 }
169                 if(!$save)return true;
170                 return false;
171         }       
172         
173         protected function mergeTemplateMeta()
174         {
175             if( isset($this->customData[$this->module][$this->viewDefs][$this->templateMetaName]) )
176             {
177                $this->newData[$this->module][$this->viewDefs][$this->templateMetaName] = $this->customData[$this->module][$this->viewDefs][$this->templateMetaName];
178             }
179             
180             if(!isset($this->newData[$this->module][$this->viewDefs][$this->templateMetaName]['maxColumnsBasic']) && isset($this->newData[$this->module][$this->viewDefs][$this->templateMetaName]['maxColumns']))
181             {
182                 $this->newData[$this->module][$this->viewDefs][$this->templateMetaName]['maxColumnsBasic'] = $this->newData[$this->module][$this->viewDefs][$this->templateMetaName]['maxColumns'];
183             }
184         }       
185         
186 }
187 ?>