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-2013 SugarCRM Inc. |
6
|
|
|
|
7
|
|
|
* SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd. |
8
|
|
|
* Copyright (C) 2011 - 2014 Salesagility Ltd. |
9
|
|
|
* |
10
|
|
|
* This program is free software; you can redistribute it and/or modify it under |
11
|
|
|
* the terms of the GNU Affero General Public License version 3 as published by the |
12
|
|
|
* Free Software Foundation with the addition of the following permission added |
13
|
|
|
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK |
14
|
|
|
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY |
15
|
|
|
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. |
16
|
|
|
* |
17
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT |
18
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
19
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more |
20
|
|
|
* details. |
21
|
|
|
* |
22
|
|
|
* You should have received a copy of the GNU Affero General Public License along with |
23
|
|
|
* this program; if not, see http://www.gnu.org/licenses or write to the Free |
24
|
|
|
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
25
|
|
|
* 02110-1301 USA. |
26
|
|
|
* |
27
|
|
|
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road, |
28
|
|
|
* SW2-130, Cupertino, CA 95014, USA. or at email address [email protected]. |
29
|
|
|
* |
30
|
|
|
* The interactive user interfaces in modified source and object code versions |
31
|
|
|
* of this program must display Appropriate Legal Notices, as required under |
32
|
|
|
* Section 5 of the GNU Affero General Public License version 3. |
33
|
|
|
* |
34
|
|
|
* In accordance with Section 7(b) of the GNU Affero General Public License version 3, |
35
|
|
|
* these Appropriate Legal Notices must retain the display of the "Powered by |
36
|
|
|
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not |
37
|
|
|
* reasonably feasible for technical reasons, the Appropriate Legal Notices must |
38
|
|
|
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM". |
39
|
|
|
********************************************************************************/ |
40
|
|
|
|
41
|
|
|
class UpgradeSavedSearch { |
42
|
|
|
|
43
|
|
|
function __construct() { |
44
|
|
|
|
45
|
|
|
$result = $GLOBALS['db']->query("SELECT id FROM saved_search"); |
46
|
|
|
while($row = $GLOBALS['db']->fetchByAssoc($result)) { |
47
|
|
|
$focus = new SavedSearch(); |
48
|
|
|
$focus->retrieve($row['id']); |
49
|
|
|
$contents = unserialize(base64_decode($focus->contents)); |
50
|
|
|
$has_team_name_saved = isset($contents['team_name_advanced']) || isset($contents['team_name_basic']) ? true : false; |
51
|
|
|
//If $contents['searchFormTab'] is set then this is coming from a 4.x saved search |
52
|
|
|
if(isset($contents['searchFormTab']) && $contents['searchFormTab'] == 'saved_views') { |
53
|
|
|
$new_contents = array(); |
54
|
|
|
$module = $contents['search_module']; |
55
|
|
|
$advanced = !empty($contents['advanced']); |
56
|
|
|
$field_map = array(); |
57
|
|
|
|
58
|
|
|
if(file_exists("custom/modules/{$module}/metadata/searchdefs.php")) { |
59
|
|
|
require("custom/modules/{$module}/metadata/searchdefs.php"); |
60
|
|
|
$field_map = $advanced ? $searchdefs[$module]['layout']['advanced_search'] : $searchdefs[$module]['layout']['basic_search']; |
61
|
|
|
}else if(file_exists("modules/{$module}/metadata/SearchFields.php")) { |
62
|
|
|
require("modules/{$module}/metadata/SearchFields.php"); |
63
|
|
|
$field_map = $searchFields[$module]; |
64
|
|
|
} else { |
65
|
|
|
|
66
|
|
|
$bean = loadBean($module); |
|
|
|
|
67
|
|
|
$field_map = $bean->field_name_map; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
//Special case for team_id field (from 4.5.x) |
71
|
|
|
if(isset($contents['team_id'])) { |
72
|
|
|
$contents['team_name'] = $contents['team_id']; |
73
|
|
|
unset($contents['team_id']); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
foreach($contents as $key=>$value) { |
77
|
|
|
if(isset($field_map[$key])) { |
78
|
|
|
$new_key = $key . ($advanced ? '_advanced' : '_basic'); |
79
|
|
|
if(preg_match('/^team_name_(advanced|basic)$/', $new_key)) { |
80
|
|
|
|
81
|
|
|
if(!is_array($value)) { |
82
|
|
|
$temp_value = array(); |
83
|
|
|
$teap_value[] = $value; |
84
|
|
|
$value = $temp_value; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$team_results = $GLOBALS['db']->query("SELECT id, name FROM teams where id in ('" . implode("','", $value) . "')"); |
88
|
|
|
if(!empty($team_results)) { |
89
|
|
|
$count = 0; |
90
|
|
|
while($team_row = $GLOBALS['db']->fetchByAssoc($team_results)) { |
91
|
|
|
$team_key = $new_key . '_collection_' . $count; |
92
|
|
|
$new_contents[$team_key] = $team_row['name']; |
93
|
|
|
$new_contents['id_' . $team_key] = $team_row['id']; |
94
|
|
|
$count++; |
95
|
|
|
} //while |
96
|
|
|
} //if |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
//Unset the original key |
100
|
|
|
unset($new_contents[$key]); |
101
|
|
|
|
102
|
|
|
//Add the any switch |
103
|
|
|
$new_contents[$new_key . '_type'] = 'any'; |
104
|
|
|
} else { |
105
|
|
|
$new_contents[$new_key] = $value; |
106
|
|
|
} |
107
|
|
|
} else { |
108
|
|
|
$new_contents[$key] = $value; |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
$new_contents['searchFormTab'] = $advanced ? 'advanced_search' : 'basic_search'; |
112
|
|
|
$content = base64_encode(serialize($new_contents)); |
113
|
|
|
$GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); |
114
|
|
|
} else if($has_team_name_saved) { |
115
|
|
|
//Otherwise, if the boolean has_team_name_saved is set to true, we also need to parse (coming from 5.x) |
116
|
|
|
if(isset($contents['team_name_advanced'])) { |
117
|
|
|
$team_results = $GLOBALS['db']->query("SELECT name FROM teams where id = '{$contents['team_name_advanced']}'"); |
118
|
|
|
if(!empty($team_results)) { |
119
|
|
|
$team_row = $GLOBALS['db']->fetchByAssoc($team_results); |
120
|
|
|
$contents['team_name_advanced_collection_0'] = $team_row['name']; |
121
|
|
|
$contents['id_team_name_advanced_collection_0'] = $contents['team_name_advanced']; |
122
|
|
|
$contents['team_name_advanced_type'] = 'any'; |
123
|
|
|
unset($contents['team_name_advanced']); |
124
|
|
|
$content = base64_encode(serialize($contents)); |
125
|
|
|
$GLOBALS['db']->query("UPDATE saved_search SET contents = '{$content}' WHERE id = '{$row['id']}'"); |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
} //while |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead |
134
|
|
|
*/ |
135
|
|
|
public function UpgradeSavedSearch(){ |
136
|
|
|
$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code'; |
137
|
|
|
if(isset($GLOBALS['log'])) { |
138
|
|
|
$GLOBALS['log']->deprecated($deprecatedMessage); |
139
|
|
|
} |
140
|
|
|
else { |
141
|
|
|
trigger_error($deprecatedMessage, E_USER_DEPRECATED); |
142
|
|
|
} |
143
|
|
|
self::__construct(); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
} |
147
|
|
|
?> |
This function has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.