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.
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');
48 * This class is used to merge list view meta data. It subclasses EditView merge and transforms listview meta data into EditView meta data for the merge and then transforms it back into list view meta data
51 class ListViewMerge extends EditViewMerge{
52 protected $varName = 'listViewDefs';
53 protected $viewDefs = 'ListView';
56 * 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 * @param STRING $module - name of the module's files that are to be merged
59 * @param STRING $original_file - path to the file that originally shipped with sugar
60 * @param STRING $new_file - path to the new file that is shipping with the patch
61 * @param STRING $custom_file - path to the custom file
63 protected function loadData($module, $original_file, $new_file, $custom_file){
64 parent::loadData($module, $original_file, $new_file, $custom_file);
65 $this->originalData = array($module=>array( $this->viewDefs=>array($this->panelName=>array('DEFAULT'=>$this->originalData[$module]))));
66 $this->customData = array($module=>array( $this->viewDefs=>array($this->panelName=>array('DEFAULT'=>$this->customData[$module]))));
67 $this->newData = array($module=>array( $this->viewDefs=>array($this->panelName=>array('DEFAULT'=>$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 ListViews don't have the concept of rows and columns it takes the panel and the row to be the field name
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
77 protected function getFields(&$panels, $multiple = true){
80 if(!$multiple)$panels = array($panels);
82 foreach($panels as $panel_id=>$panel){
84 foreach($panel as $col_id=>$col){
85 $field_name = $col_id;
86 $fields[$field_name. $panel_id] = array('data'=>$col, 'loc'=>array('row'=>$col_id, 'panel'=>$col_id));
96 * This builds the array of fields from the merged fields in the appropriate order
97 * when building the panels for a list view the most important thing is order
98 * so we ensure the fields that came from the custom file keep
99 * their order then we add any new fields at the end
103 protected function buildPanels() {
105 //first only deal with ones that have their location coming from the custom source
106 foreach($this->mergedFields as $id =>$field){
107 if($field['loc']['source'] == 'custom'){
108 $panels[$field['loc']['panel']] = $field['data'];
109 unset($this->mergedFields[$id]);
112 //now deal with the rest
113 foreach($this->mergedFields as $id =>$field){
114 //Set the default attribute to false for all the rest of these fields since they're not from custom source
115 $field['data']['default'] = false;
116 $panels[$field['loc']['panel']] = $field['data'];
122 * Since all the meta-data is just a list of fields the panel section should be all the meta data
125 protected function setPanels(){
126 $this->newData = $this->buildPanels();
130 * This will save the merged data to a file
132 * @param STRING $to - path of the file to save it to
133 * @return BOOLEAN - success or failure of the save
135 public function save($to){
136 return write_array_to_file("$this->varName['$this->module']", $this->newData, $to);
141 * Merges the fields together and stores them in $this->mergedFields
144 protected function mergeFields() {
145 foreach($this->customFields as $field=>$data){
146 //if we have this field in both the new fields and the original fields - it has existed since the last install/upgrade
147 if(isset($this->newFields[$field]) && isset($this->originalFields[$field])){
148 //if both the custom field and the original match then we take the location of the custom field since it hasn't moved
149 $loc = $this->customFields[$field]['loc'];
150 $loc['source'] = 'custom';
152 //echo var_export($loc, true);
153 //but we still merge the meta data of the three
154 $this->mergedFields[$field] = array(
155 'data'=>$this->mergeField($this->originalFields[$field]['data'], $this->newFields[$field]['data'], $this->customFields[$field]['data']),
159 //if it's not set in the new fields then it was a custom field or an original field so we take the custom fields data and set the location source to custom
160 } else if(!isset($this->newFields[$field])){
161 $this->mergedFields[$field] = $data;
162 $this->mergedFields[$field]['loc']['source'] = 'custom';
164 //otherwise the field is in both new and custom but not in the orignal so we merge the new and custom data together and take the location from the custom
165 $this->mergedFields[$field] = array(
166 'data'=>$this->mergeField('', $this->newFields[$field]['data'], $this->customFields[$field]['data']),
167 'loc'=>$this->customFields[$field]['loc']);
169 $this->mergedFields[$field]['loc']['source'] = 'custom';
170 //echo var_export($this->mergedFields[$field], true);
173 //then we clear out the field from
174 unset($this->originalFields[$field]);
175 unset($this->customFields[$field]);
176 unset($this->newFields[$field]);
181 * These are fields that were removed by the customer
183 foreach($this->originalFields as $field=>$data){
184 unset($this->originalFields[$field]);
185 unset($this->newFields[$field]);
188 foreach($this->newFields as $field=>$data){
189 $data['loc']['source']= 'new';
190 $this->mergedFields[$field] = array(
191 'data'=>$data['data'],
192 'loc'=>$data['loc']);
193 unset($this->newFields[$field]);
199 * Merges the meta data of a single field
201 * @param ARRAY $orig - the original meta-data for this field
202 * @param ARRAY $new - the new meta-data for this field
203 * @param ARRAY $custom - the custom meta-data for this field
204 * @return ARRAY $merged - the merged meta-data
206 protected function mergeField($orig, $new, $custom){
207 $orig_custom = $this->areMatchingValues($orig, $custom);
208 $new_custom = $this->areMatchingValues($new, $custom);
209 // if both are true then there is nothing to merge since all three fields match
210 if(!($orig_custom && $new_custom)){
211 $this->log('merging field');
212 $this->log('original meta-data');
214 $this->log('new meta-data');
216 $this->log('custom meta-data');
218 $this->log('merged meta-data');
223 //if orignal and custom match always take the new value or if new and custom match
224 if($orig_custom || $new_custom){
226 $new['default'] = isset($custom['default']) ? $custom['default'] : false;
229 //if original and new match always take the custom
230 if($this->areMatchingValues($orig, $new)){
235 if(is_array($custom)) {
236 //if both new and custom are arrays then at this point new != custom and orig != custom and orig != new so let's merge the custom and the new and return that
238 $new = $this->arrayMerge($custom, $new);
240 $new['default'] = $custom['default'];
243 //otherwise we know that new is not an array and custom has been 'customized' so let's keep those customizations.
249 //default to returning the New version of the field
250 $new['default'] = isset($custom['default']) ? $custom['default'] : false;