2 if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3 /*********************************************************************************
4 * SugarCRM 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/ListViewMerge.php');
48 * SearchMerge is a class for merging search meta data together. This search meta-data has a listing of fields similar to ListViews
51 class SearchMerge extends ListViewMerge{
52 protected $varName = 'searchdefs';
53 protected $viewDefs = 'Search';
54 protected $panelName = 'layout';
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
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
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]));
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
78 protected function getFields(&$panels, $multiple = true){
80 if(!$multiple)$panels = array($panels);
82 foreach($panels as $panel_id=>$panel){
83 foreach($panel as $col_id=>$col){
85 $field_name = $col['name'];
89 $fields[$field_name . $panel_id] = array('data'=>$col, 'loc'=>array('row'=>$col_id, 'panel'=>$panel_id));
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
104 protected function buildPanels(){
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]);
114 //now deal with the rest
116 foreach($this->mergedFields as $id =>$field){
117 $field['data']['default'] = false;
118 $panels[$field['loc']['panel']][] = $field['data'];
125 * Sets the panel section for the meta-data after it has been merged
128 protected function setPanels(){
129 $this->newData[$this->module][$this->viewDefs][$this->panelName] = $this->buildPanels();
130 $this->newData[$this->module] = $this->newData[$this->module][$this->viewDefs];
133 public function save($to){
134 return write_array_to_file("$this->varName['$this->module']", $this->newData[$this->module], $to);
138 * 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
140 * @param STRING $module - name of the module's files that are to be merged
141 * @param STRING $original_file - path to the file that originally shipped with sugar
142 * @param STRING $new_file - path to the new file that is shipping with the patch
143 * @param STRING $custom_file - path to the custom file
144 * @param BOOLEAN $save - boolean on if it should save the results to the custom file or not
145 * @return BOOLEAN - if the merged file was saved if false is passed in for the save parameter it always returns true
147 public function merge($module, $original_file, $new_file, $custom_file=false, $save=true){
149 if($module == 'Connectors') {
154 $this->log("\n\n". 'Starting a merge in ' . get_class($this));
155 $this->log('merging the following files');
156 $this->log('original file:' . $original_file);
157 $this->log('new file:' . $new_file);
158 $this->log('custom file:' . $custom_file);
159 if(empty($custom_file) && $save){
162 $this->loadData($module, $original_file, $new_file, $custom_file);
164 if(!isset($this->originalData[$module])) {
168 $this->mergeMetaData();
169 if($save && !empty($this->newData) && !empty($custom_file)){
171 copy($custom_file, $custom_file . '.suback.php');
172 return $this->save($custom_file);
175 if(!$save)return true;