@@ -44,226 +44,226 @@ discard block |
||
44 | 44 | class LanguageManager |
45 | 45 | { |
46 | 46 | |
47 | - /** |
|
48 | - * Called from VardefManager to allow for caching a lang file for a module |
|
49 | - * @param module - the name of the module we are working with |
|
50 | - * @param templates - an array of templates this module uses |
|
51 | - */ |
|
52 | - static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
53 | - global $mod_strings, $current_language; |
|
54 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
55 | - $refresh = true; |
|
56 | - } |
|
57 | - $temp_mod_strings = $mod_strings; |
|
58 | - $lang = $current_language; |
|
47 | + /** |
|
48 | + * Called from VardefManager to allow for caching a lang file for a module |
|
49 | + * @param module - the name of the module we are working with |
|
50 | + * @param templates - an array of templates this module uses |
|
51 | + */ |
|
52 | + static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
53 | + global $mod_strings, $current_language; |
|
54 | + if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
55 | + $refresh = true; |
|
56 | + } |
|
57 | + $temp_mod_strings = $mod_strings; |
|
58 | + $lang = $current_language; |
|
59 | 59 | if(empty($lang)) |
60 | 60 | $lang = $GLOBALS['sugar_config']['default_language']; |
61 | - static $createdModules = array(); |
|
62 | - if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
63 | - $loaded_mod_strings = array(); |
|
64 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
65 | - $createdModules[$module] = true; |
|
66 | - LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
67 | - } |
|
68 | - } |
|
61 | + static $createdModules = array(); |
|
62 | + if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
63 | + $loaded_mod_strings = array(); |
|
64 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
65 | + $createdModules[$module] = true; |
|
66 | + LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Load the module tempalte lauguage files |
|
72 | - * @param module - the name of the module we are working with |
|
73 | - * @param templates - an array of templates this module uses |
|
74 | - * @param lang - current language this module use |
|
75 | - * @param loaded_mod_strings - the string that we will add the module template language into |
|
76 | - */ |
|
77 | - static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
78 | - $templates = array_reverse($templates); |
|
79 | - foreach($templates as $template){ |
|
80 | - $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
81 | - $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
|
82 | - } |
|
83 | - return $loaded_mod_strings; |
|
84 | - } |
|
70 | + /** |
|
71 | + * Load the module tempalte lauguage files |
|
72 | + * @param module - the name of the module we are working with |
|
73 | + * @param templates - an array of templates this module uses |
|
74 | + * @param lang - current language this module use |
|
75 | + * @param loaded_mod_strings - the string that we will add the module template language into |
|
76 | + */ |
|
77 | + static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
78 | + $templates = array_reverse($templates); |
|
79 | + foreach($templates as $template){ |
|
80 | + $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
81 | + $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
|
82 | + } |
|
83 | + return $loaded_mod_strings; |
|
84 | + } |
|
85 | 85 | |
86 | - static function addTemplate($module, $lang, $template){ |
|
87 | - if($template == 'default')$template = 'basic'; |
|
88 | - $templates = array(); |
|
89 | - $fields = array(); |
|
90 | - if(empty($templates[$template])){ |
|
91 | - $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | - if(file_exists($path)){ |
|
93 | - require($path); |
|
94 | - $templates[$template] = $mod_strings; |
|
95 | - }else{ |
|
96 | - $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | - if(file_exists($path)){ |
|
98 | - require($path); |
|
99 | - $templates[$template] = $mod_strings; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - if(!empty($templates[$template])){ |
|
104 | - return $templates[$template]; |
|
105 | - } |
|
106 | - } |
|
86 | + static function addTemplate($module, $lang, $template){ |
|
87 | + if($template == 'default')$template = 'basic'; |
|
88 | + $templates = array(); |
|
89 | + $fields = array(); |
|
90 | + if(empty($templates[$template])){ |
|
91 | + $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | + if(file_exists($path)){ |
|
93 | + require($path); |
|
94 | + $templates[$template] = $mod_strings; |
|
95 | + }else{ |
|
96 | + $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | + if(file_exists($path)){ |
|
98 | + require($path); |
|
99 | + $templates[$template] = $mod_strings; |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + if(!empty($templates[$template])){ |
|
104 | + return $templates[$template]; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | - if(empty($lang)) |
|
110 | - $lang = $GLOBALS['sugar_config']['default_language']; |
|
108 | + static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | + if(empty($lang)) |
|
110 | + $lang = $GLOBALS['sugar_config']['default_language']; |
|
111 | 111 | |
112 | - $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | - write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
114 | - include($file); |
|
112 | + $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | + write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
114 | + include($file); |
|
115 | 115 | |
116 | - // put the item in the sugar cache. |
|
117 | - $key = self::getLanguageCacheKey($module,$lang); |
|
118 | - sugar_cache_put($key,$loaded_mod_strings); |
|
119 | - } |
|
116 | + // put the item in the sugar cache. |
|
117 | + $key = self::getLanguageCacheKey($module,$lang); |
|
118 | + sugar_cache_put($key,$loaded_mod_strings); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * clear out the language cache. |
|
123 | - * @param string module_dir the module_dir to clear, if not specified then clear |
|
124 | - * clear language cache for all modules. |
|
125 | - * @param string lang the name of the object we are clearing this is for sugar_cache |
|
126 | - */ |
|
127 | - static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | - if(empty($lang)) { |
|
129 | - $languages = array_keys($GLOBALS['sugar_config']['languages']); |
|
130 | - } else { |
|
131 | - $languages = array($lang); |
|
132 | - } |
|
133 | - //if we have a module name specified then just remove that language file |
|
134 | - //otherwise go through each module and clean up the language |
|
135 | - if(!empty($module_dir)) { |
|
136 | - foreach($languages as $clean_lang) { |
|
137 | - LanguageManager::_clearCache($module_dir, $clean_lang); |
|
138 | - } |
|
139 | - } else { |
|
140 | - $cache_dir = sugar_cached('modules/'); |
|
141 | - if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | - while(($entry = readdir($dir)) !== false) { |
|
143 | - if ($entry == "." || $entry == "..") continue; |
|
144 | - foreach($languages as $clean_lang) { |
|
145 | - LanguageManager::_clearCache($entry, $clean_lang); |
|
146 | - } |
|
147 | - } |
|
148 | - closedir($dir); |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
121 | + /** |
|
122 | + * clear out the language cache. |
|
123 | + * @param string module_dir the module_dir to clear, if not specified then clear |
|
124 | + * clear language cache for all modules. |
|
125 | + * @param string lang the name of the object we are clearing this is for sugar_cache |
|
126 | + */ |
|
127 | + static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | + if(empty($lang)) { |
|
129 | + $languages = array_keys($GLOBALS['sugar_config']['languages']); |
|
130 | + } else { |
|
131 | + $languages = array($lang); |
|
132 | + } |
|
133 | + //if we have a module name specified then just remove that language file |
|
134 | + //otherwise go through each module and clean up the language |
|
135 | + if(!empty($module_dir)) { |
|
136 | + foreach($languages as $clean_lang) { |
|
137 | + LanguageManager::_clearCache($module_dir, $clean_lang); |
|
138 | + } |
|
139 | + } else { |
|
140 | + $cache_dir = sugar_cached('modules/'); |
|
141 | + if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | + while(($entry = readdir($dir)) !== false) { |
|
143 | + if ($entry == "." || $entry == "..") continue; |
|
144 | + foreach($languages as $clean_lang) { |
|
145 | + LanguageManager::_clearCache($entry, $clean_lang); |
|
146 | + } |
|
147 | + } |
|
148 | + closedir($dir); |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * PRIVATE function used within clearLanguageCache so we do not repeat logic |
|
155 | - * @param string module_dir the module_dir to clear |
|
156 | - * @param string lang the name of the language file we are clearing this is for sugar_cache |
|
157 | - */ |
|
158 | - static function _clearCache($module_dir = '', $lang){ |
|
159 | - if(!empty($module_dir) && !empty($lang)){ |
|
160 | - $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
|
161 | - if(file_exists($file)){ |
|
162 | - unlink($file); |
|
163 | - $key = self::getLanguageCacheKey($module_dir,$lang); |
|
164 | - sugar_cache_clear($key); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
153 | + /** |
|
154 | + * PRIVATE function used within clearLanguageCache so we do not repeat logic |
|
155 | + * @param string module_dir the module_dir to clear |
|
156 | + * @param string lang the name of the language file we are clearing this is for sugar_cache |
|
157 | + */ |
|
158 | + static function _clearCache($module_dir = '', $lang){ |
|
159 | + if(!empty($module_dir) && !empty($lang)){ |
|
160 | + $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
|
161 | + if(file_exists($file)){ |
|
162 | + unlink($file); |
|
163 | + $key = self::getLanguageCacheKey($module_dir,$lang); |
|
164 | + sugar_cache_clear($key); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Given a module, search all of the specified locations, and any others as specified |
|
171 | - * in order to refresh the cache file |
|
172 | - * |
|
173 | - * @param string $module the given module we want to load the vardefs for |
|
174 | - * @param string $lang the given language we wish to load |
|
175 | - * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
|
176 | - */ |
|
177 | - static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
178 | - // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
179 | - $lang_paths = array( |
|
180 | - 'modules/'.$module.'/language/'.$lang.'.lang.php', |
|
181 | - 'modules/'.$module.'/language/'.$lang.'.lang.override.php', |
|
182 | - 'custom/modules/'.$module.'/language/'.$lang.'.lang.php', |
|
183 | - 'custom/modules/'.$module.'/Ext/Language/'.$lang.'.lang.ext.php', |
|
184 | - ); |
|
169 | + /** |
|
170 | + * Given a module, search all of the specified locations, and any others as specified |
|
171 | + * in order to refresh the cache file |
|
172 | + * |
|
173 | + * @param string $module the given module we want to load the vardefs for |
|
174 | + * @param string $lang the given language we wish to load |
|
175 | + * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
|
176 | + */ |
|
177 | + static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
178 | + // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
179 | + $lang_paths = array( |
|
180 | + 'modules/'.$module.'/language/'.$lang.'.lang.php', |
|
181 | + 'modules/'.$module.'/language/'.$lang.'.lang.override.php', |
|
182 | + 'custom/modules/'.$module.'/language/'.$lang.'.lang.php', |
|
183 | + 'custom/modules/'.$module.'/Ext/Language/'.$lang.'.lang.ext.php', |
|
184 | + ); |
|
185 | 185 | |
186 | - #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
|
187 | - static $createdModules; |
|
188 | - if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
189 | - $object = $GLOBALS['beanList'][$module]; |
|
186 | + #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
|
187 | + static $createdModules; |
|
188 | + if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
189 | + $object = $GLOBALS['beanList'][$module]; |
|
190 | 190 | |
191 | - if ($object == 'aCase') |
|
192 | - $object = 'Case'; |
|
191 | + if ($object == 'aCase') |
|
192 | + $object = 'Case'; |
|
193 | 193 | |
194 | - if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
195 | - $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
|
196 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
197 | - $createdModules[$module] = true; |
|
198 | - } |
|
199 | - } |
|
200 | - //end of fix #27023 |
|
194 | + if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
195 | + $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
|
196 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
197 | + $createdModules[$module] = true; |
|
198 | + } |
|
199 | + } |
|
200 | + //end of fix #27023 |
|
201 | 201 | |
202 | - // Add in additional search paths if they were provided. |
|
203 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | - { |
|
205 | - $lang_paths = array_merge($lang_paths, $additional_search_paths); |
|
206 | - } |
|
202 | + // Add in additional search paths if they were provided. |
|
203 | + if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | + { |
|
205 | + $lang_paths = array_merge($lang_paths, $additional_search_paths); |
|
206 | + } |
|
207 | 207 | |
208 | - //search a predefined set of locations for the vardef files |
|
209 | - foreach($lang_paths as $path){ |
|
210 | - if(file_exists($path)){ |
|
211 | - require($path); |
|
212 | - if(!empty($mod_strings)){ |
|
213 | - if (function_exists('sugarArrayMergeRecursive')){ |
|
214 | - $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
|
215 | - } |
|
216 | - else{ |
|
217 | - $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
208 | + //search a predefined set of locations for the vardef files |
|
209 | + foreach($lang_paths as $path){ |
|
210 | + if(file_exists($path)){ |
|
211 | + require($path); |
|
212 | + if(!empty($mod_strings)){ |
|
213 | + if (function_exists('sugarArrayMergeRecursive')){ |
|
214 | + $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
|
215 | + } |
|
216 | + else{ |
|
217 | + $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - //great! now that we have loaded all of our vardefs. |
|
224 | - //let's go save them to the cache file. |
|
225 | - if(!empty($loaded_mod_strings)) |
|
226 | - LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
227 | - } |
|
223 | + //great! now that we have loaded all of our vardefs. |
|
224 | + //let's go save them to the cache file. |
|
225 | + if(!empty($loaded_mod_strings)) |
|
226 | + LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
227 | + } |
|
228 | 228 | |
229 | - static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
230 | - //here check if the cache file exists, if it does then load it, if it doesn't |
|
231 | - //then call refreshVardef |
|
232 | - //if either our session or the system is set to developerMode then refresh is set to true |
|
229 | + static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
230 | + //here check if the cache file exists, if it does then load it, if it doesn't |
|
231 | + //then call refreshVardef |
|
232 | + //if either our session or the system is set to developerMode then refresh is set to true |
|
233 | 233 | |
234 | - // Retrieve the vardefs from cache. |
|
235 | - $key = self::getLanguageCacheKey($module,$lang); |
|
234 | + // Retrieve the vardefs from cache. |
|
235 | + $key = self::getLanguageCacheKey($module,$lang); |
|
236 | 236 | |
237 | - if(!$refresh) |
|
238 | - { |
|
239 | - $return_result = sugar_cache_retrieve($key); |
|
240 | - if(!empty($return_result) && is_array($return_result)){ |
|
241 | - return $return_result; |
|
242 | - } |
|
243 | - } |
|
237 | + if(!$refresh) |
|
238 | + { |
|
239 | + $return_result = sugar_cache_retrieve($key); |
|
240 | + if(!empty($return_result) && is_array($return_result)){ |
|
241 | + return $return_result; |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
246 | - $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
|
247 | - if($refresh || !file_exists($cachedfile)){ |
|
248 | - LanguageManager::refreshLanguage($module, $lang); |
|
249 | - } |
|
245 | + // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
246 | + $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
|
247 | + if($refresh || !file_exists($cachedfile)){ |
|
248 | + LanguageManager::refreshLanguage($module, $lang); |
|
249 | + } |
|
250 | 250 | |
251 | - //at this point we should have the cache/modules/... file |
|
252 | - //which was created from the refreshVardefs so let's try to load it. |
|
253 | - if(file_exists($cachedfile)){ |
|
254 | - global $mod_strings; |
|
251 | + //at this point we should have the cache/modules/... file |
|
252 | + //which was created from the refreshVardefs so let's try to load it. |
|
253 | + if(file_exists($cachedfile)){ |
|
254 | + global $mod_strings; |
|
255 | 255 | |
256 | - require $cachedfile; |
|
256 | + require $cachedfile; |
|
257 | 257 | |
258 | - // now that we hae loaded the data from disk, put it in the cache. |
|
259 | - if(!empty($mod_strings)) |
|
260 | - sugar_cache_put($key,$mod_strings); |
|
261 | - if(!empty($_SESSION['translation_mode'])){ |
|
262 | - $mod_strings = array_map('translated_prefix', $mod_strings); |
|
263 | - } |
|
264 | - return $mod_strings; |
|
265 | - } |
|
266 | - } |
|
258 | + // now that we hae loaded the data from disk, put it in the cache. |
|
259 | + if(!empty($mod_strings)) |
|
260 | + sugar_cache_put($key,$mod_strings); |
|
261 | + if(!empty($_SESSION['translation_mode'])){ |
|
262 | + $mod_strings = array_map('translated_prefix', $mod_strings); |
|
263 | + } |
|
264 | + return $mod_strings; |
|
265 | + } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Return the cache key for the module language definition |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * @return string |
275 | 275 | */ |
276 | 276 | public static function getLanguageCacheKey($module, $lang) |
277 | - { |
|
278 | - return "LanguageManager.$module.$lang"; |
|
279 | - } |
|
277 | + { |
|
278 | + return "LanguageManager.$module.$lang"; |
|
279 | + } |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Remove any cached js language strings. |
@@ -302,5 +302,5 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | function translated_prefix($key){ |
305 | - return '[translated]' . $key; |
|
305 | + return '[translated]' . $key; |
|
306 | 306 | } |
@@ -49,21 +49,21 @@ discard block |
||
49 | 49 | * @param module - the name of the module we are working with |
50 | 50 | * @param templates - an array of templates this module uses |
51 | 51 | */ |
52 | - static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
52 | + static function createLanguageFile($module, $templates = array('default'), $refresh = false) { |
|
53 | 53 | global $mod_strings, $current_language; |
54 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
54 | + if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { |
|
55 | 55 | $refresh = true; |
56 | 56 | } |
57 | 57 | $temp_mod_strings = $mod_strings; |
58 | 58 | $lang = $current_language; |
59 | - if(empty($lang)) |
|
59 | + if (empty($lang)) |
|
60 | 60 | $lang = $GLOBALS['sugar_config']['default_language']; |
61 | 61 | static $createdModules = array(); |
62 | - if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
62 | + if (empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))) { |
|
63 | 63 | $loaded_mod_strings = array(); |
64 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
64 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings); |
|
65 | 65 | $createdModules[$module] = true; |
66 | - LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
66 | + LanguageManager::refreshLanguage($module, $lang, $loaded_mod_strings); |
|
67 | 67 | } |
68 | 68 | } |
69 | 69 | |
@@ -74,48 +74,48 @@ discard block |
||
74 | 74 | * @param lang - current language this module use |
75 | 75 | * @param loaded_mod_strings - the string that we will add the module template language into |
76 | 76 | */ |
77 | - static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
77 | + static function loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings) { |
|
78 | 78 | $templates = array_reverse($templates); |
79 | - foreach($templates as $template){ |
|
80 | - $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
79 | + foreach ($templates as $template) { |
|
80 | + $temp = LanguageManager::addTemplate($module, $lang, $template); |
|
81 | 81 | $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
82 | 82 | } |
83 | 83 | return $loaded_mod_strings; |
84 | 84 | } |
85 | 85 | |
86 | - static function addTemplate($module, $lang, $template){ |
|
87 | - if($template == 'default')$template = 'basic'; |
|
86 | + static function addTemplate($module, $lang, $template) { |
|
87 | + if ($template == 'default')$template = 'basic'; |
|
88 | 88 | $templates = array(); |
89 | 89 | $fields = array(); |
90 | - if(empty($templates[$template])){ |
|
91 | - $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | - if(file_exists($path)){ |
|
90 | + if (empty($templates[$template])) { |
|
91 | + $path = 'include/SugarObjects/templates/'.$template.'/language/'.$lang.'.lang.php'; |
|
92 | + if (file_exists($path)) { |
|
93 | 93 | require($path); |
94 | 94 | $templates[$template] = $mod_strings; |
95 | - }else{ |
|
96 | - $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | - if(file_exists($path)){ |
|
95 | + } else { |
|
96 | + $path = 'include/SugarObjects/implements/'.$template.'/language/'.$lang.'.lang.php'; |
|
97 | + if (file_exists($path)) { |
|
98 | 98 | require($path); |
99 | 99 | $templates[$template] = $mod_strings; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
103 | - if(!empty($templates[$template])){ |
|
103 | + if (!empty($templates[$template])) { |
|
104 | 104 | return $templates[$template]; |
105 | 105 | } |
106 | 106 | } |
107 | 107 | |
108 | - static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | - if(empty($lang)) |
|
108 | + static function saveCache($module, $lang, $loaded_mod_strings, $additonal_objects = array()) { |
|
109 | + if (empty($lang)) |
|
110 | 110 | $lang = $GLOBALS['sugar_config']['default_language']; |
111 | 111 | |
112 | - $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | - write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
112 | + $file = create_cache_directory('modules/'.$module.'/language/'.$lang.'.lang.php'); |
|
113 | + write_array_to_file('mod_strings', $loaded_mod_strings, $file); |
|
114 | 114 | include($file); |
115 | 115 | |
116 | 116 | // put the item in the sugar cache. |
117 | - $key = self::getLanguageCacheKey($module,$lang); |
|
118 | - sugar_cache_put($key,$loaded_mod_strings); |
|
117 | + $key = self::getLanguageCacheKey($module, $lang); |
|
118 | + sugar_cache_put($key, $loaded_mod_strings); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | /** |
@@ -124,24 +124,24 @@ discard block |
||
124 | 124 | * clear language cache for all modules. |
125 | 125 | * @param string lang the name of the object we are clearing this is for sugar_cache |
126 | 126 | */ |
127 | - static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | - if(empty($lang)) { |
|
127 | + static function clearLanguageCache($module_dir = '', $lang = '') { |
|
128 | + if (empty($lang)) { |
|
129 | 129 | $languages = array_keys($GLOBALS['sugar_config']['languages']); |
130 | 130 | } else { |
131 | 131 | $languages = array($lang); |
132 | 132 | } |
133 | 133 | //if we have a module name specified then just remove that language file |
134 | 134 | //otherwise go through each module and clean up the language |
135 | - if(!empty($module_dir)) { |
|
136 | - foreach($languages as $clean_lang) { |
|
135 | + if (!empty($module_dir)) { |
|
136 | + foreach ($languages as $clean_lang) { |
|
137 | 137 | LanguageManager::_clearCache($module_dir, $clean_lang); |
138 | 138 | } |
139 | 139 | } else { |
140 | 140 | $cache_dir = sugar_cached('modules/'); |
141 | - if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | - while(($entry = readdir($dir)) !== false) { |
|
141 | + if (file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | + while (($entry = readdir($dir)) !== false) { |
|
143 | 143 | if ($entry == "." || $entry == "..") continue; |
144 | - foreach($languages as $clean_lang) { |
|
144 | + foreach ($languages as $clean_lang) { |
|
145 | 145 | LanguageManager::_clearCache($entry, $clean_lang); |
146 | 146 | } |
147 | 147 | } |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | * @param string module_dir the module_dir to clear |
156 | 156 | * @param string lang the name of the language file we are clearing this is for sugar_cache |
157 | 157 | */ |
158 | - static function _clearCache($module_dir = '', $lang){ |
|
159 | - if(!empty($module_dir) && !empty($lang)){ |
|
158 | + static function _clearCache($module_dir = '', $lang) { |
|
159 | + if (!empty($module_dir) && !empty($lang)) { |
|
160 | 160 | $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
161 | - if(file_exists($file)){ |
|
161 | + if (file_exists($file)) { |
|
162 | 162 | unlink($file); |
163 | - $key = self::getLanguageCacheKey($module_dir,$lang); |
|
163 | + $key = self::getLanguageCacheKey($module_dir, $lang); |
|
164 | 164 | sugar_cache_clear($key); |
165 | 165 | } |
166 | 166 | } |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @param string $lang the given language we wish to load |
175 | 175 | * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
176 | 176 | */ |
177 | - static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
177 | + static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null) { |
|
178 | 178 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
179 | 179 | $lang_paths = array( |
180 | 180 | 'modules/'.$module.'/language/'.$lang.'.lang.php', |
@@ -185,35 +185,35 @@ discard block |
||
185 | 185 | |
186 | 186 | #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
187 | 187 | static $createdModules; |
188 | - if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
188 | + if (empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])) { |
|
189 | 189 | $object = $GLOBALS['beanList'][$module]; |
190 | 190 | |
191 | 191 | if ($object == 'aCase') |
192 | 192 | $object = 'Case'; |
193 | 193 | |
194 | - if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
194 | + if (!empty($GLOBALS["dictionary"]["$object"]["templates"])) { |
|
195 | 195 | $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
196 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
196 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module, $templates, $lang, $loaded_mod_strings); |
|
197 | 197 | $createdModules[$module] = true; |
198 | 198 | } |
199 | 199 | } |
200 | 200 | //end of fix #27023 |
201 | 201 | |
202 | 202 | // Add in additional search paths if they were provided. |
203 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
203 | + if (!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | 204 | { |
205 | 205 | $lang_paths = array_merge($lang_paths, $additional_search_paths); |
206 | 206 | } |
207 | 207 | |
208 | 208 | //search a predefined set of locations for the vardef files |
209 | - foreach($lang_paths as $path){ |
|
210 | - if(file_exists($path)){ |
|
209 | + foreach ($lang_paths as $path) { |
|
210 | + if (file_exists($path)) { |
|
211 | 211 | require($path); |
212 | - if(!empty($mod_strings)){ |
|
213 | - if (function_exists('sugarArrayMergeRecursive')){ |
|
212 | + if (!empty($mod_strings)) { |
|
213 | + if (function_exists('sugarArrayMergeRecursive')) { |
|
214 | 214 | $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
215 | 215 | } |
216 | - else{ |
|
216 | + else { |
|
217 | 217 | $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
218 | 218 | } |
219 | 219 | } |
@@ -222,43 +222,43 @@ discard block |
||
222 | 222 | |
223 | 223 | //great! now that we have loaded all of our vardefs. |
224 | 224 | //let's go save them to the cache file. |
225 | - if(!empty($loaded_mod_strings)) |
|
225 | + if (!empty($loaded_mod_strings)) |
|
226 | 226 | LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
227 | 227 | } |
228 | 228 | |
229 | - static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
229 | + static function loadModuleLanguage($module, $lang, $refresh = false) { |
|
230 | 230 | //here check if the cache file exists, if it does then load it, if it doesn't |
231 | 231 | //then call refreshVardef |
232 | 232 | //if either our session or the system is set to developerMode then refresh is set to true |
233 | 233 | |
234 | 234 | // Retrieve the vardefs from cache. |
235 | - $key = self::getLanguageCacheKey($module,$lang); |
|
235 | + $key = self::getLanguageCacheKey($module, $lang); |
|
236 | 236 | |
237 | - if(!$refresh) |
|
237 | + if (!$refresh) |
|
238 | 238 | { |
239 | 239 | $return_result = sugar_cache_retrieve($key); |
240 | - if(!empty($return_result) && is_array($return_result)){ |
|
240 | + if (!empty($return_result) && is_array($return_result)) { |
|
241 | 241 | return $return_result; |
242 | 242 | } |
243 | 243 | } |
244 | 244 | |
245 | 245 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
246 | 246 | $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
247 | - if($refresh || !file_exists($cachedfile)){ |
|
247 | + if ($refresh || !file_exists($cachedfile)) { |
|
248 | 248 | LanguageManager::refreshLanguage($module, $lang); |
249 | 249 | } |
250 | 250 | |
251 | 251 | //at this point we should have the cache/modules/... file |
252 | 252 | //which was created from the refreshVardefs so let's try to load it. |
253 | - if(file_exists($cachedfile)){ |
|
253 | + if (file_exists($cachedfile)) { |
|
254 | 254 | global $mod_strings; |
255 | 255 | |
256 | 256 | require $cachedfile; |
257 | 257 | |
258 | 258 | // now that we hae loaded the data from disk, put it in the cache. |
259 | - if(!empty($mod_strings)) |
|
260 | - sugar_cache_put($key,$mod_strings); |
|
261 | - if(!empty($_SESSION['translation_mode'])){ |
|
259 | + if (!empty($mod_strings)) |
|
260 | + sugar_cache_put($key, $mod_strings); |
|
261 | + if (!empty($_SESSION['translation_mode'])) { |
|
262 | 262 | $mod_strings = array_map('translated_prefix', $mod_strings); |
263 | 263 | } |
264 | 264 | return $mod_strings; |
@@ -288,19 +288,19 @@ discard block |
||
288 | 288 | { |
289 | 289 | $jsFiles = array(); |
290 | 290 | getFiles($jsFiles, sugar_cached('jsLanguage')); |
291 | - foreach($jsFiles as $file) { |
|
291 | + foreach ($jsFiles as $file) { |
|
292 | 292 | unlink($file); |
293 | 293 | } |
294 | 294 | |
295 | - if( empty($GLOBALS['sugar_config']['js_lang_version']) ) |
|
295 | + if (empty($GLOBALS['sugar_config']['js_lang_version'])) |
|
296 | 296 | $GLOBALS['sugar_config']['js_lang_version'] = 1; |
297 | 297 | else |
298 | 298 | $GLOBALS['sugar_config']['js_lang_version'] += 1; |
299 | 299 | |
300 | - write_array_to_file( "sugar_config", $GLOBALS['sugar_config'], "config.php"); |
|
300 | + write_array_to_file("sugar_config", $GLOBALS['sugar_config'], "config.php"); |
|
301 | 301 | } |
302 | 302 | } |
303 | 303 | |
304 | -function translated_prefix($key){ |
|
305 | - return '[translated]' . $key; |
|
304 | +function translated_prefix($key) { |
|
305 | + return '[translated]'.$key; |
|
306 | 306 | } |
@@ -56,8 +56,9 @@ discard block |
||
56 | 56 | } |
57 | 57 | $temp_mod_strings = $mod_strings; |
58 | 58 | $lang = $current_language; |
59 | - if(empty($lang)) |
|
60 | - $lang = $GLOBALS['sugar_config']['default_language']; |
|
59 | + if(empty($lang)) { |
|
60 | + $lang = $GLOBALS['sugar_config']['default_language']; |
|
61 | + } |
|
61 | 62 | static $createdModules = array(); |
62 | 63 | if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
63 | 64 | $loaded_mod_strings = array(); |
@@ -84,7 +85,9 @@ discard block |
||
84 | 85 | } |
85 | 86 | |
86 | 87 | static function addTemplate($module, $lang, $template){ |
87 | - if($template == 'default')$template = 'basic'; |
|
88 | + if($template == 'default') { |
|
89 | + $template = 'basic'; |
|
90 | + } |
|
88 | 91 | $templates = array(); |
89 | 92 | $fields = array(); |
90 | 93 | if(empty($templates[$template])){ |
@@ -92,7 +95,7 @@ discard block |
||
92 | 95 | if(file_exists($path)){ |
93 | 96 | require($path); |
94 | 97 | $templates[$template] = $mod_strings; |
95 | - }else{ |
|
98 | + } else{ |
|
96 | 99 | $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
97 | 100 | if(file_exists($path)){ |
98 | 101 | require($path); |
@@ -106,8 +109,9 @@ discard block |
||
106 | 109 | } |
107 | 110 | |
108 | 111 | static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
109 | - if(empty($lang)) |
|
110 | - $lang = $GLOBALS['sugar_config']['default_language']; |
|
112 | + if(empty($lang)) { |
|
113 | + $lang = $GLOBALS['sugar_config']['default_language']; |
|
114 | + } |
|
111 | 115 | |
112 | 116 | $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
113 | 117 | write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
@@ -140,7 +144,9 @@ discard block |
||
140 | 144 | $cache_dir = sugar_cached('modules/'); |
141 | 145 | if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
142 | 146 | while(($entry = readdir($dir)) !== false) { |
143 | - if ($entry == "." || $entry == "..") continue; |
|
147 | + if ($entry == "." || $entry == "..") { |
|
148 | + continue; |
|
149 | + } |
|
144 | 150 | foreach($languages as $clean_lang) { |
145 | 151 | LanguageManager::_clearCache($entry, $clean_lang); |
146 | 152 | } |
@@ -188,8 +194,9 @@ discard block |
||
188 | 194 | if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
189 | 195 | $object = $GLOBALS['beanList'][$module]; |
190 | 196 | |
191 | - if ($object == 'aCase') |
|
192 | - $object = 'Case'; |
|
197 | + if ($object == 'aCase') { |
|
198 | + $object = 'Case'; |
|
199 | + } |
|
193 | 200 | |
194 | 201 | if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
195 | 202 | $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
@@ -212,8 +219,7 @@ discard block |
||
212 | 219 | if(!empty($mod_strings)){ |
213 | 220 | if (function_exists('sugarArrayMergeRecursive')){ |
214 | 221 | $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
215 | - } |
|
216 | - else{ |
|
222 | + } else{ |
|
217 | 223 | $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
218 | 224 | } |
219 | 225 | } |
@@ -222,8 +228,9 @@ discard block |
||
222 | 228 | |
223 | 229 | //great! now that we have loaded all of our vardefs. |
224 | 230 | //let's go save them to the cache file. |
225 | - if(!empty($loaded_mod_strings)) |
|
226 | - LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
231 | + if(!empty($loaded_mod_strings)) { |
|
232 | + LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
233 | + } |
|
227 | 234 | } |
228 | 235 | |
229 | 236 | static function loadModuleLanguage($module, $lang, $refresh=false){ |
@@ -256,8 +263,9 @@ discard block |
||
256 | 263 | require $cachedfile; |
257 | 264 | |
258 | 265 | // now that we hae loaded the data from disk, put it in the cache. |
259 | - if(!empty($mod_strings)) |
|
260 | - sugar_cache_put($key,$mod_strings); |
|
266 | + if(!empty($mod_strings)) { |
|
267 | + sugar_cache_put($key,$mod_strings); |
|
268 | + } |
|
261 | 269 | if(!empty($_SESSION['translation_mode'])){ |
262 | 270 | $mod_strings = array_map('translated_prefix', $mod_strings); |
263 | 271 | } |
@@ -292,10 +300,11 @@ discard block |
||
292 | 300 | unlink($file); |
293 | 301 | } |
294 | 302 | |
295 | - if( empty($GLOBALS['sugar_config']['js_lang_version']) ) |
|
296 | - $GLOBALS['sugar_config']['js_lang_version'] = 1; |
|
297 | - else |
|
298 | - $GLOBALS['sugar_config']['js_lang_version'] += 1; |
|
303 | + if( empty($GLOBALS['sugar_config']['js_lang_version']) ) { |
|
304 | + $GLOBALS['sugar_config']['js_lang_version'] = 1; |
|
305 | + } else { |
|
306 | + $GLOBALS['sugar_config']['js_lang_version'] += 1; |
|
307 | + } |
|
299 | 308 | |
300 | 309 | write_array_to_file( "sugar_config", $GLOBALS['sugar_config'], "config.php"); |
301 | 310 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function setCustomAllowedForModule($module, $enable) { |
91 | 91 | if ($enable && isset($custom_disabled_modules[$module])) { |
92 | - unset($custom_disabled_modules[$module]); |
|
92 | + unset($custom_disabled_modules[$module]); |
|
93 | 93 | } else if (!$enable) { |
94 | - $custom_disabled_modules[$module] = true; |
|
94 | + $custom_disabled_modules[$module] = true; |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | 'modules/'.$module.'/vardefs.php', |
237 | 237 | 'custom/modules/'.$module.'/Ext/Vardefs/vardefs.ext.php', |
238 | 238 | 'custom/Extension/modules/'.$module.'/Ext/Vardefs/vardefs.php' |
239 | - ); |
|
239 | + ); |
|
240 | 240 | |
241 | 241 | // Add in additional search paths if they were provided. |
242 | 242 | if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | //if the consumer has demanded a refresh or the cache/modules... file |
427 | 427 | //does not exist, then we should do out and try to reload things |
428 | 428 | |
429 | - $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
430 | - if($refresh || !file_exists($cachedfile)){ |
|
431 | - VardefManager::refreshVardefs($module, $object, null, true, $params); |
|
432 | - } |
|
429 | + $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
430 | + if($refresh || !file_exists($cachedfile)){ |
|
431 | + VardefManager::refreshVardefs($module, $object, null, true, $params); |
|
432 | + } |
|
433 | 433 | |
434 | 434 | //at this point we should have the cache/modules/... file |
435 | 435 | //which was created from the refreshVardefs so let's try to load it. |
@@ -96,14 +96,18 @@ discard block |
||
96 | 96 | } |
97 | 97 | |
98 | 98 | static function addTemplate($module, $object, $template, $object_name=false){ |
99 | - if($template == 'default')$template = 'basic'; |
|
99 | + if($template == 'default') { |
|
100 | + $template = 'basic'; |
|
101 | + } |
|
100 | 102 | $templates = array(); |
101 | 103 | $fields = array(); |
102 | - if(empty($object_name))$object_name = $object; |
|
104 | + if(empty($object_name)) { |
|
105 | + $object_name = $object; |
|
106 | + } |
|
103 | 107 | $_object_name = strtolower($object_name); |
104 | 108 | if(!empty($GLOBALS['dictionary'][$object]['table'])){ |
105 | 109 | $table_name = $GLOBALS['dictionary'][$object]['table']; |
106 | - }else{ |
|
110 | + } else{ |
|
107 | 111 | $table_name = strtolower($module); |
108 | 112 | } |
109 | 113 | |
@@ -112,7 +116,7 @@ discard block |
||
112 | 116 | if(file_exists($path)){ |
113 | 117 | require($path); |
114 | 118 | $templates[$template] = $vardefs; |
115 | - }else{ |
|
119 | + } else{ |
|
116 | 120 | $path = 'include/SugarObjects/implements/' . $template . '/vardefs.php'; |
117 | 121 | if(file_exists($path)){ |
118 | 122 | require($path); |
@@ -122,12 +126,22 @@ discard block |
||
122 | 126 | } |
123 | 127 | |
124 | 128 | if(!empty($templates[$template])){ |
125 | - if(empty($GLOBALS['dictionary'][$object]['fields']))$GLOBALS['dictionary'][$object]['fields'] = array(); |
|
126 | - if(empty($GLOBALS['dictionary'][$object]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
127 | - if(empty($GLOBALS['dictionary'][$object]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array(); |
|
129 | + if(empty($GLOBALS['dictionary'][$object]['fields'])) { |
|
130 | + $GLOBALS['dictionary'][$object]['fields'] = array(); |
|
131 | + } |
|
132 | + if(empty($GLOBALS['dictionary'][$object]['relationships'])) { |
|
133 | + $GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
134 | + } |
|
135 | + if(empty($GLOBALS['dictionary'][$object]['indices'])) { |
|
136 | + $GLOBALS['dictionary'][$object]['indices'] = array(); |
|
137 | + } |
|
128 | 138 | $GLOBALS['dictionary'][$object]['fields'] = array_merge($templates[$template]['fields'], $GLOBALS['dictionary'][$object]['fields']); |
129 | - if(!empty($templates[$template]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
130 | - if(!empty($templates[$template]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
139 | + if(!empty($templates[$template]['relationships'])) { |
|
140 | + $GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
141 | + } |
|
142 | + if(!empty($templates[$template]['indices'])) { |
|
143 | + $GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
144 | + } |
|
131 | 145 | // maintain a record of this objects inheritance from the SugarObject templates... |
132 | 146 | $GLOBALS['dictionary'][$object]['templates'][ $template ] = $template ; |
133 | 147 | } |
@@ -160,8 +174,9 @@ discard block |
||
160 | 174 | */ |
161 | 175 | static function saveCache($module,$object, $additonal_objects= array()){ |
162 | 176 | |
163 | - if (empty($GLOBALS['dictionary'][$object])) |
|
164 | - $object = BeanFactory::getObjectName($module); |
|
177 | + if (empty($GLOBALS['dictionary'][$object])) { |
|
178 | + $object = BeanFactory::getObjectName($module); |
|
179 | + } |
|
165 | 180 | $file = create_cache_directory('modules/' . $module . '/' . $object . 'vardefs.php'); |
166 | 181 | |
167 | 182 | $out="<?php \n \$GLOBALS[\"dictionary\"][\"". $object . "\"]=" . var_export($GLOBALS['dictionary'][$object], true) .";"; |
@@ -189,7 +204,7 @@ discard block |
||
189 | 204 | //otherwise go through each module and remove the vardefs.php |
190 | 205 | if(!empty($module_dir) && !empty($object_name)){ |
191 | 206 | VardefManager::_clearCache($module_dir, $object_name); |
192 | - }else{ |
|
207 | + } else{ |
|
193 | 208 | global $beanList; |
194 | 209 | foreach($beanList as $module_dir => $object_name){ |
195 | 210 | VardefManager::_clearCache($module_dir, $object_name); |
@@ -308,11 +323,13 @@ discard block |
||
308 | 323 | } |
309 | 324 | |
310 | 325 | //Cache link fields for this call in a static variable |
311 | - if (!isset(self::$linkFields)) |
|
312 | - self::$linkFields = array(); |
|
326 | + if (!isset(self::$linkFields)) { |
|
327 | + self::$linkFields = array(); |
|
328 | + } |
|
313 | 329 | |
314 | - if (isset(self::$linkFields[$object])) |
|
315 | - return self::$linkFields[$object]; |
|
330 | + if (isset(self::$linkFields[$object])) { |
|
331 | + return self::$linkFields[$object]; |
|
332 | + } |
|
316 | 333 | |
317 | 334 | $vardef = $dictionary[$object]; |
318 | 335 | $links = array(); |
@@ -335,8 +352,9 @@ discard block |
||
335 | 352 | { |
336 | 353 | $cacheKey = "LFR{$module}{$object}{$relName}"; |
337 | 354 | $cacheValue = sugar_cache_retrieve($cacheKey); |
338 | - if(!empty($cacheValue)) |
|
339 | - return $cacheValue; |
|
355 | + if(!empty($cacheValue)) { |
|
356 | + return $cacheValue; |
|
357 | + } |
|
340 | 358 | |
341 | 359 | $relLinkFields = self::getLinkFieldsForModule($module, $object); |
342 | 360 | $matches = array(); |
@@ -350,13 +368,15 @@ discard block |
||
350 | 368 | } |
351 | 369 | } |
352 | 370 | } |
353 | - if (empty($matches)) |
|
354 | - return false; |
|
355 | - if (sizeof($matches) == 1) |
|
356 | - $results = $matches[0]; |
|
357 | - else |
|
358 | - //For relationships where both sides are the same module, more than one link will be returned |
|
371 | + if (empty($matches)) { |
|
372 | + return false; |
|
373 | + } |
|
374 | + if (sizeof($matches) == 1) { |
|
375 | + $results = $matches[0]; |
|
376 | + } else { |
|
377 | + //For relationships where both sides are the same module, more than one link will be returned |
|
359 | 378 | $results = $matches; |
379 | + } |
|
360 | 380 | |
361 | 381 | sugar_cache_put($cacheKey, $results); |
362 | 382 | return $results ; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * Vardefs management |
43 | 43 | * @api |
44 | 44 | */ |
45 | -class VardefManager{ |
|
45 | +class VardefManager { |
|
46 | 46 | static $custom_disabled_modules = array(); |
47 | 47 | static $linkFields; |
48 | 48 | |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | if (isset(VardefManager::$custom_disabled_modules[$module])) |
68 | 68 | { |
69 | 69 | $vardef_paths = array( |
70 | - 'custom/modules/' . $module . '/Ext/Vardefs/vardefs.ext.php', |
|
71 | - 'custom/Extension/modules/' . $module . '/Ext/Vardefs/vardefs.php' |
|
70 | + 'custom/modules/'.$module.'/Ext/Vardefs/vardefs.ext.php', |
|
71 | + 'custom/Extension/modules/'.$module.'/Ext/Vardefs/vardefs.php' |
|
72 | 72 | ); |
73 | 73 | |
74 | 74 | //search a predefined set of locations for the vardef files |
@@ -95,41 +95,41 @@ discard block |
||
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
98 | - static function addTemplate($module, $object, $template, $object_name=false){ |
|
99 | - if($template == 'default')$template = 'basic'; |
|
98 | + static function addTemplate($module, $object, $template, $object_name = false) { |
|
99 | + if ($template == 'default')$template = 'basic'; |
|
100 | 100 | $templates = array(); |
101 | 101 | $fields = array(); |
102 | - if(empty($object_name))$object_name = $object; |
|
102 | + if (empty($object_name))$object_name = $object; |
|
103 | 103 | $_object_name = strtolower($object_name); |
104 | - if(!empty($GLOBALS['dictionary'][$object]['table'])){ |
|
104 | + if (!empty($GLOBALS['dictionary'][$object]['table'])) { |
|
105 | 105 | $table_name = $GLOBALS['dictionary'][$object]['table']; |
106 | - }else{ |
|
106 | + } else { |
|
107 | 107 | $table_name = strtolower($module); |
108 | 108 | } |
109 | 109 | |
110 | - if(empty($templates[$template])){ |
|
111 | - $path = 'include/SugarObjects/templates/' . $template . '/vardefs.php'; |
|
112 | - if(file_exists($path)){ |
|
110 | + if (empty($templates[$template])) { |
|
111 | + $path = 'include/SugarObjects/templates/'.$template.'/vardefs.php'; |
|
112 | + if (file_exists($path)) { |
|
113 | 113 | require($path); |
114 | 114 | $templates[$template] = $vardefs; |
115 | - }else{ |
|
116 | - $path = 'include/SugarObjects/implements/' . $template . '/vardefs.php'; |
|
117 | - if(file_exists($path)){ |
|
115 | + } else { |
|
116 | + $path = 'include/SugarObjects/implements/'.$template.'/vardefs.php'; |
|
117 | + if (file_exists($path)) { |
|
118 | 118 | require($path); |
119 | 119 | $templates[$template] = $vardefs; |
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
123 | 123 | |
124 | - if(!empty($templates[$template])){ |
|
125 | - if(empty($GLOBALS['dictionary'][$object]['fields']))$GLOBALS['dictionary'][$object]['fields'] = array(); |
|
126 | - if(empty($GLOBALS['dictionary'][$object]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
127 | - if(empty($GLOBALS['dictionary'][$object]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array(); |
|
124 | + if (!empty($templates[$template])) { |
|
125 | + if (empty($GLOBALS['dictionary'][$object]['fields']))$GLOBALS['dictionary'][$object]['fields'] = array(); |
|
126 | + if (empty($GLOBALS['dictionary'][$object]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array(); |
|
127 | + if (empty($GLOBALS['dictionary'][$object]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array(); |
|
128 | 128 | $GLOBALS['dictionary'][$object]['fields'] = array_merge($templates[$template]['fields'], $GLOBALS['dictionary'][$object]['fields']); |
129 | - if(!empty($templates[$template]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
130 | - if(!empty($templates[$template]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
129 | + if (!empty($templates[$template]['relationships']))$GLOBALS['dictionary'][$object]['relationships'] = array_merge($templates[$template]['relationships'], $GLOBALS['dictionary'][$object]['relationships']); |
|
130 | + if (!empty($templates[$template]['indices']))$GLOBALS['dictionary'][$object]['indices'] = array_merge($templates[$template]['indices'], $GLOBALS['dictionary'][$object]['indices']); |
|
131 | 131 | // maintain a record of this objects inheritance from the SugarObject templates... |
132 | - $GLOBALS['dictionary'][$object]['templates'][ $template ] = $template ; |
|
132 | + $GLOBALS['dictionary'][$object]['templates'][$template] = $template; |
|
133 | 133 | } |
134 | 134 | } |
135 | 135 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | */ |
143 | 143 | static function cleanVardefs($fieldDefs) |
144 | 144 | { |
145 | - if(isset($fieldDefs['fields'])) { |
|
145 | + if (isset($fieldDefs['fields'])) { |
|
146 | 146 | foreach ($fieldDefs['fields'] as $field => $defs) { |
147 | 147 | if (empty($defs['name']) || empty($defs['type'])) { |
148 | 148 | unset($fieldDefs['fields'][$field]); |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param string $module the name of the module |
159 | 159 | * @param string $object the name of the object |
160 | 160 | */ |
161 | - static function saveCache($module,$object, $additonal_objects= array()){ |
|
161 | + static function saveCache($module, $object, $additonal_objects = array()) { |
|
162 | 162 | |
163 | 163 | if (empty($GLOBALS['dictionary'][$object])) |
164 | 164 | $object = BeanFactory::getObjectName($module); |
@@ -166,17 +166,17 @@ discard block |
||
166 | 166 | //Sometimes bad definitions can get in from left over extensions or file system lag(caching). We need to clean those. |
167 | 167 | $data = self::cleanVardefs($GLOBALS['dictionary'][$object]); |
168 | 168 | |
169 | - $file = create_cache_directory('modules/' . $module . '/' . $object . 'vardefs.php'); |
|
169 | + $file = create_cache_directory('modules/'.$module.'/'.$object.'vardefs.php'); |
|
170 | 170 | |
171 | - $out="<?php \n \$GLOBALS[\"dictionary\"][\"". $object . "\"]=" . var_export($data, true) .";"; |
|
171 | + $out = "<?php \n \$GLOBALS[\"dictionary\"][\"".$object."\"]=".var_export($data, true).";"; |
|
172 | 172 | sugar_file_put_contents_atomic($file, $out); |
173 | - if ( sugar_is_file($file) && is_readable($file)) { |
|
173 | + if (sugar_is_file($file) && is_readable($file)) { |
|
174 | 174 | include($file); |
175 | 175 | } |
176 | 176 | |
177 | 177 | // put the item in the sugar cache. |
178 | 178 | $key = "VardefManager.$module.$object"; |
179 | - sugar_cache_put($key,$data); |
|
179 | + sugar_cache_put($key, $data); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -186,14 +186,14 @@ discard block |
||
186 | 186 | * clear vardef cache for all modules. |
187 | 187 | * @param string object_name the name of the object we are clearing this is for sugar_cache |
188 | 188 | */ |
189 | - static function clearVardef($module_dir = '', $object_name = ''){ |
|
189 | + static function clearVardef($module_dir = '', $object_name = '') { |
|
190 | 190 | //if we have a module name specified then just remove that vardef file |
191 | 191 | //otherwise go through each module and remove the vardefs.php |
192 | - if(!empty($module_dir) && !empty($object_name)){ |
|
192 | + if (!empty($module_dir) && !empty($object_name)) { |
|
193 | 193 | VardefManager::_clearCache($module_dir, $object_name); |
194 | - }else{ |
|
194 | + } else { |
|
195 | 195 | global $beanList; |
196 | - foreach($beanList as $module_dir => $object_name){ |
|
196 | + foreach ($beanList as $module_dir => $object_name) { |
|
197 | 197 | VardefManager::_clearCache($module_dir, $object_name); |
198 | 198 | } |
199 | 199 | } |
@@ -204,8 +204,8 @@ discard block |
||
204 | 204 | * @param string module_dir the module_dir to clear |
205 | 205 | * @param string object_name the name of the object we are clearing this is for sugar_cache |
206 | 206 | */ |
207 | - static function _clearCache($module_dir = '', $object_name = ''){ |
|
208 | - if(!empty($module_dir) && !empty($object_name)){ |
|
207 | + static function _clearCache($module_dir = '', $object_name = '') { |
|
208 | + if (!empty($module_dir) && !empty($object_name)) { |
|
209 | 209 | |
210 | 210 | //Some modules like cases have a bean name that doesn't match the object name |
211 | 211 | if (empty($GLOBALS['dictionary'][$object_name])) { |
@@ -213,9 +213,9 @@ discard block |
||
213 | 213 | $object_name = $newName != false ? $newName : $object_name; |
214 | 214 | } |
215 | 215 | |
216 | - $file = sugar_cached('modules/').$module_dir.'/' . $object_name . 'vardefs.php'; |
|
216 | + $file = sugar_cached('modules/').$module_dir.'/'.$object_name.'vardefs.php'; |
|
217 | 217 | |
218 | - if(file_exists($file)){ |
|
218 | + if (file_exists($file)) { |
|
219 | 219 | unlink($file); |
220 | 220 | $key = "VardefManager.$module_dir.$object_name"; |
221 | 221 | sugar_cache_clear($key); |
@@ -231,7 +231,7 @@ discard block |
||
231 | 231 | * @param string $object the given object we wish to load the vardefs for |
232 | 232 | * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
233 | 233 | */ |
234 | - static function refreshVardefs($module, $object, $additional_search_paths = null, $cacheCustom = true, $params = array()){ |
|
234 | + static function refreshVardefs($module, $object, $additional_search_paths = null, $cacheCustom = true, $params = array()) { |
|
235 | 235 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
236 | 236 | global $dictionary, $beanList; |
237 | 237 | $vardef_paths = array( |
@@ -241,20 +241,20 @@ discard block |
||
241 | 241 | ); |
242 | 242 | |
243 | 243 | // Add in additional search paths if they were provided. |
244 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
244 | + if (!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
245 | 245 | { |
246 | 246 | $vardef_paths = array_merge($vardef_paths, $additional_search_paths); |
247 | 247 | } |
248 | 248 | $found = false; |
249 | 249 | //search a predefined set of locations for the vardef files |
250 | - foreach($vardef_paths as $path){ |
|
251 | - if(file_exists($path)){ |
|
250 | + foreach ($vardef_paths as $path) { |
|
251 | + if (file_exists($path)) { |
|
252 | 252 | require($path); |
253 | 253 | $found = true; |
254 | 254 | } |
255 | 255 | } |
256 | 256 | //Some modules have multiple beans, we need to see if this object has a module_dir that is different from its module_name |
257 | - if(!$found){ |
|
257 | + if (!$found) { |
|
258 | 258 | $temp = BeanFactory::newBean($module); |
259 | 259 | if ($temp) |
260 | 260 | { |
@@ -273,15 +273,15 @@ discard block |
||
273 | 273 | } |
274 | 274 | |
275 | 275 | //load custom fields into the vardef cache |
276 | - if($cacheCustom){ |
|
276 | + if ($cacheCustom) { |
|
277 | 277 | require_once("modules/DynamicFields/DynamicField.php"); |
278 | - $df = new DynamicField ($module) ; |
|
278 | + $df = new DynamicField($module); |
|
279 | 279 | $df->buildCache($module, false); |
280 | 280 | } |
281 | 281 | |
282 | 282 | //great! now that we have loaded all of our vardefs. |
283 | 283 | //let's go save them to the cache file. |
284 | - if(!empty($dictionary[$object])) { |
|
284 | + if (!empty($dictionary[$object])) { |
|
285 | 285 | VardefManager::saveCache($module, $object); |
286 | 286 | } |
287 | 287 | } |
@@ -318,10 +318,10 @@ discard block |
||
318 | 318 | |
319 | 319 | $vardef = $dictionary[$object]; |
320 | 320 | $links = array(); |
321 | - foreach($vardef['fields'] as $name => $def) |
|
321 | + foreach ($vardef['fields'] as $name => $def) |
|
322 | 322 | { |
323 | 323 | //Look through all link fields for related modules that have calculated fields that use that relationship |
324 | - if(!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) |
|
324 | + if (!empty($def['type']) && $def['type'] == 'link' && !empty($def['relationship'])) |
|
325 | 325 | { |
326 | 326 | $links[$name] = $def; |
327 | 327 | } |
@@ -337,14 +337,14 @@ discard block |
||
337 | 337 | { |
338 | 338 | $cacheKey = "LFR{$module}{$object}{$relName}"; |
339 | 339 | $cacheValue = sugar_cache_retrieve($cacheKey); |
340 | - if(!empty($cacheValue)) |
|
340 | + if (!empty($cacheValue)) |
|
341 | 341 | return $cacheValue; |
342 | 342 | |
343 | 343 | $relLinkFields = self::getLinkFieldsForModule($module, $object); |
344 | 344 | $matches = array(); |
345 | 345 | if (!empty($relLinkFields)) |
346 | 346 | { |
347 | - foreach($relLinkFields as $rfName => $rfDef) |
|
347 | + foreach ($relLinkFields as $rfName => $rfDef) |
|
348 | 348 | { |
349 | 349 | if ($rfDef['relationship'] == $relName) |
350 | 350 | { |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | $results = $matches; |
362 | 362 | |
363 | 363 | sugar_cache_put($cacheKey, $results); |
364 | - return $results ; |
|
364 | + return $results; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -400,22 +400,22 @@ discard block |
||
400 | 400 | * @param string $object the given object we wish to load the vardefs for |
401 | 401 | * @param bool $refresh whether or not we wish to refresh the cache file. |
402 | 402 | */ |
403 | - static function loadVardef($module, $object, $refresh=false, $params = array()){ |
|
403 | + static function loadVardef($module, $object, $refresh = false, $params = array()) { |
|
404 | 404 | //here check if the cache file exists, if it does then load it, if it doesn't |
405 | 405 | //then call refreshVardef |
406 | 406 | //if either our session or the system is set to developerMode then refresh is set to true |
407 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
407 | + if (inDeveloperMode() || !empty($_SESSION['developerMode'])) { |
|
408 | 408 | $refresh = true; |
409 | 409 | } |
410 | 410 | // Retrieve the vardefs from cache. |
411 | 411 | $key = "VardefManager.$module.$object"; |
412 | 412 | |
413 | - if(!$refresh) |
|
413 | + if (!$refresh) |
|
414 | 414 | { |
415 | 415 | $return_result = sugar_cache_retrieve($key); |
416 | 416 | $return_result = self::applyGlobalAccountRequirements($return_result); |
417 | 417 | |
418 | - if(!empty($return_result)) |
|
418 | + if (!empty($return_result)) |
|
419 | 419 | { |
420 | 420 | $GLOBALS['dictionary'][$object] = $return_result; |
421 | 421 | return; |
@@ -424,28 +424,28 @@ discard block |
||
424 | 424 | |
425 | 425 | // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
426 | 426 | global $dictionary; |
427 | - if(empty($GLOBALS['dictionary'][$object]) || $refresh){ |
|
427 | + if (empty($GLOBALS['dictionary'][$object]) || $refresh) { |
|
428 | 428 | //if the consumer has demanded a refresh or the cache/modules... file |
429 | 429 | //does not exist, then we should do out and try to reload things |
430 | 430 | |
431 | - $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
432 | - if($refresh || !file_exists($cachedfile)){ |
|
431 | + $cachedfile = sugar_cached('modules/').$module.'/'.$object.'vardefs.php'; |
|
432 | + if ($refresh || !file_exists($cachedfile)) { |
|
433 | 433 | VardefManager::refreshVardefs($module, $object, null, true, $params); |
434 | 434 | } |
435 | 435 | |
436 | 436 | //at this point we should have the cache/modules/... file |
437 | 437 | //which was created from the refreshVardefs so let's try to load it. |
438 | - if(file_exists($cachedfile)) |
|
438 | + if (file_exists($cachedfile)) |
|
439 | 439 | { |
440 | 440 | if (is_readable($cachedfile)) |
441 | 441 | { |
442 | 442 | include($cachedfile); |
443 | 443 | } |
444 | 444 | // now that we hae loaded the data from disk, put it in the cache. |
445 | - if(!empty($GLOBALS['dictionary'][$object])) |
|
445 | + if (!empty($GLOBALS['dictionary'][$object])) |
|
446 | 446 | { |
447 | 447 | $GLOBALS['dictionary'][$object] = self::applyGlobalAccountRequirements($GLOBALS['dictionary'][$object]); |
448 | - sugar_cache_put($key,$GLOBALS['dictionary'][$object]); |
|
448 | + sugar_cache_put($key, $GLOBALS['dictionary'][$object]); |
|
449 | 449 | } |
450 | 450 | } |
451 | 451 | } |
@@ -39,141 +39,141 @@ discard block |
||
39 | 39 | |
40 | 40 | $vardefs = array( |
41 | 41 | 'fields' => array ( |
42 | - 'id' => |
|
43 | - array ( |
|
44 | - 'name' => 'id', |
|
45 | - 'vname' => 'LBL_ID', |
|
46 | - 'type' => 'id', |
|
47 | - 'required'=>true, |
|
48 | - 'reportable'=>true, |
|
49 | - 'comment' => 'Unique identifier', |
|
50 | - 'inline_edit' => false, |
|
51 | - ), |
|
52 | - 'name'=> |
|
53 | - array( |
|
54 | - 'name'=>'name', |
|
55 | - 'vname'=> 'LBL_NAME', |
|
56 | - 'type'=>'name', |
|
57 | - 'link' => true, // bug 39288 |
|
58 | - 'dbType' => 'varchar', |
|
59 | - 'len'=>255, |
|
42 | + 'id' => |
|
43 | + array ( |
|
44 | + 'name' => 'id', |
|
45 | + 'vname' => 'LBL_ID', |
|
46 | + 'type' => 'id', |
|
47 | + 'required'=>true, |
|
48 | + 'reportable'=>true, |
|
49 | + 'comment' => 'Unique identifier', |
|
50 | + 'inline_edit' => false, |
|
51 | + ), |
|
52 | + 'name'=> |
|
53 | + array( |
|
54 | + 'name'=>'name', |
|
55 | + 'vname'=> 'LBL_NAME', |
|
56 | + 'type'=>'name', |
|
57 | + 'link' => true, // bug 39288 |
|
58 | + 'dbType' => 'varchar', |
|
59 | + 'len'=>255, |
|
60 | 60 | 'unified_search' => true, |
61 | 61 | 'full_text_search' => array('boost' => 3), |
62 | 62 | 'required'=>true, |
63 | - 'importable' => 'required', |
|
63 | + 'importable' => 'required', |
|
64 | 64 | 'duplicate_merge' => 'enabled', |
65 | 65 | //'duplicate_merge_dom_value' => '3', |
66 | 66 | 'merge_filter' => 'selected', |
67 | - ), |
|
68 | - 'date_entered' => |
|
69 | - array ( |
|
70 | - 'name' => 'date_entered', |
|
71 | - 'vname' => 'LBL_DATE_ENTERED', |
|
72 | - 'type' => 'datetime', |
|
73 | - 'group'=>'created_by_name', |
|
74 | - 'comment' => 'Date record created', |
|
75 | - 'enable_range_search' => true, |
|
76 | - 'options' => 'date_range_search_dom', |
|
77 | - 'inline_edit' => false, |
|
78 | - ), |
|
79 | - 'date_modified' => |
|
80 | - array ( |
|
81 | - 'name' => 'date_modified', |
|
82 | - 'vname' => 'LBL_DATE_MODIFIED', |
|
83 | - 'type' => 'datetime', |
|
84 | - 'group'=>'modified_by_name', |
|
85 | - 'comment' => 'Date record last modified', |
|
86 | - 'enable_range_search' => true, |
|
87 | - 'options' => 'date_range_search_dom', |
|
88 | - 'inline_edit' => false, |
|
89 | - ), |
|
90 | - 'modified_user_id' => |
|
91 | - array ( |
|
92 | - 'name' => 'modified_user_id', |
|
93 | - 'rname' => 'user_name', |
|
94 | - 'id_name' => 'modified_user_id', |
|
95 | - 'vname' => 'LBL_MODIFIED', |
|
96 | - 'type' => 'assigned_user_name', |
|
97 | - 'table' => 'users', |
|
98 | - 'isnull' => 'false', |
|
99 | - 'group'=>'modified_by_name', |
|
100 | - 'dbType' => 'id', |
|
101 | - 'reportable'=>true, |
|
102 | - 'comment' => 'User who last modified record', |
|
67 | + ), |
|
68 | + 'date_entered' => |
|
69 | + array ( |
|
70 | + 'name' => 'date_entered', |
|
71 | + 'vname' => 'LBL_DATE_ENTERED', |
|
72 | + 'type' => 'datetime', |
|
73 | + 'group'=>'created_by_name', |
|
74 | + 'comment' => 'Date record created', |
|
75 | + 'enable_range_search' => true, |
|
76 | + 'options' => 'date_range_search_dom', |
|
77 | + 'inline_edit' => false, |
|
78 | + ), |
|
79 | + 'date_modified' => |
|
80 | + array ( |
|
81 | + 'name' => 'date_modified', |
|
82 | + 'vname' => 'LBL_DATE_MODIFIED', |
|
83 | + 'type' => 'datetime', |
|
84 | + 'group'=>'modified_by_name', |
|
85 | + 'comment' => 'Date record last modified', |
|
86 | + 'enable_range_search' => true, |
|
87 | + 'options' => 'date_range_search_dom', |
|
88 | + 'inline_edit' => false, |
|
89 | + ), |
|
90 | + 'modified_user_id' => |
|
91 | + array ( |
|
92 | + 'name' => 'modified_user_id', |
|
93 | + 'rname' => 'user_name', |
|
94 | + 'id_name' => 'modified_user_id', |
|
95 | + 'vname' => 'LBL_MODIFIED', |
|
96 | + 'type' => 'assigned_user_name', |
|
97 | + 'table' => 'users', |
|
98 | + 'isnull' => 'false', |
|
99 | + 'group'=>'modified_by_name', |
|
100 | + 'dbType' => 'id', |
|
101 | + 'reportable'=>true, |
|
102 | + 'comment' => 'User who last modified record', |
|
103 | 103 | 'massupdate' => false, |
104 | - 'inline_edit' => false, |
|
105 | - ), |
|
106 | - 'modified_by_name' => |
|
107 | - array ( |
|
108 | - 'name' => 'modified_by_name', |
|
109 | - 'vname' => 'LBL_MODIFIED_NAME', |
|
110 | - 'type' => 'relate', |
|
111 | - 'reportable'=>false, |
|
112 | - 'source'=>'non-db', |
|
113 | - 'rname'=>'user_name', |
|
114 | - 'table' => 'users', |
|
115 | - 'id_name' => 'modified_user_id', |
|
116 | - 'module'=>'Users', |
|
117 | - 'link'=>'modified_user_link', |
|
118 | - 'duplicate_merge'=>'disabled', |
|
104 | + 'inline_edit' => false, |
|
105 | + ), |
|
106 | + 'modified_by_name' => |
|
107 | + array ( |
|
108 | + 'name' => 'modified_by_name', |
|
109 | + 'vname' => 'LBL_MODIFIED_NAME', |
|
110 | + 'type' => 'relate', |
|
111 | + 'reportable'=>false, |
|
112 | + 'source'=>'non-db', |
|
113 | + 'rname'=>'user_name', |
|
114 | + 'table' => 'users', |
|
115 | + 'id_name' => 'modified_user_id', |
|
116 | + 'module'=>'Users', |
|
117 | + 'link'=>'modified_user_link', |
|
118 | + 'duplicate_merge'=>'disabled', |
|
119 | 119 | 'massupdate' => false, |
120 | - 'inline_edit' => false, |
|
121 | - ), |
|
122 | - 'created_by' => |
|
123 | - array ( |
|
124 | - 'name' => 'created_by', |
|
125 | - 'rname' => 'user_name', |
|
126 | - 'id_name' => 'modified_user_id', |
|
127 | - 'vname' => 'LBL_CREATED', |
|
128 | - 'type' => 'assigned_user_name', |
|
129 | - 'table' => 'users', |
|
130 | - 'isnull' => 'false', |
|
131 | - 'dbType' => 'id', |
|
132 | - 'group'=>'created_by_name', |
|
133 | - 'comment' => 'User who created record', |
|
120 | + 'inline_edit' => false, |
|
121 | + ), |
|
122 | + 'created_by' => |
|
123 | + array ( |
|
124 | + 'name' => 'created_by', |
|
125 | + 'rname' => 'user_name', |
|
126 | + 'id_name' => 'modified_user_id', |
|
127 | + 'vname' => 'LBL_CREATED', |
|
128 | + 'type' => 'assigned_user_name', |
|
129 | + 'table' => 'users', |
|
130 | + 'isnull' => 'false', |
|
131 | + 'dbType' => 'id', |
|
132 | + 'group'=>'created_by_name', |
|
133 | + 'comment' => 'User who created record', |
|
134 | 134 | 'massupdate' => false, |
135 | - 'inline_edit' => false, |
|
136 | - ), |
|
137 | - 'created_by_name' => |
|
138 | - array ( |
|
139 | - 'name' => 'created_by_name', |
|
140 | - 'vname' => 'LBL_CREATED', |
|
141 | - 'type' => 'relate', |
|
142 | - 'reportable'=>false, |
|
143 | - 'link' => 'created_by_link', |
|
144 | - 'rname' => 'user_name', |
|
145 | - 'source'=>'non-db', |
|
146 | - 'table' => 'users', |
|
147 | - 'id_name' => 'created_by', |
|
148 | - 'module'=>'Users', |
|
149 | - 'duplicate_merge'=>'disabled', |
|
135 | + 'inline_edit' => false, |
|
136 | + ), |
|
137 | + 'created_by_name' => |
|
138 | + array ( |
|
139 | + 'name' => 'created_by_name', |
|
140 | + 'vname' => 'LBL_CREATED', |
|
141 | + 'type' => 'relate', |
|
142 | + 'reportable'=>false, |
|
143 | + 'link' => 'created_by_link', |
|
144 | + 'rname' => 'user_name', |
|
145 | + 'source'=>'non-db', |
|
146 | + 'table' => 'users', |
|
147 | + 'id_name' => 'created_by', |
|
148 | + 'module'=>'Users', |
|
149 | + 'duplicate_merge'=>'disabled', |
|
150 | 150 | 'importable' => 'false', |
151 | 151 | 'massupdate' => false, |
152 | - 'inline_edit' => false, |
|
153 | - ), |
|
154 | - 'description' => |
|
155 | - array ( |
|
156 | - 'name' => 'description', |
|
157 | - 'vname' => 'LBL_DESCRIPTION', |
|
158 | - 'type' => 'text', |
|
159 | - 'comment' => 'Full text of the note', |
|
160 | - 'rows' => 6, |
|
161 | - 'cols' => 80, |
|
162 | - ), |
|
163 | - 'deleted' => |
|
164 | - array ( |
|
165 | - 'name' => 'deleted', |
|
166 | - 'vname' => 'LBL_DELETED', |
|
167 | - 'type' => 'bool', |
|
168 | - 'default' => '0', |
|
169 | - 'reportable'=>false, |
|
170 | - 'comment' => 'Record deletion indicator' |
|
171 | - ), |
|
152 | + 'inline_edit' => false, |
|
153 | + ), |
|
154 | + 'description' => |
|
155 | + array ( |
|
156 | + 'name' => 'description', |
|
157 | + 'vname' => 'LBL_DESCRIPTION', |
|
158 | + 'type' => 'text', |
|
159 | + 'comment' => 'Full text of the note', |
|
160 | + 'rows' => 6, |
|
161 | + 'cols' => 80, |
|
162 | + ), |
|
163 | + 'deleted' => |
|
164 | + array ( |
|
165 | + 'name' => 'deleted', |
|
166 | + 'vname' => 'LBL_DELETED', |
|
167 | + 'type' => 'bool', |
|
168 | + 'default' => '0', |
|
169 | + 'reportable'=>false, |
|
170 | + 'comment' => 'Record deletion indicator' |
|
171 | + ), |
|
172 | 172 | |
173 | 173 | /////////////////RELATIONSHIP LINKS//////////////////////////// |
174 | - 'created_by_link' => |
|
175 | - array ( |
|
176 | - 'name' => 'created_by_link', |
|
174 | + 'created_by_link' => |
|
175 | + array ( |
|
176 | + 'name' => 'created_by_link', |
|
177 | 177 | 'type' => 'link', |
178 | 178 | 'relationship' => strtolower($module) . '_created_by', |
179 | 179 | 'vname' => 'LBL_CREATED_USER', |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | 'module'=>'Users', |
182 | 182 | 'bean_name'=>'User', |
183 | 183 | 'source'=>'non-db', |
184 | - ), |
|
185 | - 'modified_user_link' => |
|
186 | - array ( |
|
184 | + ), |
|
185 | + 'modified_user_link' => |
|
186 | + array ( |
|
187 | 187 | 'name' => 'modified_user_link', |
188 | 188 | 'type' => 'link', |
189 | 189 | 'relationship' => strtolower($module). '_modified_user', |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | 'module'=>'Users', |
193 | 193 | 'bean_name'=>'User', |
194 | 194 | 'source'=>'non-db', |
195 | - ), |
|
195 | + ), |
|
196 | 196 | |
197 | 197 | ), |
198 | 198 | 'indices' => array ( |
199 | - 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
|
200 | - ), |
|
199 | + 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
|
200 | + ), |
|
201 | 201 | 'relationships'=>array( |
202 | - strtolower($module).'_modified_user' => |
|
203 | - array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
204 | - 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'modified_user_id', |
|
205 | - 'relationship_type'=>'one-to-many') |
|
206 | - ,strtolower($module).'_created_by' => |
|
207 | - array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
208 | - 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'created_by', |
|
209 | - 'relationship_type'=>'one-to-many') |
|
202 | + strtolower($module).'_modified_user' => |
|
203 | + array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
204 | + 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'modified_user_id', |
|
205 | + 'relationship_type'=>'one-to-many') |
|
206 | + ,strtolower($module).'_created_by' => |
|
207 | + array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
208 | + 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'created_by', |
|
209 | + 'relationship_type'=>'one-to-many') |
|
210 | 210 | ), |
211 | 211 | |
212 | 212 |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | ********************************************************************************/ |
39 | 39 | |
40 | 40 | $vardefs = array( |
41 | -'fields' => array ( |
|
41 | +'fields' => array( |
|
42 | 42 | 'id' => |
43 | - array ( |
|
43 | + array( |
|
44 | 44 | 'name' => 'id', |
45 | 45 | 'vname' => 'LBL_ID', |
46 | 46 | 'type' => 'id', |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | 'merge_filter' => 'selected', |
67 | 67 | ), |
68 | 68 | 'date_entered' => |
69 | - array ( |
|
69 | + array( |
|
70 | 70 | 'name' => 'date_entered', |
71 | 71 | 'vname' => 'LBL_DATE_ENTERED', |
72 | 72 | 'type' => 'datetime', |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'inline_edit' => false, |
78 | 78 | ), |
79 | 79 | 'date_modified' => |
80 | - array ( |
|
80 | + array( |
|
81 | 81 | 'name' => 'date_modified', |
82 | 82 | 'vname' => 'LBL_DATE_MODIFIED', |
83 | 83 | 'type' => 'datetime', |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | 'inline_edit' => false, |
89 | 89 | ), |
90 | 90 | 'modified_user_id' => |
91 | - array ( |
|
91 | + array( |
|
92 | 92 | 'name' => 'modified_user_id', |
93 | 93 | 'rname' => 'user_name', |
94 | 94 | 'id_name' => 'modified_user_id', |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | 'inline_edit' => false, |
105 | 105 | ), |
106 | 106 | 'modified_by_name' => |
107 | - array ( |
|
107 | + array( |
|
108 | 108 | 'name' => 'modified_by_name', |
109 | 109 | 'vname' => 'LBL_MODIFIED_NAME', |
110 | 110 | 'type' => 'relate', |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | 'inline_edit' => false, |
121 | 121 | ), |
122 | 122 | 'created_by' => |
123 | - array ( |
|
123 | + array( |
|
124 | 124 | 'name' => 'created_by', |
125 | 125 | 'rname' => 'user_name', |
126 | 126 | 'id_name' => 'modified_user_id', |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | 'inline_edit' => false, |
136 | 136 | ), |
137 | 137 | 'created_by_name' => |
138 | - array ( |
|
138 | + array( |
|
139 | 139 | 'name' => 'created_by_name', |
140 | 140 | 'vname' => 'LBL_CREATED', |
141 | 141 | 'type' => 'relate', |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | 'inline_edit' => false, |
153 | 153 | ), |
154 | 154 | 'description' => |
155 | - array ( |
|
155 | + array( |
|
156 | 156 | 'name' => 'description', |
157 | 157 | 'vname' => 'LBL_DESCRIPTION', |
158 | 158 | 'type' => 'text', |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | 'cols' => 80, |
162 | 162 | ), |
163 | 163 | 'deleted' => |
164 | - array ( |
|
164 | + array( |
|
165 | 165 | 'name' => 'deleted', |
166 | 166 | 'vname' => 'LBL_DELETED', |
167 | 167 | 'type' => 'bool', |
@@ -172,10 +172,10 @@ discard block |
||
172 | 172 | |
173 | 173 | /////////////////RELATIONSHIP LINKS//////////////////////////// |
174 | 174 | 'created_by_link' => |
175 | - array ( |
|
175 | + array( |
|
176 | 176 | 'name' => 'created_by_link', |
177 | 177 | 'type' => 'link', |
178 | - 'relationship' => strtolower($module) . '_created_by', |
|
178 | + 'relationship' => strtolower($module).'_created_by', |
|
179 | 179 | 'vname' => 'LBL_CREATED_USER', |
180 | 180 | 'link_type' => 'one', |
181 | 181 | 'module'=>'Users', |
@@ -183,10 +183,10 @@ discard block |
||
183 | 183 | 'source'=>'non-db', |
184 | 184 | ), |
185 | 185 | 'modified_user_link' => |
186 | - array ( |
|
186 | + array( |
|
187 | 187 | 'name' => 'modified_user_link', |
188 | 188 | 'type' => 'link', |
189 | - 'relationship' => strtolower($module). '_modified_user', |
|
189 | + 'relationship' => strtolower($module).'_modified_user', |
|
190 | 190 | 'vname' => 'LBL_MODIFIED_USER', |
191 | 191 | 'link_type' => 'one', |
192 | 192 | 'module'=>'Users', |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | ), |
196 | 196 | |
197 | 197 | ), |
198 | -'indices' => array ( |
|
198 | +'indices' => array( |
|
199 | 199 | 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
200 | 200 | ), |
201 | 201 | 'relationships'=>array( |
@@ -54,7 +54,7 @@ |
||
54 | 54 | 'LBL_MODIFIED_USER'=>'Modified by User', |
55 | 55 | 'LBL_LIST_NAME'=>'Name', |
56 | 56 | 'LBL_EDIT_BUTTON' => 'Edit', |
57 | - 'LBL_REMOVE' => 'Remove', |
|
57 | + 'LBL_REMOVE' => 'Remove', |
|
58 | 58 | |
59 | 59 | |
60 | 60 | ); |
61 | 61 | \ No newline at end of file |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | 'url' => 'nvarchar', |
144 | 144 | 'encrypt' => 'nvarchar', |
145 | 145 | 'file' => 'nvarchar', |
146 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
146 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | 147 | ); |
148 | 148 | |
149 | - /** |
|
149 | + /** |
|
150 | 150 | * @see DBManager::connect() |
151 | 151 | */ |
152 | 152 | public function connect(array $configOptions = null, $dieOnError = false) |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | return true; |
204 | 204 | } |
205 | 205 | |
206 | - /** |
|
206 | + /** |
|
207 | 207 | * @see DBManager::query() |
208 | - */ |
|
209 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
208 | + */ |
|
209 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
210 | 210 | { |
211 | 211 | if(is_array($sql)) { |
212 | 212 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | return $result; |
233 | 233 | } |
234 | 234 | |
235 | - /** |
|
235 | + /** |
|
236 | 236 | * @see DBManager::getFieldsArray() |
237 | 237 | */ |
238 | - public function getFieldsArray($result, $make_lower_case = false) |
|
239 | - { |
|
238 | + public function getFieldsArray($result, $make_lower_case = false) |
|
239 | + { |
|
240 | 240 | $field_array = array(); |
241 | 241 | |
242 | 242 | if ( !$result ) { |
243 | - return false; |
|
243 | + return false; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | foreach ( sqlsrv_field_metadata($result) as $fieldMetadata ) { |
@@ -252,16 +252,16 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | return $field_array; |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * @see DBManager::fetchRow() |
|
259 | - */ |
|
260 | - public function fetchRow($result) |
|
261 | - { |
|
262 | - if (empty($result)) return false; |
|
257 | + /** |
|
258 | + * @see DBManager::fetchRow() |
|
259 | + */ |
|
260 | + public function fetchRow($result) |
|
261 | + { |
|
262 | + if (empty($result)) return false; |
|
263 | 263 | |
264 | - $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
264 | + $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
265 | 265 | if (empty($row)) { |
266 | 266 | return false; |
267 | 267 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | return $row; |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @see DBManager::convert() |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | return parent::convert($string, $type, $additional_parameters); |
292 | 292 | } |
293 | 293 | |
294 | - /** |
|
294 | + /** |
|
295 | 295 | * Compares two vardefs. Overriding 39098 due to bug: 39098 . IN 6.0 we changed the id columns to dbType = 'id' |
296 | 296 | * for example emails_beans. In 554 the field email_id was nvarchar but in 6.0 since it id dbType = 'id' we would want to alter |
297 | 297 | * it to varchar. This code will prevent it. |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function disconnect() |
319 | 319 | { |
320 | - $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
320 | + $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
321 | 321 | if(!empty($this->database)){ |
322 | 322 | $this->freeResult(); |
323 | 323 | sqlsrv_close($this->database); |
@@ -335,10 +335,10 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * Detect if no clustered index has been created for a table; if none created then just pick the first index and make it that |
|
340 | - * |
|
341 | - * @see MssqlHelper::indexSQL() |
|
338 | + /** |
|
339 | + * Detect if no clustered index has been created for a table; if none created then just pick the first index and make it that |
|
340 | + * |
|
341 | + * @see MssqlHelper::indexSQL() |
|
342 | 342 | */ |
343 | 343 | public function getConstraintSql($indices, $table) |
344 | 344 | { |
@@ -378,12 +378,12 @@ discard block |
||
378 | 378 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
379 | 379 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
380 | 380 | } |
381 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | - if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | - $columns[$column_name]['len']='max'; |
|
385 | - } |
|
386 | - } |
|
381 | + elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | + $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | + if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | + $columns[$column_name]['len']='max'; |
|
385 | + } |
|
386 | + } |
|
387 | 387 | elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
388 | 388 | $columns[$column_name]['len']=strtolower($row['LENGTH']); |
389 | 389 | } |
@@ -488,21 +488,21 @@ discard block |
||
488 | 488 | return "TRUNCATE TABLE $name"; |
489 | 489 | } |
490 | 490 | |
491 | - /** |
|
492 | - * (non-PHPdoc) |
|
493 | - * @see DBManager::lastDbError() |
|
494 | - */ |
|
491 | + /** |
|
492 | + * (non-PHPdoc) |
|
493 | + * @see DBManager::lastDbError() |
|
494 | + */ |
|
495 | 495 | public function lastDbError() |
496 | 496 | { |
497 | 497 | $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); |
498 | 498 | if(empty($errors)) return false; |
499 | 499 | global $app_strings; |
500 | 500 | if (empty($app_strings) |
501 | - or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
502 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
501 | + or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
502 | + or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
503 | 503 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
504 | 504 | //only if connection if made before languge is set. |
505 | - return false; |
|
505 | + return false; |
|
506 | 506 | } |
507 | 507 | $messages = array(); |
508 | 508 | foreach($errors as $error) { |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | } |
516 | 516 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
517 | 517 | $sqlpos2 = strpos($sqlmsg, $app_strings['ERR_MSSQL_WARNING']); |
518 | - if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
518 | + if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
519 | 519 | continue; |
520 | 520 | } |
521 | 521 | $messages[] = $sqlmsg; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | "ReturnDatesAsStrings" => true, |
176 | 176 | "MultipleActiveResultSets" => true, |
177 | 177 | ); |
178 | - if(!empty($configOptions['db_name'])) { |
|
178 | + if (!empty($configOptions['db_name'])) { |
|
179 | 179 | $options["Database"] = $configOptions['db_name']; |
180 | 180 | } |
181 | 181 | $this->database = sqlsrv_connect($connect_param, $options); |
182 | - if(empty($this->database)) { |
|
182 | + if (empty($this->database)) { |
|
183 | 183 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name']."."); |
184 | - if($dieOnError) { |
|
185 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
184 | + if ($dieOnError) { |
|
185 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
186 | 186 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
187 | 187 | } else { |
188 | 188 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | } |
194 | 194 | |
195 | - if($this->checkError('Could Not Connect:', $dieOnError)) |
|
195 | + if ($this->checkError('Could Not Connect:', $dieOnError)) |
|
196 | 196 | $GLOBALS['log']->info("connected to db"); |
197 | 197 | |
198 | 198 | sqlsrv_query($this->database, 'SET DATEFORMAT mdy'); |
@@ -208,26 +208,26 @@ discard block |
||
208 | 208 | */ |
209 | 209 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
210 | 210 | { |
211 | - if(is_array($sql)) { |
|
211 | + if (is_array($sql)) { |
|
212 | 212 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
213 | 213 | } |
214 | 214 | $sql = $this->_appendN($sql); |
215 | 215 | |
216 | 216 | $this->countQuery($sql); |
217 | - $GLOBALS['log']->info('Query:' . $sql); |
|
217 | + $GLOBALS['log']->info('Query:'.$sql); |
|
218 | 218 | $this->checkConnection(); |
219 | 219 | $this->query_time = microtime(true); |
220 | 220 | |
221 | - $result = $suppress?@sqlsrv_query($this->database, $sql):sqlsrv_query($this->database, $sql); |
|
221 | + $result = $suppress ? @sqlsrv_query($this->database, $sql) : sqlsrv_query($this->database, $sql); |
|
222 | 222 | |
223 | 223 | $this->query_time = microtime(true) - $this->query_time; |
224 | 224 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
225 | 225 | |
226 | 226 | |
227 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
227 | + $this->checkError($msg.' Query Failed:'.$sql.'::', $dieOnError); |
|
228 | 228 | |
229 | 229 | //suppress non error messages |
230 | - sqlsrv_configure('WarningsReturnAsErrors',false); |
|
230 | + sqlsrv_configure('WarningsReturnAsErrors', false); |
|
231 | 231 | |
232 | 232 | return $result; |
233 | 233 | } |
@@ -239,13 +239,13 @@ discard block |
||
239 | 239 | { |
240 | 240 | $field_array = array(); |
241 | 241 | |
242 | - if ( !$result ) { |
|
242 | + if (!$result) { |
|
243 | 243 | return false; |
244 | 244 | } |
245 | 245 | |
246 | - foreach ( sqlsrv_field_metadata($result) as $fieldMetadata ) { |
|
246 | + foreach (sqlsrv_field_metadata($result) as $fieldMetadata) { |
|
247 | 247 | $key = $fieldMetadata['Name']; |
248 | - if($make_lower_case==true) |
|
248 | + if ($make_lower_case == true) |
|
249 | 249 | $key = strtolower($key); |
250 | 250 | |
251 | 251 | $field_array[] = $key; |
@@ -261,12 +261,12 @@ discard block |
||
261 | 261 | { |
262 | 262 | if (empty($result)) return false; |
263 | 263 | |
264 | - $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
264 | + $row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC); |
|
265 | 265 | if (empty($row)) { |
266 | 266 | return false; |
267 | 267 | } |
268 | 268 | |
269 | - foreach($row as $key => $column) { |
|
269 | + foreach ($row as $key => $column) { |
|
270 | 270 | // MSSQL returns a space " " when a varchar column is empty ("") and not null. |
271 | 271 | // We need to strip empty spaces |
272 | 272 | // notice we only strip if one space is returned. we do not want to strip |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | */ |
285 | 285 | public function convert($string, $type, array $additional_parameters = array()) |
286 | 286 | { |
287 | - if ( $type == 'datetime') |
|
287 | + if ($type == 'datetime') |
|
288 | 288 | // see http://msdn.microsoft.com/en-us/library/ms187928.aspx for details |
289 | 289 | return "CONVERT(datetime,$string,120)"; |
290 | 290 | else |
@@ -300,10 +300,10 @@ discard block |
||
300 | 300 | * @param array $fielddef2 |
301 | 301 | * @return bool true if they match, false if they don't |
302 | 302 | */ |
303 | - public function compareVarDefs($fielddef1,$fielddef2, $ignoreName = false) |
|
303 | + public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
|
304 | 304 | { |
305 | - if((isset($fielddef2['dbType']) && $fielddef2['dbType'] == 'id') || preg_match('/(_id$|^id$)/', $fielddef2['name'])){ |
|
306 | - if(isset($fielddef1['type']) && isset($fielddef2['type'])){ |
|
305 | + if ((isset($fielddef2['dbType']) && $fielddef2['dbType'] == 'id') || preg_match('/(_id$|^id$)/', $fielddef2['name'])) { |
|
306 | + if (isset($fielddef1['type']) && isset($fielddef2['type'])) { |
|
307 | 307 | $fielddef2['type'] = $fielddef1['type']; |
308 | 308 | } |
309 | 309 | } |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function disconnect() |
319 | 319 | { |
320 | 320 | $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
321 | - if(!empty($this->database)){ |
|
321 | + if (!empty($this->database)) { |
|
322 | 322 | $this->freeResult(); |
323 | 323 | sqlsrv_close($this->database); |
324 | 324 | $this->database = null; |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | */ |
331 | 331 | protected function freeDbResult($dbResult) |
332 | 332 | { |
333 | - if(!empty($dbResult)) |
|
333 | + if (!empty($dbResult)) |
|
334 | 334 | sqlsrv_free_stmt($dbResult); |
335 | 335 | } |
336 | 336 | |
@@ -342,19 +342,19 @@ discard block |
||
342 | 342 | */ |
343 | 343 | public function getConstraintSql($indices, $table) |
344 | 344 | { |
345 | - if ( $this->doesTableHaveAClusteredIndexDefined($table) ) { |
|
345 | + if ($this->doesTableHaveAClusteredIndexDefined($table)) { |
|
346 | 346 | return parent::getConstraintSql($indices, $table); |
347 | 347 | } |
348 | 348 | |
349 | 349 | // check to see if one of the passed in indices is a primary one; if so we can bail as well |
350 | - foreach ( $indices as $index ) { |
|
351 | - if ( $index['type'] == 'primary' ) { |
|
350 | + foreach ($indices as $index) { |
|
351 | + if ($index['type'] == 'primary') { |
|
352 | 352 | return parent::getConstraintSql($indices, $table); |
353 | 353 | } |
354 | 354 | } |
355 | 355 | |
356 | 356 | // Change the first index listed to be a clustered one instead ( so we have at least one for the table ) |
357 | - if ( isset($indices[0]) ) { |
|
357 | + if (isset($indices[0])) { |
|
358 | 358 | $indices[0]['type'] = 'clustered'; |
359 | 359 | } |
360 | 360 | |
@@ -370,41 +370,41 @@ discard block |
||
370 | 370 | $result = $this->query("sp_columns_90 $tablename"); |
371 | 371 | |
372 | 372 | $columns = array(); |
373 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
373 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
374 | 374 | $column_name = strtolower($row['COLUMN_NAME']); |
375 | - $columns[$column_name]['name']=$column_name; |
|
376 | - $columns[$column_name]['type']=strtolower($row['TYPE_NAME']); |
|
377 | - if ( $row['TYPE_NAME'] == 'decimal' ) { |
|
378 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
379 | - $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
|
375 | + $columns[$column_name]['name'] = $column_name; |
|
376 | + $columns[$column_name]['type'] = strtolower($row['TYPE_NAME']); |
|
377 | + if ($row['TYPE_NAME'] == 'decimal') { |
|
378 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
379 | + $columns[$column_name]['len'] .= ','.strtolower($row['SCALE']); |
|
380 | 380 | } |
381 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | - if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | - $columns[$column_name]['len']='max'; |
|
381 | + elseif (in_array($row['TYPE_NAME'], array('nchar', 'nvarchar'))) { |
|
382 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
383 | + if ($row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0') { |
|
384 | + $columns[$column_name]['len'] = 'max'; |
|
385 | 385 | } |
386 | 386 | } |
387 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
|
388 | - $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
387 | + elseif (!in_array($row['TYPE_NAME'], array('datetime', 'text'))) { |
|
388 | + $columns[$column_name]['len'] = strtolower($row['LENGTH']); |
|
389 | 389 | } |
390 | - if ( stristr($row['TYPE_NAME'],'identity') ) { |
|
390 | + if (stristr($row['TYPE_NAME'], 'identity')) { |
|
391 | 391 | $columns[$column_name]['auto_increment'] = '1'; |
392 | - $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
|
392 | + $columns[$column_name]['type'] = str_replace(' identity', '', strtolower($row['TYPE_NAME'])); |
|
393 | 393 | } |
394 | 394 | |
395 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
395 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'], 'PRI'))) |
|
396 | 396 | $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
397 | 397 | |
398 | 398 | $column_def = 1; |
399 | - if ( strtolower($tablename) == 'relationships' ) { |
|
399 | + if (strtolower($tablename) == 'relationships') { |
|
400 | 400 | $column_def = $this->getOne("select cdefault from syscolumns where id = object_id('relationships') and name = '$column_name'"); |
401 | 401 | } |
402 | - if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
402 | + if ($column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
403 | 403 | $matches = array(); |
404 | - $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
|
405 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
404 | + $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'], ENT_QUOTES); |
|
405 | + if (preg_match('/\([\(|\'](.*)[\)|\']\)/i', $row['COLUMN_DEF'], $matches)) |
|
406 | 406 | $columns[$column_name]['default'] = $matches[1]; |
407 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
407 | + elseif (preg_match('/\(N\'(.*)\'\)/i', $row['COLUMN_DEF'], $matches)) |
|
408 | 408 | $columns[$column_name]['default'] = $matches[1]; |
409 | 409 | else |
410 | 410 | $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | EOSQL; |
431 | 431 | |
432 | 432 | $result = $this->getOne($query); |
433 | - if ( !$result ) { |
|
433 | + if (!$result) { |
|
434 | 434 | return false; |
435 | 435 | } |
436 | 436 | |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | EOSQL; |
454 | 454 | |
455 | 455 | $result = $this->getOne($query); |
456 | - if ( !$result ) { |
|
456 | + if (!$result) { |
|
457 | 457 | return false; |
458 | 458 | } |
459 | 459 | |
@@ -466,10 +466,10 @@ discard block |
||
466 | 466 | * @see DBManager::changeColumnSQL() |
467 | 467 | * @see MssqlHelper::changeColumnSQL() |
468 | 468 | */ |
469 | - protected function changeColumnSQL($tablename,$fieldDefs, $action, $ignoreRequired = false) |
|
469 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
470 | 470 | { |
471 | 471 | $sql = ''; |
472 | - if ( $action == 'drop' && $this->doesTableHaveAFulltextIndexDefined($tablename) ) { |
|
472 | + if ($action == 'drop' && $this->doesTableHaveAFulltextIndexDefined($tablename)) { |
|
473 | 473 | $sql .= "DROP FULLTEXT INDEX ON {$tablename}"; |
474 | 474 | } |
475 | 475 | |
@@ -495,33 +495,33 @@ discard block |
||
495 | 495 | public function lastDbError() |
496 | 496 | { |
497 | 497 | $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); |
498 | - if(empty($errors)) return false; |
|
498 | + if (empty($errors)) return false; |
|
499 | 499 | global $app_strings; |
500 | 500 | if (empty($app_strings) |
501 | 501 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
502 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
502 | + or !isset($app_strings['ERR_MSSQL_WARNING'])) { |
|
503 | 503 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
504 | 504 | //only if connection if made before languge is set. |
505 | 505 | return false; |
506 | 506 | } |
507 | 507 | $messages = array(); |
508 | - foreach($errors as $error) { |
|
508 | + foreach ($errors as $error) { |
|
509 | 509 | $sqlmsg = $error['message']; |
510 | 510 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
511 | 511 | $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
512 | 512 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
513 | - if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
|
513 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) { |
|
514 | 514 | continue; |
515 | 515 | } |
516 | 516 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
517 | 517 | $sqlpos2 = strpos($sqlmsg, $app_strings['ERR_MSSQL_WARNING']); |
518 | - if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
518 | + if ($sqlpos !== false || $sqlpos2 !== false) { |
|
519 | 519 | continue; |
520 | 520 | } |
521 | 521 | $messages[] = $sqlmsg; |
522 | 522 | } |
523 | 523 | |
524 | - if(!empty($messages)) { |
|
524 | + if (!empty($messages)) { |
|
525 | 525 | return join("\n", $messages); |
526 | 526 | } |
527 | 527 | return false; |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | protected function verifyGenericQueryRollback($type, $table, $query) |
549 | 549 | { |
550 | 550 | $this->log->debug("verifying $type statement"); |
551 | - if(!sqlsrv_begin_transaction($this->database)) { |
|
551 | + if (!sqlsrv_begin_transaction($this->database)) { |
|
552 | 552 | return "Failed to create transaction"; |
553 | 553 | } |
554 | 554 | $this->query($query, false); |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
3 | + die('Not A Valid Entry Point'); |
|
4 | +} |
|
3 | 5 | /********************************************************************************* |
4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -153,16 +155,18 @@ discard block |
||
153 | 155 | { |
154 | 156 | global $sugar_config; |
155 | 157 | |
156 | - if (is_null($configOptions)) |
|
157 | - $configOptions = $sugar_config['dbconfig']; |
|
158 | + if (is_null($configOptions)) { |
|
159 | + $configOptions = $sugar_config['dbconfig']; |
|
160 | + } |
|
158 | 161 | |
159 | 162 | //set the connections parameters |
160 | 163 | $connect_param = ''; |
161 | 164 | $configOptions['db_host_instance'] = trim($configOptions['db_host_instance']); |
162 | - if (empty($configOptions['db_host_instance'])) |
|
163 | - $connect_param = $configOptions['db_host_name']; |
|
164 | - else |
|
165 | - $connect_param = $configOptions['db_host_name']."\\".$configOptions['db_host_instance']; |
|
165 | + if (empty($configOptions['db_host_instance'])) { |
|
166 | + $connect_param = $configOptions['db_host_name']; |
|
167 | + } else { |
|
168 | + $connect_param = $configOptions['db_host_name']."\\".$configOptions['db_host_instance']; |
|
169 | + } |
|
166 | 170 | |
167 | 171 | /* |
168 | 172 | * Don't try to specifically use a persistent connection |
@@ -192,8 +196,9 @@ discard block |
||
192 | 196 | } |
193 | 197 | } |
194 | 198 | |
195 | - if($this->checkError('Could Not Connect:', $dieOnError)) |
|
196 | - $GLOBALS['log']->info("connected to db"); |
|
199 | + if($this->checkError('Could Not Connect:', $dieOnError)) { |
|
200 | + $GLOBALS['log']->info("connected to db"); |
|
201 | + } |
|
197 | 202 | |
198 | 203 | sqlsrv_query($this->database, 'SET DATEFORMAT mdy'); |
199 | 204 | |
@@ -245,8 +250,9 @@ discard block |
||
245 | 250 | |
246 | 251 | foreach ( sqlsrv_field_metadata($result) as $fieldMetadata ) { |
247 | 252 | $key = $fieldMetadata['Name']; |
248 | - if($make_lower_case==true) |
|
249 | - $key = strtolower($key); |
|
253 | + if($make_lower_case==true) { |
|
254 | + $key = strtolower($key); |
|
255 | + } |
|
250 | 256 | |
251 | 257 | $field_array[] = $key; |
252 | 258 | } |
@@ -259,7 +265,9 @@ discard block |
||
259 | 265 | */ |
260 | 266 | public function fetchRow($result) |
261 | 267 | { |
262 | - if (empty($result)) return false; |
|
268 | + if (empty($result)) { |
|
269 | + return false; |
|
270 | + } |
|
263 | 271 | |
264 | 272 | $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
265 | 273 | if (empty($row)) { |
@@ -284,11 +292,12 @@ discard block |
||
284 | 292 | */ |
285 | 293 | public function convert($string, $type, array $additional_parameters = array()) |
286 | 294 | { |
287 | - if ( $type == 'datetime') |
|
288 | - // see http://msdn.microsoft.com/en-us/library/ms187928.aspx for details |
|
295 | + if ( $type == 'datetime') { |
|
296 | + // see http://msdn.microsoft.com/en-us/library/ms187928.aspx for details |
|
289 | 297 | return "CONVERT(datetime,$string,120)"; |
290 | - else |
|
291 | - return parent::convert($string, $type, $additional_parameters); |
|
298 | + } else { |
|
299 | + return parent::convert($string, $type, $additional_parameters); |
|
300 | + } |
|
292 | 301 | } |
293 | 302 | |
294 | 303 | /** |
@@ -330,8 +339,9 @@ discard block |
||
330 | 339 | */ |
331 | 340 | protected function freeDbResult($dbResult) |
332 | 341 | { |
333 | - if(!empty($dbResult)) |
|
334 | - sqlsrv_free_stmt($dbResult); |
|
342 | + if(!empty($dbResult)) { |
|
343 | + sqlsrv_free_stmt($dbResult); |
|
344 | + } |
|
335 | 345 | } |
336 | 346 | |
337 | 347 | |
@@ -377,14 +387,12 @@ discard block |
||
377 | 387 | if ( $row['TYPE_NAME'] == 'decimal' ) { |
378 | 388 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
379 | 389 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
380 | - } |
|
381 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
390 | + } elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | 391 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
383 | 392 | if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
384 | 393 | $columns[$column_name]['len']='max'; |
385 | 394 | } |
386 | - } |
|
387 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
|
395 | + } elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
|
388 | 396 | $columns[$column_name]['len']=strtolower($row['LENGTH']); |
389 | 397 | } |
390 | 398 | if ( stristr($row['TYPE_NAME'],'identity') ) { |
@@ -392,8 +400,9 @@ discard block |
||
392 | 400 | $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
393 | 401 | } |
394 | 402 | |
395 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
396 | - $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
|
403 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) { |
|
404 | + $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
|
405 | + } |
|
397 | 406 | |
398 | 407 | $column_def = 1; |
399 | 408 | if ( strtolower($tablename) == 'relationships' ) { |
@@ -402,12 +411,13 @@ discard block |
||
402 | 411 | if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
403 | 412 | $matches = array(); |
404 | 413 | $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
405 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
406 | - $columns[$column_name]['default'] = $matches[1]; |
|
407 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
408 | - $columns[$column_name]['default'] = $matches[1]; |
|
409 | - else |
|
410 | - $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
|
414 | + if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) { |
|
415 | + $columns[$column_name]['default'] = $matches[1]; |
|
416 | + } elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) { |
|
417 | + $columns[$column_name]['default'] = $matches[1]; |
|
418 | + } else { |
|
419 | + $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
|
420 | + } |
|
411 | 421 | } |
412 | 422 | } |
413 | 423 | return $columns; |
@@ -495,7 +505,9 @@ discard block |
||
495 | 505 | public function lastDbError() |
496 | 506 | { |
497 | 507 | $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); |
498 | - if(empty($errors)) return false; |
|
508 | + if(empty($errors)) { |
|
509 | + return false; |
|
510 | + } |
|
499 | 511 | global $app_strings; |
500 | 512 | if (empty($app_strings) |
501 | 513 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
@@ -1304,24 +1304,24 @@ discard block |
||
1304 | 1304 | protected function alterSQLRep($action, array $def, $ignoreRequired, $tablename) |
1305 | 1305 | { |
1306 | 1306 | switch($action){ |
1307 | - case 'add': |
|
1308 | - $f_def=$this->oneColumnSQLRep($def, $ignoreRequired,$tablename,false); |
|
1309 | - return "ADD " . $f_def; |
|
1310 | - break; |
|
1311 | - case 'drop': |
|
1312 | - return "DROP COLUMN " . $def['name']; |
|
1313 | - break; |
|
1314 | - case 'modify': |
|
1315 | - //You cannot specify a default value for a column for MSSQL |
|
1316 | - $f_def = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true); |
|
1317 | - $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '. |
|
1318 | - $f_def['required'].' '.$f_def['auto_increment']."\n"; |
|
1319 | - if (!empty( $f_def['default'])) |
|
1320 | - $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1321 | - return $f_stmt; |
|
1322 | - break; |
|
1323 | - default: |
|
1324 | - return ''; |
|
1307 | + case 'add': |
|
1308 | + $f_def=$this->oneColumnSQLRep($def, $ignoreRequired,$tablename,false); |
|
1309 | + return "ADD " . $f_def; |
|
1310 | + break; |
|
1311 | + case 'drop': |
|
1312 | + return "DROP COLUMN " . $def['name']; |
|
1313 | + break; |
|
1314 | + case 'modify': |
|
1315 | + //You cannot specify a default value for a column for MSSQL |
|
1316 | + $f_def = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true); |
|
1317 | + $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '. |
|
1318 | + $f_def['required'].' '.$f_def['auto_increment']."\n"; |
|
1319 | + if (!empty( $f_def['default'])) |
|
1320 | + $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1321 | + return $f_stmt; |
|
1322 | + break; |
|
1323 | + default: |
|
1324 | + return ''; |
|
1325 | 1325 | } |
1326 | 1326 | } |
1327 | 1327 | |
@@ -1511,59 +1511,59 @@ discard block |
||
1511 | 1511 | |
1512 | 1512 | switch ($type){ |
1513 | 1513 | // generic indices |
1514 | - case 'index': |
|
1515 | - case 'alternate_key': |
|
1516 | - if ($drop) |
|
1517 | - $sql = "DROP INDEX {$name} ON {$table}"; |
|
1518 | - else |
|
1519 | - $sql = "CREATE INDEX {$name} ON {$table} ({$fields})"; |
|
1520 | - break; |
|
1521 | - case 'clustered': |
|
1522 | - if ($drop) |
|
1523 | - $sql = "DROP INDEX {$name} ON {$table}"; |
|
1524 | - else |
|
1525 | - $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)"; |
|
1526 | - break; |
|
1527 | - // constraints as indices |
|
1528 | - case 'unique': |
|
1529 | - if ($drop) |
|
1530 | - $sql = "ALTER TABLE {$table} DROP CONSTRAINT $name"; |
|
1531 | - else |
|
1532 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE ({$fields})"; |
|
1533 | - break; |
|
1534 | - case 'primary': |
|
1535 | - if ($drop) |
|
1536 | - $sql = "ALTER TABLE {$table} DROP CONSTRAINT {$name}"; |
|
1537 | - else |
|
1538 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} PRIMARY KEY ({$fields})"; |
|
1539 | - break; |
|
1540 | - case 'foreign': |
|
1541 | - if ($drop) |
|
1542 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
1543 | - else |
|
1544 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} FOREIGN KEY ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignFields']})"; |
|
1545 | - break; |
|
1546 | - case 'fulltext': |
|
1547 | - if ($this->full_text_indexing_enabled() && $drop) { |
|
1548 | - $sql = "DROP FULLTEXT INDEX ON {$table}"; |
|
1549 | - } elseif ($this->full_text_indexing_enabled()) { |
|
1550 | - $catalog_name=$this->ftsCatalogName(); |
|
1551 | - if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1552 | - $catalog_name = $definition['catalog_name']; |
|
1553 | - |
|
1554 | - $language = "Language 1033"; |
|
1555 | - if (isset($definition['language']) && !empty($definition['language'])) |
|
1556 | - $language = "Language " . $definition['language']; |
|
1557 | - |
|
1558 | - $key_index = $definition['key_index']; |
|
1559 | - |
|
1560 | - $change_tracking = "auto"; |
|
1561 | - if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) |
|
1562 | - $change_tracking = $definition['change_tracking']; |
|
1563 | - |
|
1564 | - $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ; |
|
1565 | - } |
|
1566 | - break; |
|
1514 | + case 'index': |
|
1515 | + case 'alternate_key': |
|
1516 | + if ($drop) |
|
1517 | + $sql = "DROP INDEX {$name} ON {$table}"; |
|
1518 | + else |
|
1519 | + $sql = "CREATE INDEX {$name} ON {$table} ({$fields})"; |
|
1520 | + break; |
|
1521 | + case 'clustered': |
|
1522 | + if ($drop) |
|
1523 | + $sql = "DROP INDEX {$name} ON {$table}"; |
|
1524 | + else |
|
1525 | + $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)"; |
|
1526 | + break; |
|
1527 | + // constraints as indices |
|
1528 | + case 'unique': |
|
1529 | + if ($drop) |
|
1530 | + $sql = "ALTER TABLE {$table} DROP CONSTRAINT $name"; |
|
1531 | + else |
|
1532 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE ({$fields})"; |
|
1533 | + break; |
|
1534 | + case 'primary': |
|
1535 | + if ($drop) |
|
1536 | + $sql = "ALTER TABLE {$table} DROP CONSTRAINT {$name}"; |
|
1537 | + else |
|
1538 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} PRIMARY KEY ({$fields})"; |
|
1539 | + break; |
|
1540 | + case 'foreign': |
|
1541 | + if ($drop) |
|
1542 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
1543 | + else |
|
1544 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} FOREIGN KEY ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignFields']})"; |
|
1545 | + break; |
|
1546 | + case 'fulltext': |
|
1547 | + if ($this->full_text_indexing_enabled() && $drop) { |
|
1548 | + $sql = "DROP FULLTEXT INDEX ON {$table}"; |
|
1549 | + } elseif ($this->full_text_indexing_enabled()) { |
|
1550 | + $catalog_name=$this->ftsCatalogName(); |
|
1551 | + if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1552 | + $catalog_name = $definition['catalog_name']; |
|
1553 | + |
|
1554 | + $language = "Language 1033"; |
|
1555 | + if (isset($definition['language']) && !empty($definition['language'])) |
|
1556 | + $language = "Language " . $definition['language']; |
|
1557 | + |
|
1558 | + $key_index = $definition['key_index']; |
|
1559 | + |
|
1560 | + $change_tracking = "auto"; |
|
1561 | + if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) |
|
1562 | + $change_tracking = $definition['change_tracking']; |
|
1563 | + |
|
1564 | + $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ; |
|
1565 | + } |
|
1566 | + break; |
|
1567 | 1567 | } |
1568 | 1568 | return $sql; |
1569 | 1569 | } |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | 'relate' => 'varchar', |
141 | 141 | 'multienum'=> 'text', |
142 | 142 | 'html' => 'text', |
143 | - 'longhtml' => 'text', |
|
144 | - 'datetime' => 'datetime', |
|
143 | + 'longhtml' => 'text', |
|
144 | + 'datetime' => 'datetime', |
|
145 | 145 | 'datetimecombo' => 'datetime', |
146 | 146 | 'time' => 'datetime', |
147 | 147 | 'bool' => 'bit', |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | 'url' => 'varchar', |
157 | 157 | 'encrypt' => 'varchar', |
158 | 158 | 'file' => 'varchar', |
159 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
159 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | protected $connectOptions = null; |
@@ -236,16 +236,16 @@ discard block |
||
236 | 236 | //it will throw an Unable to select database message. |
237 | 237 | |
238 | 238 | if(!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)){ |
239 | - $connected = false; |
|
240 | - for($i=0;$i<5;$i++){ |
|
241 | - usleep(200000); |
|
242 | - if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
243 | - $connected = true; |
|
244 | - break; |
|
245 | - } |
|
246 | - } |
|
247 | - if(!$connected){ |
|
248 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
239 | + $connected = false; |
|
240 | + for($i=0;$i<5;$i++){ |
|
241 | + usleep(200000); |
|
242 | + if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
243 | + $connected = true; |
|
244 | + break; |
|
245 | + } |
|
246 | + } |
|
247 | + if(!$connected){ |
|
248 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
249 | 249 | if($dieOnError) { |
250 | 250 | if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
251 | 251 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | } else { |
256 | 256 | return false; |
257 | 257 | } |
258 | - } |
|
259 | - } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | if(!$this->checkError('Could Not Connect', $dieOnError)) |
262 | 262 | $GLOBALS['log']->info("connected to db"); |
@@ -267,18 +267,18 @@ discard block |
||
267 | 267 | return true; |
268 | 268 | } |
269 | 269 | |
270 | - /** |
|
270 | + /** |
|
271 | 271 | * @see DBManager::version() |
272 | 272 | */ |
273 | 273 | public function version() |
274 | 274 | { |
275 | 275 | return $this->getOne("SELECT @@VERSION as version"); |
276 | - } |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
278 | + /** |
|
279 | 279 | * @see DBManager::query() |
280 | - */ |
|
281 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
280 | + */ |
|
281 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
282 | 282 | { |
283 | 283 | if(is_array($sql)) { |
284 | 284 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | if ((substr_count($sql, "'") & 1)) |
288 | 288 | $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
289 | 289 | |
290 | - $sql = $this->_appendN($sql); |
|
290 | + $sql = $this->_appendN($sql); |
|
291 | 291 | |
292 | 292 | $GLOBALS['log']->info('Query:' . $sql); |
293 | 293 | $this->checkConnection(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | $this->query_time = microtime(true); |
296 | 296 | |
297 | 297 | // Bug 34892 - Clear out previous error message by checking the @@ERROR global variable |
298 | - @mssql_query("SELECT @@ERROR", $this->database); |
|
298 | + @mssql_query("SELECT @@ERROR", $this->database); |
|
299 | 299 | |
300 | 300 | $result = $suppress?@mssql_query($sql, $this->database):mssql_query($sql, $this->database); |
301 | 301 | |
@@ -305,18 +305,18 @@ discard block |
||
305 | 305 | // not affect the functionality of the query |
306 | 306 | $sqlmsg = mssql_get_last_message(); |
307 | 307 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
308 | - $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
|
309 | - $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
|
308 | + $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
|
309 | + $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
|
310 | 310 | |
311 | - if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
|
312 | - $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
313 | - else { |
|
314 | - $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | - if($dieOnError) |
|
316 | - sugar_die('SQL Error : ' . $sqlmsg); |
|
317 | - else |
|
318 | - echo 'SQL Error : ' . $sqlmsg; |
|
319 | - } |
|
311 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
|
312 | + $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
313 | + else { |
|
314 | + $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | + if($dieOnError) |
|
316 | + sugar_die('SQL Error : ' . $sqlmsg); |
|
317 | + else |
|
318 | + echo 'SQL Error : ' . $sqlmsg; |
|
319 | + } |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | $this->query_time = microtime(true) - $this->query_time; |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | return $limitUnionSQL; |
427 | 427 | } |
428 | 428 | |
429 | - /** |
|
430 | - * FIXME: verify and thoroughly test this code, these regexps look fishy |
|
429 | + /** |
|
430 | + * FIXME: verify and thoroughly test this code, these regexps look fishy |
|
431 | 431 | * @see DBManager::limitQuery() |
432 | 432 | */ |
433 | 433 | public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | while ($i<$count && $offset<strlen($p_sql)) { |
637 | 637 | if ($offset > strlen($p_sql)) |
638 | 638 | { |
639 | - break; |
|
639 | + break; |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | $beg_sin = strpos($p_sql, $strip_beg, $offset); |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | * @param array $pattern_array |
677 | 677 | * @return string |
678 | 678 | */ |
679 | - private function addPatternToSQL($token, array $pattern_array) |
|
679 | + private function addPatternToSQL($token, array $pattern_array) |
|
680 | 680 | { |
681 | 681 | //strip all single quotes out |
682 | 682 | $pattern_array = array_reverse($pattern_array); |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | * @param string $alias |
696 | 696 | * @return string |
697 | 697 | */ |
698 | - private function getAliasFromSQL($sql, $alias) |
|
698 | + private function getAliasFromSQL($sql, $alias) |
|
699 | 699 | { |
700 | 700 | $matches = array(); |
701 | 701 | preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU',$sql, $matches); |
@@ -797,7 +797,7 @@ discard block |
||
797 | 797 | |
798 | 798 | // If there is no ordering direction (ASC/DESC), use ASC by default |
799 | 799 | if (strpos($orig_order_match, " ") === false) { |
800 | - $orig_order_match .= " ASC"; |
|
800 | + $orig_order_match .= " ASC"; |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | //grab first space in order by |
@@ -821,11 +821,11 @@ discard block |
||
821 | 821 | $lastSpacePos = strrpos($containsColStr, " "); |
822 | 822 | //use positions of column name, space before name, and length of column to find the correct column name |
823 | 823 | $col_name = substr($sql, $lastSpacePos, $colMatchPos-$lastSpacePos+strlen($orderMatch)); |
824 | - //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
|
825 | - $containsCommaPos = strpos($col_name, ","); |
|
826 | - if($containsCommaPos !== false) { |
|
827 | - $col_name = substr($col_name, $containsCommaPos+1); |
|
828 | - } |
|
824 | + //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
|
825 | + $containsCommaPos = strpos($col_name, ","); |
|
826 | + if($containsCommaPos !== false) { |
|
827 | + $col_name = substr($col_name, $containsCommaPos+1); |
|
828 | + } |
|
829 | 829 | //add the "asc/desc" order back |
830 | 830 | $col_name = $col_name. " ". $asc_desc; |
831 | 831 | |
@@ -978,14 +978,14 @@ discard block |
||
978 | 978 | } |
979 | 979 | |
980 | 980 | |
981 | - /** |
|
981 | + /** |
|
982 | 982 | * @see DBManager::getFieldsArray() |
983 | 983 | */ |
984 | - public function getFieldsArray($result, $make_lower_case = false) |
|
985 | - { |
|
986 | - $field_array = array(); |
|
984 | + public function getFieldsArray($result, $make_lower_case = false) |
|
985 | + { |
|
986 | + $field_array = array(); |
|
987 | 987 | |
988 | - if(! isset($result) || empty($result)) |
|
988 | + if(! isset($result) || empty($result)) |
|
989 | 989 | return 0; |
990 | 990 | |
991 | 991 | $i = 0; |
@@ -1002,37 +1002,37 @@ discard block |
||
1002 | 1002 | } |
1003 | 1003 | |
1004 | 1004 | return $field_array; |
1005 | - } |
|
1005 | + } |
|
1006 | 1006 | |
1007 | 1007 | /** |
1008 | 1008 | * @see DBManager::getAffectedRowCount() |
1009 | 1009 | */ |
1010 | - public function getAffectedRowCount($result) |
|
1010 | + public function getAffectedRowCount($result) |
|
1011 | 1011 | { |
1012 | 1012 | return $this->getOne("SELECT @@ROWCOUNT"); |
1013 | 1013 | } |
1014 | 1014 | |
1015 | - /** |
|
1016 | - * @see DBManager::fetchRow() |
|
1017 | - */ |
|
1018 | - public function fetchRow($result) |
|
1019 | - { |
|
1020 | - if (empty($result)) return false; |
|
1015 | + /** |
|
1016 | + * @see DBManager::fetchRow() |
|
1017 | + */ |
|
1018 | + public function fetchRow($result) |
|
1019 | + { |
|
1020 | + if (empty($result)) return false; |
|
1021 | 1021 | |
1022 | 1022 | $row = mssql_fetch_assoc($result); |
1023 | 1023 | //MSSQL returns a space " " when a varchar column is empty ("") and not null. |
1024 | 1024 | //We need to iterate through the returned row array and strip empty spaces |
1025 | 1025 | if(!empty($row)){ |
1026 | 1026 | foreach($row as $key => $column) { |
1027 | - //notice we only strip if one space is returned. we do not want to strip |
|
1028 | - //strings with intentional spaces (" foo ") |
|
1029 | - if (!empty($column) && $column ==" ") { |
|
1030 | - $row[$key] = ''; |
|
1031 | - } |
|
1027 | + //notice we only strip if one space is returned. we do not want to strip |
|
1028 | + //strings with intentional spaces (" foo ") |
|
1029 | + if (!empty($column) && $column ==" ") { |
|
1030 | + $row[$key] = ''; |
|
1031 | + } |
|
1032 | 1032 | } |
1033 | 1033 | } |
1034 | 1034 | return $row; |
1035 | - } |
|
1035 | + } |
|
1036 | 1036 | |
1037 | 1037 | /** |
1038 | 1038 | * @see DBManager::quote() |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | if (!empty($r)) { |
1081 | 1081 | while ($a = $this->fetchByAssoc($r)) { |
1082 | 1082 | $row = array_values($a); |
1083 | - $tables[]=$row[0]; |
|
1083 | + $tables[]=$row[0]; |
|
1084 | 1084 | } |
1085 | 1085 | return $tables; |
1086 | 1086 | } |
@@ -1137,7 +1137,7 @@ discard block |
||
1137 | 1137 | ) |
1138 | 1138 | "; |
1139 | 1139 | //create full text index |
1140 | - $FTSqry[] = "CREATE FULLTEXT INDEX ON fts_wakeup |
|
1140 | + $FTSqry[] = "CREATE FULLTEXT INDEX ON fts_wakeup |
|
1141 | 1141 | ( |
1142 | 1142 | body |
1143 | 1143 | Language 0X0 |
@@ -1206,7 +1206,7 @@ discard block |
||
1206 | 1206 | $len = $this->date_formats[$additional_parameters[0]]; |
1207 | 1207 | return "LEFT(CONVERT(varchar($len),". $string . ",120),$len)"; |
1208 | 1208 | } else { |
1209 | - return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1209 | + return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1210 | 1210 | } |
1211 | 1211 | case 'ifnull': |
1212 | 1212 | if(empty($additional_parameters_string)) { |
@@ -1248,14 +1248,14 @@ discard block |
||
1248 | 1248 | case 'datetime': return substr($string, 0,19); |
1249 | 1249 | case 'date': return substr($string, 0, 10); |
1250 | 1250 | case 'time': return substr($string, 11); |
1251 | - } |
|
1252 | - return $string; |
|
1251 | + } |
|
1252 | + return $string; |
|
1253 | 1253 | } |
1254 | 1254 | |
1255 | 1255 | /** |
1256 | 1256 | * @see DBManager::createTableSQLParams() |
1257 | 1257 | */ |
1258 | - public function createTableSQLParams($tablename, $fieldDefs, $indices) |
|
1258 | + public function createTableSQLParams($tablename, $fieldDefs, $indices) |
|
1259 | 1259 | { |
1260 | 1260 | if (empty($tablename) || empty($fieldDefs)) |
1261 | 1261 | return ''; |
@@ -1333,7 +1333,7 @@ discard block |
||
1333 | 1333 | break; |
1334 | 1334 | default: |
1335 | 1335 | return ''; |
1336 | - } |
|
1336 | + } |
|
1337 | 1337 | } |
1338 | 1338 | |
1339 | 1339 | /** |
@@ -1349,14 +1349,14 @@ discard block |
||
1349 | 1349 | $columns = array(); |
1350 | 1350 | if ($this->isFieldArray($fieldDefs)) { |
1351 | 1351 | foreach ($fieldDefs as $def) |
1352 | - { |
|
1353 | - //if the column is being modified drop the default value |
|
1354 | - //constraint if it exists. alterSQLRep will add the constraint back |
|
1355 | - if (!empty($constraints[$def['name']])) { |
|
1356 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1357 | - } |
|
1358 | - //check to see if we need to drop related indexes before the alter |
|
1359 | - $indices = $this->get_indices($tablename); |
|
1352 | + { |
|
1353 | + //if the column is being modified drop the default value |
|
1354 | + //constraint if it exists. alterSQLRep will add the constraint back |
|
1355 | + if (!empty($constraints[$def['name']])) { |
|
1356 | + $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1357 | + } |
|
1358 | + //check to see if we need to drop related indexes before the alter |
|
1359 | + $indices = $this->get_indices($tablename); |
|
1360 | 1360 | foreach ( $indices as $index ) { |
1361 | 1361 | if ( in_array($def['name'],$index['fields']) ) { |
1362 | 1362 | $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
@@ -1364,16 +1364,16 @@ discard block |
||
1364 | 1364 | } |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1368 | - } |
|
1367 | + $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1368 | + } |
|
1369 | 1369 | } |
1370 | 1370 | else { |
1371 | 1371 | //if the column is being modified drop the default value |
1372 | - //constraint if it exists. alterSQLRep will add the constraint back |
|
1373 | - if (!empty($constraints[$fieldDefs['name']])) { |
|
1374 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1375 | - } |
|
1376 | - //check to see if we need to drop related indexes before the alter |
|
1372 | + //constraint if it exists. alterSQLRep will add the constraint back |
|
1373 | + if (!empty($constraints[$fieldDefs['name']])) { |
|
1374 | + $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1375 | + } |
|
1376 | + //check to see if we need to drop related indexes before the alter |
|
1377 | 1377 | $indices = $this->get_indices($tablename); |
1378 | 1378 | foreach ( $indices as $index ) { |
1379 | 1379 | if ( in_array($fieldDefs['name'],$index['fields']) ) { |
@@ -1383,7 +1383,7 @@ discard block |
||
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | |
1386 | - $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1386 | + $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | $columns = implode(", ", $columns); |
@@ -1394,8 +1394,8 @@ discard block |
||
1394 | 1394 | |
1395 | 1395 | protected function setAutoIncrement($table, $field_name) |
1396 | 1396 | { |
1397 | - return "identity(1,1)"; |
|
1398 | - } |
|
1397 | + return "identity(1,1)"; |
|
1398 | + } |
|
1399 | 1399 | |
1400 | 1400 | /** |
1401 | 1401 | * @see DBManager::setAutoIncrementStart() |
@@ -1404,16 +1404,16 @@ discard block |
||
1404 | 1404 | { |
1405 | 1405 | if($start_value > 1) |
1406 | 1406 | $start_value -= 1; |
1407 | - $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
|
1407 | + $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
|
1408 | 1408 | return true; |
1409 | 1409 | } |
1410 | 1410 | |
1411 | - /** |
|
1411 | + /** |
|
1412 | 1412 | * @see DBManager::getAutoIncrement() |
1413 | 1413 | */ |
1414 | 1414 | public function getAutoIncrement($table, $field_name) |
1415 | 1415 | { |
1416 | - $result = $this->getOne("select IDENT_CURRENT('$table') + IDENT_INCR ( '$table' ) as 'Auto_increment'"); |
|
1416 | + $result = $this->getOne("select IDENT_CURRENT('$table') + IDENT_INCR ( '$table' ) as 'Auto_increment'"); |
|
1417 | 1417 | return $result; |
1418 | 1418 | } |
1419 | 1419 | |
@@ -1468,8 +1468,8 @@ discard block |
||
1468 | 1468 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
1469 | 1469 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
1470 | 1470 | } |
1471 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1472 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1471 | + elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1472 | + $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1473 | 1473 | elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) |
1474 | 1474 | $columns[$column_name]['len']=strtolower($row['LENGTH']); |
1475 | 1475 | if ( stristr($row['TYPE_NAME'],'identity') ) { |
@@ -1596,7 +1596,7 @@ discard block |
||
1596 | 1596 | protected function full_text_indexing_enabled($dbname = null) |
1597 | 1597 | { |
1598 | 1598 | // check to see if we already have install setting in session |
1599 | - if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1599 | + if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1600 | 1600 | $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
1601 | 1601 | |
1602 | 1602 | // check to see if FTS Indexing service is installed |
@@ -1604,27 +1604,27 @@ discard block |
||
1604 | 1604 | return false; |
1605 | 1605 | |
1606 | 1606 | // grab the dbname if it was not passed through |
1607 | - if (empty($dbname)) { |
|
1608 | - global $sugar_config; |
|
1609 | - $dbname = $sugar_config['dbconfig']['db_name']; |
|
1610 | - } |
|
1607 | + if (empty($dbname)) { |
|
1608 | + global $sugar_config; |
|
1609 | + $dbname = $sugar_config['dbconfig']['db_name']; |
|
1610 | + } |
|
1611 | 1611 | //we already know that Indexing service is installed, now check |
1612 | 1612 | //to see if it is enabled |
1613 | - $res = $this->getOne("SELECT DATABASEPROPERTY('$dbname', 'IsFulltextEnabled') ftext"); |
|
1613 | + $res = $this->getOne("SELECT DATABASEPROPERTY('$dbname', 'IsFulltextEnabled') ftext"); |
|
1614 | 1614 | return !empty($res); |
1615 | - } |
|
1615 | + } |
|
1616 | 1616 | |
1617 | 1617 | /** |
1618 | 1618 | * Creates default full text catalog |
1619 | 1619 | */ |
1620 | - protected function create_default_full_text_catalog() |
|
1620 | + protected function create_default_full_text_catalog() |
|
1621 | 1621 | { |
1622 | - if ($this->full_text_indexing_enabled()) { |
|
1623 | - $catalog = $this->ftsCatalogName(); |
|
1622 | + if ($this->full_text_indexing_enabled()) { |
|
1623 | + $catalog = $this->ftsCatalogName(); |
|
1624 | 1624 | $GLOBALS['log']->debug("Creating the default catalog for full-text indexing, $catalog"); |
1625 | 1625 | |
1626 | 1626 | //drop catalog if exists. |
1627 | - $ret = $this->query(" |
|
1627 | + $ret = $this->query(" |
|
1628 | 1628 | if not exists( |
1629 | 1629 | select * |
1630 | 1630 | from sys.fulltext_catalogs |
@@ -1632,11 +1632,11 @@ discard block |
||
1632 | 1632 | ) |
1633 | 1633 | CREATE FULLTEXT CATALOG $catalog"); |
1634 | 1634 | |
1635 | - if (empty($ret)) { |
|
1636 | - $GLOBALS['log']->error("Error creating default full-text catalog, $catalog"); |
|
1637 | - } |
|
1638 | - } |
|
1639 | - } |
|
1635 | + if (empty($ret)) { |
|
1636 | + $GLOBALS['log']->error("Error creating default full-text catalog, $catalog"); |
|
1637 | + } |
|
1638 | + } |
|
1639 | + } |
|
1640 | 1640 | |
1641 | 1641 | /** |
1642 | 1642 | * Function returns name of the constraint automatically generated by sql-server. |
@@ -1646,7 +1646,7 @@ discard block |
||
1646 | 1646 | * @param string $column |
1647 | 1647 | * @return string |
1648 | 1648 | */ |
1649 | - private function get_field_default_constraint_name($table, $column = null) |
|
1649 | + private function get_field_default_constraint_name($table, $column = null) |
|
1650 | 1650 | { |
1651 | 1651 | static $results = array(); |
1652 | 1652 | |
@@ -1681,7 +1681,7 @@ discard block |
||
1681 | 1681 | } |
1682 | 1682 | |
1683 | 1683 | return null; |
1684 | - } |
|
1684 | + } |
|
1685 | 1685 | |
1686 | 1686 | /** |
1687 | 1687 | * @see DBManager::massageFieldDef() |
@@ -1703,7 +1703,7 @@ discard block |
||
1703 | 1703 | case 'varchar' : |
1704 | 1704 | case 'nvarchar' : |
1705 | 1705 | $fieldDef['len'] = $this->isTextType($fieldDef['dbType']) ? 'max' : '255'; |
1706 | - break; |
|
1706 | + break; |
|
1707 | 1707 | case 'image' : $fieldDef['len'] = '2147483647'; break; |
1708 | 1708 | case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
1709 | 1709 | } |
@@ -1712,7 +1712,7 @@ discard block |
||
1712 | 1712 | && empty($fieldDef['precision']) |
1713 | 1713 | && !strpos($fieldDef['len'], ',')) |
1714 | 1714 | { |
1715 | - $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
|
1715 | + $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
|
1716 | 1716 | } |
1717 | 1717 | |
1718 | 1718 | if(empty($fieldDef['default']) |
@@ -1720,8 +1720,8 @@ discard block |
||
1720 | 1720 | { |
1721 | 1721 | $fieldDef['default'] = '0'; |
1722 | 1722 | } |
1723 | - if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1724 | - $fieldDef['default'] = ''; |
|
1723 | + if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1724 | + $fieldDef['default'] = ''; |
|
1725 | 1725 | // if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
1726 | 1726 | // $fieldDef['len'] = '1'; |
1727 | 1727 | // if ($fieldDef['type'] == 'bool' && empty($fieldDef['len']) ) |
@@ -1750,30 +1750,30 @@ discard block |
||
1750 | 1750 | */ |
1751 | 1751 | protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
1752 | 1752 | { |
1753 | - //Bug 25814 |
|
1754 | - if(isset($fieldDef['name'])){ |
|
1755 | - $colType = $this->getFieldType($fieldDef); |
|
1756 | - if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1757 | - $fieldDef['len'] = min($fieldDef['len'],38); |
|
1758 | - } |
|
1759 | - //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
|
1760 | - if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1761 | - unset($fieldDef['len']); |
|
1762 | - } |
|
1763 | - } |
|
1764 | - |
|
1765 | - // always return as array for post-processing |
|
1766 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
1767 | - |
|
1768 | - // Bug 24307 - Don't add precision for float fields. |
|
1769 | - if ( stristr($ref['colType'],'float') ) |
|
1770 | - $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1753 | + //Bug 25814 |
|
1754 | + if(isset($fieldDef['name'])){ |
|
1755 | + $colType = $this->getFieldType($fieldDef); |
|
1756 | + if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1757 | + $fieldDef['len'] = min($fieldDef['len'],38); |
|
1758 | + } |
|
1759 | + //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
|
1760 | + if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1761 | + unset($fieldDef['len']); |
|
1762 | + } |
|
1763 | + } |
|
1764 | + |
|
1765 | + // always return as array for post-processing |
|
1766 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
1767 | + |
|
1768 | + // Bug 24307 - Don't add precision for float fields. |
|
1769 | + if ( stristr($ref['colType'],'float') ) |
|
1770 | + $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1771 | 1771 | |
1772 | 1772 | if ( $return_as_array ) |
1773 | 1773 | return $ref; |
1774 | 1774 | else |
1775 | 1775 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
1776 | - } |
|
1776 | + } |
|
1777 | 1777 | |
1778 | 1778 | /** |
1779 | 1779 | * Saves changes to module's audit table |
@@ -1782,13 +1782,13 @@ discard block |
||
1782 | 1782 | * @param array $changes changes |
1783 | 1783 | */ |
1784 | 1784 | public function save_audit_records(SugarBean $bean, $changes) |
1785 | - { |
|
1786 | - //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
|
1787 | - if($changes['data_type'] == 'date'){ |
|
1788 | - $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1789 | - } |
|
1790 | - parent::save_audit_records($bean,$changes); |
|
1791 | - } |
|
1785 | + { |
|
1786 | + //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
|
1787 | + if($changes['data_type'] == 'date'){ |
|
1788 | + $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1789 | + } |
|
1790 | + parent::save_audit_records($bean,$changes); |
|
1791 | + } |
|
1792 | 1792 | |
1793 | 1793 | /** |
1794 | 1794 | * Disconnects from the database |
@@ -1797,7 +1797,7 @@ discard block |
||
1797 | 1797 | */ |
1798 | 1798 | public function disconnect() |
1799 | 1799 | { |
1800 | - $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
1800 | + $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
1801 | 1801 | if(!empty($this->database)){ |
1802 | 1802 | $this->freeResult(); |
1803 | 1803 | mssql_close($this->database); |
@@ -1814,21 +1814,21 @@ discard block |
||
1814 | 1814 | mssql_free_result($dbResult); |
1815 | 1815 | } |
1816 | 1816 | |
1817 | - /** |
|
1818 | - * (non-PHPdoc) |
|
1819 | - * @see DBManager::lastDbError() |
|
1820 | - */ |
|
1817 | + /** |
|
1818 | + * (non-PHPdoc) |
|
1819 | + * @see DBManager::lastDbError() |
|
1820 | + */ |
|
1821 | 1821 | public function lastDbError() |
1822 | 1822 | { |
1823 | 1823 | $sqlmsg = mssql_get_last_message(); |
1824 | 1824 | if(empty($sqlmsg)) return false; |
1825 | 1825 | global $app_strings; |
1826 | 1826 | if (empty($app_strings) |
1827 | - or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
1828 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1827 | + or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
1828 | + or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1829 | 1829 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1830 | 1830 | //only if connection if made before language is set. |
1831 | - return false; |
|
1831 | + return false; |
|
1832 | 1832 | } |
1833 | 1833 | |
1834 | 1834 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
@@ -1837,7 +1837,7 @@ discard block |
||
1837 | 1837 | if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
1838 | 1838 | return false; |
1839 | 1839 | } else { |
1840 | - global $app_strings; |
|
1840 | + global $app_strings; |
|
1841 | 1841 | //ERR_MSSQL_DB_CONTEXT: localized version of 'Changed database context to' message |
1842 | 1842 | if (empty($app_strings) or !isset($app_strings['ERR_MSSQL_DB_CONTEXT'])) { |
1843 | 1843 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
@@ -1853,7 +1853,7 @@ discard block |
||
1853 | 1853 | } |
1854 | 1854 | |
1855 | 1855 | if ( strlen($sqlmsg) > 2 ) { |
1856 | - return "SQL Server error: " . $sqlmsg; |
|
1856 | + return "SQL Server error: " . $sqlmsg; |
|
1857 | 1857 | } |
1858 | 1858 | |
1859 | 1859 | return false; |
@@ -2076,7 +2076,7 @@ discard block |
||
2076 | 2076 | public function installConfig() |
2077 | 2077 | { |
2078 | 2078 | return array( |
2079 | - 'LBL_DBCONFIG_MSG3' => array( |
|
2079 | + 'LBL_DBCONFIG_MSG3' => array( |
|
2080 | 2080 | "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
2081 | 2081 | ), |
2082 | 2082 | 'LBL_DBCONFIG_MSG2' => array( |
@@ -2108,8 +2108,8 @@ discard block |
||
2108 | 2108 | * @return string |
2109 | 2109 | */ |
2110 | 2110 | |
2111 | - public function getGuidSQL() |
|
2111 | + public function getGuidSQL() |
|
2112 | 2112 | { |
2113 | - return 'NEWID()'; |
|
2113 | + return 'NEWID()'; |
|
2114 | 2114 | } |
2115 | 2115 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -175,11 +175,11 @@ discard block |
||
175 | 175 | ini_set('mssql.datetimeconvert', '0'); |
176 | 176 | |
177 | 177 | //set the text size and textlimit to max number so that blob columns are not truncated |
178 | - ini_set('mssql.textlimit','2147483647'); |
|
179 | - ini_set('mssql.textsize','2147483647'); |
|
180 | - ini_set('mssql.charset','UTF-8'); |
|
178 | + ini_set('mssql.textlimit', '2147483647'); |
|
179 | + ini_set('mssql.textsize', '2147483647'); |
|
180 | + ini_set('mssql.charset', 'UTF-8'); |
|
181 | 181 | |
182 | - if(!empty($configOptions['db_host_instance'])) { |
|
182 | + if (!empty($configOptions['db_host_instance'])) { |
|
183 | 183 | $configOptions['db_host_instance'] = trim($configOptions['db_host_instance']); |
184 | 184 | } |
185 | 185 | //set the connections parameters |
@@ -191,37 +191,37 @@ discard block |
||
191 | 191 | |
192 | 192 | //create persistent connection |
193 | 193 | if ($this->getOption('persistent')) { |
194 | - $this->database =@mssql_pconnect( |
|
195 | - $connect_param , |
|
194 | + $this->database = @mssql_pconnect( |
|
195 | + $connect_param, |
|
196 | 196 | $configOptions['db_user_name'], |
197 | 197 | $configOptions['db_password'] |
198 | 198 | ); |
199 | 199 | } |
200 | 200 | //if no persistent connection created, then create regular connection |
201 | - if(!$this->database){ |
|
201 | + if (!$this->database) { |
|
202 | 202 | $this->database = mssql_connect( |
203 | - $connect_param , |
|
203 | + $connect_param, |
|
204 | 204 | $configOptions['db_user_name'], |
205 | 205 | $configOptions['db_password'] |
206 | 206 | ); |
207 | - if(!$this->database){ |
|
207 | + if (!$this->database) { |
|
208 | 208 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']. |
209 | 209 | " as ".$configOptions['db_user_name']."."); |
210 | - if($dieOnError) { |
|
210 | + if ($dieOnError) { |
|
211 | 211 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
212 | 212 | } else { |
213 | 213 | return false; |
214 | 214 | } |
215 | 215 | } |
216 | - if($this->database && $this->getOption('persistent')){ |
|
216 | + if ($this->database && $this->getOption('persistent')) { |
|
217 | 217 | $_SESSION['administrator_error'] = "<B>Severe Performance Degradation: Persistent Database Connections " |
218 | 218 | . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false in your " |
219 | 219 | . "config.php file</B>"; |
220 | 220 | } |
221 | 221 | } |
222 | 222 | //make sure connection exists |
223 | - if(!$this->database) { |
|
224 | - if($dieOnError) { |
|
223 | + if (!$this->database) { |
|
224 | + if ($dieOnError) { |
|
225 | 225 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
226 | 226 | } else { |
227 | 227 | return false; |
@@ -235,19 +235,19 @@ discard block |
||
235 | 235 | //mssql db maximum number of 5 times at the interval of .2 second. If can not connect |
236 | 236 | //it will throw an Unable to select database message. |
237 | 237 | |
238 | - if(!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
238 | + if (!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)) { |
|
239 | 239 | $connected = false; |
240 | - for($i=0;$i<5;$i++){ |
|
240 | + for ($i = 0; $i < 5; $i++) { |
|
241 | 241 | usleep(200000); |
242 | - if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
242 | + if (@mssql_select_db($configOptions['db_name'], $this->database)) { |
|
243 | 243 | $connected = true; |
244 | 244 | break; |
245 | 245 | } |
246 | 246 | } |
247 | - if(!$connected){ |
|
248 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
249 | - if($dieOnError) { |
|
250 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
247 | + if (!$connected) { |
|
248 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}"); |
|
249 | + if ($dieOnError) { |
|
250 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
251 | 251 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
252 | 252 | } else { |
253 | 253 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | } |
259 | 259 | } |
260 | 260 | |
261 | - if(!$this->checkError('Could Not Connect', $dieOnError)) |
|
261 | + if (!$this->checkError('Could Not Connect', $dieOnError)) |
|
262 | 262 | $GLOBALS['log']->info("connected to db"); |
263 | 263 | |
264 | 264 | $this->connectOptions = $configOptions; |
@@ -280,16 +280,16 @@ discard block |
||
280 | 280 | */ |
281 | 281 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
282 | 282 | { |
283 | - if(is_array($sql)) { |
|
283 | + if (is_array($sql)) { |
|
284 | 284 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
285 | 285 | } |
286 | 286 | // Flag if there are odd number of single quotes |
287 | 287 | if ((substr_count($sql, "'") & 1)) |
288 | - $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
288 | + $GLOBALS['log']->error("SQL statement[".$sql."] has odd number of single quotes."); |
|
289 | 289 | |
290 | 290 | $sql = $this->_appendN($sql); |
291 | 291 | |
292 | - $GLOBALS['log']->info('Query:' . $sql); |
|
292 | + $GLOBALS['log']->info('Query:'.$sql); |
|
293 | 293 | $this->checkConnection(); |
294 | 294 | $this->countQuery($sql); |
295 | 295 | $this->query_time = microtime(true); |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | // Bug 34892 - Clear out previous error message by checking the @@ERROR global variable |
298 | 298 | @mssql_query("SELECT @@ERROR", $this->database); |
299 | 299 | |
300 | - $result = $suppress?@mssql_query($sql, $this->database):mssql_query($sql, $this->database); |
|
300 | + $result = $suppress ? @mssql_query($sql, $this->database) : mssql_query($sql, $this->database); |
|
301 | 301 | |
302 | 302 | if (!$result) { |
303 | 303 | // awu Bug 10657: ignoring mssql error message 'Changed database context to' - an intermittent |
@@ -309,13 +309,13 @@ discard block |
||
309 | 309 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
310 | 310 | |
311 | 311 | if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
312 | - $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
312 | + $GLOBALS['log']->debug($sqlmsg.": ".$sql); |
|
313 | 313 | else { |
314 | - $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | - if($dieOnError) |
|
316 | - sugar_die('SQL Error : ' . $sqlmsg); |
|
314 | + $GLOBALS['log']->fatal($sqlmsg.": ".$sql); |
|
315 | + if ($dieOnError) |
|
316 | + sugar_die('SQL Error : '.$sqlmsg); |
|
317 | 317 | else |
318 | - echo 'SQL Error : ' . $sqlmsg; |
|
318 | + echo 'SQL Error : '.$sqlmsg; |
|
319 | 319 | } |
320 | 320 | } |
321 | 321 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
324 | 324 | |
325 | 325 | |
326 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
326 | + $this->checkError($msg.' Query Failed: '.$sql, $dieOnError); |
|
327 | 327 | |
328 | 328 | return $result; |
329 | 329 | } |
@@ -341,14 +341,14 @@ discard block |
||
341 | 341 | { |
342 | 342 | //set the start to 0, no negs |
343 | 343 | if ($start < 0) |
344 | - $start=0; |
|
344 | + $start = 0; |
|
345 | 345 | |
346 | - $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
|
346 | + $GLOBALS['log']->debug(print_r(func_get_args(), true)); |
|
347 | 347 | |
348 | 348 | $this->lastsql = $sql; |
349 | 349 | |
350 | 350 | //change the casing to lower for easier string comparison, and trim whitespaces |
351 | - $sql = strtolower(trim($sql)) ; |
|
351 | + $sql = strtolower(trim($sql)); |
|
352 | 352 | |
353 | 353 | //set default sql |
354 | 354 | $limitUnionSQL = $sql; |
@@ -364,16 +364,16 @@ discard block |
||
364 | 364 | $arr_count = 0; |
365 | 365 | |
366 | 366 | //process if there are elements |
367 | - if ($unionOrderByCount){ |
|
367 | + if ($unionOrderByCount) { |
|
368 | 368 | //we really want the last order by, so reconstruct string |
369 | 369 | //adding a 1 to count, as we dont wish to process the last element |
370 | 370 | $unionsql = ''; |
371 | - while ($unionOrderByCount>$arr_count+1) { |
|
371 | + while ($unionOrderByCount > $arr_count + 1) { |
|
372 | 372 | $unionsql .= $orderByArray[$arr_count]; |
373 | - $arr_count = $arr_count+1; |
|
373 | + $arr_count = $arr_count + 1; |
|
374 | 374 | //add an "order by" string back if we are coming into loop again |
375 | 375 | //remember they were taken out when array was created |
376 | - if ($unionOrderByCount>$arr_count+1) { |
|
376 | + if ($unionOrderByCount > $arr_count + 1) { |
|
377 | 377 | $unionsql .= "order by"; |
378 | 378 | } |
379 | 379 | } |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | //so we do not want to strip the alias like in other queries. Just add the "order by" string and |
404 | 404 | //pass column name as is |
405 | 405 | if ($unionOrderBy != '') { |
406 | - $unionOrderBy = ' order by ' . $unionOrderBy; |
|
406 | + $unionOrderBy = ' order by '.$unionOrderBy; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | //Bug 56560, use top query in conjunction with rownumber() function |
@@ -412,13 +412,13 @@ discard block |
||
412 | 412 | //If not for paging, no need to use rownumber() function |
413 | 413 | if ($count == 1 && $start == 0) |
414 | 414 | { |
415 | - $limitUnionSQL = "SELECT TOP $count * FROM (" .$unionsql .") as top_count ".$unionOrderBy; |
|
415 | + $limitUnionSQL = "SELECT TOP $count * FROM (".$unionsql.") as top_count ".$unionOrderBy; |
|
416 | 416 | } |
417 | 417 | else |
418 | 418 | { |
419 | 419 | $limitUnionSQL = "SELECT TOP $count * FROM( select ROW_NUMBER() OVER ( order by " |
420 | 420 | .$rowNumOrderBy.") AS row_number, * FROM (" |
421 | - .$unionsql .") As numbered) " |
|
421 | + .$unionsql.") As numbered) " |
|
422 | 422 | . "As top_count_limit WHERE row_number > $start " |
423 | 423 | .$unionOrderBy; |
424 | 424 | } |
@@ -437,64 +437,64 @@ discard block |
||
437 | 437 | $newSQL = $sql; |
438 | 438 | $distinctSQLARRAY = array(); |
439 | 439 | if (strpos($sql, "UNION") && !preg_match("/(')(UNION).?(')/i", $sql)) |
440 | - $newSQL = $this->handleUnionLimitQuery($sql,$start,$count); |
|
440 | + $newSQL = $this->handleUnionLimitQuery($sql, $start, $count); |
|
441 | 441 | else { |
442 | 442 | if ($start < 0) |
443 | 443 | $start = 0; |
444 | - $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
|
444 | + $GLOBALS['log']->debug(print_r(func_get_args(), true)); |
|
445 | 445 | $this->lastsql = $sql; |
446 | 446 | $matches = array(); |
447 | - preg_match('/^(.*SELECT\b)(.*?\bFROM\b.*\bWHERE\b)(.*)$/isU',$sql, $matches); |
|
447 | + preg_match('/^(.*SELECT\b)(.*?\bFROM\b.*\bWHERE\b)(.*)$/isU', $sql, $matches); |
|
448 | 448 | if (!empty($matches[3])) { |
449 | 449 | if ($start == 0) { |
450 | 450 | $match_two = strtolower($matches[2]); |
451 | - if (!strpos($match_two, "distinct")> 0 && strpos($match_two, "distinct") !==0) { |
|
451 | + if (!strpos($match_two, "distinct") > 0 && strpos($match_two, "distinct") !== 0) { |
|
452 | 452 | $orderByMatch = array(); |
453 | - preg_match('/^(.*)(\bORDER BY\b)(.*)$/is',$matches[3], $orderByMatch); |
|
453 | + preg_match('/^(.*)(\bORDER BY\b)(.*)$/is', $matches[3], $orderByMatch); |
|
454 | 454 | if (!empty($orderByMatch[3])) { |
455 | 455 | $selectPart = array(); |
456 | 456 | preg_match('/^(.*)(\bFROM\b.*)$/isU', $matches[2], $selectPart); |
457 | 457 | $newSQL = "SELECT TOP $count * FROM |
458 | 458 | ( |
459 | - " . $matches[1] . $selectPart[1] . ", ROW_NUMBER() |
|
460 | - OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]) . ") AS row_number |
|
461 | - " . $selectPart[2] . $orderByMatch[1]. " |
|
459 | + ".$matches[1].$selectPart[1].", ROW_NUMBER() |
|
460 | + OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]).") AS row_number |
|
461 | + " . $selectPart[2].$orderByMatch[1]." |
|
462 | 462 | ) AS a |
463 | 463 | WHERE row_number > $start"; |
464 | 464 | } |
465 | 465 | else { |
466 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
466 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | else { |
470 | 470 | $distinct_o = strpos($match_two, "distinct"); |
471 | 471 | $up_to_distinct_str = substr($match_two, 0, $distinct_o); |
472 | 472 | //check to see if the distinct is within a function, if so, then proceed as normal |
473 | - if (strpos($up_to_distinct_str,"(")) { |
|
473 | + if (strpos($up_to_distinct_str, "(")) { |
|
474 | 474 | //proceed as normal |
475 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
475 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
476 | 476 | } |
477 | 477 | else { |
478 | 478 | //if distinct is not within a function, then parse |
479 | 479 | //string contains distinct clause, "TOP needs to come after Distinct" |
480 | 480 | //get position of distinct |
481 | 481 | $match_zero = strtolower($matches[0]); |
482 | - $distinct_pos = strpos($match_zero , "distinct"); |
|
482 | + $distinct_pos = strpos($match_zero, "distinct"); |
|
483 | 483 | //get position of where |
484 | 484 | $where_pos = strpos($match_zero, "where"); |
485 | 485 | //parse through string |
486 | - $beg = substr($matches[0], 0, $distinct_pos+9 ); |
|
487 | - $mid = substr($matches[0], strlen($beg), ($where_pos+5) - (strlen($beg))); |
|
488 | - $end = substr($matches[0], strlen($beg) + strlen($mid) ); |
|
486 | + $beg = substr($matches[0], 0, $distinct_pos + 9); |
|
487 | + $mid = substr($matches[0], strlen($beg), ($where_pos + 5) - (strlen($beg))); |
|
488 | + $end = substr($matches[0], strlen($beg) + strlen($mid)); |
|
489 | 489 | //repopulate matches array |
490 | 490 | $matches[1] = $beg; $matches[2] = $mid; $matches[3] = $end; |
491 | 491 | |
492 | - $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
|
492 | + $newSQL = $matches[1]." TOP $count ".$matches[2].$matches[3]; |
|
493 | 493 | } |
494 | 494 | } |
495 | 495 | } else { |
496 | 496 | $orderByMatch = array(); |
497 | - preg_match('/^(.*)(\bORDER BY\b)(.*)$/is',$matches[3], $orderByMatch); |
|
497 | + preg_match('/^(.*)(\bORDER BY\b)(.*)$/is', $matches[3], $orderByMatch); |
|
498 | 498 | |
499 | 499 | //if there is a distinct clause, parse sql string as we will have to insert the rownumber |
500 | 500 | //for paging, AFTER the distinct clause |
@@ -513,8 +513,8 @@ discard block |
||
513 | 513 | |
514 | 514 | //take out the select and distinct from string so we can reuse in group by |
515 | 515 | $dist_str = 'distinct'; |
516 | - preg_match('/\b' . $dist_str . '\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
|
517 | - $matches_sql = trim(substr($matches_sql,$matchesPartSQL[0][1] + strlen($dist_str))); |
|
516 | + preg_match('/\b'.$dist_str.'\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
|
517 | + $matches_sql = trim(substr($matches_sql, $matchesPartSQL[0][1] + strlen($dist_str))); |
|
518 | 518 | //get the position of where and from for further processing |
519 | 519 | preg_match('/\bfrom\b/simU', $matches_sql, $matchesPartSQL, PREG_OFFSET_CAPTURE); |
520 | 520 | $from_pos = $matchesPartSQL[0][1]; |
@@ -522,17 +522,17 @@ discard block |
||
522 | 522 | $where_pos = $matchesPartSQL[0][1]; |
523 | 523 | //split the sql into a string before and after the from clause |
524 | 524 | //we will use the columns being selected to construct the group by clause |
525 | - if ($from_pos>0 ) { |
|
525 | + if ($from_pos > 0) { |
|
526 | 526 | $distinctSQLARRAY[0] = substr($matches_sql, 0, $from_pos); |
527 | 527 | $distinctSQLARRAY[1] = substr($matches_sql, $from_pos); |
528 | 528 | //get position of order by (if it exists) so we can strip it from the string |
529 | 529 | $ob_pos = strpos($distinctSQLARRAY[1], "order by"); |
530 | 530 | if ($ob_pos) { |
531 | - $distinctSQLARRAY[1] = substr($distinctSQLARRAY[1],0,$ob_pos); |
|
531 | + $distinctSQLARRAY[1] = substr($distinctSQLARRAY[1], 0, $ob_pos); |
|
532 | 532 | } |
533 | 533 | |
534 | 534 | // strip off last closing parentheses from the where clause |
535 | - $distinctSQLARRAY[1] = preg_replace('/\)\s$/',' ',$distinctSQLARRAY[1]); |
|
535 | + $distinctSQLARRAY[1] = preg_replace('/\)\s$/', ' ', $distinctSQLARRAY[1]); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | $grpByStr = array(); |
@@ -555,18 +555,18 @@ discard block |
||
555 | 555 | $newSQL = "SELECT TOP $count * FROM |
556 | 556 | ( |
557 | 557 | SELECT ROW_NUMBER() |
558 | - OVER (ORDER BY " . preg_replace('/^' . $dist_str . '\s+/', '', $this->returnOrderBy($sql, $orderByMatch[3])) . ") AS row_number, |
|
559 | - count(*) counter, " . $distinctSQLARRAY[0] . " |
|
560 | - " . $distinctSQLARRAY[1] . " |
|
561 | - group by " . $grpByStr . " |
|
558 | + OVER (ORDER BY ".preg_replace('/^'.$dist_str.'\s+/', '', $this->returnOrderBy($sql, $orderByMatch[3])).") AS row_number, |
|
559 | + count(*) counter, " . $distinctSQLARRAY[0]." |
|
560 | + " . $distinctSQLARRAY[1]." |
|
561 | + group by " . $grpByStr." |
|
562 | 562 | ) AS a |
563 | 563 | WHERE row_number > $start"; |
564 | 564 | } else { |
565 | 565 | $newSQL = "SELECT TOP $count * FROM |
566 | 566 | ( |
567 | - " . $matches[1] . " ROW_NUMBER() |
|
568 | - OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]) . ") AS row_number, |
|
569 | - " . $matches[2] . $orderByMatch[1] . " |
|
567 | + ".$matches[1]." ROW_NUMBER() |
|
568 | + OVER (ORDER BY " . $this->returnOrderBy($sql, $orderByMatch[3]).") AS row_number, |
|
569 | + " . $matches[2].$orderByMatch[1]." |
|
570 | 570 | ) AS a |
571 | 571 | WHERE row_number > $start"; |
572 | 572 | } |
@@ -575,23 +575,23 @@ discard block |
||
575 | 575 | if ($hasDistinct) { |
576 | 576 | $newSQL = "SELECT TOP $count * FROM |
577 | 577 | ( |
578 | - SELECT ROW_NUMBER() OVER (ORDER BY " . $grpByStr . ") AS row_number, count(*) counter, " . $distinctSQLARRAY[0] . " |
|
579 | - " . $distinctSQLARRAY[1] . " |
|
580 | - group by " . $grpByStr . " |
|
578 | + SELECT ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, count(*) counter, ".$distinctSQLARRAY[0]." |
|
579 | + " . $distinctSQLARRAY[1]." |
|
580 | + group by " . $grpByStr." |
|
581 | 581 | ) |
582 | 582 | AS a |
583 | 583 | WHERE row_number > $start"; |
584 | 584 | } elseif ($hasGroupBy) { |
585 | 585 | $newSQL = "SELECT TOP $count * FROM |
586 | 586 | ( |
587 | - " . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $grpByStr . ") AS row_number, " . $matches[2] . $matches[3] . " |
|
587 | + ".$matches[1]." ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, ".$matches[2].$matches[3]." |
|
588 | 588 | ) |
589 | 589 | AS a |
590 | 590 | WHERE row_number > $start"; |
591 | 591 | } else { |
592 | 592 | $newSQL = "SELECT TOP $count * FROM |
593 | 593 | ( |
594 | - " . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3] . " |
|
594 | + ".$matches[1]." ROW_NUMBER() OVER (ORDER BY ".$sqlArray['FROM'][0]['alias'].".id) AS row_number, ".$matches[2].$matches[3]." |
|
595 | 595 | ) |
596 | 596 | AS a |
597 | 597 | WHERE row_number > $start"; |
@@ -601,9 +601,9 @@ discard block |
||
601 | 601 | } |
602 | 602 | } |
603 | 603 | |
604 | - $GLOBALS['log']->debug('Limit Query: ' . $newSQL); |
|
605 | - if($execute) { |
|
606 | - $result = $this->query($newSQL, $dieOnError, $msg); |
|
604 | + $GLOBALS['log']->debug('Limit Query: '.$newSQL); |
|
605 | + if ($execute) { |
|
606 | + $result = $this->query($newSQL, $dieOnError, $msg); |
|
607 | 607 | $this->dump_slow_queries($newSQL); |
608 | 608 | return $result; |
609 | 609 | } else { |
@@ -625,15 +625,15 @@ discard block |
||
625 | 625 | private function removePatternFromSQL($p_sql, $strip_beg, $strip_end, $patt = 'patt') |
626 | 626 | { |
627 | 627 | //strip all single quotes out |
628 | - $count = substr_count ( $p_sql, $strip_beg); |
|
628 | + $count = substr_count($p_sql, $strip_beg); |
|
629 | 629 | $increment = 1; |
630 | 630 | if ($strip_beg != $strip_end) |
631 | 631 | $increment = 2; |
632 | 632 | |
633 | - $i=0; |
|
633 | + $i = 0; |
|
634 | 634 | $offset = 0; |
635 | 635 | $strip_array = array(); |
636 | - while ($i<$count && $offset<strlen($p_sql)) { |
|
636 | + while ($i < $count && $offset < strlen($p_sql)) { |
|
637 | 637 | if ($offset > strlen($p_sql)) |
638 | 638 | { |
639 | 639 | break; |
@@ -644,23 +644,23 @@ discard block |
||
644 | 644 | { |
645 | 645 | break; |
646 | 646 | } |
647 | - $sec_sin = strpos($p_sql, $strip_end, $beg_sin+1); |
|
648 | - $strip_array[$patt.$i] = substr($p_sql, $beg_sin, $sec_sin - $beg_sin +1); |
|
647 | + $sec_sin = strpos($p_sql, $strip_end, $beg_sin + 1); |
|
648 | + $strip_array[$patt.$i] = substr($p_sql, $beg_sin, $sec_sin - $beg_sin + 1); |
|
649 | 649 | if ($increment > 1) { |
650 | 650 | //we are in here because beginning and end patterns are not identical, so search for nesting |
651 | - $exists = strpos($strip_array[$patt.$i], $strip_beg ); |
|
652 | - if ($exists>=0) { |
|
653 | - $nested_pos = (strrpos($strip_array[$patt.$i], $strip_beg )); |
|
654 | - $strip_array[$patt.$i] = substr($p_sql,$nested_pos+$beg_sin,$sec_sin - ($nested_pos+$beg_sin)+1); |
|
655 | - $p_sql = substr($p_sql, 0, $nested_pos+$beg_sin) . " ##". $patt.$i."## " . substr($p_sql, $sec_sin+1); |
|
651 | + $exists = strpos($strip_array[$patt.$i], $strip_beg); |
|
652 | + if ($exists >= 0) { |
|
653 | + $nested_pos = (strrpos($strip_array[$patt.$i], $strip_beg)); |
|
654 | + $strip_array[$patt.$i] = substr($p_sql, $nested_pos + $beg_sin, $sec_sin - ($nested_pos + $beg_sin) + 1); |
|
655 | + $p_sql = substr($p_sql, 0, $nested_pos + $beg_sin)." ##".$patt.$i."## ".substr($p_sql, $sec_sin + 1); |
|
656 | 656 | $i = $i + 1; |
657 | 657 | continue; |
658 | 658 | } |
659 | 659 | } |
660 | - $p_len = strlen("##". $patt.$i."##"); |
|
661 | - $p_sql = substr($p_sql, 0, $beg_sin) . " ##". $patt.$i."## " . substr($p_sql, $sec_sin+1); |
|
660 | + $p_len = strlen("##".$patt.$i."##"); |
|
661 | + $p_sql = substr($p_sql, 0, $beg_sin)." ##".$patt.$i."## ".substr($p_sql, $sec_sin + 1); |
|
662 | 662 | //move the marker up |
663 | - $offset = ($sec_sin-($sec_sin-$beg_sin))+$p_len+1; // Adjusting the starting point of the marker |
|
663 | + $offset = ($sec_sin - ($sec_sin - $beg_sin)) + $p_len + 1; // Adjusting the starting point of the marker |
|
664 | 664 | |
665 | 665 | $i = $i + 1; |
666 | 666 | } |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | $pattern_array = array_reverse($pattern_array); |
683 | 683 | |
684 | 684 | foreach ($pattern_array as $key => $replace) { |
685 | - $token = str_replace( " ##".$key."## ", $replace,$token); |
|
685 | + $token = str_replace(" ##".$key."## ", $replace, $token); |
|
686 | 686 | } |
687 | 687 | |
688 | 688 | return $token; |
@@ -698,11 +698,11 @@ discard block |
||
698 | 698 | private function getAliasFromSQL($sql, $alias) |
699 | 699 | { |
700 | 700 | $matches = array(); |
701 | - preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU',$sql, $matches); |
|
701 | + preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU', $sql, $matches); |
|
702 | 702 | //parse all single and double quotes out of array |
703 | - $sin_array = $this->removePatternFromSQL($matches[2], "'", "'","sin_"); |
|
703 | + $sin_array = $this->removePatternFromSQL($matches[2], "'", "'", "sin_"); |
|
704 | 704 | $new_sql = array_pop($sin_array); |
705 | - $dub_array = $this->removePatternFromSQL($new_sql, "\"", "\"","dub_"); |
|
705 | + $dub_array = $this->removePatternFromSQL($new_sql, "\"", "\"", "dub_"); |
|
706 | 706 | $new_sql = array_pop($dub_array); |
707 | 707 | |
708 | 708 | //search for parenthesis |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | |
712 | 712 | //all functions should be removed now, so split the array on commas |
713 | 713 | $mstr_sql_array = explode(",", $new_sql); |
714 | - foreach($mstr_sql_array as $token ) { |
|
714 | + foreach ($mstr_sql_array as $token) { |
|
715 | 715 | if (strpos($token, $alias)) { |
716 | 716 | //found token, add back comments |
717 | 717 | $token = $this->addPatternToSQL($token, $paren_array); |
@@ -749,7 +749,7 @@ discard block |
||
749 | 749 | $found = $found_in_sql; |
750 | 750 | |
751 | 751 | //if still no match found, then we need to parse through the string |
752 | - if (!$found_in_sql){ |
|
752 | + if (!$found_in_sql) { |
|
753 | 753 | //get count of how many times the match exists in string |
754 | 754 | $found_count = substr_count($sql, $orderMatch); |
755 | 755 | $i = 0; |
@@ -758,21 +758,21 @@ discard block |
||
758 | 758 | //loop through string as many times as there is a match |
759 | 759 | while ($found_count > $i) { |
760 | 760 | //get the first match |
761 | - $found_in_sql = strpos($sql, $orderMatch,$first_); |
|
761 | + $found_in_sql = strpos($sql, $orderMatch, $first_); |
|
762 | 762 | //make sure there was a match |
763 | - if($found_in_sql){ |
|
763 | + if ($found_in_sql) { |
|
764 | 764 | //grab the next 2 individual characters |
765 | - $str_plusone = substr($sql,$found_in_sql + $len,1); |
|
766 | - $str_plustwo = substr($sql,$found_in_sql + $len+1,1); |
|
765 | + $str_plusone = substr($sql, $found_in_sql + $len, 1); |
|
766 | + $str_plustwo = substr($sql, $found_in_sql + $len + 1, 1); |
|
767 | 767 | //if one of those characters is a comma, then we have our alias |
768 | - if ($str_plusone === "," || $str_plustwo === ","){ |
|
768 | + if ($str_plusone === "," || $str_plustwo === ",") { |
|
769 | 769 | //keep track of this position |
770 | 770 | $found = $found_in_sql; |
771 | 771 | } |
772 | 772 | } |
773 | 773 | //set the offset and increase the iteration counter |
774 | - $first_ = $found_in_sql+$len; |
|
775 | - $i = $i+1; |
|
774 | + $first_ = $found_in_sql + $len; |
|
775 | + $i = $i + 1; |
|
776 | 776 | } |
777 | 777 | } |
778 | 778 | //return $found, defaults have been set, so if no match was found it will be a negative number |
@@ -804,8 +804,8 @@ discard block |
||
804 | 804 | $firstSpace = strpos($orig_order_match, " "); |
805 | 805 | |
806 | 806 | //split order by into column name and ascending/descending |
807 | - $orderMatch = " " . strtolower(substr($orig_order_match, 0, $firstSpace)); |
|
808 | - $asc_desc = trim(substr($orig_order_match,$firstSpace)); |
|
807 | + $orderMatch = " ".strtolower(substr($orig_order_match, 0, $firstSpace)); |
|
808 | + $asc_desc = trim(substr($orig_order_match, $firstSpace)); |
|
809 | 809 | |
810 | 810 | //look for column name as an alias in sql string |
811 | 811 | $found_in_sql = $this->findColumnByAlias($sql, $orderMatch); |
@@ -816,18 +816,18 @@ discard block |
||
816 | 816 | $colMatchPos = strpos($sql, $orderMatch); |
817 | 817 | if ($colMatchPos !== false) { |
818 | 818 | //grab sub string up to column name |
819 | - $containsColStr = substr($sql,0, $colMatchPos); |
|
819 | + $containsColStr = substr($sql, 0, $colMatchPos); |
|
820 | 820 | //get position of first space, so we can grab table name |
821 | 821 | $lastSpacePos = strrpos($containsColStr, " "); |
822 | 822 | //use positions of column name, space before name, and length of column to find the correct column name |
823 | - $col_name = substr($sql, $lastSpacePos, $colMatchPos-$lastSpacePos+strlen($orderMatch)); |
|
823 | + $col_name = substr($sql, $lastSpacePos, $colMatchPos - $lastSpacePos + strlen($orderMatch)); |
|
824 | 824 | //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
825 | 825 | $containsCommaPos = strpos($col_name, ","); |
826 | - if($containsCommaPos !== false) { |
|
827 | - $col_name = substr($col_name, $containsCommaPos+1); |
|
826 | + if ($containsCommaPos !== false) { |
|
827 | + $col_name = substr($col_name, $containsCommaPos + 1); |
|
828 | 828 | } |
829 | 829 | //add the "asc/desc" order back |
830 | - $col_name = $col_name. " ". $asc_desc; |
|
830 | + $col_name = $col_name." ".$asc_desc; |
|
831 | 831 | |
832 | 832 | //return column name |
833 | 833 | return $col_name; |
@@ -841,22 +841,22 @@ discard block |
||
841 | 841 | //grab string up to the aliased column |
842 | 842 | $GLOBALS['log']->debug("order by found, process sql string"); |
843 | 843 | |
844 | - $psql = (trim($this->getAliasFromSQL($sql, $orderMatch ))); |
|
844 | + $psql = (trim($this->getAliasFromSQL($sql, $orderMatch))); |
|
845 | 845 | if (empty($psql)) |
846 | 846 | $psql = trim(substr($sql, 0, $found_in_sql)); |
847 | 847 | |
848 | 848 | //grab the last comma before the alias |
849 | - preg_match('/\s+' . trim($orderMatch). '/', $psql, $match, PREG_OFFSET_CAPTURE); |
|
849 | + preg_match('/\s+'.trim($orderMatch).'/', $psql, $match, PREG_OFFSET_CAPTURE); |
|
850 | 850 | $comma_pos = $match[0][1]; |
851 | 851 | //substring between the comma and the alias to find the joined_table alias and column name |
852 | - $col_name = substr($psql,0, $comma_pos); |
|
852 | + $col_name = substr($psql, 0, $comma_pos); |
|
853 | 853 | |
854 | 854 | //make sure the string does not have an end parenthesis |
855 | 855 | //and is not part of a function (i.e. "ISNULL(leads.last_name,'') as name" ) |
856 | 856 | //this is especially true for unified search from home screen |
857 | 857 | |
858 | 858 | $alias_beg_pos = 0; |
859 | - if(strpos($psql, " as ")) |
|
859 | + if (strpos($psql, " as ")) |
|
860 | 860 | $alias_beg_pos = strpos($psql, " as "); |
861 | 861 | |
862 | 862 | // Bug # 44923 - This breaks the query and does not properly filter isnull |
@@ -865,13 +865,13 @@ discard block |
||
865 | 865 | $alias_beg_pos = strpos($psql, " "); */ |
866 | 866 | |
867 | 867 | if ($alias_beg_pos > 0) { |
868 | - $col_name = substr($psql,0, $alias_beg_pos ); |
|
868 | + $col_name = substr($psql, 0, $alias_beg_pos); |
|
869 | 869 | } |
870 | 870 | //add the "asc/desc" order back |
871 | - $col_name = $col_name. " ". $asc_desc; |
|
871 | + $col_name = $col_name." ".$asc_desc; |
|
872 | 872 | |
873 | 873 | //pass in new order by |
874 | - $GLOBALS['log']->debug("order by being returned is " . $col_name); |
|
874 | + $GLOBALS['log']->debug("order by being returned is ".$col_name); |
|
875 | 875 | return $col_name; |
876 | 876 | } |
877 | 877 | } |
@@ -887,12 +887,12 @@ discard block |
||
887 | 887 | { |
888 | 888 | |
889 | 889 | global $beanList, $beanFiles; |
890 | - $GLOBALS['log']->debug("Module being processed is " . $module_str); |
|
890 | + $GLOBALS['log']->debug("Module being processed is ".$module_str); |
|
891 | 891 | //get the right module files |
892 | 892 | //the module string exists in bean list, then process bean for correct table name |
893 | 893 | //note that we exempt the reports module from this, as queries from reporting module should be parsed for |
894 | 894 | //correct table name. |
895 | - if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str]) && isset($beanFiles[$beanList[$module_str]])){ |
|
895 | + if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str]) && isset($beanFiles[$beanList[$module_str]])) { |
|
896 | 896 | //if the class is not already loaded, then load files |
897 | 897 | if (!class_exists($beanList[$module_str])) |
898 | 898 | require_once($beanFiles[$beanList[$module_str]]); |
@@ -904,7 +904,7 @@ discard block |
||
904 | 904 | //make sure table name is not just a blank space, or empty |
905 | 905 | $tbl_name = trim($tbl_name); |
906 | 906 | |
907 | - if(empty($tbl_name)){ |
|
907 | + if (empty($tbl_name)) { |
|
908 | 908 | $GLOBALS['log']->debug("Could not find table name for module $module_str. "); |
909 | 909 | $tbl_name = $module_str; |
910 | 910 | } |
@@ -921,20 +921,20 @@ discard block |
||
921 | 921 | $sql = str_replace(array("\n", "\r"), " ", $sql); |
922 | 922 | |
923 | 923 | //look for the location of the "from" in sql string |
924 | - $fromLoc = strpos($sql," from " ); |
|
925 | - if ($fromLoc>0){ |
|
924 | + $fromLoc = strpos($sql, " from "); |
|
925 | + if ($fromLoc > 0) { |
|
926 | 926 | //found from, substring from the " FROM " string in sql to end |
927 | - $tableEnd = substr($sql, $fromLoc+6); |
|
927 | + $tableEnd = substr($sql, $fromLoc + 6); |
|
928 | 928 | //We know that tablename will be next parameter after from, so |
929 | 929 | //grab the next space after table name. |
930 | 930 | // MFH BUG #14009: Also check to see if there are any carriage returns before the next space so that we don't grab any arbitrary joins or other tables. |
931 | - $carriage_ret = strpos($tableEnd,"\n"); |
|
932 | - $next_space = strpos($tableEnd," " ); |
|
931 | + $carriage_ret = strpos($tableEnd, "\n"); |
|
932 | + $next_space = strpos($tableEnd, " "); |
|
933 | 933 | if ($carriage_ret < $next_space) |
934 | 934 | $next_space = $carriage_ret; |
935 | 935 | if ($next_space > 0) { |
936 | - $tbl_name= substr($tableEnd,0, $next_space); |
|
937 | - if(empty($tbl_name)){ |
|
936 | + $tbl_name = substr($tableEnd, 0, $next_space); |
|
937 | + if (empty($tbl_name)) { |
|
938 | 938 | $GLOBALS['log']->debug("Could not find table name sql either, return $module_str. "); |
939 | 939 | $tbl_name = $module_str; |
940 | 940 | } |
@@ -942,11 +942,11 @@ discard block |
||
942 | 942 | |
943 | 943 | //grab the table, to see if it is aliased |
944 | 944 | $aliasTableEnd = trim(substr($tableEnd, $next_space)); |
945 | - $alias_space = strpos ($aliasTableEnd, " " ); |
|
946 | - if ($alias_space > 0){ |
|
947 | - $alias_tbl_name= substr($aliasTableEnd,0, $alias_space); |
|
945 | + $alias_space = strpos($aliasTableEnd, " "); |
|
946 | + if ($alias_space > 0) { |
|
947 | + $alias_tbl_name = substr($aliasTableEnd, 0, $alias_space); |
|
948 | 948 | strtolower($alias_tbl_name); |
949 | - if(empty($alias_tbl_name) |
|
949 | + if (empty($alias_tbl_name) |
|
950 | 950 | || $alias_tbl_name == "where" |
951 | 951 | || $alias_tbl_name == "inner" |
952 | 952 | || $alias_tbl_name == "left" |
@@ -958,9 +958,9 @@ discard block |
||
958 | 958 | elseif ($alias_tbl_name == "as") { |
959 | 959 | //the next word is the table name |
960 | 960 | $aliasTableEnd = trim(substr($aliasTableEnd, $alias_space)); |
961 | - $alias_space = strpos ($aliasTableEnd, " " ); |
|
961 | + $alias_space = strpos($aliasTableEnd, " "); |
|
962 | 962 | if ($alias_space > 0) { |
963 | - $alias_tbl_name= trim(substr($aliasTableEnd,0, $alias_space)); |
|
963 | + $alias_tbl_name = trim(substr($aliasTableEnd, 0, $alias_space)); |
|
964 | 964 | if (!empty($alias_tbl_name)) |
965 | 965 | $tbl_name = $alias_tbl_name; |
966 | 966 | } |
@@ -985,7 +985,7 @@ discard block |
||
985 | 985 | { |
986 | 986 | $field_array = array(); |
987 | 987 | |
988 | - if(! isset($result) || empty($result)) |
|
988 | + if (!isset($result) || empty($result)) |
|
989 | 989 | return 0; |
990 | 990 | |
991 | 991 | $i = 0; |
@@ -993,7 +993,7 @@ discard block |
||
993 | 993 | $meta = mssql_fetch_field($result, $i); |
994 | 994 | if (!$meta) |
995 | 995 | return 0; |
996 | - if($make_lower_case==true) |
|
996 | + if ($make_lower_case == true) |
|
997 | 997 | $meta->name = strtolower($meta->name); |
998 | 998 | |
999 | 999 | $field_array[] = $meta->name; |
@@ -1022,11 +1022,11 @@ discard block |
||
1022 | 1022 | $row = mssql_fetch_assoc($result); |
1023 | 1023 | //MSSQL returns a space " " when a varchar column is empty ("") and not null. |
1024 | 1024 | //We need to iterate through the returned row array and strip empty spaces |
1025 | - if(!empty($row)){ |
|
1026 | - foreach($row as $key => $column) { |
|
1025 | + if (!empty($row)) { |
|
1026 | + foreach ($row as $key => $column) { |
|
1027 | 1027 | //notice we only strip if one space is returned. we do not want to strip |
1028 | 1028 | //strings with intentional spaces (" foo ") |
1029 | - if (!empty($column) && $column ==" ") { |
|
1029 | + if (!empty($column) && $column == " ") { |
|
1030 | 1030 | $row[$key] = ''; |
1031 | 1031 | } |
1032 | 1032 | } |
@@ -1039,10 +1039,10 @@ discard block |
||
1039 | 1039 | */ |
1040 | 1040 | public function quote($string) |
1041 | 1041 | { |
1042 | - if(is_array($string)) { |
|
1042 | + if (is_array($string)) { |
|
1043 | 1043 | return $this->arrayQuote($string); |
1044 | 1044 | } |
1045 | - return str_replace("'","''", $this->quoteInternal($string)); |
|
1045 | + return str_replace("'", "''", $this->quoteInternal($string)); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | /** |
@@ -1080,7 +1080,7 @@ discard block |
||
1080 | 1080 | if (!empty($r)) { |
1081 | 1081 | while ($a = $this->fetchByAssoc($r)) { |
1082 | 1082 | $row = array_values($a); |
1083 | - $tables[]=$row[0]; |
|
1083 | + $tables[] = $row[0]; |
|
1084 | 1084 | } |
1085 | 1085 | return $tables; |
1086 | 1086 | } |
@@ -1095,7 +1095,7 @@ discard block |
||
1095 | 1095 | { |
1096 | 1096 | $GLOBALS['log']->debug('MSSQL fetching table list'); |
1097 | 1097 | |
1098 | - if($this->getDatabase()) { |
|
1098 | + if ($this->getDatabase()) { |
|
1099 | 1099 | $tables = array(); |
1100 | 1100 | $r = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES'); |
1101 | 1101 | if (is_resource($r)) { |
@@ -1119,7 +1119,7 @@ discard block |
||
1119 | 1119 | { |
1120 | 1120 | $GLOBALS['log']->debug('MSSQL about to wakeup FTS'); |
1121 | 1121 | |
1122 | - if($this->getDatabase()) { |
|
1122 | + if ($this->getDatabase()) { |
|
1123 | 1123 | //create wakeup catalog |
1124 | 1124 | $FTSqry[] = "if not exists( select * from sys.fulltext_catalogs where name ='wakeup_catalog' ) |
1125 | 1125 | CREATE FULLTEXT CATALOG wakeup_catalog |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | $FTSqry[] = 'ALTER FULLTEXT INDEX ON fts_wakeup START FULL POPULATION'; |
1160 | 1160 | $FTSqry[] = 'ALTER FULLTEXT INDEX ON fts_wakeup SET CHANGE_TRACKING AUTO'; |
1161 | 1161 | |
1162 | - foreach($FTSqry as $q){ |
|
1162 | + foreach ($FTSqry as $q) { |
|
1163 | 1163 | sleep(3); |
1164 | 1164 | $this->query($q); |
1165 | 1165 | } |
@@ -1182,12 +1182,12 @@ discard block |
||
1182 | 1182 | { |
1183 | 1183 | // convert the parameters array into a comma delimited string |
1184 | 1184 | if (!empty($additional_parameters)) { |
1185 | - $additional_parameters_string = ','.implode(',',$additional_parameters); |
|
1185 | + $additional_parameters_string = ','.implode(',', $additional_parameters); |
|
1186 | 1186 | } else { |
1187 | 1187 | $additional_parameters_string = ''; |
1188 | 1188 | } |
1189 | 1189 | $all_parameters = $additional_parameters; |
1190 | - if(is_array($string)) { |
|
1190 | + if (is_array($string)) { |
|
1191 | 1191 | $all_parameters = array_merge($string, $all_parameters); |
1192 | 1192 | } elseif (!is_null($string)) { |
1193 | 1193 | array_unshift($all_parameters, $string); |
@@ -1199,22 +1199,22 @@ discard block |
||
1199 | 1199 | case 'left': |
1200 | 1200 | return "LEFT($string$additional_parameters_string)"; |
1201 | 1201 | case 'date_format': |
1202 | - if(!empty($additional_parameters[0]) && $additional_parameters[0][0] == "'") { |
|
1202 | + if (!empty($additional_parameters[0]) && $additional_parameters[0][0] == "'") { |
|
1203 | 1203 | $additional_parameters[0] = trim($additional_parameters[0], "'"); |
1204 | 1204 | } |
1205 | - if(!empty($additional_parameters) && isset($this->date_formats[$additional_parameters[0]])) { |
|
1205 | + if (!empty($additional_parameters) && isset($this->date_formats[$additional_parameters[0]])) { |
|
1206 | 1206 | $len = $this->date_formats[$additional_parameters[0]]; |
1207 | - return "LEFT(CONVERT(varchar($len),". $string . ",120),$len)"; |
|
1207 | + return "LEFT(CONVERT(varchar($len),".$string.",120),$len)"; |
|
1208 | 1208 | } else { |
1209 | - return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1209 | + return "LEFT(CONVERT(varchar(10),".$string.",120),10)"; |
|
1210 | 1210 | } |
1211 | 1211 | case 'ifnull': |
1212 | - if(empty($additional_parameters_string)) { |
|
1212 | + if (empty($additional_parameters_string)) { |
|
1213 | 1213 | $additional_parameters_string = ",''"; |
1214 | 1214 | } |
1215 | 1215 | return "ISNULL($string$additional_parameters_string)"; |
1216 | 1216 | case 'concat': |
1217 | - return implode("+",$all_parameters); |
|
1217 | + return implode("+", $all_parameters); |
|
1218 | 1218 | case 'text2char': |
1219 | 1219 | return "CAST($string AS varchar(8000))"; |
1220 | 1220 | case 'quarter': |
@@ -1230,7 +1230,7 @@ discard block |
||
1230 | 1230 | case 'add_tz_offset' : |
1231 | 1231 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
1232 | 1232 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
1233 | - return 'DATEADD(minute, ' . $operation . abs($getUserUTCOffset) . ', ' . $string. ')'; |
|
1233 | + return 'DATEADD(minute, '.$operation.abs($getUserUTCOffset).', '.$string.')'; |
|
1234 | 1234 | case 'avg': |
1235 | 1235 | return "avg($string)"; |
1236 | 1236 | } |
@@ -1243,9 +1243,9 @@ discard block |
||
1243 | 1243 | */ |
1244 | 1244 | public function fromConvert($string, $type) |
1245 | 1245 | { |
1246 | - switch($type) { |
|
1246 | + switch ($type) { |
|
1247 | 1247 | case 'datetimecombo': |
1248 | - case 'datetime': return substr($string, 0,19); |
|
1248 | + case 'datetime': return substr($string, 0, 19); |
|
1249 | 1249 | case 'date': return substr($string, 0, 10); |
1250 | 1250 | case 'time': return substr($string, 11); |
1251 | 1251 | } |
@@ -1274,8 +1274,8 @@ discard block |
||
1274 | 1274 | public function isTextType($type) |
1275 | 1275 | { |
1276 | 1276 | $type = strtolower($type); |
1277 | - if(!isset($this->type_map[$type])) return false; |
|
1278 | - return in_array($this->type_map[$type], array('ntext','text','image', 'nvarchar(max)')); |
|
1277 | + if (!isset($this->type_map[$type])) return false; |
|
1278 | + return in_array($this->type_map[$type], array('ntext', 'text', 'image', 'nvarchar(max)')); |
|
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | /** |
@@ -1285,13 +1285,13 @@ discard block |
||
1285 | 1285 | public function emptyValue($type) |
1286 | 1286 | { |
1287 | 1287 | $ctype = $this->getColumnType($type); |
1288 | - if($ctype == "datetime") { |
|
1288 | + if ($ctype == "datetime") { |
|
1289 | 1289 | return $this->convert($this->quoted("1970-01-01 00:00:00"), "datetime"); |
1290 | 1290 | } |
1291 | - if($ctype == "date") { |
|
1291 | + if ($ctype == "date") { |
|
1292 | 1292 | return $this->convert($this->quoted("1970-01-01"), "datetime"); |
1293 | 1293 | } |
1294 | - if($ctype == "time") { |
|
1294 | + if ($ctype == "time") { |
|
1295 | 1295 | return $this->convert($this->quoted("00:00:00"), "time"); |
1296 | 1296 | } |
1297 | 1297 | return parent::emptyValue($type); |
@@ -1314,21 +1314,21 @@ discard block |
||
1314 | 1314 | */ |
1315 | 1315 | protected function alterSQLRep($action, array $def, $ignoreRequired, $tablename) |
1316 | 1316 | { |
1317 | - switch($action){ |
|
1317 | + switch ($action) { |
|
1318 | 1318 | case 'add': |
1319 | - $f_def=$this->oneColumnSQLRep($def, $ignoreRequired,$tablename,false); |
|
1320 | - return "ADD " . $f_def; |
|
1319 | + $f_def = $this->oneColumnSQLRep($def, $ignoreRequired, $tablename, false); |
|
1320 | + return "ADD ".$f_def; |
|
1321 | 1321 | break; |
1322 | 1322 | case 'drop': |
1323 | - return "DROP COLUMN " . $def['name']; |
|
1323 | + return "DROP COLUMN ".$def['name']; |
|
1324 | 1324 | break; |
1325 | 1325 | case 'modify': |
1326 | 1326 | //You cannot specify a default value for a column for MSSQL |
1327 | - $f_def = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true); |
|
1327 | + $f_def = $this->oneColumnSQLRep($def, $ignoreRequired, $tablename, true); |
|
1328 | 1328 | $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '. |
1329 | 1329 | $f_def['required'].' '.$f_def['auto_increment']."\n"; |
1330 | - if (!empty( $f_def['default'])) |
|
1331 | - $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1330 | + if (!empty($f_def['default'])) |
|
1331 | + $f_stmt .= " ALTER TABLE ".$tablename." ADD ".$f_def['default']." FOR ".$def['name']; |
|
1332 | 1332 | return $f_stmt; |
1333 | 1333 | break; |
1334 | 1334 | default: |
@@ -1344,7 +1344,7 @@ discard block |
||
1344 | 1344 | */ |
1345 | 1345 | protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
1346 | 1346 | { |
1347 | - $sql=$sql2=''; |
|
1347 | + $sql = $sql2 = ''; |
|
1348 | 1348 | $constraints = $this->get_field_default_constraint_name($tablename); |
1349 | 1349 | $columns = array(); |
1350 | 1350 | if ($this->isFieldArray($fieldDefs)) { |
@@ -1353,41 +1353,41 @@ discard block |
||
1353 | 1353 | //if the column is being modified drop the default value |
1354 | 1354 | //constraint if it exists. alterSQLRep will add the constraint back |
1355 | 1355 | if (!empty($constraints[$def['name']])) { |
1356 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1356 | + $sql .= " ALTER TABLE ".$tablename." DROP CONSTRAINT ".$constraints[$def['name']]; |
|
1357 | 1357 | } |
1358 | 1358 | //check to see if we need to drop related indexes before the alter |
1359 | 1359 | $indices = $this->get_indices($tablename); |
1360 | - foreach ( $indices as $index ) { |
|
1361 | - if ( in_array($def['name'],$index['fields']) ) { |
|
1362 | - $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
|
1363 | - $sql2 .= ' ' . $this->add_drop_constraint($tablename,$index,false).' '; |
|
1360 | + foreach ($indices as $index) { |
|
1361 | + if (in_array($def['name'], $index['fields'])) { |
|
1362 | + $sql .= ' '.$this->add_drop_constraint($tablename, $index, true).' '; |
|
1363 | + $sql2 .= ' '.$this->add_drop_constraint($tablename, $index, false).' '; |
|
1364 | 1364 | } |
1365 | 1365 | } |
1366 | 1366 | |
1367 | - $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1367 | + $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired, $tablename); |
|
1368 | 1368 | } |
1369 | 1369 | } |
1370 | 1370 | else { |
1371 | 1371 | //if the column is being modified drop the default value |
1372 | 1372 | //constraint if it exists. alterSQLRep will add the constraint back |
1373 | 1373 | if (!empty($constraints[$fieldDefs['name']])) { |
1374 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1374 | + $sql .= " ALTER TABLE ".$tablename." DROP CONSTRAINT ".$constraints[$fieldDefs['name']]; |
|
1375 | 1375 | } |
1376 | 1376 | //check to see if we need to drop related indexes before the alter |
1377 | 1377 | $indices = $this->get_indices($tablename); |
1378 | - foreach ( $indices as $index ) { |
|
1379 | - if ( in_array($fieldDefs['name'],$index['fields']) ) { |
|
1380 | - $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
|
1381 | - $sql2 .= ' ' . $this->add_drop_constraint($tablename,$index,false).' '; |
|
1378 | + foreach ($indices as $index) { |
|
1379 | + if (in_array($fieldDefs['name'], $index['fields'])) { |
|
1380 | + $sql .= ' '.$this->add_drop_constraint($tablename, $index, true).' '; |
|
1381 | + $sql2 .= ' '.$this->add_drop_constraint($tablename, $index, false).' '; |
|
1382 | 1382 | } |
1383 | 1383 | } |
1384 | 1384 | |
1385 | 1385 | |
1386 | - $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1386 | + $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired, $tablename); |
|
1387 | 1387 | } |
1388 | 1388 | |
1389 | 1389 | $columns = implode(", ", $columns); |
1390 | - $sql .= " ALTER TABLE $tablename $columns " . $sql2; |
|
1390 | + $sql .= " ALTER TABLE $tablename $columns ".$sql2; |
|
1391 | 1391 | |
1392 | 1392 | return $sql; |
1393 | 1393 | } |
@@ -1402,7 +1402,7 @@ discard block |
||
1402 | 1402 | */ |
1403 | 1403 | public function setAutoIncrementStart($table, $field_name, $start_value) |
1404 | 1404 | { |
1405 | - if($start_value > 1) |
|
1405 | + if ($start_value > 1) |
|
1406 | 1406 | $start_value -= 1; |
1407 | 1407 | $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
1408 | 1408 | return true; |
@@ -1437,11 +1437,11 @@ discard block |
||
1437 | 1437 | $result = $this->query($query); |
1438 | 1438 | |
1439 | 1439 | $indices = array(); |
1440 | - while (($row=$this->fetchByAssoc($result)) != null) { |
|
1440 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
1441 | 1441 | $index_type = 'index'; |
1442 | 1442 | if ($row['is_primary_key'] == '1') |
1443 | 1443 | $index_type = 'primary'; |
1444 | - elseif ($row['is_unique'] == 1 ) |
|
1444 | + elseif ($row['is_unique'] == 1) |
|
1445 | 1445 | $index_type = 'unique'; |
1446 | 1446 | $name = strtolower($row['index_name']); |
1447 | 1447 | $indices[$name]['name'] = $name; |
@@ -1460,36 +1460,36 @@ discard block |
||
1460 | 1460 | $result = $this->query("sp_columns $tablename"); |
1461 | 1461 | |
1462 | 1462 | $columns = array(); |
1463 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
1463 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
1464 | 1464 | $column_name = strtolower($row['COLUMN_NAME']); |
1465 | - $columns[$column_name]['name']=$column_name; |
|
1466 | - $columns[$column_name]['type']=strtolower($row['TYPE_NAME']); |
|
1467 | - if ( $row['TYPE_NAME'] == 'decimal' ) { |
|
1468 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1469 | - $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
|
1465 | + $columns[$column_name]['name'] = $column_name; |
|
1466 | + $columns[$column_name]['type'] = strtolower($row['TYPE_NAME']); |
|
1467 | + if ($row['TYPE_NAME'] == 'decimal') { |
|
1468 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
1469 | + $columns[$column_name]['len'] .= ','.strtolower($row['SCALE']); |
|
1470 | 1470 | } |
1471 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1472 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1473 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) |
|
1474 | - $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
1475 | - if ( stristr($row['TYPE_NAME'],'identity') ) { |
|
1471 | + elseif (in_array($row['TYPE_NAME'], array('nchar', 'nvarchar'))) |
|
1472 | + $columns[$column_name]['len'] = strtolower($row['PRECISION']); |
|
1473 | + elseif (!in_array($row['TYPE_NAME'], array('datetime', 'text'))) |
|
1474 | + $columns[$column_name]['len'] = strtolower($row['LENGTH']); |
|
1475 | + if (stristr($row['TYPE_NAME'], 'identity')) { |
|
1476 | 1476 | $columns[$column_name]['auto_increment'] = '1'; |
1477 | - $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
|
1477 | + $columns[$column_name]['type'] = str_replace(' identity', '', strtolower($row['TYPE_NAME'])); |
|
1478 | 1478 | } |
1479 | 1479 | |
1480 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
1480 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'], 'PRI'))) |
|
1481 | 1481 | $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
1482 | 1482 | |
1483 | 1483 | $column_def = 1; |
1484 | - if ( strtolower($tablename) == 'relationships' ) { |
|
1484 | + if (strtolower($tablename) == 'relationships') { |
|
1485 | 1485 | $column_def = $this->getOne("select cdefault from syscolumns where id = object_id('relationships') and name = '$column_name'"); |
1486 | 1486 | } |
1487 | - if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
1487 | + if ($column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
|
1488 | 1488 | $matches = array(); |
1489 | - $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
|
1490 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1489 | + $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'], ENT_QUOTES); |
|
1490 | + if (preg_match('/\([\(|\'](.*)[\)|\']\)/i', $row['COLUMN_DEF'], $matches)) |
|
1491 | 1491 | $columns[$column_name]['default'] = $matches[1]; |
1492 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1492 | + elseif (preg_match('/\(N\'(.*)\'\)/i', $row['COLUMN_DEF'], $matches)) |
|
1493 | 1493 | $columns[$column_name]['default'] = $matches[1]; |
1494 | 1494 | else |
1495 | 1495 | $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
@@ -1504,7 +1504,7 @@ discard block |
||
1504 | 1504 | */ |
1505 | 1505 | protected function ftsCatalogName() |
1506 | 1506 | { |
1507 | - if(isset($this->connectOptions['db_name'])) { |
|
1507 | + if (isset($this->connectOptions['db_name'])) { |
|
1508 | 1508 | return $this->connectOptions['db_name']."_fts_catalog"; |
1509 | 1509 | } |
1510 | 1510 | return 'sugar_fts_catalog'; |
@@ -1516,11 +1516,11 @@ discard block |
||
1516 | 1516 | public function add_drop_constraint($table, $definition, $drop = false) |
1517 | 1517 | { |
1518 | 1518 | $type = $definition['type']; |
1519 | - $fields = is_array($definition['fields'])?implode(',',$definition['fields']):$definition['fields']; |
|
1519 | + $fields = is_array($definition['fields']) ? implode(',', $definition['fields']) : $definition['fields']; |
|
1520 | 1520 | $name = $definition['name']; |
1521 | 1521 | $sql = ''; |
1522 | 1522 | |
1523 | - switch ($type){ |
|
1523 | + switch ($type) { |
|
1524 | 1524 | // generic indices |
1525 | 1525 | case 'index': |
1526 | 1526 | case 'alternate_key': |
@@ -1558,13 +1558,13 @@ discard block |
||
1558 | 1558 | if ($this->full_text_indexing_enabled() && $drop) { |
1559 | 1559 | $sql = "DROP FULLTEXT INDEX ON {$table}"; |
1560 | 1560 | } elseif ($this->full_text_indexing_enabled()) { |
1561 | - $catalog_name=$this->ftsCatalogName(); |
|
1562 | - if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1561 | + $catalog_name = $this->ftsCatalogName(); |
|
1562 | + if (isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1563 | 1563 | $catalog_name = $definition['catalog_name']; |
1564 | 1564 | |
1565 | 1565 | $language = "Language 1033"; |
1566 | 1566 | if (isset($definition['language']) && !empty($definition['language'])) |
1567 | - $language = "Language " . $definition['language']; |
|
1567 | + $language = "Language ".$definition['language']; |
|
1568 | 1568 | |
1569 | 1569 | $key_index = $definition['key_index']; |
1570 | 1570 | |
@@ -1572,7 +1572,7 @@ discard block |
||
1572 | 1572 | if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) |
1573 | 1573 | $change_tracking = $definition['change_tracking']; |
1574 | 1574 | |
1575 | - $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ; |
|
1575 | + $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking"; |
|
1576 | 1576 | } |
1577 | 1577 | break; |
1578 | 1578 | } |
@@ -1596,11 +1596,11 @@ discard block |
||
1596 | 1596 | protected function full_text_indexing_enabled($dbname = null) |
1597 | 1597 | { |
1598 | 1598 | // check to see if we already have install setting in session |
1599 | - if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1599 | + if (!isset($_SESSION['IsFulltextInstalled'])) |
|
1600 | 1600 | $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
1601 | 1601 | |
1602 | 1602 | // check to see if FTS Indexing service is installed |
1603 | - if(empty($_SESSION['IsFulltextInstalled'])) |
|
1603 | + if (empty($_SESSION['IsFulltextInstalled'])) |
|
1604 | 1604 | return false; |
1605 | 1605 | |
1606 | 1606 | // grab the dbname if it was not passed through |
@@ -1650,7 +1650,7 @@ discard block |
||
1650 | 1650 | { |
1651 | 1651 | static $results = array(); |
1652 | 1652 | |
1653 | - if ( empty($column) && isset($results[$table]) ) |
|
1653 | + if (empty($column) && isset($results[$table])) |
|
1654 | 1654 | return $results[$table]; |
1655 | 1655 | |
1656 | 1656 | $query = <<<EOQ |
@@ -1664,17 +1664,17 @@ discard block |
||
1664 | 1664 | on s.schema_id = o.schema_id |
1665 | 1665 | where o.name = '$table' |
1666 | 1666 | EOQ; |
1667 | - if ( !empty($column) ) |
|
1667 | + if (!empty($column)) |
|
1668 | 1668 | $query .= " and c.name = '$column'"; |
1669 | 1669 | $res = $this->query($query); |
1670 | - if ( !empty($column) ) { |
|
1670 | + if (!empty($column)) { |
|
1671 | 1671 | $row = $this->fetchByAssoc($res); |
1672 | 1672 | if (!empty($row)) |
1673 | 1673 | return $row['ctrt']; |
1674 | 1674 | } |
1675 | 1675 | else { |
1676 | 1676 | $returnResult = array(); |
1677 | - while ( $row = $this->fetchByAssoc($res) ) |
|
1677 | + while ($row = $this->fetchByAssoc($res)) |
|
1678 | 1678 | $returnResult[$row['dtrt']] = $row['ctrt']; |
1679 | 1679 | $results[$table] = $returnResult; |
1680 | 1680 | return $returnResult; |
@@ -1688,14 +1688,14 @@ discard block |
||
1688 | 1688 | */ |
1689 | 1689 | public function massageFieldDef(&$fieldDef, $tablename) |
1690 | 1690 | { |
1691 | - parent::massageFieldDef($fieldDef,$tablename); |
|
1691 | + parent::massageFieldDef($fieldDef, $tablename); |
|
1692 | 1692 | |
1693 | 1693 | if ($fieldDef['type'] == 'int') |
1694 | 1694 | $fieldDef['len'] = '4'; |
1695 | 1695 | |
1696 | - if(empty($fieldDef['len'])) |
|
1696 | + if (empty($fieldDef['len'])) |
|
1697 | 1697 | { |
1698 | - switch($fieldDef['type']) { |
|
1698 | + switch ($fieldDef['type']) { |
|
1699 | 1699 | case 'bit' : |
1700 | 1700 | case 'bool' : $fieldDef['len'] = '1'; break; |
1701 | 1701 | case 'smallint' : $fieldDef['len'] = '2'; break; |
@@ -1705,22 +1705,22 @@ discard block |
||
1705 | 1705 | $fieldDef['len'] = $this->isTextType($fieldDef['dbType']) ? 'max' : '255'; |
1706 | 1706 | break; |
1707 | 1707 | case 'image' : $fieldDef['len'] = '2147483647'; break; |
1708 | - case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
|
1708 | + case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
|
1709 | 1709 | } |
1710 | 1710 | } |
1711 | - if($fieldDef['type'] == 'decimal' |
|
1711 | + if ($fieldDef['type'] == 'decimal' |
|
1712 | 1712 | && empty($fieldDef['precision']) |
1713 | 1713 | && !strpos($fieldDef['len'], ',')) |
1714 | 1714 | { |
1715 | 1715 | $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
1716 | 1716 | } |
1717 | 1717 | |
1718 | - if(empty($fieldDef['default']) |
|
1719 | - && in_array($fieldDef['type'],array('bit','bool'))) |
|
1718 | + if (empty($fieldDef['default']) |
|
1719 | + && in_array($fieldDef['type'], array('bit', 'bool'))) |
|
1720 | 1720 | { |
1721 | 1721 | $fieldDef['default'] = '0'; |
1722 | 1722 | } |
1723 | - if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1723 | + if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default'])) |
|
1724 | 1724 | $fieldDef['default'] = ''; |
1725 | 1725 | // if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
1726 | 1726 | // $fieldDef['len'] = '1'; |
@@ -1751,13 +1751,13 @@ discard block |
||
1751 | 1751 | protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
1752 | 1752 | { |
1753 | 1753 | //Bug 25814 |
1754 | - if(isset($fieldDef['name'])){ |
|
1754 | + if (isset($fieldDef['name'])) { |
|
1755 | 1755 | $colType = $this->getFieldType($fieldDef); |
1756 | - if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1757 | - $fieldDef['len'] = min($fieldDef['len'],38); |
|
1756 | + if (stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])) { |
|
1757 | + $fieldDef['len'] = min($fieldDef['len'], 38); |
|
1758 | 1758 | } |
1759 | 1759 | //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
1760 | - if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1760 | + if (stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8) { |
|
1761 | 1761 | unset($fieldDef['len']); |
1762 | 1762 | } |
1763 | 1763 | } |
@@ -1766,10 +1766,10 @@ discard block |
||
1766 | 1766 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
1767 | 1767 | |
1768 | 1768 | // Bug 24307 - Don't add precision for float fields. |
1769 | - if ( stristr($ref['colType'],'float') ) |
|
1770 | - $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1769 | + if (stristr($ref['colType'], 'float')) |
|
1770 | + $ref['colType'] = preg_replace('/(,\d+)/', '', $ref['colType']); |
|
1771 | 1771 | |
1772 | - if ( $return_as_array ) |
|
1772 | + if ($return_as_array) |
|
1773 | 1773 | return $ref; |
1774 | 1774 | else |
1775 | 1775 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
@@ -1784,10 +1784,10 @@ discard block |
||
1784 | 1784 | public function save_audit_records(SugarBean $bean, $changes) |
1785 | 1785 | { |
1786 | 1786 | //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
1787 | - if($changes['data_type'] == 'date'){ |
|
1788 | - $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1787 | + if ($changes['data_type'] == 'date') { |
|
1788 | + $changes['before'] = str_replace(' 00:00:00', '', $changes['before']); |
|
1789 | 1789 | } |
1790 | - parent::save_audit_records($bean,$changes); |
|
1790 | + parent::save_audit_records($bean, $changes); |
|
1791 | 1791 | } |
1792 | 1792 | |
1793 | 1793 | /** |
@@ -1798,7 +1798,7 @@ discard block |
||
1798 | 1798 | public function disconnect() |
1799 | 1799 | { |
1800 | 1800 | $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
1801 | - if(!empty($this->database)){ |
|
1801 | + if (!empty($this->database)) { |
|
1802 | 1802 | $this->freeResult(); |
1803 | 1803 | mssql_close($this->database); |
1804 | 1804 | $this->database = null; |
@@ -1810,7 +1810,7 @@ discard block |
||
1810 | 1810 | */ |
1811 | 1811 | protected function freeDbResult($dbResult) |
1812 | 1812 | { |
1813 | - if(!empty($dbResult)) |
|
1813 | + if (!empty($dbResult)) |
|
1814 | 1814 | mssql_free_result($dbResult); |
1815 | 1815 | } |
1816 | 1816 | |
@@ -1821,11 +1821,11 @@ discard block |
||
1821 | 1821 | public function lastDbError() |
1822 | 1822 | { |
1823 | 1823 | $sqlmsg = mssql_get_last_message(); |
1824 | - if(empty($sqlmsg)) return false; |
|
1824 | + if (empty($sqlmsg)) return false; |
|
1825 | 1825 | global $app_strings; |
1826 | 1826 | if (empty($app_strings) |
1827 | 1827 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
1828 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1828 | + or !isset($app_strings['ERR_MSSQL_WARNING'])) { |
|
1829 | 1829 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1830 | 1830 | //only if connection if made before language is set. |
1831 | 1831 | return false; |
@@ -1834,7 +1834,7 @@ discard block |
||
1834 | 1834 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
1835 | 1835 | $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
1836 | 1836 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
1837 | - if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
|
1837 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) { |
|
1838 | 1838 | return false; |
1839 | 1839 | } else { |
1840 | 1840 | global $app_strings; |
@@ -1842,18 +1842,18 @@ discard block |
||
1842 | 1842 | if (empty($app_strings) or !isset($app_strings['ERR_MSSQL_DB_CONTEXT'])) { |
1843 | 1843 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1844 | 1844 | //only if connection if made before languge is set. |
1845 | - $GLOBALS['log']->debug("Ignoring this database message: " . $sqlmsg); |
|
1845 | + $GLOBALS['log']->debug("Ignoring this database message: ".$sqlmsg); |
|
1846 | 1846 | return false; |
1847 | 1847 | } |
1848 | 1848 | else { |
1849 | 1849 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
1850 | - if ( $sqlpos !== false ) |
|
1850 | + if ($sqlpos !== false) |
|
1851 | 1851 | return false; |
1852 | 1852 | } |
1853 | 1853 | } |
1854 | 1854 | |
1855 | - if ( strlen($sqlmsg) > 2 ) { |
|
1856 | - return "SQL Server error: " . $sqlmsg; |
|
1855 | + if (strlen($sqlmsg) > 2) { |
|
1856 | + return "SQL Server error: ".$sqlmsg; |
|
1857 | 1857 | } |
1858 | 1858 | |
1859 | 1859 | return false; |
@@ -1874,7 +1874,7 @@ discard block |
||
1874 | 1874 | */ |
1875 | 1875 | public function validateQuery($query) |
1876 | 1876 | { |
1877 | - if(!$this->isSelect($query)) { |
|
1877 | + if (!$this->isSelect($query)) { |
|
1878 | 1878 | return false; |
1879 | 1879 | } |
1880 | 1880 | $this->query("SET SHOWPLAN_TEXT ON"); |
@@ -1898,7 +1898,7 @@ discard block |
||
1898 | 1898 | |
1899 | 1899 | // Flag if there are odd number of single quotes, just continue without trying to append N |
1900 | 1900 | if ((substr_count($sql, "'") & 1)) { |
1901 | - $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
1901 | + $GLOBALS['log']->error("SQL statement[".$sql."] has odd number of single quotes."); |
|
1902 | 1902 | return $sql; |
1903 | 1903 | } |
1904 | 1904 | |
@@ -1928,7 +1928,7 @@ discard block |
||
1928 | 1928 | // We are assuming that all nvarchar columns are no more than 200 characters in length |
1929 | 1929 | // One problem we face is the image column type in reports which cannot accept nvarchar data |
1930 | 1930 | if (!empty($value) && !is_numeric(trim(str_replace(array("'", ","), "", $value))) && !preg_match('/^\'[\,]\'$/', $value)) { |
1931 | - $replace[$value] = 'N' . trim($value, "N"); |
|
1931 | + $replace[$value] = 'N'.trim($value, "N"); |
|
1932 | 1932 | } |
1933 | 1933 | } |
1934 | 1934 | } |
@@ -1939,7 +1939,7 @@ discard block |
||
1939 | 1939 | if (!empty($pairs)) |
1940 | 1940 | $sql = str_replace(array_keys($pairs), $pairs, $sql); |
1941 | 1941 | |
1942 | - if(strpos($sql, "<@#@#@PAIR@#@#@>")) |
|
1942 | + if (strpos($sql, "<@#@#@PAIR@#@#@>")) |
|
1943 | 1943 | $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql); |
1944 | 1944 | |
1945 | 1945 | return $sql; |
@@ -1966,22 +1966,22 @@ discard block |
||
1966 | 1966 | public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
1967 | 1967 | { |
1968 | 1968 | $condition = $or_condition = array(); |
1969 | - foreach($must_terms as $term) { |
|
1969 | + foreach ($must_terms as $term) { |
|
1970 | 1970 | $condition[] = $this->quoteTerm($term); |
1971 | 1971 | } |
1972 | 1972 | |
1973 | - foreach($terms as $term) { |
|
1973 | + foreach ($terms as $term) { |
|
1974 | 1974 | $or_condition[] = $this->quoteTerm($term); |
1975 | 1975 | } |
1976 | 1976 | |
1977 | - if(!empty($or_condition)) { |
|
1977 | + if (!empty($or_condition)) { |
|
1978 | 1978 | $condition[] = "(".join(" | ", $or_condition).")"; |
1979 | 1979 | } |
1980 | 1980 | |
1981 | - foreach($exclude_terms as $term) { |
|
1981 | + foreach ($exclude_terms as $term) { |
|
1982 | 1982 | $condition[] = " NOT ".$this->quoteTerm($term); |
1983 | 1983 | } |
1984 | - $condition = $this->quoted(join(" AND ",$condition)); |
|
1984 | + $condition = $this->quoted(join(" AND ", $condition)); |
|
1985 | 1985 | return "CONTAINS($field, $condition)"; |
1986 | 1986 | } |
1987 | 1987 | |
@@ -2070,7 +2070,7 @@ discard block |
||
2070 | 2070 | public function isDatabaseNameValid($name) |
2071 | 2071 | { |
2072 | 2072 | // No funny chars, does not begin with number |
2073 | - return preg_match('/^[0-9#@]+|[\"\'\*\/\\?\:\\<\>\-\ \&\!\(\)\[\]\{\}\;\,\.\`\~\|\\\\]+/', $name)==0; |
|
2073 | + return preg_match('/^[0-9#@]+|[\"\'\*\/\\?\:\\<\>\-\ \&\!\(\)\[\]\{\}\;\,\.\`\~\|\\\\]+/', $name) == 0; |
|
2074 | 2074 | } |
2075 | 2075 | |
2076 | 2076 | public function installConfig() |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
3 | + die('Not A Valid Entry Point'); |
|
4 | +} |
|
3 | 5 | /********************************************************************************* |
4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -168,8 +170,9 @@ discard block |
||
168 | 170 | { |
169 | 171 | global $sugar_config; |
170 | 172 | |
171 | - if (is_null($configOptions)) |
|
172 | - $configOptions = $sugar_config['dbconfig']; |
|
173 | + if (is_null($configOptions)) { |
|
174 | + $configOptions = $sugar_config['dbconfig']; |
|
175 | + } |
|
173 | 176 | |
174 | 177 | //SET DATEFORMAT to 'YYYY-MM-DD'' |
175 | 178 | ini_set('mssql.datetimeconvert', '0'); |
@@ -258,8 +261,9 @@ discard block |
||
258 | 261 | } |
259 | 262 | } |
260 | 263 | |
261 | - if(!$this->checkError('Could Not Connect', $dieOnError)) |
|
262 | - $GLOBALS['log']->info("connected to db"); |
|
264 | + if(!$this->checkError('Could Not Connect', $dieOnError)) { |
|
265 | + $GLOBALS['log']->info("connected to db"); |
|
266 | + } |
|
263 | 267 | |
264 | 268 | $this->connectOptions = $configOptions; |
265 | 269 | |
@@ -284,8 +288,9 @@ discard block |
||
284 | 288 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
285 | 289 | } |
286 | 290 | // Flag if there are odd number of single quotes |
287 | - if ((substr_count($sql, "'") & 1)) |
|
288 | - $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
291 | + if ((substr_count($sql, "'") & 1)) { |
|
292 | + $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
|
293 | + } |
|
289 | 294 | |
290 | 295 | $sql = $this->_appendN($sql); |
291 | 296 | |
@@ -308,14 +313,16 @@ discard block |
||
308 | 313 | $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
309 | 314 | $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
310 | 315 | |
311 | - if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
|
316 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) { |
|
317 | + // if sqlmsg has 'Changed database context to', just log it |
|
312 | 318 | $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
313 | - else { |
|
319 | + } else { |
|
314 | 320 | $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
315 | - if($dieOnError) |
|
316 | - sugar_die('SQL Error : ' . $sqlmsg); |
|
317 | - else |
|
318 | - echo 'SQL Error : ' . $sqlmsg; |
|
321 | + if($dieOnError) { |
|
322 | + sugar_die('SQL Error : ' . $sqlmsg); |
|
323 | + } else { |
|
324 | + echo 'SQL Error : ' . $sqlmsg; |
|
325 | + } |
|
319 | 326 | } |
320 | 327 | } |
321 | 328 | |
@@ -340,8 +347,9 @@ discard block |
||
340 | 347 | private function handleUnionLimitQuery($sql, $start, $count) |
341 | 348 | { |
342 | 349 | //set the start to 0, no negs |
343 | - if ($start < 0) |
|
344 | - $start=0; |
|
350 | + if ($start < 0) { |
|
351 | + $start=0; |
|
352 | + } |
|
345 | 353 | |
346 | 354 | $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
347 | 355 | |
@@ -390,8 +398,7 @@ discard block |
||
390 | 398 | $rowNumOrderBy = 'id'; |
391 | 399 | $unionOrderBy = ""; |
392 | 400 | } |
393 | - } |
|
394 | - else { |
|
401 | + } else { |
|
395 | 402 | //there are no order by elements, so just pass back string |
396 | 403 | $unionsql = $sql; |
397 | 404 | //with no guidance on what to use for required order by in rownumber function, |
@@ -413,8 +420,7 @@ discard block |
||
413 | 420 | if ($count == 1 && $start == 0) |
414 | 421 | { |
415 | 422 | $limitUnionSQL = "SELECT TOP $count * FROM (" .$unionsql .") as top_count ".$unionOrderBy; |
416 | - } |
|
417 | - else |
|
423 | + } else |
|
418 | 424 | { |
419 | 425 | $limitUnionSQL = "SELECT TOP $count * FROM( select ROW_NUMBER() OVER ( order by " |
420 | 426 | .$rowNumOrderBy.") AS row_number, * FROM (" |
@@ -436,11 +442,12 @@ discard block |
||
436 | 442 | $count = (int)$count; |
437 | 443 | $newSQL = $sql; |
438 | 444 | $distinctSQLARRAY = array(); |
439 | - if (strpos($sql, "UNION") && !preg_match("/(')(UNION).?(')/i", $sql)) |
|
440 | - $newSQL = $this->handleUnionLimitQuery($sql,$start,$count); |
|
441 | - else { |
|
442 | - if ($start < 0) |
|
443 | - $start = 0; |
|
445 | + if (strpos($sql, "UNION") && !preg_match("/(')(UNION).?(')/i", $sql)) { |
|
446 | + $newSQL = $this->handleUnionLimitQuery($sql,$start,$count); |
|
447 | + } else { |
|
448 | + if ($start < 0) { |
|
449 | + $start = 0; |
|
450 | + } |
|
444 | 451 | $GLOBALS['log']->debug(print_r(func_get_args(),true)); |
445 | 452 | $this->lastsql = $sql; |
446 | 453 | $matches = array(); |
@@ -461,20 +468,17 @@ discard block |
||
461 | 468 | " . $selectPart[2] . $orderByMatch[1]. " |
462 | 469 | ) AS a |
463 | 470 | WHERE row_number > $start"; |
464 | - } |
|
465 | - else { |
|
471 | + } else { |
|
466 | 472 | $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
467 | 473 | } |
468 | - } |
|
469 | - else { |
|
474 | + } else { |
|
470 | 475 | $distinct_o = strpos($match_two, "distinct"); |
471 | 476 | $up_to_distinct_str = substr($match_two, 0, $distinct_o); |
472 | 477 | //check to see if the distinct is within a function, if so, then proceed as normal |
473 | 478 | if (strpos($up_to_distinct_str,"(")) { |
474 | 479 | //proceed as normal |
475 | 480 | $newSQL = $matches[1] . " TOP $count " . $matches[2] . $matches[3]; |
476 | - } |
|
477 | - else { |
|
481 | + } else { |
|
478 | 482 | //if distinct is not within a function, then parse |
479 | 483 | //string contains distinct clause, "TOP needs to come after Distinct" |
480 | 484 | //get position of distinct |
@@ -627,8 +631,9 @@ discard block |
||
627 | 631 | //strip all single quotes out |
628 | 632 | $count = substr_count ( $p_sql, $strip_beg); |
629 | 633 | $increment = 1; |
630 | - if ($strip_beg != $strip_end) |
|
631 | - $increment = 2; |
|
634 | + if ($strip_beg != $strip_end) { |
|
635 | + $increment = 2; |
|
636 | + } |
|
632 | 637 | |
633 | 638 | $i=0; |
634 | 639 | $offset = 0; |
@@ -791,9 +796,10 @@ discard block |
||
791 | 796 | { |
792 | 797 | $sql = strtolower($sql); |
793 | 798 | $orig_order_match = trim($orig_order_match); |
794 | - if (strpos($orig_order_match, ".") != 0) |
|
795 | - //this has a tablename defined, pass in the order match |
|
799 | + if (strpos($orig_order_match, ".") != 0) { |
|
800 | + //this has a tablename defined, pass in the order match |
|
796 | 801 | return $orig_order_match; |
802 | + } |
|
797 | 803 | |
798 | 804 | // If there is no ordering direction (ASC/DESC), use ASC by default |
799 | 805 | if (strpos($orig_order_match, " ") === false) { |
@@ -835,15 +841,15 @@ discard block |
||
835 | 841 | //break out of here, log this |
836 | 842 | $GLOBALS['log']->debug("No match was found for order by, pass string back untouched as: $orig_order_match"); |
837 | 843 | return $orig_order_match; |
838 | - } |
|
839 | - else { |
|
844 | + } else { |
|
840 | 845 | //if found, then parse and return |
841 | 846 | //grab string up to the aliased column |
842 | 847 | $GLOBALS['log']->debug("order by found, process sql string"); |
843 | 848 | |
844 | 849 | $psql = (trim($this->getAliasFromSQL($sql, $orderMatch ))); |
845 | - if (empty($psql)) |
|
846 | - $psql = trim(substr($sql, 0, $found_in_sql)); |
|
850 | + if (empty($psql)) { |
|
851 | + $psql = trim(substr($sql, 0, $found_in_sql)); |
|
852 | + } |
|
847 | 853 | |
848 | 854 | //grab the last comma before the alias |
849 | 855 | preg_match('/\s+' . trim($orderMatch). '/', $psql, $match, PREG_OFFSET_CAPTURE); |
@@ -856,8 +862,9 @@ discard block |
||
856 | 862 | //this is especially true for unified search from home screen |
857 | 863 | |
858 | 864 | $alias_beg_pos = 0; |
859 | - if(strpos($psql, " as ")) |
|
860 | - $alias_beg_pos = strpos($psql, " as "); |
|
865 | + if(strpos($psql, " as ")) { |
|
866 | + $alias_beg_pos = strpos($psql, " as "); |
|
867 | + } |
|
861 | 868 | |
862 | 869 | // Bug # 44923 - This breaks the query and does not properly filter isnull |
863 | 870 | // as there are other functions such as ltrim and rtrim. |
@@ -894,8 +901,9 @@ discard block |
||
894 | 901 | //correct table name. |
895 | 902 | if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str]) && isset($beanFiles[$beanList[$module_str]])){ |
896 | 903 | //if the class is not already loaded, then load files |
897 | - if (!class_exists($beanList[$module_str])) |
|
898 | - require_once($beanFiles[$beanList[$module_str]]); |
|
904 | + if (!class_exists($beanList[$module_str])) { |
|
905 | + require_once($beanFiles[$beanList[$module_str]]); |
|
906 | + } |
|
899 | 907 | |
900 | 908 | //instantiate new bean |
901 | 909 | $module_bean = new $beanList[$module_str](); |
@@ -908,8 +916,7 @@ discard block |
||
908 | 916 | $GLOBALS['log']->debug("Could not find table name for module $module_str. "); |
909 | 917 | $tbl_name = $module_str; |
910 | 918 | } |
911 | - } |
|
912 | - else { |
|
919 | + } else { |
|
913 | 920 | //since the module does NOT exist in beanlist, then we have to parse the string |
914 | 921 | //and grab the table name from the passed in sql |
915 | 922 | $GLOBALS['log']->debug("Could not find table name from module in request, retrieve from passed in sql"); |
@@ -930,8 +937,9 @@ discard block |
||
930 | 937 | // MFH BUG #14009: Also check to see if there are any carriage returns before the next space so that we don't grab any arbitrary joins or other tables. |
931 | 938 | $carriage_ret = strpos($tableEnd,"\n"); |
932 | 939 | $next_space = strpos($tableEnd," " ); |
933 | - if ($carriage_ret < $next_space) |
|
934 | - $next_space = $carriage_ret; |
|
940 | + if ($carriage_ret < $next_space) { |
|
941 | + $next_space = $carriage_ret; |
|
942 | + } |
|
935 | 943 | if ($next_space > 0) { |
936 | 944 | $tbl_name= substr($tableEnd,0, $next_space); |
937 | 945 | if(empty($tbl_name)){ |
@@ -954,18 +962,17 @@ discard block |
||
954 | 962 | || $alias_tbl_name == "outer" |
955 | 963 | || $alias_tbl_name == "right") { |
956 | 964 | //not aliased, do nothing |
957 | - } |
|
958 | - elseif ($alias_tbl_name == "as") { |
|
965 | + } elseif ($alias_tbl_name == "as") { |
|
959 | 966 | //the next word is the table name |
960 | 967 | $aliasTableEnd = trim(substr($aliasTableEnd, $alias_space)); |
961 | 968 | $alias_space = strpos ($aliasTableEnd, " " ); |
962 | 969 | if ($alias_space > 0) { |
963 | 970 | $alias_tbl_name= trim(substr($aliasTableEnd,0, $alias_space)); |
964 | - if (!empty($alias_tbl_name)) |
|
965 | - $tbl_name = $alias_tbl_name; |
|
971 | + if (!empty($alias_tbl_name)) { |
|
972 | + $tbl_name = $alias_tbl_name; |
|
973 | + } |
|
966 | 974 | } |
967 | - } |
|
968 | - else { |
|
975 | + } else { |
|
969 | 976 | //this is table alias |
970 | 977 | $tbl_name = $alias_tbl_name; |
971 | 978 | } |
@@ -985,16 +992,19 @@ discard block |
||
985 | 992 | { |
986 | 993 | $field_array = array(); |
987 | 994 | |
988 | - if(! isset($result) || empty($result)) |
|
989 | - return 0; |
|
995 | + if(! isset($result) || empty($result)) { |
|
996 | + return 0; |
|
997 | + } |
|
990 | 998 | |
991 | 999 | $i = 0; |
992 | 1000 | while ($i < mssql_num_fields($result)) { |
993 | 1001 | $meta = mssql_fetch_field($result, $i); |
994 | - if (!$meta) |
|
995 | - return 0; |
|
996 | - if($make_lower_case==true) |
|
997 | - $meta->name = strtolower($meta->name); |
|
1002 | + if (!$meta) { |
|
1003 | + return 0; |
|
1004 | + } |
|
1005 | + if($make_lower_case==true) { |
|
1006 | + $meta->name = strtolower($meta->name); |
|
1007 | + } |
|
998 | 1008 | |
999 | 1009 | $field_array[] = $meta->name; |
1000 | 1010 | |
@@ -1017,7 +1027,9 @@ discard block |
||
1017 | 1027 | */ |
1018 | 1028 | public function fetchRow($result) |
1019 | 1029 | { |
1020 | - if (empty($result)) return false; |
|
1030 | + if (empty($result)) { |
|
1031 | + return false; |
|
1032 | + } |
|
1021 | 1033 | |
1022 | 1034 | $row = mssql_fetch_assoc($result); |
1023 | 1035 | //MSSQL returns a space " " when a varchar column is empty ("") and not null. |
@@ -1099,8 +1111,9 @@ discard block |
||
1099 | 1111 | $tables = array(); |
1100 | 1112 | $r = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES'); |
1101 | 1113 | if (is_resource($r)) { |
1102 | - while ($a = $this->fetchByAssoc($r)) |
|
1103 | - $tables[] = $a['TABLE_NAME']; |
|
1114 | + while ($a = $this->fetchByAssoc($r)) { |
|
1115 | + $tables[] = $a['TABLE_NAME']; |
|
1116 | + } |
|
1104 | 1117 | |
1105 | 1118 | return $tables; |
1106 | 1119 | } |
@@ -1257,12 +1270,14 @@ discard block |
||
1257 | 1270 | */ |
1258 | 1271 | public function createTableSQLParams($tablename, $fieldDefs, $indices) |
1259 | 1272 | { |
1260 | - if (empty($tablename) || empty($fieldDefs)) |
|
1261 | - return ''; |
|
1273 | + if (empty($tablename) || empty($fieldDefs)) { |
|
1274 | + return ''; |
|
1275 | + } |
|
1262 | 1276 | |
1263 | 1277 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
1264 | - if (empty($columns)) |
|
1265 | - return ''; |
|
1278 | + if (empty($columns)) { |
|
1279 | + return ''; |
|
1280 | + } |
|
1266 | 1281 | |
1267 | 1282 | return "CREATE TABLE $tablename ($columns)"; |
1268 | 1283 | } |
@@ -1274,7 +1289,9 @@ discard block |
||
1274 | 1289 | public function isTextType($type) |
1275 | 1290 | { |
1276 | 1291 | $type = strtolower($type); |
1277 | - if(!isset($this->type_map[$type])) return false; |
|
1292 | + if(!isset($this->type_map[$type])) { |
|
1293 | + return false; |
|
1294 | + } |
|
1278 | 1295 | return in_array($this->type_map[$type], array('ntext','text','image', 'nvarchar(max)')); |
1279 | 1296 | } |
1280 | 1297 | |
@@ -1327,8 +1344,9 @@ discard block |
||
1327 | 1344 | $f_def = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true); |
1328 | 1345 | $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '. |
1329 | 1346 | $f_def['required'].' '.$f_def['auto_increment']."\n"; |
1330 | - if (!empty( $f_def['default'])) |
|
1331 | - $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1347 | + if (!empty( $f_def['default'])) { |
|
1348 | + $f_stmt .= " ALTER TABLE " . $tablename . " ADD ". $f_def['default'] . " FOR " . $def['name']; |
|
1349 | + } |
|
1332 | 1350 | return $f_stmt; |
1333 | 1351 | break; |
1334 | 1352 | default: |
@@ -1366,8 +1384,7 @@ discard block |
||
1366 | 1384 | |
1367 | 1385 | $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
1368 | 1386 | } |
1369 | - } |
|
1370 | - else { |
|
1387 | + } else { |
|
1371 | 1388 | //if the column is being modified drop the default value |
1372 | 1389 | //constraint if it exists. alterSQLRep will add the constraint back |
1373 | 1390 | if (!empty($constraints[$fieldDefs['name']])) { |
@@ -1402,8 +1419,9 @@ discard block |
||
1402 | 1419 | */ |
1403 | 1420 | public function setAutoIncrementStart($table, $field_name, $start_value) |
1404 | 1421 | { |
1405 | - if($start_value > 1) |
|
1406 | - $start_value -= 1; |
|
1422 | + if($start_value > 1) { |
|
1423 | + $start_value -= 1; |
|
1424 | + } |
|
1407 | 1425 | $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
1408 | 1426 | return true; |
1409 | 1427 | } |
@@ -1439,10 +1457,11 @@ discard block |
||
1439 | 1457 | $indices = array(); |
1440 | 1458 | while (($row=$this->fetchByAssoc($result)) != null) { |
1441 | 1459 | $index_type = 'index'; |
1442 | - if ($row['is_primary_key'] == '1') |
|
1443 | - $index_type = 'primary'; |
|
1444 | - elseif ($row['is_unique'] == 1 ) |
|
1445 | - $index_type = 'unique'; |
|
1460 | + if ($row['is_primary_key'] == '1') { |
|
1461 | + $index_type = 'primary'; |
|
1462 | + } elseif ($row['is_unique'] == 1 ) { |
|
1463 | + $index_type = 'unique'; |
|
1464 | + } |
|
1446 | 1465 | $name = strtolower($row['index_name']); |
1447 | 1466 | $indices[$name]['name'] = $name; |
1448 | 1467 | $indices[$name]['type'] = $index_type; |
@@ -1467,18 +1486,19 @@ discard block |
||
1467 | 1486 | if ( $row['TYPE_NAME'] == 'decimal' ) { |
1468 | 1487 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
1469 | 1488 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
1489 | + } elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
1490 | + $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1491 | + } elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
|
1492 | + $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
1470 | 1493 | } |
1471 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1472 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1473 | - elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) |
|
1474 | - $columns[$column_name]['len']=strtolower($row['LENGTH']); |
|
1475 | 1494 | if ( stristr($row['TYPE_NAME'],'identity') ) { |
1476 | 1495 | $columns[$column_name]['auto_increment'] = '1'; |
1477 | 1496 | $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME'])); |
1478 | 1497 | } |
1479 | 1498 | |
1480 | - if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) |
|
1481 | - $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
|
1499 | + if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) { |
|
1500 | + $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true'; |
|
1501 | + } |
|
1482 | 1502 | |
1483 | 1503 | $column_def = 1; |
1484 | 1504 | if ( strtolower($tablename) == 'relationships' ) { |
@@ -1487,12 +1507,13 @@ discard block |
||
1487 | 1507 | if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) { // NOTE Not using !empty as an empty string may be a viable default value. |
1488 | 1508 | $matches = array(); |
1489 | 1509 | $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES); |
1490 | - if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1491 | - $columns[$column_name]['default'] = $matches[1]; |
|
1492 | - elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) |
|
1493 | - $columns[$column_name]['default'] = $matches[1]; |
|
1494 | - else |
|
1495 | - $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
|
1510 | + if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) { |
|
1511 | + $columns[$column_name]['default'] = $matches[1]; |
|
1512 | + } elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) { |
|
1513 | + $columns[$column_name]['default'] = $matches[1]; |
|
1514 | + } else { |
|
1515 | + $columns[$column_name]['default'] = $row['COLUMN_DEF']; |
|
1516 | + } |
|
1496 | 1517 | } |
1497 | 1518 | } |
1498 | 1519 | return $columns; |
@@ -1524,53 +1545,61 @@ discard block |
||
1524 | 1545 | // generic indices |
1525 | 1546 | case 'index': |
1526 | 1547 | case 'alternate_key': |
1527 | - if ($drop) |
|
1528 | - $sql = "DROP INDEX {$name} ON {$table}"; |
|
1529 | - else |
|
1530 | - $sql = "CREATE INDEX {$name} ON {$table} ({$fields})"; |
|
1548 | + if ($drop) { |
|
1549 | + $sql = "DROP INDEX {$name} ON {$table}"; |
|
1550 | + } else { |
|
1551 | + $sql = "CREATE INDEX {$name} ON {$table} ({$fields})"; |
|
1552 | + } |
|
1531 | 1553 | break; |
1532 | 1554 | case 'clustered': |
1533 | - if ($drop) |
|
1534 | - $sql = "DROP INDEX {$name} ON {$table}"; |
|
1535 | - else |
|
1536 | - $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)"; |
|
1555 | + if ($drop) { |
|
1556 | + $sql = "DROP INDEX {$name} ON {$table}"; |
|
1557 | + } else { |
|
1558 | + $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)"; |
|
1559 | + } |
|
1537 | 1560 | break; |
1538 | 1561 | // constraints as indices |
1539 | 1562 | case 'unique': |
1540 | - if ($drop) |
|
1541 | - $sql = "ALTER TABLE {$table} DROP CONSTRAINT $name"; |
|
1542 | - else |
|
1543 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE ({$fields})"; |
|
1563 | + if ($drop) { |
|
1564 | + $sql = "ALTER TABLE {$table} DROP CONSTRAINT $name"; |
|
1565 | + } else { |
|
1566 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE ({$fields})"; |
|
1567 | + } |
|
1544 | 1568 | break; |
1545 | 1569 | case 'primary': |
1546 | - if ($drop) |
|
1547 | - $sql = "ALTER TABLE {$table} DROP CONSTRAINT {$name}"; |
|
1548 | - else |
|
1549 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} PRIMARY KEY ({$fields})"; |
|
1570 | + if ($drop) { |
|
1571 | + $sql = "ALTER TABLE {$table} DROP CONSTRAINT {$name}"; |
|
1572 | + } else { |
|
1573 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} PRIMARY KEY ({$fields})"; |
|
1574 | + } |
|
1550 | 1575 | break; |
1551 | 1576 | case 'foreign': |
1552 | - if ($drop) |
|
1553 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
1554 | - else |
|
1555 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} FOREIGN KEY ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignFields']})"; |
|
1577 | + if ($drop) { |
|
1578 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
1579 | + } else { |
|
1580 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} FOREIGN KEY ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignFields']})"; |
|
1581 | + } |
|
1556 | 1582 | break; |
1557 | 1583 | case 'fulltext': |
1558 | 1584 | if ($this->full_text_indexing_enabled() && $drop) { |
1559 | 1585 | $sql = "DROP FULLTEXT INDEX ON {$table}"; |
1560 | 1586 | } elseif ($this->full_text_indexing_enabled()) { |
1561 | 1587 | $catalog_name=$this->ftsCatalogName(); |
1562 | - if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') |
|
1563 | - $catalog_name = $definition['catalog_name']; |
|
1588 | + if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') { |
|
1589 | + $catalog_name = $definition['catalog_name']; |
|
1590 | + } |
|
1564 | 1591 | |
1565 | 1592 | $language = "Language 1033"; |
1566 | - if (isset($definition['language']) && !empty($definition['language'])) |
|
1567 | - $language = "Language " . $definition['language']; |
|
1593 | + if (isset($definition['language']) && !empty($definition['language'])) { |
|
1594 | + $language = "Language " . $definition['language']; |
|
1595 | + } |
|
1568 | 1596 | |
1569 | 1597 | $key_index = $definition['key_index']; |
1570 | 1598 | |
1571 | 1599 | $change_tracking = "auto"; |
1572 | - if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) |
|
1573 | - $change_tracking = $definition['change_tracking']; |
|
1600 | + if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) { |
|
1601 | + $change_tracking = $definition['change_tracking']; |
|
1602 | + } |
|
1574 | 1603 | |
1575 | 1604 | $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ; |
1576 | 1605 | } |
@@ -1596,12 +1625,14 @@ discard block |
||
1596 | 1625 | protected function full_text_indexing_enabled($dbname = null) |
1597 | 1626 | { |
1598 | 1627 | // check to see if we already have install setting in session |
1599 | - if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1600 | - $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
|
1628 | + if(!isset($_SESSION['IsFulltextInstalled'])) { |
|
1629 | + $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
|
1630 | + } |
|
1601 | 1631 | |
1602 | 1632 | // check to see if FTS Indexing service is installed |
1603 | - if(empty($_SESSION['IsFulltextInstalled'])) |
|
1604 | - return false; |
|
1633 | + if(empty($_SESSION['IsFulltextInstalled'])) { |
|
1634 | + return false; |
|
1635 | + } |
|
1605 | 1636 | |
1606 | 1637 | // grab the dbname if it was not passed through |
1607 | 1638 | if (empty($dbname)) { |
@@ -1650,8 +1681,9 @@ discard block |
||
1650 | 1681 | { |
1651 | 1682 | static $results = array(); |
1652 | 1683 | |
1653 | - if ( empty($column) && isset($results[$table]) ) |
|
1654 | - return $results[$table]; |
|
1684 | + if ( empty($column) && isset($results[$table]) ) { |
|
1685 | + return $results[$table]; |
|
1686 | + } |
|
1655 | 1687 | |
1656 | 1688 | $query = <<<EOQ |
1657 | 1689 | select s.name, o.name, c.name dtrt, d.name ctrt |
@@ -1664,18 +1696,20 @@ discard block |
||
1664 | 1696 | on s.schema_id = o.schema_id |
1665 | 1697 | where o.name = '$table' |
1666 | 1698 | EOQ; |
1667 | - if ( !empty($column) ) |
|
1668 | - $query .= " and c.name = '$column'"; |
|
1699 | + if ( !empty($column) ) { |
|
1700 | + $query .= " and c.name = '$column'"; |
|
1701 | + } |
|
1669 | 1702 | $res = $this->query($query); |
1670 | 1703 | if ( !empty($column) ) { |
1671 | 1704 | $row = $this->fetchByAssoc($res); |
1672 | - if (!empty($row)) |
|
1673 | - return $row['ctrt']; |
|
1674 | - } |
|
1675 | - else { |
|
1705 | + if (!empty($row)) { |
|
1706 | + return $row['ctrt']; |
|
1707 | + } |
|
1708 | + } else { |
|
1676 | 1709 | $returnResult = array(); |
1677 | - while ( $row = $this->fetchByAssoc($res) ) |
|
1678 | - $returnResult[$row['dtrt']] = $row['ctrt']; |
|
1710 | + while ( $row = $this->fetchByAssoc($res) ) { |
|
1711 | + $returnResult[$row['dtrt']] = $row['ctrt']; |
|
1712 | + } |
|
1679 | 1713 | $results[$table] = $returnResult; |
1680 | 1714 | return $returnResult; |
1681 | 1715 | } |
@@ -1690,8 +1724,9 @@ discard block |
||
1690 | 1724 | { |
1691 | 1725 | parent::massageFieldDef($fieldDef,$tablename); |
1692 | 1726 | |
1693 | - if ($fieldDef['type'] == 'int') |
|
1694 | - $fieldDef['len'] = '4'; |
|
1727 | + if ($fieldDef['type'] == 'int') { |
|
1728 | + $fieldDef['len'] = '4'; |
|
1729 | + } |
|
1695 | 1730 | |
1696 | 1731 | if(empty($fieldDef['len'])) |
1697 | 1732 | { |
@@ -1720,9 +1755,10 @@ discard block |
||
1720 | 1755 | { |
1721 | 1756 | $fieldDef['default'] = '0'; |
1722 | 1757 | } |
1723 | - if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1724 | - $fieldDef['default'] = ''; |
|
1725 | -// if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
|
1758 | + if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) { |
|
1759 | + $fieldDef['default'] = ''; |
|
1760 | + } |
|
1761 | + // if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
|
1726 | 1762 | // $fieldDef['len'] = '1'; |
1727 | 1763 | // if ($fieldDef['type'] == 'bool' && empty($fieldDef['len']) ) |
1728 | 1764 | // $fieldDef['len'] = '1'; |
@@ -1766,13 +1802,15 @@ discard block |
||
1766 | 1802 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
1767 | 1803 | |
1768 | 1804 | // Bug 24307 - Don't add precision for float fields. |
1769 | - if ( stristr($ref['colType'],'float') ) |
|
1770 | - $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1805 | + if ( stristr($ref['colType'],'float') ) { |
|
1806 | + $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1807 | + } |
|
1771 | 1808 | |
1772 | - if ( $return_as_array ) |
|
1773 | - return $ref; |
|
1774 | - else |
|
1775 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
1809 | + if ( $return_as_array ) { |
|
1810 | + return $ref; |
|
1811 | + } else { |
|
1812 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
1813 | + } |
|
1776 | 1814 | } |
1777 | 1815 | |
1778 | 1816 | /** |
@@ -1810,8 +1848,9 @@ discard block |
||
1810 | 1848 | */ |
1811 | 1849 | protected function freeDbResult($dbResult) |
1812 | 1850 | { |
1813 | - if(!empty($dbResult)) |
|
1814 | - mssql_free_result($dbResult); |
|
1851 | + if(!empty($dbResult)) { |
|
1852 | + mssql_free_result($dbResult); |
|
1853 | + } |
|
1815 | 1854 | } |
1816 | 1855 | |
1817 | 1856 | /** |
@@ -1821,7 +1860,9 @@ discard block |
||
1821 | 1860 | public function lastDbError() |
1822 | 1861 | { |
1823 | 1862 | $sqlmsg = mssql_get_last_message(); |
1824 | - if(empty($sqlmsg)) return false; |
|
1863 | + if(empty($sqlmsg)) { |
|
1864 | + return false; |
|
1865 | + } |
|
1825 | 1866 | global $app_strings; |
1826 | 1867 | if (empty($app_strings) |
1827 | 1868 | or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
@@ -1844,11 +1885,11 @@ discard block |
||
1844 | 1885 | //only if connection if made before languge is set. |
1845 | 1886 | $GLOBALS['log']->debug("Ignoring this database message: " . $sqlmsg); |
1846 | 1887 | return false; |
1847 | - } |
|
1848 | - else { |
|
1888 | + } else { |
|
1849 | 1889 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
1850 | - if ( $sqlpos !== false ) |
|
1851 | - return false; |
|
1890 | + if ( $sqlpos !== false ) { |
|
1891 | + return false; |
|
1892 | + } |
|
1852 | 1893 | } |
1853 | 1894 | } |
1854 | 1895 | |
@@ -1893,8 +1934,9 @@ discard block |
||
1893 | 1934 | protected function _appendN($sql) |
1894 | 1935 | { |
1895 | 1936 | // If there are no single quotes, don't bother, will just assume there is no character data |
1896 | - if (strpos($sql, "'") === false) |
|
1897 | - return $sql; |
|
1937 | + if (strpos($sql, "'") === false) { |
|
1938 | + return $sql; |
|
1939 | + } |
|
1898 | 1940 | |
1899 | 1941 | // Flag if there are odd number of single quotes, just continue without trying to append N |
1900 | 1942 | if ((substr_count($sql, "'") & 1)) { |
@@ -1933,14 +1975,17 @@ discard block |
||
1933 | 1975 | } |
1934 | 1976 | } |
1935 | 1977 | |
1936 | - if (!empty($replace)) |
|
1937 | - $sql = str_replace(array_keys($replace), $replace, $sql); |
|
1978 | + if (!empty($replace)) { |
|
1979 | + $sql = str_replace(array_keys($replace), $replace, $sql); |
|
1980 | + } |
|
1938 | 1981 | |
1939 | - if (!empty($pairs)) |
|
1940 | - $sql = str_replace(array_keys($pairs), $pairs, $sql); |
|
1982 | + if (!empty($pairs)) { |
|
1983 | + $sql = str_replace(array_keys($pairs), $pairs, $sql); |
|
1984 | + } |
|
1941 | 1985 | |
1942 | - if(strpos($sql, "<@#@#@PAIR@#@#@>")) |
|
1943 | - $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql); |
|
1986 | + if(strpos($sql, "<@#@#@PAIR@#@#@>")) { |
|
1987 | + $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql); |
|
1988 | + } |
|
1944 | 1989 | |
1945 | 1990 | return $sql; |
1946 | 1991 | } |
@@ -96,368 +96,368 @@ discard block |
||
96 | 96 | */ |
97 | 97 | class MysqlManager extends DBManager |
98 | 98 | { |
99 | - /** |
|
100 | - * @see DBManager::$dbType |
|
101 | - */ |
|
102 | - public $dbType = 'mysql'; |
|
103 | - public $variant = 'mysql'; |
|
104 | - public $dbName = 'MySQL'; |
|
105 | - public $label = 'LBL_MYSQL'; |
|
106 | - |
|
107 | - protected $maxNameLengths = array( |
|
108 | - 'table' => 64, |
|
109 | - 'column' => 64, |
|
110 | - 'index' => 64, |
|
111 | - 'alias' => 256 |
|
112 | - ); |
|
113 | - |
|
114 | - protected $type_map = array( |
|
115 | - 'int' => 'int', |
|
116 | - 'double' => 'double', |
|
117 | - 'float' => 'float', |
|
118 | - 'uint' => 'int unsigned', |
|
119 | - 'ulong' => 'bigint unsigned', |
|
120 | - 'long' => 'bigint', |
|
121 | - 'short' => 'smallint', |
|
122 | - 'varchar' => 'varchar', |
|
123 | - 'text' => 'text', |
|
124 | - 'longtext' => 'longtext', |
|
125 | - 'date' => 'date', |
|
126 | - 'enum' => 'varchar', |
|
127 | - 'relate' => 'varchar', |
|
128 | - 'multienum'=> 'text', |
|
129 | - 'html' => 'text', |
|
130 | - 'longhtml' => 'longtext', |
|
131 | - 'datetime' => 'datetime', |
|
132 | - 'datetimecombo' => 'datetime', |
|
133 | - 'time' => 'time', |
|
134 | - 'bool' => 'bool', |
|
135 | - 'tinyint' => 'tinyint', |
|
136 | - 'char' => 'char', |
|
137 | - 'blob' => 'blob', |
|
138 | - 'longblob' => 'longblob', |
|
139 | - 'currency' => 'decimal(26,6)', |
|
140 | - 'decimal' => 'decimal', |
|
141 | - 'decimal2' => 'decimal', |
|
142 | - 'id' => 'char(36)', |
|
143 | - 'url' => 'varchar', |
|
144 | - 'encrypt' => 'varchar', |
|
145 | - 'file' => 'varchar', |
|
146 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - protected $capabilities = array( |
|
151 | - "affected_rows" => true, |
|
152 | - "select_rows" => true, |
|
153 | - "inline_keys" => true, |
|
154 | - "create_user" => true, |
|
155 | - "fulltext" => true, |
|
156 | - "collation" => true, |
|
157 | - "create_db" => true, |
|
158 | - "disable_keys" => true, |
|
159 | - ); |
|
160 | - |
|
161 | - /** |
|
162 | - * Parses and runs queries |
|
163 | - * |
|
164 | - * @param string $sql SQL Statement to execute |
|
165 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
166 | - * @param string $msg Message to log if error occurs |
|
167 | - * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
168 | - * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
169 | - * @return resource result set |
|
170 | - */ |
|
171 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
172 | - { |
|
173 | - if(is_array($sql)) { |
|
174 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
175 | - } |
|
176 | - |
|
177 | - parent::countQuery($sql); |
|
178 | - $GLOBALS['log']->info('Query:' . $sql); |
|
179 | - $this->checkConnection(); |
|
180 | - $this->query_time = microtime(true); |
|
181 | - $this->lastsql = $sql; |
|
182 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
183 | - |
|
184 | - $this->query_time = microtime(true) - $this->query_time; |
|
185 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
186 | - |
|
187 | - |
|
188 | - if($keepResult) |
|
189 | - $this->lastResult = $result; |
|
190 | - |
|
191 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
192 | - return $result; |
|
193 | - } |
|
99 | + /** |
|
100 | + * @see DBManager::$dbType |
|
101 | + */ |
|
102 | + public $dbType = 'mysql'; |
|
103 | + public $variant = 'mysql'; |
|
104 | + public $dbName = 'MySQL'; |
|
105 | + public $label = 'LBL_MYSQL'; |
|
106 | + |
|
107 | + protected $maxNameLengths = array( |
|
108 | + 'table' => 64, |
|
109 | + 'column' => 64, |
|
110 | + 'index' => 64, |
|
111 | + 'alias' => 256 |
|
112 | + ); |
|
113 | + |
|
114 | + protected $type_map = array( |
|
115 | + 'int' => 'int', |
|
116 | + 'double' => 'double', |
|
117 | + 'float' => 'float', |
|
118 | + 'uint' => 'int unsigned', |
|
119 | + 'ulong' => 'bigint unsigned', |
|
120 | + 'long' => 'bigint', |
|
121 | + 'short' => 'smallint', |
|
122 | + 'varchar' => 'varchar', |
|
123 | + 'text' => 'text', |
|
124 | + 'longtext' => 'longtext', |
|
125 | + 'date' => 'date', |
|
126 | + 'enum' => 'varchar', |
|
127 | + 'relate' => 'varchar', |
|
128 | + 'multienum'=> 'text', |
|
129 | + 'html' => 'text', |
|
130 | + 'longhtml' => 'longtext', |
|
131 | + 'datetime' => 'datetime', |
|
132 | + 'datetimecombo' => 'datetime', |
|
133 | + 'time' => 'time', |
|
134 | + 'bool' => 'bool', |
|
135 | + 'tinyint' => 'tinyint', |
|
136 | + 'char' => 'char', |
|
137 | + 'blob' => 'blob', |
|
138 | + 'longblob' => 'longblob', |
|
139 | + 'currency' => 'decimal(26,6)', |
|
140 | + 'decimal' => 'decimal', |
|
141 | + 'decimal2' => 'decimal', |
|
142 | + 'id' => 'char(36)', |
|
143 | + 'url' => 'varchar', |
|
144 | + 'encrypt' => 'varchar', |
|
145 | + 'file' => 'varchar', |
|
146 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + protected $capabilities = array( |
|
151 | + "affected_rows" => true, |
|
152 | + "select_rows" => true, |
|
153 | + "inline_keys" => true, |
|
154 | + "create_user" => true, |
|
155 | + "fulltext" => true, |
|
156 | + "collation" => true, |
|
157 | + "create_db" => true, |
|
158 | + "disable_keys" => true, |
|
159 | + ); |
|
160 | + |
|
161 | + /** |
|
162 | + * Parses and runs queries |
|
163 | + * |
|
164 | + * @param string $sql SQL Statement to execute |
|
165 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
166 | + * @param string $msg Message to log if error occurs |
|
167 | + * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
168 | + * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
169 | + * @return resource result set |
|
170 | + */ |
|
171 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
172 | + { |
|
173 | + if(is_array($sql)) { |
|
174 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
175 | + } |
|
176 | + |
|
177 | + parent::countQuery($sql); |
|
178 | + $GLOBALS['log']->info('Query:' . $sql); |
|
179 | + $this->checkConnection(); |
|
180 | + $this->query_time = microtime(true); |
|
181 | + $this->lastsql = $sql; |
|
182 | + $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
183 | + |
|
184 | + $this->query_time = microtime(true) - $this->query_time; |
|
185 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
186 | + |
|
187 | + |
|
188 | + if($keepResult) |
|
189 | + $this->lastResult = $result; |
|
190 | + |
|
191 | + $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
192 | + return $result; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Returns the number of rows affected by the last query |
197 | 197 | * @param $result |
198 | 198 | * @return int |
199 | 199 | */ |
200 | - public function getAffectedRowCount($result) |
|
201 | - { |
|
202 | - return mysql_affected_rows($this->getDatabase()); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Returns the number of rows returned by the result |
|
207 | - * |
|
208 | - * This function can't be reliably implemented on most DB, do not use it. |
|
209 | - * @abstract |
|
210 | - * @deprecated |
|
211 | - * @param resource $result |
|
212 | - * @return int |
|
213 | - */ |
|
214 | - public function getRowCount($result) |
|
215 | - { |
|
216 | - return mysql_num_rows($result); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Disconnects from the database |
|
221 | - * |
|
222 | - * Also handles any cleanup needed |
|
223 | - */ |
|
224 | - public function disconnect() |
|
225 | - { |
|
226 | - $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
227 | - if(!empty($this->database)){ |
|
228 | - $this->freeResult(); |
|
229 | - mysql_close($this->database); |
|
230 | - $this->database = null; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @see DBManager::freeDbResult() |
|
236 | - */ |
|
237 | - protected function freeDbResult($dbResult) |
|
238 | - { |
|
239 | - if(!empty($dbResult)) |
|
240 | - mysql_free_result($dbResult); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * @abstract |
|
246 | - * Check if query has LIMIT clause |
|
247 | - * Relevant for now only for Mysql |
|
248 | - * @param string $sql |
|
249 | - * @return bool |
|
250 | - */ |
|
251 | - protected function hasLimit($sql) |
|
252 | - { |
|
253 | - return stripos($sql, " limit ") !== false; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @see DBManager::limitQuery() |
|
258 | - */ |
|
259 | - public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
260 | - { |
|
200 | + public function getAffectedRowCount($result) |
|
201 | + { |
|
202 | + return mysql_affected_rows($this->getDatabase()); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Returns the number of rows returned by the result |
|
207 | + * |
|
208 | + * This function can't be reliably implemented on most DB, do not use it. |
|
209 | + * @abstract |
|
210 | + * @deprecated |
|
211 | + * @param resource $result |
|
212 | + * @return int |
|
213 | + */ |
|
214 | + public function getRowCount($result) |
|
215 | + { |
|
216 | + return mysql_num_rows($result); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Disconnects from the database |
|
221 | + * |
|
222 | + * Also handles any cleanup needed |
|
223 | + */ |
|
224 | + public function disconnect() |
|
225 | + { |
|
226 | + $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
227 | + if(!empty($this->database)){ |
|
228 | + $this->freeResult(); |
|
229 | + mysql_close($this->database); |
|
230 | + $this->database = null; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @see DBManager::freeDbResult() |
|
236 | + */ |
|
237 | + protected function freeDbResult($dbResult) |
|
238 | + { |
|
239 | + if(!empty($dbResult)) |
|
240 | + mysql_free_result($dbResult); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @abstract |
|
246 | + * Check if query has LIMIT clause |
|
247 | + * Relevant for now only for Mysql |
|
248 | + * @param string $sql |
|
249 | + * @return bool |
|
250 | + */ |
|
251 | + protected function hasLimit($sql) |
|
252 | + { |
|
253 | + return stripos($sql, " limit ") !== false; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @see DBManager::limitQuery() |
|
258 | + */ |
|
259 | + public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
260 | + { |
|
261 | 261 | $start = (int)$start; |
262 | 262 | $count = (int)$count; |
263 | - if ($start < 0) |
|
264 | - $start = 0; |
|
265 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
266 | - |
|
267 | - $sql = "$sql LIMIT $start,$count"; |
|
268 | - $this->lastsql = $sql; |
|
269 | - |
|
270 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
271 | - $this->checkQuery($sql); |
|
272 | - } |
|
273 | - if(!$execute) { |
|
274 | - return $sql; |
|
275 | - } |
|
276 | - |
|
277 | - return $this->query($sql, $dieOnError, $msg); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @see DBManager::checkQuery() |
|
283 | - */ |
|
284 | - protected function checkQuery($sql, $object_name = false) |
|
285 | - { |
|
286 | - $result = $this->query('EXPLAIN ' . $sql); |
|
287 | - $badQuery = array(); |
|
288 | - while ($row = $this->fetchByAssoc($result)) { |
|
289 | - if (empty($row['table'])) |
|
290 | - continue; |
|
291 | - $badQuery[$row['table']] = ''; |
|
292 | - if (strtoupper($row['type']) == 'ALL') |
|
293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | - if (empty($row['key'])) |
|
295 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
296 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
297 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
298 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
299 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
300 | - } |
|
301 | - |
|
302 | - if ( empty($badQuery) ) |
|
303 | - return true; |
|
304 | - |
|
305 | - foreach($badQuery as $table=>$data ){ |
|
306 | - if(!empty($data)){ |
|
307 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
308 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
309 | - $GLOBALS['log']->fatal($sql); |
|
310 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
311 | - } |
|
312 | - else{ |
|
313 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - return false; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * @see DBManager::get_columns() |
|
323 | - */ |
|
324 | - public function get_columns($tablename) |
|
325 | - { |
|
326 | - //find all unique indexes and primary keys. |
|
327 | - $result = $this->query("DESCRIBE $tablename"); |
|
328 | - |
|
329 | - $columns = array(); |
|
330 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
331 | - $name = strtolower($row['Field']); |
|
332 | - $columns[$name]['name']=$name; |
|
333 | - $matches = array(); |
|
334 | - preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
335 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
339 | - $columns[$name]['auto_increment'] = '1'; |
|
340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
341 | - $columns[$name]['required'] = 'true'; |
|
342 | - if (!empty($row['Default']) ) |
|
343 | - $columns[$name]['default'] = $row['Default']; |
|
344 | - } |
|
345 | - return $columns; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @see DBManager::getFieldsArray() |
|
350 | - */ |
|
351 | - public function getFieldsArray($result, $make_lower_case=false) |
|
352 | - { |
|
353 | - $field_array = array(); |
|
354 | - |
|
355 | - if(empty($result)) |
|
356 | - return 0; |
|
357 | - |
|
358 | - $fields = mysql_num_fields($result); |
|
359 | - for ($i=0; $i < $fields; $i++) { |
|
360 | - $meta = mysql_fetch_field($result, $i); |
|
361 | - if (!$meta) |
|
362 | - return array(); |
|
363 | - |
|
364 | - if($make_lower_case == true) |
|
365 | - $meta->name = strtolower($meta->name); |
|
366 | - |
|
367 | - $field_array[] = $meta->name; |
|
368 | - } |
|
369 | - |
|
370 | - return $field_array; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * @see DBManager::fetchRow() |
|
375 | - */ |
|
376 | - public function fetchRow($result) |
|
377 | - { |
|
378 | - if (empty($result)) return false; |
|
379 | - |
|
380 | - return mysql_fetch_assoc($result); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * @see DBManager::getTablesArray() |
|
385 | - */ |
|
386 | - public function getTablesArray() |
|
387 | - { |
|
388 | - $this->log->debug('Fetching table list'); |
|
389 | - |
|
390 | - if ($this->getDatabase()) { |
|
391 | - $tables = array(); |
|
392 | - $r = $this->query('SHOW TABLES'); |
|
393 | - if (!empty($r)) { |
|
394 | - while ($a = $this->fetchByAssoc($r)) { |
|
395 | - $row = array_values($a); |
|
396 | - $tables[]=$row[0]; |
|
397 | - } |
|
398 | - return $tables; |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - return false; // no database available |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * @see DBManager::version() |
|
407 | - */ |
|
408 | - public function version() |
|
409 | - { |
|
410 | - return $this->getOne("SELECT version() version"); |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * @see DBManager::tableExists() |
|
415 | - */ |
|
416 | - public function tableExists($tableName) |
|
417 | - { |
|
418 | - $this->log->info("tableExists: $tableName"); |
|
419 | - |
|
420 | - if ($this->getDatabase()) { |
|
421 | - $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
422 | - if(empty($result)) return false; |
|
423 | - $row = $this->fetchByAssoc($result); |
|
424 | - return !empty($row); |
|
425 | - } |
|
426 | - |
|
427 | - return false; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Get tables like expression |
|
432 | - * @param $like string |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - public function tablesLike($like) |
|
436 | - { |
|
437 | - if ($this->getDatabase()) { |
|
438 | - $tables = array(); |
|
439 | - $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
440 | - if (!empty($r)) { |
|
441 | - while ($a = $this->fetchByAssoc($r)) { |
|
442 | - $row = array_values($a); |
|
443 | - $tables[]=$row[0]; |
|
444 | - } |
|
445 | - return $tables; |
|
446 | - } |
|
447 | - } |
|
448 | - return false; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * @see DBManager::quote() |
|
453 | - */ |
|
454 | - public function quote($string) |
|
455 | - { |
|
456 | - if(is_array($string)) { |
|
457 | - return $this->arrayQuote($string); |
|
458 | - } |
|
459 | - return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
460 | - } |
|
263 | + if ($start < 0) |
|
264 | + $start = 0; |
|
265 | + $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
266 | + |
|
267 | + $sql = "$sql LIMIT $start,$count"; |
|
268 | + $this->lastsql = $sql; |
|
269 | + |
|
270 | + if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
271 | + $this->checkQuery($sql); |
|
272 | + } |
|
273 | + if(!$execute) { |
|
274 | + return $sql; |
|
275 | + } |
|
276 | + |
|
277 | + return $this->query($sql, $dieOnError, $msg); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @see DBManager::checkQuery() |
|
283 | + */ |
|
284 | + protected function checkQuery($sql, $object_name = false) |
|
285 | + { |
|
286 | + $result = $this->query('EXPLAIN ' . $sql); |
|
287 | + $badQuery = array(); |
|
288 | + while ($row = $this->fetchByAssoc($result)) { |
|
289 | + if (empty($row['table'])) |
|
290 | + continue; |
|
291 | + $badQuery[$row['table']] = ''; |
|
292 | + if (strtoupper($row['type']) == 'ALL') |
|
293 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | + if (empty($row['key'])) |
|
295 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
296 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
297 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
298 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
299 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
300 | + } |
|
301 | + |
|
302 | + if ( empty($badQuery) ) |
|
303 | + return true; |
|
304 | + |
|
305 | + foreach($badQuery as $table=>$data ){ |
|
306 | + if(!empty($data)){ |
|
307 | + $warning = ' Table:' . $table . ' Data:' . $data; |
|
308 | + if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
309 | + $GLOBALS['log']->fatal($sql); |
|
310 | + $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
311 | + } |
|
312 | + else{ |
|
313 | + $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + return false; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * @see DBManager::get_columns() |
|
323 | + */ |
|
324 | + public function get_columns($tablename) |
|
325 | + { |
|
326 | + //find all unique indexes and primary keys. |
|
327 | + $result = $this->query("DESCRIBE $tablename"); |
|
328 | + |
|
329 | + $columns = array(); |
|
330 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
331 | + $name = strtolower($row['Field']); |
|
332 | + $columns[$name]['name']=$name; |
|
333 | + $matches = array(); |
|
334 | + preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
335 | + $columns[$name]['type']=strtolower($matches[1][0]); |
|
336 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | + if ( stristr($row['Extra'],'auto_increment') ) |
|
339 | + $columns[$name]['auto_increment'] = '1'; |
|
340 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
341 | + $columns[$name]['required'] = 'true'; |
|
342 | + if (!empty($row['Default']) ) |
|
343 | + $columns[$name]['default'] = $row['Default']; |
|
344 | + } |
|
345 | + return $columns; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @see DBManager::getFieldsArray() |
|
350 | + */ |
|
351 | + public function getFieldsArray($result, $make_lower_case=false) |
|
352 | + { |
|
353 | + $field_array = array(); |
|
354 | + |
|
355 | + if(empty($result)) |
|
356 | + return 0; |
|
357 | + |
|
358 | + $fields = mysql_num_fields($result); |
|
359 | + for ($i=0; $i < $fields; $i++) { |
|
360 | + $meta = mysql_fetch_field($result, $i); |
|
361 | + if (!$meta) |
|
362 | + return array(); |
|
363 | + |
|
364 | + if($make_lower_case == true) |
|
365 | + $meta->name = strtolower($meta->name); |
|
366 | + |
|
367 | + $field_array[] = $meta->name; |
|
368 | + } |
|
369 | + |
|
370 | + return $field_array; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * @see DBManager::fetchRow() |
|
375 | + */ |
|
376 | + public function fetchRow($result) |
|
377 | + { |
|
378 | + if (empty($result)) return false; |
|
379 | + |
|
380 | + return mysql_fetch_assoc($result); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * @see DBManager::getTablesArray() |
|
385 | + */ |
|
386 | + public function getTablesArray() |
|
387 | + { |
|
388 | + $this->log->debug('Fetching table list'); |
|
389 | + |
|
390 | + if ($this->getDatabase()) { |
|
391 | + $tables = array(); |
|
392 | + $r = $this->query('SHOW TABLES'); |
|
393 | + if (!empty($r)) { |
|
394 | + while ($a = $this->fetchByAssoc($r)) { |
|
395 | + $row = array_values($a); |
|
396 | + $tables[]=$row[0]; |
|
397 | + } |
|
398 | + return $tables; |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + return false; // no database available |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * @see DBManager::version() |
|
407 | + */ |
|
408 | + public function version() |
|
409 | + { |
|
410 | + return $this->getOne("SELECT version() version"); |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * @see DBManager::tableExists() |
|
415 | + */ |
|
416 | + public function tableExists($tableName) |
|
417 | + { |
|
418 | + $this->log->info("tableExists: $tableName"); |
|
419 | + |
|
420 | + if ($this->getDatabase()) { |
|
421 | + $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
422 | + if(empty($result)) return false; |
|
423 | + $row = $this->fetchByAssoc($result); |
|
424 | + return !empty($row); |
|
425 | + } |
|
426 | + |
|
427 | + return false; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Get tables like expression |
|
432 | + * @param $like string |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + public function tablesLike($like) |
|
436 | + { |
|
437 | + if ($this->getDatabase()) { |
|
438 | + $tables = array(); |
|
439 | + $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
440 | + if (!empty($r)) { |
|
441 | + while ($a = $this->fetchByAssoc($r)) { |
|
442 | + $row = array_values($a); |
|
443 | + $tables[]=$row[0]; |
|
444 | + } |
|
445 | + return $tables; |
|
446 | + } |
|
447 | + } |
|
448 | + return false; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * @see DBManager::quote() |
|
453 | + */ |
|
454 | + public function quote($string) |
|
455 | + { |
|
456 | + if(is_array($string)) { |
|
457 | + return $this->arrayQuote($string); |
|
458 | + } |
|
459 | + return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
460 | + } |
|
461 | 461 | |
462 | 462 | /** |
463 | 463 | * @see DBManager::quoteIdentifier() |
@@ -467,272 +467,272 @@ discard block |
||
467 | 467 | return '`'.$string.'`'; |
468 | 468 | } |
469 | 469 | |
470 | - /** |
|
471 | - * @see DBManager::connect() |
|
472 | - */ |
|
473 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
474 | - { |
|
475 | - global $sugar_config; |
|
476 | - |
|
477 | - if(is_null($configOptions)) |
|
478 | - $configOptions = $sugar_config['dbconfig']; |
|
479 | - |
|
480 | - if ($this->getOption('persistent')) { |
|
481 | - $this->database = @mysql_pconnect( |
|
482 | - $configOptions['db_host_name'], |
|
483 | - $configOptions['db_user_name'], |
|
484 | - $configOptions['db_password'] |
|
485 | - ); |
|
486 | - } |
|
487 | - |
|
488 | - if (!$this->database) { |
|
489 | - $this->database = mysql_connect( |
|
490 | - $configOptions['db_host_name'], |
|
491 | - $configOptions['db_user_name'], |
|
492 | - $configOptions['db_password'] |
|
493 | - ); |
|
494 | - if(empty($this->database)) { |
|
495 | - $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
496 | - if($dieOnError) { |
|
497 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
498 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
499 | - } else { |
|
500 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
501 | - } |
|
502 | - } else { |
|
503 | - return false; |
|
504 | - } |
|
505 | - } |
|
506 | - // Do not pass connection information because we have not connected yet |
|
507 | - if($this->database && $this->getOption('persistent')){ |
|
508 | - $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
509 | - . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
510 | - . "in your config.php file</b>"; |
|
511 | - } |
|
512 | - } |
|
513 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
515 | - if($dieOnError) { |
|
516 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
517 | - } else { |
|
518 | - return false; |
|
519 | - } |
|
520 | - } |
|
521 | - |
|
522 | - // cn: using direct calls to prevent this from spamming the Logs |
|
523 | - mysql_query("SET CHARACTER SET utf8", $this->database); |
|
524 | - $names = "SET NAMES 'utf8'"; |
|
525 | - $collation = $this->getOption('collation'); |
|
526 | - if(!empty($collation)) { |
|
527 | - $names .= " COLLATE '$collation'"; |
|
528 | - } |
|
529 | - mysql_query($names, $this->database); |
|
530 | - |
|
531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | - $GLOBALS['log']->info("connected to db"); |
|
533 | - $this->connectOptions = $configOptions; |
|
534 | - |
|
535 | - $GLOBALS['log']->info("Connect:".$this->database); |
|
536 | - return true; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * @see DBManager::repairTableParams() |
|
541 | - * |
|
542 | - * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
543 | - * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
544 | - */ |
|
545 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
546 | - { |
|
547 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
548 | - |
|
549 | - if ( $sql == '' ) |
|
550 | - return ''; |
|
551 | - |
|
552 | - if ( stristr($sql,'create table') ) |
|
553 | - { |
|
554 | - if ($execute) { |
|
555 | - $msg = "Error creating table: ".$tablename. ":"; |
|
556 | - $this->query($sql,true,$msg); |
|
557 | - } |
|
558 | - return $sql; |
|
559 | - } |
|
560 | - |
|
561 | - // first, parse out all the comments |
|
562 | - $match = array(); |
|
563 | - preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
564 | - $commentBlocks = $match[0]; |
|
565 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
566 | - |
|
567 | - // now, we should only have alter table statements |
|
568 | - // let's replace the 'alter table name' part with a comma |
|
569 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
570 | - |
|
571 | - // re-add it at the beginning |
|
572 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
573 | - $sql = str_replace(";","",$sql); |
|
574 | - $sql = str_replace("\n","",$sql); |
|
575 | - $sql = "ALTER TABLE $tablename $sql"; |
|
576 | - |
|
577 | - if ( $execute ) |
|
578 | - $this->query($sql,'Error with MySQL repair table'); |
|
579 | - |
|
580 | - // and re-add the comments at the beginning |
|
581 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
582 | - |
|
583 | - return $sql; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * @see DBManager::convert() |
|
588 | - */ |
|
589 | - public function convert($string, $type, array $additional_parameters = array()) |
|
590 | - { |
|
591 | - $all_parameters = $additional_parameters; |
|
592 | - if(is_array($string)) { |
|
593 | - $all_parameters = array_merge($string, $all_parameters); |
|
594 | - } elseif (!is_null($string)) { |
|
595 | - array_unshift($all_parameters, $string); |
|
596 | - } |
|
597 | - $all_strings = implode(',', $all_parameters); |
|
598 | - |
|
599 | - switch (strtolower($type)) { |
|
600 | - case 'today': |
|
601 | - return "CURDATE()"; |
|
602 | - case 'left': |
|
603 | - return "LEFT($all_strings)"; |
|
604 | - case 'date_format': |
|
605 | - if(empty($additional_parameters)) { |
|
606 | - return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
607 | - } else { |
|
608 | - $format = $additional_parameters[0]; |
|
609 | - if($format[0] != "'") { |
|
610 | - $format = $this->quoted($format); |
|
611 | - } |
|
612 | - return "DATE_FORMAT($string,$format)"; |
|
613 | - } |
|
614 | - case 'ifnull': |
|
615 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
616 | - $all_strings .= ",''"; |
|
617 | - } |
|
618 | - return "IFNULL($all_strings)"; |
|
619 | - case 'concat': |
|
620 | - return "CONCAT($all_strings)"; |
|
621 | - case 'quarter': |
|
622 | - return "QUARTER($string)"; |
|
623 | - case "length": |
|
624 | - return "LENGTH($string)"; |
|
625 | - case 'month': |
|
626 | - return "MONTH($string)"; |
|
627 | - case 'add_date': |
|
628 | - return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
629 | - case 'add_time': |
|
630 | - return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
470 | + /** |
|
471 | + * @see DBManager::connect() |
|
472 | + */ |
|
473 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
474 | + { |
|
475 | + global $sugar_config; |
|
476 | + |
|
477 | + if(is_null($configOptions)) |
|
478 | + $configOptions = $sugar_config['dbconfig']; |
|
479 | + |
|
480 | + if ($this->getOption('persistent')) { |
|
481 | + $this->database = @mysql_pconnect( |
|
482 | + $configOptions['db_host_name'], |
|
483 | + $configOptions['db_user_name'], |
|
484 | + $configOptions['db_password'] |
|
485 | + ); |
|
486 | + } |
|
487 | + |
|
488 | + if (!$this->database) { |
|
489 | + $this->database = mysql_connect( |
|
490 | + $configOptions['db_host_name'], |
|
491 | + $configOptions['db_user_name'], |
|
492 | + $configOptions['db_password'] |
|
493 | + ); |
|
494 | + if(empty($this->database)) { |
|
495 | + $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
496 | + if($dieOnError) { |
|
497 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
498 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
499 | + } else { |
|
500 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
501 | + } |
|
502 | + } else { |
|
503 | + return false; |
|
504 | + } |
|
505 | + } |
|
506 | + // Do not pass connection information because we have not connected yet |
|
507 | + if($this->database && $this->getOption('persistent')){ |
|
508 | + $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
509 | + . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
510 | + . "in your config.php file</b>"; |
|
511 | + } |
|
512 | + } |
|
513 | + if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
515 | + if($dieOnError) { |
|
516 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
517 | + } else { |
|
518 | + return false; |
|
519 | + } |
|
520 | + } |
|
521 | + |
|
522 | + // cn: using direct calls to prevent this from spamming the Logs |
|
523 | + mysql_query("SET CHARACTER SET utf8", $this->database); |
|
524 | + $names = "SET NAMES 'utf8'"; |
|
525 | + $collation = $this->getOption('collation'); |
|
526 | + if(!empty($collation)) { |
|
527 | + $names .= " COLLATE '$collation'"; |
|
528 | + } |
|
529 | + mysql_query($names, $this->database); |
|
530 | + |
|
531 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | + $GLOBALS['log']->info("connected to db"); |
|
533 | + $this->connectOptions = $configOptions; |
|
534 | + |
|
535 | + $GLOBALS['log']->info("Connect:".$this->database); |
|
536 | + return true; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * @see DBManager::repairTableParams() |
|
541 | + * |
|
542 | + * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
543 | + * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
544 | + */ |
|
545 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
546 | + { |
|
547 | + $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
548 | + |
|
549 | + if ( $sql == '' ) |
|
550 | + return ''; |
|
551 | + |
|
552 | + if ( stristr($sql,'create table') ) |
|
553 | + { |
|
554 | + if ($execute) { |
|
555 | + $msg = "Error creating table: ".$tablename. ":"; |
|
556 | + $this->query($sql,true,$msg); |
|
557 | + } |
|
558 | + return $sql; |
|
559 | + } |
|
560 | + |
|
561 | + // first, parse out all the comments |
|
562 | + $match = array(); |
|
563 | + preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
564 | + $commentBlocks = $match[0]; |
|
565 | + $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
566 | + |
|
567 | + // now, we should only have alter table statements |
|
568 | + // let's replace the 'alter table name' part with a comma |
|
569 | + $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
570 | + |
|
571 | + // re-add it at the beginning |
|
572 | + $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
573 | + $sql = str_replace(";","",$sql); |
|
574 | + $sql = str_replace("\n","",$sql); |
|
575 | + $sql = "ALTER TABLE $tablename $sql"; |
|
576 | + |
|
577 | + if ( $execute ) |
|
578 | + $this->query($sql,'Error with MySQL repair table'); |
|
579 | + |
|
580 | + // and re-add the comments at the beginning |
|
581 | + $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
582 | + |
|
583 | + return $sql; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * @see DBManager::convert() |
|
588 | + */ |
|
589 | + public function convert($string, $type, array $additional_parameters = array()) |
|
590 | + { |
|
591 | + $all_parameters = $additional_parameters; |
|
592 | + if(is_array($string)) { |
|
593 | + $all_parameters = array_merge($string, $all_parameters); |
|
594 | + } elseif (!is_null($string)) { |
|
595 | + array_unshift($all_parameters, $string); |
|
596 | + } |
|
597 | + $all_strings = implode(',', $all_parameters); |
|
598 | + |
|
599 | + switch (strtolower($type)) { |
|
600 | + case 'today': |
|
601 | + return "CURDATE()"; |
|
602 | + case 'left': |
|
603 | + return "LEFT($all_strings)"; |
|
604 | + case 'date_format': |
|
605 | + if(empty($additional_parameters)) { |
|
606 | + return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
607 | + } else { |
|
608 | + $format = $additional_parameters[0]; |
|
609 | + if($format[0] != "'") { |
|
610 | + $format = $this->quoted($format); |
|
611 | + } |
|
612 | + return "DATE_FORMAT($string,$format)"; |
|
613 | + } |
|
614 | + case 'ifnull': |
|
615 | + if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
616 | + $all_strings .= ",''"; |
|
617 | + } |
|
618 | + return "IFNULL($all_strings)"; |
|
619 | + case 'concat': |
|
620 | + return "CONCAT($all_strings)"; |
|
621 | + case 'quarter': |
|
622 | + return "QUARTER($string)"; |
|
623 | + case "length": |
|
624 | + return "LENGTH($string)"; |
|
625 | + case 'month': |
|
626 | + return "MONTH($string)"; |
|
627 | + case 'add_date': |
|
628 | + return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
629 | + case 'add_time': |
|
630 | + return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
631 | 631 | case 'add_tz_offset' : |
632 | 632 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
633 | 633 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
634 | 634 | return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
635 | 635 | case 'avg': |
636 | 636 | return "avg($string)"; |
637 | - } |
|
638 | - |
|
639 | - return $string; |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * (non-PHPdoc) |
|
644 | - * @see DBManager::fromConvert() |
|
645 | - */ |
|
646 | - public function fromConvert($string, $type) |
|
647 | - { |
|
648 | - return $string; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Returns the name of the engine to use or null if we are to use the default |
|
653 | - * |
|
654 | - * @param object $bean SugarBean instance |
|
655 | - * @return string |
|
656 | - */ |
|
657 | - protected function getEngine($bean) |
|
658 | - { |
|
659 | - global $dictionary; |
|
660 | - $engine = null; |
|
661 | - if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
662 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
663 | - } |
|
664 | - return $engine; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Returns true if the engine given is enabled in the backend |
|
669 | - * |
|
670 | - * @param string $engine |
|
671 | - * @return bool |
|
672 | - */ |
|
673 | - protected function isEngineEnabled($engine) |
|
674 | - { |
|
675 | - if(!is_string($engine)) return false; |
|
676 | - |
|
677 | - $engine = strtoupper($engine); |
|
678 | - |
|
679 | - $r = $this->query("SHOW ENGINES"); |
|
680 | - |
|
681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
683 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
684 | - |
|
685 | - return false; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @see DBManager::createTableSQL() |
|
690 | - */ |
|
691 | - public function createTableSQL(SugarBean $bean) |
|
692 | - { |
|
693 | - $tablename = $bean->getTableName(); |
|
694 | - $fieldDefs = $bean->getFieldDefinitions(); |
|
695 | - $indices = $bean->getIndices(); |
|
696 | - $engine = $this->getEngine($bean); |
|
697 | - return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Generates sql for create table statement for a bean. |
|
702 | - * |
|
703 | - * @param string $tablename |
|
704 | - * @param array $fieldDefs |
|
705 | - * @param array $indices |
|
706 | - * @param string $engine optional, MySQL engine to use |
|
707 | - * @return string SQL Create Table statement |
|
708 | - */ |
|
709 | - public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
710 | - { |
|
711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
712 | - $engine = $fieldDefs['engine']; |
|
713 | - if ( !$this->isEngineEnabled($engine) ) |
|
714 | - $engine = ''; |
|
715 | - |
|
716 | - $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
717 | - if (empty($columns)) |
|
718 | - return false; |
|
719 | - |
|
720 | - $keys = $this->keysSQL($indices); |
|
721 | - if (!empty($keys)) |
|
722 | - $keys = ",$keys"; |
|
723 | - |
|
724 | - // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
725 | - $collation = $this->getOption('collation'); |
|
726 | - if(empty($collation)) { |
|
727 | - $collation = 'utf8_general_ci'; |
|
728 | - } |
|
729 | - $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
730 | - |
|
731 | - if (!empty($engine)) |
|
732 | - $sql.= " ENGINE=$engine"; |
|
733 | - |
|
734 | - return $sql; |
|
735 | - } |
|
637 | + } |
|
638 | + |
|
639 | + return $string; |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * (non-PHPdoc) |
|
644 | + * @see DBManager::fromConvert() |
|
645 | + */ |
|
646 | + public function fromConvert($string, $type) |
|
647 | + { |
|
648 | + return $string; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Returns the name of the engine to use or null if we are to use the default |
|
653 | + * |
|
654 | + * @param object $bean SugarBean instance |
|
655 | + * @return string |
|
656 | + */ |
|
657 | + protected function getEngine($bean) |
|
658 | + { |
|
659 | + global $dictionary; |
|
660 | + $engine = null; |
|
661 | + if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
662 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
663 | + } |
|
664 | + return $engine; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Returns true if the engine given is enabled in the backend |
|
669 | + * |
|
670 | + * @param string $engine |
|
671 | + * @return bool |
|
672 | + */ |
|
673 | + protected function isEngineEnabled($engine) |
|
674 | + { |
|
675 | + if(!is_string($engine)) return false; |
|
676 | + |
|
677 | + $engine = strtoupper($engine); |
|
678 | + |
|
679 | + $r = $this->query("SHOW ENGINES"); |
|
680 | + |
|
681 | + while ( $row = $this->fetchByAssoc($r) ) |
|
682 | + if ( strtoupper($row['Engine']) == $engine ) |
|
683 | + return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
684 | + |
|
685 | + return false; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @see DBManager::createTableSQL() |
|
690 | + */ |
|
691 | + public function createTableSQL(SugarBean $bean) |
|
692 | + { |
|
693 | + $tablename = $bean->getTableName(); |
|
694 | + $fieldDefs = $bean->getFieldDefinitions(); |
|
695 | + $indices = $bean->getIndices(); |
|
696 | + $engine = $this->getEngine($bean); |
|
697 | + return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Generates sql for create table statement for a bean. |
|
702 | + * |
|
703 | + * @param string $tablename |
|
704 | + * @param array $fieldDefs |
|
705 | + * @param array $indices |
|
706 | + * @param string $engine optional, MySQL engine to use |
|
707 | + * @return string SQL Create Table statement |
|
708 | + */ |
|
709 | + public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
710 | + { |
|
711 | + if ( empty($engine) && isset($fieldDefs['engine'])) |
|
712 | + $engine = $fieldDefs['engine']; |
|
713 | + if ( !$this->isEngineEnabled($engine) ) |
|
714 | + $engine = ''; |
|
715 | + |
|
716 | + $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
717 | + if (empty($columns)) |
|
718 | + return false; |
|
719 | + |
|
720 | + $keys = $this->keysSQL($indices); |
|
721 | + if (!empty($keys)) |
|
722 | + $keys = ",$keys"; |
|
723 | + |
|
724 | + // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
725 | + $collation = $this->getOption('collation'); |
|
726 | + if(empty($collation)) { |
|
727 | + $collation = 'utf8_general_ci'; |
|
728 | + } |
|
729 | + $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
730 | + |
|
731 | + if (!empty($engine)) |
|
732 | + $sql.= " ENGINE=$engine"; |
|
733 | + |
|
734 | + return $sql; |
|
735 | + } |
|
736 | 736 | |
737 | 737 | /** |
738 | 738 | * Does this type represent text (i.e., non-varchar) value? |
@@ -744,745 +744,745 @@ discard block |
||
744 | 744 | return in_array($type, array('blob','text','longblob', 'longtext')); |
745 | 745 | } |
746 | 746 | |
747 | - /** |
|
748 | - * @see DBManager::oneColumnSQLRep() |
|
749 | - */ |
|
750 | - protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
751 | - { |
|
752 | - // always return as array for post-processing |
|
753 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
747 | + /** |
|
748 | + * @see DBManager::oneColumnSQLRep() |
|
749 | + */ |
|
750 | + protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
751 | + { |
|
752 | + // always return as array for post-processing |
|
753 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
754 | 754 | |
755 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
756 | - $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
757 | - } |
|
755 | + if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
756 | + $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
757 | + } |
|
758 | 758 | |
759 | - // bug 22338 - don't set a default value on text or blob fields |
|
760 | - if ( isset($ref['default']) && |
|
759 | + // bug 22338 - don't set a default value on text or blob fields |
|
760 | + if ( isset($ref['default']) && |
|
761 | 761 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
762 | - $ref['default'] = ''; |
|
763 | - |
|
764 | - if ( $return_as_array ) |
|
765 | - return $ref; |
|
766 | - else |
|
767 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * @see DBManager::changeColumnSQL() |
|
772 | - */ |
|
773 | - protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
774 | - { |
|
775 | - $columns = array(); |
|
776 | - if ($this->isFieldArray($fieldDefs)){ |
|
777 | - foreach ($fieldDefs as $def){ |
|
778 | - if ($action == 'drop') |
|
779 | - $columns[] = $def['name']; |
|
780 | - else |
|
781 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
782 | - } |
|
783 | - } else { |
|
784 | - if ($action == 'drop') |
|
785 | - $columns[] = $fieldDefs['name']; |
|
786 | - else |
|
787 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
788 | - } |
|
789 | - |
|
790 | - return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Generates SQL for key specification inside CREATE TABLE statement |
|
795 | - * |
|
796 | - * The passes array is an array of field definitions or a field definition |
|
797 | - * itself. The keys generated will be either primary, foreign, unique, index |
|
798 | - * or none at all depending on the setting of the "key" parameter of a field definition |
|
799 | - * |
|
800 | - * @param array $indices |
|
801 | - * @param bool $alter_table |
|
802 | - * @param string $alter_action |
|
803 | - * @return string SQL Statement |
|
804 | - */ |
|
805 | - protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
806 | - { |
|
807 | - // check if the passed value is an array of fields. |
|
808 | - // if not, convert it into an array |
|
809 | - if (!$this->isFieldArray($indices)) |
|
810 | - $indices[] = $indices; |
|
811 | - |
|
812 | - $columns = array(); |
|
813 | - foreach ($indices as $index) { |
|
814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | - continue; |
|
816 | - if (isset($index['source']) && $index['source'] != 'db') |
|
817 | - continue; |
|
818 | - |
|
819 | - $type = $index['type']; |
|
820 | - $name = $index['name']; |
|
821 | - |
|
822 | - if (is_array($index['fields'])) |
|
823 | - $fields = implode(", ", $index['fields']); |
|
824 | - else |
|
825 | - $fields = $index['fields']; |
|
826 | - |
|
827 | - switch ($type) { |
|
828 | - case 'unique': |
|
829 | - $columns[] = " UNIQUE $name ($fields)"; |
|
830 | - break; |
|
831 | - case 'primary': |
|
832 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | - break; |
|
834 | - case 'index': |
|
835 | - case 'foreign': |
|
836 | - case 'clustered': |
|
837 | - case 'alternate_key': |
|
838 | - /** |
|
839 | - * @todo here it is assumed that the primary key of the foreign |
|
840 | - * table will always be named 'id'. It must be noted though |
|
841 | - * that this can easily be fixed by referring to db dictionary |
|
842 | - * to find the correct primary field name |
|
843 | - */ |
|
844 | - if ( $alter_table ) |
|
845 | - $columns[] = " INDEX $name ($fields)"; |
|
846 | - else |
|
847 | - $columns[] = " KEY $name ($fields)"; |
|
848 | - break; |
|
849 | - case 'fulltext': |
|
850 | - if ($this->full_text_indexing_installed()) |
|
851 | - $columns[] = " FULLTEXT ($fields)"; |
|
852 | - else |
|
853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | - break; |
|
855 | - } |
|
856 | - } |
|
857 | - $columns = implode(", $alter_action ", $columns); |
|
858 | - if(!empty($alter_action)){ |
|
859 | - $columns = $alter_action . ' '. $columns; |
|
860 | - } |
|
861 | - return $columns; |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * @see DBManager::setAutoIncrement() |
|
866 | - */ |
|
867 | - protected function setAutoIncrement($table, $field_name) |
|
868 | - { |
|
869 | - return "auto_increment"; |
|
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * Sets the next auto-increment value of a column to a specific value. |
|
874 | - * |
|
875 | - * @param string $table tablename |
|
876 | - * @param string $field_name |
|
877 | - */ |
|
878 | - public function setAutoIncrementStart($table, $field_name, $start_value) |
|
879 | - { |
|
880 | - $start_value = (int)$start_value; |
|
881 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Returns the next value for an auto increment |
|
886 | - * |
|
887 | - * @param string $table tablename |
|
888 | - * @param string $field_name |
|
889 | - * @return string |
|
890 | - */ |
|
891 | - public function getAutoIncrement($table, $field_name) |
|
892 | - { |
|
893 | - $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
894 | - $row = $this->fetchByAssoc($result); |
|
895 | - if (!empty($row['Auto_increment'])) |
|
896 | - return $row['Auto_increment']; |
|
897 | - |
|
898 | - return ""; |
|
899 | - } |
|
900 | - |
|
901 | - /** |
|
902 | - * @see DBManager::get_indices() |
|
903 | - */ |
|
904 | - public function get_indices($tablename) |
|
905 | - { |
|
906 | - //find all unique indexes and primary keys. |
|
907 | - $result = $this->query("SHOW INDEX FROM $tablename"); |
|
908 | - |
|
909 | - $indices = array(); |
|
910 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
911 | - $index_type='index'; |
|
912 | - if ($row['Key_name'] =='PRIMARY') { |
|
913 | - $index_type='primary'; |
|
914 | - } |
|
915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
916 | - $index_type='unique'; |
|
917 | - } |
|
918 | - $name = strtolower($row['Key_name']); |
|
919 | - $indices[$name]['name']=$name; |
|
920 | - $indices[$name]['type']=$index_type; |
|
921 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
922 | - } |
|
923 | - return $indices; |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * @see DBManager::add_drop_constraint() |
|
928 | - */ |
|
929 | - public function add_drop_constraint($table, $definition, $drop = false) |
|
930 | - { |
|
931 | - $type = $definition['type']; |
|
932 | - $fields = implode(',',$definition['fields']); |
|
933 | - $name = $definition['name']; |
|
934 | - $sql = ''; |
|
935 | - |
|
936 | - switch ($type){ |
|
937 | - // generic indices |
|
938 | - case 'index': |
|
939 | - case 'alternate_key': |
|
940 | - case 'clustered': |
|
941 | - if ($drop) |
|
942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | - else |
|
944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | - break; |
|
946 | - // constraints as indices |
|
947 | - case 'unique': |
|
948 | - if ($drop) |
|
949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | - else |
|
951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | - break; |
|
953 | - case 'primary': |
|
954 | - if ($drop) |
|
955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | - else |
|
957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | - break; |
|
959 | - case 'foreign': |
|
960 | - if ($drop) |
|
961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | - else |
|
963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | - break; |
|
965 | - } |
|
966 | - return $sql; |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Runs a query and returns a single row |
|
971 | - * |
|
972 | - * @param string $sql SQL Statement to execute |
|
973 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
974 | - * @param string $msg Message to log if error occurs |
|
975 | - * @param bool $suppress Message to log if error occurs |
|
976 | - * @return array single row from the query |
|
977 | - */ |
|
978 | - public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
979 | - { |
|
980 | - if(stripos($sql, ' LIMIT ') === false) { |
|
981 | - // little optimization to just fetch one row |
|
982 | - $sql .= " LIMIT 0,1"; |
|
983 | - } |
|
984 | - return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
985 | - } |
|
986 | - |
|
987 | - /** |
|
988 | - * @see DBManager::full_text_indexing_installed() |
|
989 | - */ |
|
990 | - public function full_text_indexing_installed($dbname = null) |
|
991 | - { |
|
992 | - return $this->isEngineEnabled('MyISAM'); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * @see DBManager::massageFieldDef() |
|
997 | - */ |
|
998 | - public function massageFieldDef(&$fieldDef, $tablename) |
|
999 | - { |
|
1000 | - parent::massageFieldDef($fieldDef,$tablename); |
|
1001 | - |
|
1002 | - if ( isset($fieldDef['default']) && |
|
1003 | - ($fieldDef['dbType'] == 'text' |
|
1004 | - || $fieldDef['dbType'] == 'blob' |
|
1005 | - || $fieldDef['dbType'] == 'longtext' |
|
1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
1007 | - unset($fieldDef['default']); |
|
1008 | - if ($fieldDef['dbType'] == 'uint') |
|
1009 | - $fieldDef['len'] = '10'; |
|
1010 | - if ($fieldDef['dbType'] == 'ulong') |
|
1011 | - $fieldDef['len'] = '20'; |
|
1012 | - if ($fieldDef['dbType'] == 'bool') |
|
1013 | - $fieldDef['type'] = 'tinyint'; |
|
1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1015 | - $fieldDef['default'] = '0'; |
|
1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1017 | - $fieldDef['len'] = '255'; |
|
1018 | - if ($fieldDef['dbType'] == 'uint') |
|
1019 | - $fieldDef['len'] = '10'; |
|
1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1021 | - $fieldDef['len'] = '11'; |
|
1022 | - |
|
1023 | - if($fieldDef['dbType'] == 'decimal') { |
|
1024 | - if(isset($fieldDef['len'])) { |
|
1025 | - if(strstr($fieldDef['len'], ",") === false) { |
|
1026 | - $fieldDef['len'] .= ",0"; |
|
1027 | - } |
|
1028 | - } else { |
|
1029 | - $fieldDef['len'] = '10,0'; |
|
1030 | - } |
|
1031 | - } |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * Generates SQL for dropping a table. |
|
1036 | - * |
|
1037 | - * @param string $name table name |
|
1038 | - * @return string SQL statement |
|
1039 | - */ |
|
1040 | - public function dropTableNameSQL($name) |
|
1041 | - { |
|
1042 | - return "DROP TABLE IF EXISTS ".$name; |
|
1043 | - } |
|
1044 | - |
|
1045 | - public function dropIndexes($tablename, $indexes, $execute = true) |
|
1046 | - { |
|
1047 | - $sql = array(); |
|
1048 | - foreach ($indexes as $index) { |
|
1049 | - $name =$index['name']; |
|
1050 | - if($execute) { |
|
1051 | - unset(self::$index_descriptions[$tablename][$name]); |
|
1052 | - } |
|
1053 | - if ($index['type'] == 'primary') { |
|
1054 | - $sql[] = 'DROP PRIMARY KEY'; |
|
1055 | - } else { |
|
1056 | - $sql[] = "DROP INDEX $name"; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - if (!empty($sql)) { |
|
762 | + $ref['default'] = ''; |
|
763 | + |
|
764 | + if ( $return_as_array ) |
|
765 | + return $ref; |
|
766 | + else |
|
767 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * @see DBManager::changeColumnSQL() |
|
772 | + */ |
|
773 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
774 | + { |
|
775 | + $columns = array(); |
|
776 | + if ($this->isFieldArray($fieldDefs)){ |
|
777 | + foreach ($fieldDefs as $def){ |
|
778 | + if ($action == 'drop') |
|
779 | + $columns[] = $def['name']; |
|
780 | + else |
|
781 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
782 | + } |
|
783 | + } else { |
|
784 | + if ($action == 'drop') |
|
785 | + $columns[] = $fieldDefs['name']; |
|
786 | + else |
|
787 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
788 | + } |
|
789 | + |
|
790 | + return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Generates SQL for key specification inside CREATE TABLE statement |
|
795 | + * |
|
796 | + * The passes array is an array of field definitions or a field definition |
|
797 | + * itself. The keys generated will be either primary, foreign, unique, index |
|
798 | + * or none at all depending on the setting of the "key" parameter of a field definition |
|
799 | + * |
|
800 | + * @param array $indices |
|
801 | + * @param bool $alter_table |
|
802 | + * @param string $alter_action |
|
803 | + * @return string SQL Statement |
|
804 | + */ |
|
805 | + protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
806 | + { |
|
807 | + // check if the passed value is an array of fields. |
|
808 | + // if not, convert it into an array |
|
809 | + if (!$this->isFieldArray($indices)) |
|
810 | + $indices[] = $indices; |
|
811 | + |
|
812 | + $columns = array(); |
|
813 | + foreach ($indices as $index) { |
|
814 | + if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | + continue; |
|
816 | + if (isset($index['source']) && $index['source'] != 'db') |
|
817 | + continue; |
|
818 | + |
|
819 | + $type = $index['type']; |
|
820 | + $name = $index['name']; |
|
821 | + |
|
822 | + if (is_array($index['fields'])) |
|
823 | + $fields = implode(", ", $index['fields']); |
|
824 | + else |
|
825 | + $fields = $index['fields']; |
|
826 | + |
|
827 | + switch ($type) { |
|
828 | + case 'unique': |
|
829 | + $columns[] = " UNIQUE $name ($fields)"; |
|
830 | + break; |
|
831 | + case 'primary': |
|
832 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | + break; |
|
834 | + case 'index': |
|
835 | + case 'foreign': |
|
836 | + case 'clustered': |
|
837 | + case 'alternate_key': |
|
838 | + /** |
|
839 | + * @todo here it is assumed that the primary key of the foreign |
|
840 | + * table will always be named 'id'. It must be noted though |
|
841 | + * that this can easily be fixed by referring to db dictionary |
|
842 | + * to find the correct primary field name |
|
843 | + */ |
|
844 | + if ( $alter_table ) |
|
845 | + $columns[] = " INDEX $name ($fields)"; |
|
846 | + else |
|
847 | + $columns[] = " KEY $name ($fields)"; |
|
848 | + break; |
|
849 | + case 'fulltext': |
|
850 | + if ($this->full_text_indexing_installed()) |
|
851 | + $columns[] = " FULLTEXT ($fields)"; |
|
852 | + else |
|
853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | + break; |
|
855 | + } |
|
856 | + } |
|
857 | + $columns = implode(", $alter_action ", $columns); |
|
858 | + if(!empty($alter_action)){ |
|
859 | + $columns = $alter_action . ' '. $columns; |
|
860 | + } |
|
861 | + return $columns; |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * @see DBManager::setAutoIncrement() |
|
866 | + */ |
|
867 | + protected function setAutoIncrement($table, $field_name) |
|
868 | + { |
|
869 | + return "auto_increment"; |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * Sets the next auto-increment value of a column to a specific value. |
|
874 | + * |
|
875 | + * @param string $table tablename |
|
876 | + * @param string $field_name |
|
877 | + */ |
|
878 | + public function setAutoIncrementStart($table, $field_name, $start_value) |
|
879 | + { |
|
880 | + $start_value = (int)$start_value; |
|
881 | + return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Returns the next value for an auto increment |
|
886 | + * |
|
887 | + * @param string $table tablename |
|
888 | + * @param string $field_name |
|
889 | + * @return string |
|
890 | + */ |
|
891 | + public function getAutoIncrement($table, $field_name) |
|
892 | + { |
|
893 | + $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
894 | + $row = $this->fetchByAssoc($result); |
|
895 | + if (!empty($row['Auto_increment'])) |
|
896 | + return $row['Auto_increment']; |
|
897 | + |
|
898 | + return ""; |
|
899 | + } |
|
900 | + |
|
901 | + /** |
|
902 | + * @see DBManager::get_indices() |
|
903 | + */ |
|
904 | + public function get_indices($tablename) |
|
905 | + { |
|
906 | + //find all unique indexes and primary keys. |
|
907 | + $result = $this->query("SHOW INDEX FROM $tablename"); |
|
908 | + |
|
909 | + $indices = array(); |
|
910 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
911 | + $index_type='index'; |
|
912 | + if ($row['Key_name'] =='PRIMARY') { |
|
913 | + $index_type='primary'; |
|
914 | + } |
|
915 | + elseif ( $row['Non_unique'] == '0' ) { |
|
916 | + $index_type='unique'; |
|
917 | + } |
|
918 | + $name = strtolower($row['Key_name']); |
|
919 | + $indices[$name]['name']=$name; |
|
920 | + $indices[$name]['type']=$index_type; |
|
921 | + $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
922 | + } |
|
923 | + return $indices; |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * @see DBManager::add_drop_constraint() |
|
928 | + */ |
|
929 | + public function add_drop_constraint($table, $definition, $drop = false) |
|
930 | + { |
|
931 | + $type = $definition['type']; |
|
932 | + $fields = implode(',',$definition['fields']); |
|
933 | + $name = $definition['name']; |
|
934 | + $sql = ''; |
|
935 | + |
|
936 | + switch ($type){ |
|
937 | + // generic indices |
|
938 | + case 'index': |
|
939 | + case 'alternate_key': |
|
940 | + case 'clustered': |
|
941 | + if ($drop) |
|
942 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | + else |
|
944 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | + break; |
|
946 | + // constraints as indices |
|
947 | + case 'unique': |
|
948 | + if ($drop) |
|
949 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | + else |
|
951 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | + break; |
|
953 | + case 'primary': |
|
954 | + if ($drop) |
|
955 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | + else |
|
957 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | + break; |
|
959 | + case 'foreign': |
|
960 | + if ($drop) |
|
961 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | + else |
|
963 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | + break; |
|
965 | + } |
|
966 | + return $sql; |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Runs a query and returns a single row |
|
971 | + * |
|
972 | + * @param string $sql SQL Statement to execute |
|
973 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
974 | + * @param string $msg Message to log if error occurs |
|
975 | + * @param bool $suppress Message to log if error occurs |
|
976 | + * @return array single row from the query |
|
977 | + */ |
|
978 | + public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
979 | + { |
|
980 | + if(stripos($sql, ' LIMIT ') === false) { |
|
981 | + // little optimization to just fetch one row |
|
982 | + $sql .= " LIMIT 0,1"; |
|
983 | + } |
|
984 | + return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
985 | + } |
|
986 | + |
|
987 | + /** |
|
988 | + * @see DBManager::full_text_indexing_installed() |
|
989 | + */ |
|
990 | + public function full_text_indexing_installed($dbname = null) |
|
991 | + { |
|
992 | + return $this->isEngineEnabled('MyISAM'); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * @see DBManager::massageFieldDef() |
|
997 | + */ |
|
998 | + public function massageFieldDef(&$fieldDef, $tablename) |
|
999 | + { |
|
1000 | + parent::massageFieldDef($fieldDef,$tablename); |
|
1001 | + |
|
1002 | + if ( isset($fieldDef['default']) && |
|
1003 | + ($fieldDef['dbType'] == 'text' |
|
1004 | + || $fieldDef['dbType'] == 'blob' |
|
1005 | + || $fieldDef['dbType'] == 'longtext' |
|
1006 | + || $fieldDef['dbType'] == 'longblob' )) |
|
1007 | + unset($fieldDef['default']); |
|
1008 | + if ($fieldDef['dbType'] == 'uint') |
|
1009 | + $fieldDef['len'] = '10'; |
|
1010 | + if ($fieldDef['dbType'] == 'ulong') |
|
1011 | + $fieldDef['len'] = '20'; |
|
1012 | + if ($fieldDef['dbType'] == 'bool') |
|
1013 | + $fieldDef['type'] = 'tinyint'; |
|
1014 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1015 | + $fieldDef['default'] = '0'; |
|
1016 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1017 | + $fieldDef['len'] = '255'; |
|
1018 | + if ($fieldDef['dbType'] == 'uint') |
|
1019 | + $fieldDef['len'] = '10'; |
|
1020 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1021 | + $fieldDef['len'] = '11'; |
|
1022 | + |
|
1023 | + if($fieldDef['dbType'] == 'decimal') { |
|
1024 | + if(isset($fieldDef['len'])) { |
|
1025 | + if(strstr($fieldDef['len'], ",") === false) { |
|
1026 | + $fieldDef['len'] .= ",0"; |
|
1027 | + } |
|
1028 | + } else { |
|
1029 | + $fieldDef['len'] = '10,0'; |
|
1030 | + } |
|
1031 | + } |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * Generates SQL for dropping a table. |
|
1036 | + * |
|
1037 | + * @param string $name table name |
|
1038 | + * @return string SQL statement |
|
1039 | + */ |
|
1040 | + public function dropTableNameSQL($name) |
|
1041 | + { |
|
1042 | + return "DROP TABLE IF EXISTS ".$name; |
|
1043 | + } |
|
1044 | + |
|
1045 | + public function dropIndexes($tablename, $indexes, $execute = true) |
|
1046 | + { |
|
1047 | + $sql = array(); |
|
1048 | + foreach ($indexes as $index) { |
|
1049 | + $name =$index['name']; |
|
1050 | + if($execute) { |
|
1051 | + unset(self::$index_descriptions[$tablename][$name]); |
|
1052 | + } |
|
1053 | + if ($index['type'] == 'primary') { |
|
1054 | + $sql[] = 'DROP PRIMARY KEY'; |
|
1055 | + } else { |
|
1056 | + $sql[] = "DROP INDEX $name"; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + if (!empty($sql)) { |
|
1060 | 1060 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
1061 | - if($execute) |
|
1062 | - $this->query($sql); |
|
1063 | - } else { |
|
1064 | - $sql = ''; |
|
1065 | - } |
|
1066 | - return $sql; |
|
1067 | - } |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * List of available collation settings |
|
1071 | - * @return string |
|
1072 | - */ |
|
1073 | - public function getDefaultCollation() |
|
1074 | - { |
|
1075 | - return "utf8_general_ci"; |
|
1076 | - } |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * List of available collation settings |
|
1080 | - * @return array |
|
1081 | - */ |
|
1082 | - public function getCollationList() |
|
1083 | - { |
|
1084 | - $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
1085 | - $r = $this->query($q); |
|
1086 | - $res = array(); |
|
1087 | - while($a = $this->fetchByAssoc($r)) { |
|
1088 | - $res[] = $a['Collation']; |
|
1089 | - } |
|
1090 | - return $res; |
|
1091 | - } |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * (non-PHPdoc) |
|
1095 | - * @see DBManager::renameColumnSQL() |
|
1096 | - */ |
|
1097 | - public function renameColumnSQL($tablename, $column, $newname) |
|
1098 | - { |
|
1099 | - $field = $this->describeField($column, $tablename); |
|
1100 | - $field['name'] = $newname; |
|
1101 | - return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
1102 | - } |
|
1103 | - |
|
1104 | - public function emptyValue($type) |
|
1105 | - { |
|
1106 | - $ctype = $this->getColumnType($type); |
|
1107 | - if($ctype == "datetime") { |
|
1108 | - return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
1109 | - } |
|
1110 | - if($ctype == "date") { |
|
1111 | - return $this->convert($this->quoted("0000-00-00"), "date"); |
|
1112 | - } |
|
1113 | - if($ctype == "time") { |
|
1114 | - return $this->convert($this->quoted("00:00:00"), "time"); |
|
1115 | - } |
|
1116 | - return parent::emptyValue($type); |
|
1117 | - } |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * (non-PHPdoc) |
|
1121 | - * @see DBManager::lastDbError() |
|
1122 | - */ |
|
1123 | - public function lastDbError() |
|
1124 | - { |
|
1125 | - if($this->database) { |
|
1126 | - if(mysql_errno($this->database)) { |
|
1127 | - return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
1128 | - } |
|
1129 | - } else { |
|
1130 | - $err = mysql_error(); |
|
1131 | - if($err) { |
|
1132 | - return $err; |
|
1133 | - } |
|
1134 | - } |
|
1061 | + if($execute) |
|
1062 | + $this->query($sql); |
|
1063 | + } else { |
|
1064 | + $sql = ''; |
|
1065 | + } |
|
1066 | + return $sql; |
|
1067 | + } |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * List of available collation settings |
|
1071 | + * @return string |
|
1072 | + */ |
|
1073 | + public function getDefaultCollation() |
|
1074 | + { |
|
1075 | + return "utf8_general_ci"; |
|
1076 | + } |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * List of available collation settings |
|
1080 | + * @return array |
|
1081 | + */ |
|
1082 | + public function getCollationList() |
|
1083 | + { |
|
1084 | + $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
1085 | + $r = $this->query($q); |
|
1086 | + $res = array(); |
|
1087 | + while($a = $this->fetchByAssoc($r)) { |
|
1088 | + $res[] = $a['Collation']; |
|
1089 | + } |
|
1090 | + return $res; |
|
1091 | + } |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * (non-PHPdoc) |
|
1095 | + * @see DBManager::renameColumnSQL() |
|
1096 | + */ |
|
1097 | + public function renameColumnSQL($tablename, $column, $newname) |
|
1098 | + { |
|
1099 | + $field = $this->describeField($column, $tablename); |
|
1100 | + $field['name'] = $newname; |
|
1101 | + return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
1102 | + } |
|
1103 | + |
|
1104 | + public function emptyValue($type) |
|
1105 | + { |
|
1106 | + $ctype = $this->getColumnType($type); |
|
1107 | + if($ctype == "datetime") { |
|
1108 | + return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
1109 | + } |
|
1110 | + if($ctype == "date") { |
|
1111 | + return $this->convert($this->quoted("0000-00-00"), "date"); |
|
1112 | + } |
|
1113 | + if($ctype == "time") { |
|
1114 | + return $this->convert($this->quoted("00:00:00"), "time"); |
|
1115 | + } |
|
1116 | + return parent::emptyValue($type); |
|
1117 | + } |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * (non-PHPdoc) |
|
1121 | + * @see DBManager::lastDbError() |
|
1122 | + */ |
|
1123 | + public function lastDbError() |
|
1124 | + { |
|
1125 | + if($this->database) { |
|
1126 | + if(mysql_errno($this->database)) { |
|
1127 | + return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
1128 | + } |
|
1129 | + } else { |
|
1130 | + $err = mysql_error(); |
|
1131 | + if($err) { |
|
1132 | + return $err; |
|
1133 | + } |
|
1134 | + } |
|
1135 | 1135 | return false; |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - /** |
|
1139 | - * Quote MySQL search term |
|
1140 | - * @param unknown_type $term |
|
1141 | - */ |
|
1142 | - protected function quoteTerm($term) |
|
1143 | - { |
|
1144 | - if(strpos($term, ' ') !== false) { |
|
1145 | - return '"'.$term.'"'; |
|
1146 | - } |
|
1147 | - return $term; |
|
1148 | - } |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Generate fulltext query from set of terms |
|
1152 | - * @param string $fields Field to search against |
|
1153 | - * @param array $terms Search terms that may be or not be in the result |
|
1154 | - * @param array $must_terms Search terms that have to be in the result |
|
1155 | - * @param array $exclude_terms Search terms that have to be not in the result |
|
1156 | - */ |
|
1157 | - public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
1158 | - { |
|
1159 | - $condition = array(); |
|
1160 | - foreach($terms as $term) { |
|
1161 | - $condition[] = $this->quoteTerm($term); |
|
1162 | - } |
|
1163 | - foreach($must_terms as $term) { |
|
1164 | - $condition[] = "+".$this->quoteTerm($term); |
|
1165 | - } |
|
1166 | - foreach($exclude_terms as $term) { |
|
1167 | - $condition[] = "-".$this->quoteTerm($term); |
|
1168 | - } |
|
1169 | - $condition = $this->quoted(join(" ",$condition)); |
|
1170 | - return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * Get list of all defined charsets |
|
1175 | - * @return array |
|
1176 | - */ |
|
1177 | - protected function getCharsetInfo() |
|
1178 | - { |
|
1179 | - $charsets = array(); |
|
1180 | - $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
1181 | - while($row = $this->fetchByAssoc($res)) { |
|
1182 | - $charsets[$row['Variable_name']] = $row['Value']; |
|
1183 | - } |
|
1184 | - return $charsets; |
|
1185 | - } |
|
1186 | - |
|
1187 | - public function getDbInfo() |
|
1188 | - { |
|
1189 | - $charsets = $this->getCharsetInfo(); |
|
1190 | - $charset_str = array(); |
|
1191 | - foreach($charsets as $name => $value) { |
|
1192 | - $charset_str[] = "$name = $value"; |
|
1193 | - } |
|
1194 | - return array( |
|
1195 | - "MySQL Version" => @mysql_get_client_info(), |
|
1196 | - "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
1197 | - "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
1198 | - "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
1199 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
1200 | - ); |
|
1201 | - } |
|
1202 | - |
|
1203 | - public function validateQuery($query) |
|
1204 | - { |
|
1205 | - $res = $this->query("EXPLAIN $query"); |
|
1206 | - return !empty($res); |
|
1207 | - } |
|
1208 | - |
|
1209 | - protected function makeTempTableCopy($table) |
|
1210 | - { |
|
1211 | - $this->log->debug("creating temp table for [$table]..."); |
|
1212 | - $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
1213 | - if(empty($result)) { |
|
1214 | - return false; |
|
1215 | - } |
|
1216 | - $row = $this->fetchByAssoc($result); |
|
1217 | - if(empty($row) || empty($row['Create Table'])) { |
|
1218 | - return false; |
|
1219 | - } |
|
1220 | - $create = $row['Create Table']; |
|
1221 | - // rewrite DDL with _temp name |
|
1222 | - $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
1223 | - $r2 = $this->query($tempTableQuery); |
|
1224 | - if(empty($r2)) { |
|
1225 | - return false; |
|
1226 | - } |
|
1227 | - |
|
1228 | - // get sample data into the temp table to test for data/constraint conflicts |
|
1229 | - $this->log->debug('inserting temp dataset...'); |
|
1230 | - $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
1231 | - $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
1232 | - return true; |
|
1233 | - } |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Tests an ALTER TABLE query |
|
1237 | - * @param string table The table name to get DDL |
|
1238 | - * @param string query The query to test. |
|
1239 | - * @return string Non-empty if error found |
|
1240 | - */ |
|
1241 | - protected function verifyAlterTable($table, $query) |
|
1242 | - { |
|
1243 | - $this->log->debug("verifying ALTER TABLE"); |
|
1244 | - // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
1245 | - // over to the temp tables |
|
1246 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1247 | - $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
1248 | - return ''; |
|
1249 | - } |
|
1250 | - if(!$this->makeTempTableCopy($table)) { |
|
1251 | - return 'Could not create temp table copy'; |
|
1252 | - } |
|
1253 | - |
|
1254 | - // test the query on the test table |
|
1255 | - $this->log->debug('testing query: ['.$query.']'); |
|
1256 | - $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
1257 | - if (strpos($tempTableTestQuery, 'idx') === false) { |
|
1258 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1259 | - return 'Could not use a temp table to test query!'; |
|
1260 | - } |
|
1261 | - |
|
1262 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
1263 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1264 | - } else { |
|
1265 | - // test insertion of an index on a table |
|
1266 | - $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
1267 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
1268 | - $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
1269 | - } |
|
1270 | - $mysqlError = $this->getL(); |
|
1271 | - if(!empty($mysqlError)) { |
|
1272 | - return $mysqlError; |
|
1273 | - } |
|
1274 | - $this->dropTableName("{$table}__uw_temp"); |
|
1275 | - |
|
1276 | - return ''; |
|
1277 | - } |
|
1278 | - |
|
1279 | - protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
1280 | - { |
|
1281 | - $this->log->debug("verifying $querytype statement"); |
|
1282 | - |
|
1283 | - if(!$this->makeTempTableCopy($table)) { |
|
1284 | - return 'Could not create temp table copy'; |
|
1285 | - } |
|
1286 | - // test the query on the test table |
|
1287 | - $this->log->debug('testing query: ['.$query.']'); |
|
1288 | - $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
1289 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1290 | - return 'Could not use a temp table to test query!'; |
|
1291 | - } |
|
1292 | - |
|
1293 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1294 | - $error = $this->lastError(); // empty on no-errors |
|
1295 | - $this->dropTableName("{$table}__uw_temp"); // just in case |
|
1296 | - return $error; |
|
1297 | - } |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * Tests a DROP TABLE query |
|
1301 | - * @param string table The table name to get DDL |
|
1302 | - * @param string query The query to test. |
|
1303 | - * @return string Non-empty if error found |
|
1304 | - */ |
|
1305 | - public function verifyDropTable($table, $query) |
|
1306 | - { |
|
1307 | - return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Tests an INSERT INTO query |
|
1312 | - * @param string table The table name to get DDL |
|
1313 | - * @param string query The query to test. |
|
1314 | - * @return string Non-empty if error found |
|
1315 | - */ |
|
1316 | - public function verifyInsertInto($table, $query) |
|
1317 | - { |
|
1318 | - return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * Tests an UPDATE query |
|
1323 | - * @param string table The table name to get DDL |
|
1324 | - * @param string query The query to test. |
|
1325 | - * @return string Non-empty if error found |
|
1326 | - */ |
|
1327 | - public function verifyUpdate($table, $query) |
|
1328 | - { |
|
1329 | - return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
1330 | - } |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Tests an DELETE FROM query |
|
1334 | - * @param string table The table name to get DDL |
|
1335 | - * @param string query The query to test. |
|
1336 | - * @return string Non-empty if error found |
|
1337 | - */ |
|
1338 | - public function verifyDeleteFrom($table, $query) |
|
1339 | - { |
|
1340 | - return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Check if certain database exists |
|
1345 | - * @param string $dbname |
|
1346 | - */ |
|
1347 | - public function dbExists($dbname) |
|
1348 | - { |
|
1349 | - $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
1350 | - return !empty($db); |
|
1351 | - } |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Select database |
|
1355 | - * @param string $dbname |
|
1356 | - */ |
|
1357 | - protected function selectDb($dbname) |
|
1358 | - { |
|
1359 | - return mysql_select_db($dbname); |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Check if certain DB user exists |
|
1364 | - * @param string $username |
|
1365 | - */ |
|
1366 | - public function userExists($username) |
|
1367 | - { |
|
1368 | - $db = $this->getOne("SELECT DATABASE()"); |
|
1369 | - if(!$this->selectDb("mysql")) { |
|
1370 | - return false; |
|
1371 | - } |
|
1372 | - $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
1373 | - if(!$this->selectDb($db)) { |
|
1374 | - $this->checkError("Cannot select database $db", true); |
|
1375 | - } |
|
1376 | - return !empty($user); |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Create DB user |
|
1381 | - * @param string $database_name |
|
1382 | - * @param string $host_name |
|
1383 | - * @param string $user |
|
1384 | - * @param string $password |
|
1385 | - */ |
|
1386 | - public function createDbUser($database_name, $host_name, $user, $password) |
|
1387 | - { |
|
1388 | - $qpassword = $this->quote($password); |
|
1389 | - $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
1138 | + /** |
|
1139 | + * Quote MySQL search term |
|
1140 | + * @param unknown_type $term |
|
1141 | + */ |
|
1142 | + protected function quoteTerm($term) |
|
1143 | + { |
|
1144 | + if(strpos($term, ' ') !== false) { |
|
1145 | + return '"'.$term.'"'; |
|
1146 | + } |
|
1147 | + return $term; |
|
1148 | + } |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Generate fulltext query from set of terms |
|
1152 | + * @param string $fields Field to search against |
|
1153 | + * @param array $terms Search terms that may be or not be in the result |
|
1154 | + * @param array $must_terms Search terms that have to be in the result |
|
1155 | + * @param array $exclude_terms Search terms that have to be not in the result |
|
1156 | + */ |
|
1157 | + public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
1158 | + { |
|
1159 | + $condition = array(); |
|
1160 | + foreach($terms as $term) { |
|
1161 | + $condition[] = $this->quoteTerm($term); |
|
1162 | + } |
|
1163 | + foreach($must_terms as $term) { |
|
1164 | + $condition[] = "+".$this->quoteTerm($term); |
|
1165 | + } |
|
1166 | + foreach($exclude_terms as $term) { |
|
1167 | + $condition[] = "-".$this->quoteTerm($term); |
|
1168 | + } |
|
1169 | + $condition = $this->quoted(join(" ",$condition)); |
|
1170 | + return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * Get list of all defined charsets |
|
1175 | + * @return array |
|
1176 | + */ |
|
1177 | + protected function getCharsetInfo() |
|
1178 | + { |
|
1179 | + $charsets = array(); |
|
1180 | + $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
1181 | + while($row = $this->fetchByAssoc($res)) { |
|
1182 | + $charsets[$row['Variable_name']] = $row['Value']; |
|
1183 | + } |
|
1184 | + return $charsets; |
|
1185 | + } |
|
1186 | + |
|
1187 | + public function getDbInfo() |
|
1188 | + { |
|
1189 | + $charsets = $this->getCharsetInfo(); |
|
1190 | + $charset_str = array(); |
|
1191 | + foreach($charsets as $name => $value) { |
|
1192 | + $charset_str[] = "$name = $value"; |
|
1193 | + } |
|
1194 | + return array( |
|
1195 | + "MySQL Version" => @mysql_get_client_info(), |
|
1196 | + "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
1197 | + "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
1198 | + "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
1199 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
1200 | + ); |
|
1201 | + } |
|
1202 | + |
|
1203 | + public function validateQuery($query) |
|
1204 | + { |
|
1205 | + $res = $this->query("EXPLAIN $query"); |
|
1206 | + return !empty($res); |
|
1207 | + } |
|
1208 | + |
|
1209 | + protected function makeTempTableCopy($table) |
|
1210 | + { |
|
1211 | + $this->log->debug("creating temp table for [$table]..."); |
|
1212 | + $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
1213 | + if(empty($result)) { |
|
1214 | + return false; |
|
1215 | + } |
|
1216 | + $row = $this->fetchByAssoc($result); |
|
1217 | + if(empty($row) || empty($row['Create Table'])) { |
|
1218 | + return false; |
|
1219 | + } |
|
1220 | + $create = $row['Create Table']; |
|
1221 | + // rewrite DDL with _temp name |
|
1222 | + $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
1223 | + $r2 = $this->query($tempTableQuery); |
|
1224 | + if(empty($r2)) { |
|
1225 | + return false; |
|
1226 | + } |
|
1227 | + |
|
1228 | + // get sample data into the temp table to test for data/constraint conflicts |
|
1229 | + $this->log->debug('inserting temp dataset...'); |
|
1230 | + $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
1231 | + $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
1232 | + return true; |
|
1233 | + } |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Tests an ALTER TABLE query |
|
1237 | + * @param string table The table name to get DDL |
|
1238 | + * @param string query The query to test. |
|
1239 | + * @return string Non-empty if error found |
|
1240 | + */ |
|
1241 | + protected function verifyAlterTable($table, $query) |
|
1242 | + { |
|
1243 | + $this->log->debug("verifying ALTER TABLE"); |
|
1244 | + // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
1245 | + // over to the temp tables |
|
1246 | + if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1247 | + $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
1248 | + return ''; |
|
1249 | + } |
|
1250 | + if(!$this->makeTempTableCopy($table)) { |
|
1251 | + return 'Could not create temp table copy'; |
|
1252 | + } |
|
1253 | + |
|
1254 | + // test the query on the test table |
|
1255 | + $this->log->debug('testing query: ['.$query.']'); |
|
1256 | + $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
1257 | + if (strpos($tempTableTestQuery, 'idx') === false) { |
|
1258 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1259 | + return 'Could not use a temp table to test query!'; |
|
1260 | + } |
|
1261 | + |
|
1262 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
1263 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1264 | + } else { |
|
1265 | + // test insertion of an index on a table |
|
1266 | + $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
1267 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
1268 | + $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
1269 | + } |
|
1270 | + $mysqlError = $this->getL(); |
|
1271 | + if(!empty($mysqlError)) { |
|
1272 | + return $mysqlError; |
|
1273 | + } |
|
1274 | + $this->dropTableName("{$table}__uw_temp"); |
|
1275 | + |
|
1276 | + return ''; |
|
1277 | + } |
|
1278 | + |
|
1279 | + protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
1280 | + { |
|
1281 | + $this->log->debug("verifying $querytype statement"); |
|
1282 | + |
|
1283 | + if(!$this->makeTempTableCopy($table)) { |
|
1284 | + return 'Could not create temp table copy'; |
|
1285 | + } |
|
1286 | + // test the query on the test table |
|
1287 | + $this->log->debug('testing query: ['.$query.']'); |
|
1288 | + $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
1289 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1290 | + return 'Could not use a temp table to test query!'; |
|
1291 | + } |
|
1292 | + |
|
1293 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1294 | + $error = $this->lastError(); // empty on no-errors |
|
1295 | + $this->dropTableName("{$table}__uw_temp"); // just in case |
|
1296 | + return $error; |
|
1297 | + } |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * Tests a DROP TABLE query |
|
1301 | + * @param string table The table name to get DDL |
|
1302 | + * @param string query The query to test. |
|
1303 | + * @return string Non-empty if error found |
|
1304 | + */ |
|
1305 | + public function verifyDropTable($table, $query) |
|
1306 | + { |
|
1307 | + return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Tests an INSERT INTO query |
|
1312 | + * @param string table The table name to get DDL |
|
1313 | + * @param string query The query to test. |
|
1314 | + * @return string Non-empty if error found |
|
1315 | + */ |
|
1316 | + public function verifyInsertInto($table, $query) |
|
1317 | + { |
|
1318 | + return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * Tests an UPDATE query |
|
1323 | + * @param string table The table name to get DDL |
|
1324 | + * @param string query The query to test. |
|
1325 | + * @return string Non-empty if error found |
|
1326 | + */ |
|
1327 | + public function verifyUpdate($table, $query) |
|
1328 | + { |
|
1329 | + return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
1330 | + } |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Tests an DELETE FROM query |
|
1334 | + * @param string table The table name to get DDL |
|
1335 | + * @param string query The query to test. |
|
1336 | + * @return string Non-empty if error found |
|
1337 | + */ |
|
1338 | + public function verifyDeleteFrom($table, $query) |
|
1339 | + { |
|
1340 | + return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Check if certain database exists |
|
1345 | + * @param string $dbname |
|
1346 | + */ |
|
1347 | + public function dbExists($dbname) |
|
1348 | + { |
|
1349 | + $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
1350 | + return !empty($db); |
|
1351 | + } |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Select database |
|
1355 | + * @param string $dbname |
|
1356 | + */ |
|
1357 | + protected function selectDb($dbname) |
|
1358 | + { |
|
1359 | + return mysql_select_db($dbname); |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Check if certain DB user exists |
|
1364 | + * @param string $username |
|
1365 | + */ |
|
1366 | + public function userExists($username) |
|
1367 | + { |
|
1368 | + $db = $this->getOne("SELECT DATABASE()"); |
|
1369 | + if(!$this->selectDb("mysql")) { |
|
1370 | + return false; |
|
1371 | + } |
|
1372 | + $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
1373 | + if(!$this->selectDb($db)) { |
|
1374 | + $this->checkError("Cannot select database $db", true); |
|
1375 | + } |
|
1376 | + return !empty($user); |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Create DB user |
|
1381 | + * @param string $database_name |
|
1382 | + * @param string $host_name |
|
1383 | + * @param string $user |
|
1384 | + * @param string $password |
|
1385 | + */ |
|
1386 | + public function createDbUser($database_name, $host_name, $user, $password) |
|
1387 | + { |
|
1388 | + $qpassword = $this->quote($password); |
|
1389 | + $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
1390 | 1390 | ON `$database_name`.* |
1391 | 1391 | TO \"$user\"@\"$host_name\" |
1392 | 1392 | IDENTIFIED BY '{$qpassword}';", true); |
1393 | 1393 | |
1394 | - $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
1395 | - if($host_name != 'localhost') { |
|
1396 | - $this->createDbUser($database_name, "localhost", $user, $password); |
|
1397 | - } |
|
1398 | - } |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * Create a database |
|
1402 | - * @param string $dbname |
|
1403 | - */ |
|
1404 | - public function createDatabase($dbname) |
|
1405 | - { |
|
1406 | - $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
1407 | - } |
|
1408 | - |
|
1409 | - public function preInstall() |
|
1410 | - { |
|
1411 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
1412 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
1413 | - |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * Drop a database |
|
1418 | - * @param string $dbname |
|
1419 | - */ |
|
1420 | - public function dropDatabase($dbname) |
|
1421 | - { |
|
1422 | - return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
1423 | - } |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * Check if this driver can be used |
|
1427 | - * @return bool |
|
1428 | - */ |
|
1429 | - public function valid() |
|
1430 | - { |
|
1431 | - return function_exists("mysql_connect"); |
|
1432 | - } |
|
1433 | - |
|
1434 | - /** |
|
1435 | - * Check DB version |
|
1436 | - * @see DBManager::canInstall() |
|
1437 | - */ |
|
1438 | - public function canInstall() |
|
1439 | - { |
|
1440 | - $db_version = $this->version(); |
|
1441 | - if(empty($db_version)) { |
|
1442 | - return array('ERR_DB_VERSION_FAILURE'); |
|
1443 | - } |
|
1444 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
1445 | - return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
1446 | - } |
|
1447 | - return true; |
|
1448 | - } |
|
1449 | - |
|
1450 | - public function installConfig() |
|
1451 | - { |
|
1452 | - return array( |
|
1453 | - 'LBL_DBCONFIG_MSG3' => array( |
|
1454 | - "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
1455 | - ), |
|
1456 | - 'LBL_DBCONFIG_MSG2' => array( |
|
1457 | - "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
1458 | - ), |
|
1459 | - 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
1460 | - 'LBL_DBCONFIG_B_MSG1' => array( |
|
1461 | - "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
1462 | - "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
1463 | - ) |
|
1464 | - ); |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Disable keys on the table |
|
1469 | - * @abstract |
|
1470 | - * @param string $tableName |
|
1471 | - */ |
|
1472 | - public function disableKeys($tableName) |
|
1473 | - { |
|
1474 | - return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * Re-enable keys on the table |
|
1479 | - * @abstract |
|
1480 | - * @param string $tableName |
|
1481 | - */ |
|
1482 | - public function enableKeys($tableName) |
|
1483 | - { |
|
1484 | - return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
1485 | - } |
|
1394 | + $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
1395 | + if($host_name != 'localhost') { |
|
1396 | + $this->createDbUser($database_name, "localhost", $user, $password); |
|
1397 | + } |
|
1398 | + } |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * Create a database |
|
1402 | + * @param string $dbname |
|
1403 | + */ |
|
1404 | + public function createDatabase($dbname) |
|
1405 | + { |
|
1406 | + $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
1407 | + } |
|
1408 | + |
|
1409 | + public function preInstall() |
|
1410 | + { |
|
1411 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
1412 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
1413 | + |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * Drop a database |
|
1418 | + * @param string $dbname |
|
1419 | + */ |
|
1420 | + public function dropDatabase($dbname) |
|
1421 | + { |
|
1422 | + return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
1423 | + } |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * Check if this driver can be used |
|
1427 | + * @return bool |
|
1428 | + */ |
|
1429 | + public function valid() |
|
1430 | + { |
|
1431 | + return function_exists("mysql_connect"); |
|
1432 | + } |
|
1433 | + |
|
1434 | + /** |
|
1435 | + * Check DB version |
|
1436 | + * @see DBManager::canInstall() |
|
1437 | + */ |
|
1438 | + public function canInstall() |
|
1439 | + { |
|
1440 | + $db_version = $this->version(); |
|
1441 | + if(empty($db_version)) { |
|
1442 | + return array('ERR_DB_VERSION_FAILURE'); |
|
1443 | + } |
|
1444 | + if(version_compare($db_version, '4.1.2') < 0) { |
|
1445 | + return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
1446 | + } |
|
1447 | + return true; |
|
1448 | + } |
|
1449 | + |
|
1450 | + public function installConfig() |
|
1451 | + { |
|
1452 | + return array( |
|
1453 | + 'LBL_DBCONFIG_MSG3' => array( |
|
1454 | + "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
1455 | + ), |
|
1456 | + 'LBL_DBCONFIG_MSG2' => array( |
|
1457 | + "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
1458 | + ), |
|
1459 | + 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
1460 | + 'LBL_DBCONFIG_B_MSG1' => array( |
|
1461 | + "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
1462 | + "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
1463 | + ) |
|
1464 | + ); |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Disable keys on the table |
|
1469 | + * @abstract |
|
1470 | + * @param string $tableName |
|
1471 | + */ |
|
1472 | + public function disableKeys($tableName) |
|
1473 | + { |
|
1474 | + return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * Re-enable keys on the table |
|
1479 | + * @abstract |
|
1480 | + * @param string $tableName |
|
1481 | + */ |
|
1482 | + public function enableKeys($tableName) |
|
1483 | + { |
|
1484 | + return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
1485 | + } |
|
1486 | 1486 | |
1487 | 1487 | /** |
1488 | 1488 | * Returns a DB specific FROM clause which can be used to select against functions. |
@@ -1501,8 +1501,8 @@ discard block |
||
1501 | 1501 | * @return string |
1502 | 1502 | */ |
1503 | 1503 | |
1504 | - public function getGuidSQL() |
|
1504 | + public function getGuidSQL() |
|
1505 | 1505 | { |
1506 | - return 'UUID()'; |
|
1506 | + return 'UUID()'; |
|
1507 | 1507 | } |
1508 | 1508 | } |
@@ -825,33 +825,33 @@ discard block |
||
825 | 825 | $fields = $index['fields']; |
826 | 826 | |
827 | 827 | switch ($type) { |
828 | - case 'unique': |
|
829 | - $columns[] = " UNIQUE $name ($fields)"; |
|
830 | - break; |
|
831 | - case 'primary': |
|
832 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | - break; |
|
834 | - case 'index': |
|
835 | - case 'foreign': |
|
836 | - case 'clustered': |
|
837 | - case 'alternate_key': |
|
838 | - /** |
|
828 | + case 'unique': |
|
829 | + $columns[] = " UNIQUE $name ($fields)"; |
|
830 | + break; |
|
831 | + case 'primary': |
|
832 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | + break; |
|
834 | + case 'index': |
|
835 | + case 'foreign': |
|
836 | + case 'clustered': |
|
837 | + case 'alternate_key': |
|
838 | + /** |
|
839 | 839 | * @todo here it is assumed that the primary key of the foreign |
840 | 840 | * table will always be named 'id'. It must be noted though |
841 | 841 | * that this can easily be fixed by referring to db dictionary |
842 | 842 | * to find the correct primary field name |
843 | 843 | */ |
844 | - if ( $alter_table ) |
|
845 | - $columns[] = " INDEX $name ($fields)"; |
|
846 | - else |
|
847 | - $columns[] = " KEY $name ($fields)"; |
|
848 | - break; |
|
849 | - case 'fulltext': |
|
850 | - if ($this->full_text_indexing_installed()) |
|
851 | - $columns[] = " FULLTEXT ($fields)"; |
|
852 | - else |
|
853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | - break; |
|
844 | + if ( $alter_table ) |
|
845 | + $columns[] = " INDEX $name ($fields)"; |
|
846 | + else |
|
847 | + $columns[] = " KEY $name ($fields)"; |
|
848 | + break; |
|
849 | + case 'fulltext': |
|
850 | + if ($this->full_text_indexing_installed()) |
|
851 | + $columns[] = " FULLTEXT ($fields)"; |
|
852 | + else |
|
853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | + break; |
|
855 | 855 | } |
856 | 856 | } |
857 | 857 | $columns = implode(", $alter_action ", $columns); |
@@ -935,33 +935,33 @@ discard block |
||
935 | 935 | |
936 | 936 | switch ($type){ |
937 | 937 | // generic indices |
938 | - case 'index': |
|
939 | - case 'alternate_key': |
|
940 | - case 'clustered': |
|
941 | - if ($drop) |
|
942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | - else |
|
944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | - break; |
|
946 | - // constraints as indices |
|
947 | - case 'unique': |
|
948 | - if ($drop) |
|
949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | - else |
|
951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | - break; |
|
953 | - case 'primary': |
|
954 | - if ($drop) |
|
955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | - else |
|
957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | - break; |
|
959 | - case 'foreign': |
|
960 | - if ($drop) |
|
961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | - else |
|
963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | - break; |
|
938 | + case 'index': |
|
939 | + case 'alternate_key': |
|
940 | + case 'clustered': |
|
941 | + if ($drop) |
|
942 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | + else |
|
944 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | + break; |
|
946 | + // constraints as indices |
|
947 | + case 'unique': |
|
948 | + if ($drop) |
|
949 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | + else |
|
951 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | + break; |
|
953 | + case 'primary': |
|
954 | + if ($drop) |
|
955 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | + else |
|
957 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | + break; |
|
959 | + case 'foreign': |
|
960 | + if ($drop) |
|
961 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | + else |
|
963 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | + break; |
|
965 | 965 | } |
966 | 966 | return $sql; |
967 | 967 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -170,25 +170,25 @@ discard block |
||
170 | 170 | */ |
171 | 171 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
172 | 172 | { |
173 | - if(is_array($sql)) { |
|
173 | + if (is_array($sql)) { |
|
174 | 174 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
175 | 175 | } |
176 | 176 | |
177 | 177 | parent::countQuery($sql); |
178 | - $GLOBALS['log']->info('Query:' . $sql); |
|
178 | + $GLOBALS['log']->info('Query:'.$sql); |
|
179 | 179 | $this->checkConnection(); |
180 | 180 | $this->query_time = microtime(true); |
181 | 181 | $this->lastsql = $sql; |
182 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
182 | + $result = $suppress ? @mysql_query($sql, $this->database) : mysql_query($sql, $this->database); |
|
183 | 183 | |
184 | 184 | $this->query_time = microtime(true) - $this->query_time; |
185 | 185 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
186 | 186 | |
187 | 187 | |
188 | - if($keepResult) |
|
188 | + if ($keepResult) |
|
189 | 189 | $this->lastResult = $result; |
190 | 190 | |
191 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
191 | + $this->checkError($msg.' Query Failed:'.$sql.'::', $dieOnError); |
|
192 | 192 | return $result; |
193 | 193 | } |
194 | 194 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | public function disconnect() |
225 | 225 | { |
226 | 226 | $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
227 | - if(!empty($this->database)){ |
|
227 | + if (!empty($this->database)) { |
|
228 | 228 | $this->freeResult(); |
229 | 229 | mysql_close($this->database); |
230 | 230 | $this->database = null; |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | */ |
237 | 237 | protected function freeDbResult($dbResult) |
238 | 238 | { |
239 | - if(!empty($dbResult)) |
|
239 | + if (!empty($dbResult)) |
|
240 | 240 | mysql_free_result($dbResult); |
241 | 241 | } |
242 | 242 | |
@@ -262,15 +262,15 @@ discard block |
||
262 | 262 | $count = (int)$count; |
263 | 263 | if ($start < 0) |
264 | 264 | $start = 0; |
265 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
265 | + $GLOBALS['log']->debug('Limit Query:'.$sql.' Start: '.$start.' count: '.$count); |
|
266 | 266 | |
267 | 267 | $sql = "$sql LIMIT $start,$count"; |
268 | 268 | $this->lastsql = $sql; |
269 | 269 | |
270 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
270 | + if (!empty($GLOBALS['sugar_config']['check_query'])) { |
|
271 | 271 | $this->checkQuery($sql); |
272 | 272 | } |
273 | - if(!$execute) { |
|
273 | + if (!$execute) { |
|
274 | 274 | return $sql; |
275 | 275 | } |
276 | 276 | |
@@ -283,14 +283,14 @@ discard block |
||
283 | 283 | */ |
284 | 284 | protected function checkQuery($sql, $object_name = false) |
285 | 285 | { |
286 | - $result = $this->query('EXPLAIN ' . $sql); |
|
286 | + $result = $this->query('EXPLAIN '.$sql); |
|
287 | 287 | $badQuery = array(); |
288 | 288 | while ($row = $this->fetchByAssoc($result)) { |
289 | 289 | if (empty($row['table'])) |
290 | 290 | continue; |
291 | 291 | $badQuery[$row['table']] = ''; |
292 | 292 | if (strtoupper($row['type']) == 'ALL') |
293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
293 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | 294 | if (empty($row['key'])) |
295 | 295 | $badQuery[$row['table']] .= ' No Index Key Used;'; |
296 | 296 | if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
@@ -299,18 +299,18 @@ discard block |
||
299 | 299 | $badQuery[$row['table']] .= ' Using Temporary Table;'; |
300 | 300 | } |
301 | 301 | |
302 | - if ( empty($badQuery) ) |
|
302 | + if (empty($badQuery)) |
|
303 | 303 | return true; |
304 | 304 | |
305 | - foreach($badQuery as $table=>$data ){ |
|
306 | - if(!empty($data)){ |
|
307 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
308 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
305 | + foreach ($badQuery as $table=>$data) { |
|
306 | + if (!empty($data)) { |
|
307 | + $warning = ' Table:'.$table.' Data:'.$data; |
|
308 | + if (!empty($GLOBALS['sugar_config']['check_query_log'])) { |
|
309 | 309 | $GLOBALS['log']->fatal($sql); |
310 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
310 | + $GLOBALS['log']->fatal('CHECK QUERY:'.$warning); |
|
311 | 311 | } |
312 | - else{ |
|
313 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
312 | + else { |
|
313 | + $GLOBALS['log']->warn('CHECK QUERY:'.$warning); |
|
314 | 314 | } |
315 | 315 | } |
316 | 316 | } |
@@ -327,19 +327,19 @@ discard block |
||
327 | 327 | $result = $this->query("DESCRIBE $tablename"); |
328 | 328 | |
329 | 329 | $columns = array(); |
330 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
330 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
331 | 331 | $name = strtolower($row['Field']); |
332 | - $columns[$name]['name']=$name; |
|
332 | + $columns[$name]['name'] = $name; |
|
333 | 333 | $matches = array(); |
334 | 334 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
335 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
335 | + $columns[$name]['type'] = strtolower($matches[1][0]); |
|
336 | + if (isset($matches[2][0]) && in_array(strtolower($matches[1][0]), array('varchar', 'char', 'varchar2', 'int', 'decimal', 'float'))) |
|
337 | + $columns[$name]['len'] = strtolower($matches[2][0]); |
|
338 | + if (stristr($row['Extra'], 'auto_increment')) |
|
339 | 339 | $columns[$name]['auto_increment'] = '1'; |
340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
340 | + if ($row['Null'] == 'NO' && !stristr($row['Key'], 'PRI')) |
|
341 | 341 | $columns[$name]['required'] = 'true'; |
342 | - if (!empty($row['Default']) ) |
|
342 | + if (!empty($row['Default'])) |
|
343 | 343 | $columns[$name]['default'] = $row['Default']; |
344 | 344 | } |
345 | 345 | return $columns; |
@@ -348,20 +348,20 @@ discard block |
||
348 | 348 | /** |
349 | 349 | * @see DBManager::getFieldsArray() |
350 | 350 | */ |
351 | - public function getFieldsArray($result, $make_lower_case=false) |
|
351 | + public function getFieldsArray($result, $make_lower_case = false) |
|
352 | 352 | { |
353 | 353 | $field_array = array(); |
354 | 354 | |
355 | - if(empty($result)) |
|
355 | + if (empty($result)) |
|
356 | 356 | return 0; |
357 | 357 | |
358 | 358 | $fields = mysql_num_fields($result); |
359 | - for ($i=0; $i < $fields; $i++) { |
|
359 | + for ($i = 0; $i < $fields; $i++) { |
|
360 | 360 | $meta = mysql_fetch_field($result, $i); |
361 | 361 | if (!$meta) |
362 | 362 | return array(); |
363 | 363 | |
364 | - if($make_lower_case == true) |
|
364 | + if ($make_lower_case == true) |
|
365 | 365 | $meta->name = strtolower($meta->name); |
366 | 366 | |
367 | 367 | $field_array[] = $meta->name; |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | if (!empty($r)) { |
394 | 394 | while ($a = $this->fetchByAssoc($r)) { |
395 | 395 | $row = array_values($a); |
396 | - $tables[]=$row[0]; |
|
396 | + $tables[] = $row[0]; |
|
397 | 397 | } |
398 | 398 | return $tables; |
399 | 399 | } |
@@ -419,7 +419,7 @@ discard block |
||
419 | 419 | |
420 | 420 | if ($this->getDatabase()) { |
421 | 421 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
422 | - if(empty($result)) return false; |
|
422 | + if (empty($result)) return false; |
|
423 | 423 | $row = $this->fetchByAssoc($result); |
424 | 424 | return !empty($row); |
425 | 425 | } |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | if (!empty($r)) { |
441 | 441 | while ($a = $this->fetchByAssoc($r)) { |
442 | 442 | $row = array_values($a); |
443 | - $tables[]=$row[0]; |
|
443 | + $tables[] = $row[0]; |
|
444 | 444 | } |
445 | 445 | return $tables; |
446 | 446 | } |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | */ |
454 | 454 | public function quote($string) |
455 | 455 | { |
456 | - if(is_array($string)) { |
|
456 | + if (is_array($string)) { |
|
457 | 457 | return $this->arrayQuote($string); |
458 | 458 | } |
459 | 459 | return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
@@ -474,7 +474,7 @@ discard block |
||
474 | 474 | { |
475 | 475 | global $sugar_config; |
476 | 476 | |
477 | - if(is_null($configOptions)) |
|
477 | + if (is_null($configOptions)) |
|
478 | 478 | $configOptions = $sugar_config['dbconfig']; |
479 | 479 | |
480 | 480 | if ($this->getOption('persistent')) { |
@@ -491,10 +491,10 @@ discard block |
||
491 | 491 | $configOptions['db_user_name'], |
492 | 492 | $configOptions['db_password'] |
493 | 493 | ); |
494 | - if(empty($this->database)) { |
|
494 | + if (empty($this->database)) { |
|
495 | 495 | $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
496 | - if($dieOnError) { |
|
497 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
496 | + if ($dieOnError) { |
|
497 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
498 | 498 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
499 | 499 | } else { |
500 | 500 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -504,15 +504,15 @@ discard block |
||
504 | 504 | } |
505 | 505 | } |
506 | 506 | // Do not pass connection information because we have not connected yet |
507 | - if($this->database && $this->getOption('persistent')){ |
|
507 | + if ($this->database && $this->getOption('persistent')) { |
|
508 | 508 | $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
509 | 509 | . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
510 | 510 | . "in your config.php file</b>"; |
511 | 511 | } |
512 | 512 | } |
513 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
515 | - if($dieOnError) { |
|
513 | + if (!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}: ".mysql_error($this->database)); |
|
515 | + if ($dieOnError) { |
|
516 | 516 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
517 | 517 | } else { |
518 | 518 | return false; |
@@ -523,12 +523,12 @@ discard block |
||
523 | 523 | mysql_query("SET CHARACTER SET utf8", $this->database); |
524 | 524 | $names = "SET NAMES 'utf8'"; |
525 | 525 | $collation = $this->getOption('collation'); |
526 | - if(!empty($collation)) { |
|
526 | + if (!empty($collation)) { |
|
527 | 527 | $names .= " COLLATE '$collation'"; |
528 | 528 | } |
529 | 529 | mysql_query($names, $this->database); |
530 | 530 | |
531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
531 | + if (!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | 532 | $GLOBALS['log']->info("connected to db"); |
533 | 533 | $this->connectOptions = $configOptions; |
534 | 534 | |
@@ -544,16 +544,16 @@ discard block |
||
544 | 544 | */ |
545 | 545 | public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
546 | 546 | { |
547 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
547 | + $sql = parent::repairTableParams($tablename, $fielddefs, $indices, false, $engine); |
|
548 | 548 | |
549 | - if ( $sql == '' ) |
|
549 | + if ($sql == '') |
|
550 | 550 | return ''; |
551 | 551 | |
552 | - if ( stristr($sql,'create table') ) |
|
552 | + if (stristr($sql, 'create table')) |
|
553 | 553 | { |
554 | 554 | if ($execute) { |
555 | - $msg = "Error creating table: ".$tablename. ":"; |
|
556 | - $this->query($sql,true,$msg); |
|
555 | + $msg = "Error creating table: ".$tablename.":"; |
|
556 | + $this->query($sql, true, $msg); |
|
557 | 557 | } |
558 | 558 | return $sql; |
559 | 559 | } |
@@ -562,23 +562,23 @@ discard block |
||
562 | 562 | $match = array(); |
563 | 563 | preg_match_all('!/\*.*?\*/!is', $sql, $match); |
564 | 564 | $commentBlocks = $match[0]; |
565 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
565 | + $sql = preg_replace('!/\*.*?\*/!is', '', $sql); |
|
566 | 566 | |
567 | 567 | // now, we should only have alter table statements |
568 | 568 | // let's replace the 'alter table name' part with a comma |
569 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
569 | + $sql = preg_replace("!alter table $tablename!is", ', ', $sql); |
|
570 | 570 | |
571 | 571 | // re-add it at the beginning |
572 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
573 | - $sql = str_replace(";","",$sql); |
|
574 | - $sql = str_replace("\n","",$sql); |
|
572 | + $sql = substr_replace($sql, '', strpos($sql, ','), 1); |
|
573 | + $sql = str_replace(";", "", $sql); |
|
574 | + $sql = str_replace("\n", "", $sql); |
|
575 | 575 | $sql = "ALTER TABLE $tablename $sql"; |
576 | 576 | |
577 | - if ( $execute ) |
|
578 | - $this->query($sql,'Error with MySQL repair table'); |
|
577 | + if ($execute) |
|
578 | + $this->query($sql, 'Error with MySQL repair table'); |
|
579 | 579 | |
580 | 580 | // and re-add the comments at the beginning |
581 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
581 | + $sql = implode("\n", $commentBlocks)."\n".$sql."\n"; |
|
582 | 582 | |
583 | 583 | return $sql; |
584 | 584 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | public function convert($string, $type, array $additional_parameters = array()) |
590 | 590 | { |
591 | 591 | $all_parameters = $additional_parameters; |
592 | - if(is_array($string)) { |
|
592 | + if (is_array($string)) { |
|
593 | 593 | $all_parameters = array_merge($string, $all_parameters); |
594 | 594 | } elseif (!is_null($string)) { |
595 | 595 | array_unshift($all_parameters, $string); |
@@ -602,17 +602,17 @@ discard block |
||
602 | 602 | case 'left': |
603 | 603 | return "LEFT($all_strings)"; |
604 | 604 | case 'date_format': |
605 | - if(empty($additional_parameters)) { |
|
605 | + if (empty($additional_parameters)) { |
|
606 | 606 | return "DATE_FORMAT($string,'%Y-%m-%d')"; |
607 | 607 | } else { |
608 | 608 | $format = $additional_parameters[0]; |
609 | - if($format[0] != "'") { |
|
609 | + if ($format[0] != "'") { |
|
610 | 610 | $format = $this->quoted($format); |
611 | 611 | } |
612 | 612 | return "DATE_FORMAT($string,$format)"; |
613 | 613 | } |
614 | 614 | case 'ifnull': |
615 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
615 | + if (empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
616 | 616 | $all_strings .= ",''"; |
617 | 617 | } |
618 | 618 | return "IFNULL($all_strings)"; |
@@ -631,7 +631,7 @@ discard block |
||
631 | 631 | case 'add_tz_offset' : |
632 | 632 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
633 | 633 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
634 | - return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
|
634 | + return $string.' '.$operation.' INTERVAL '.abs($getUserUTCOffset).' MINUTE'; |
|
635 | 635 | case 'avg': |
636 | 636 | return "avg($string)"; |
637 | 637 | } |
@@ -672,15 +672,15 @@ discard block |
||
672 | 672 | */ |
673 | 673 | protected function isEngineEnabled($engine) |
674 | 674 | { |
675 | - if(!is_string($engine)) return false; |
|
675 | + if (!is_string($engine)) return false; |
|
676 | 676 | |
677 | 677 | $engine = strtoupper($engine); |
678 | 678 | |
679 | 679 | $r = $this->query("SHOW ENGINES"); |
680 | 680 | |
681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
683 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
681 | + while ($row = $this->fetchByAssoc($r)) |
|
682 | + if (strtoupper($row['Engine']) == $engine) |
|
683 | + return ($row['Support'] == 'YES' || $row['Support'] == 'DEFAULT'); |
|
684 | 684 | |
685 | 685 | return false; |
686 | 686 | } |
@@ -708,9 +708,9 @@ discard block |
||
708 | 708 | */ |
709 | 709 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
710 | 710 | { |
711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
711 | + if (empty($engine) && isset($fieldDefs['engine'])) |
|
712 | 712 | $engine = $fieldDefs['engine']; |
713 | - if ( !$this->isEngineEnabled($engine) ) |
|
713 | + if (!$this->isEngineEnabled($engine)) |
|
714 | 714 | $engine = ''; |
715 | 715 | |
716 | 716 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
@@ -723,13 +723,13 @@ discard block |
||
723 | 723 | |
724 | 724 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
725 | 725 | $collation = $this->getOption('collation'); |
726 | - if(empty($collation)) { |
|
726 | + if (empty($collation)) { |
|
727 | 727 | $collation = 'utf8_general_ci'; |
728 | 728 | } |
729 | 729 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
730 | 730 | |
731 | 731 | if (!empty($engine)) |
732 | - $sql.= " ENGINE=$engine"; |
|
732 | + $sql .= " ENGINE=$engine"; |
|
733 | 733 | |
734 | 734 | return $sql; |
735 | 735 | } |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | public function isTextType($type) |
742 | 742 | { |
743 | 743 | $type = $this->getColumnType(strtolower($type)); |
744 | - return in_array($type, array('blob','text','longblob', 'longtext')); |
|
744 | + return in_array($type, array('blob', 'text', 'longblob', 'longtext')); |
|
745 | 745 | } |
746 | 746 | |
747 | 747 | /** |
@@ -752,16 +752,16 @@ discard block |
||
752 | 752 | // always return as array for post-processing |
753 | 753 | $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
754 | 754 | |
755 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
755 | + if ($ref['colType'] == 'int' && !empty($fieldDef['len'])) { |
|
756 | 756 | $ref['colType'] .= "(".$fieldDef['len'].")"; |
757 | 757 | } |
758 | 758 | |
759 | 759 | // bug 22338 - don't set a default value on text or blob fields |
760 | - if ( isset($ref['default']) && |
|
760 | + if (isset($ref['default']) && |
|
761 | 761 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
762 | 762 | $ref['default'] = ''; |
763 | 763 | |
764 | - if ( $return_as_array ) |
|
764 | + if ($return_as_array) |
|
765 | 765 | return $ref; |
766 | 766 | else |
767 | 767 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
@@ -773,8 +773,8 @@ discard block |
||
773 | 773 | protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
774 | 774 | { |
775 | 775 | $columns = array(); |
776 | - if ($this->isFieldArray($fieldDefs)){ |
|
777 | - foreach ($fieldDefs as $def){ |
|
776 | + if ($this->isFieldArray($fieldDefs)) { |
|
777 | + foreach ($fieldDefs as $def) { |
|
778 | 778 | if ($action == 'drop') |
779 | 779 | $columns[] = $def['name']; |
780 | 780 | else |
@@ -811,7 +811,7 @@ discard block |
||
811 | 811 | |
812 | 812 | $columns = array(); |
813 | 813 | foreach ($indices as $index) { |
814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
814 | + if (!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | 815 | continue; |
816 | 816 | if (isset($index['source']) && $index['source'] != 'db') |
817 | 817 | continue; |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | * that this can easily be fixed by referring to db dictionary |
842 | 842 | * to find the correct primary field name |
843 | 843 | */ |
844 | - if ( $alter_table ) |
|
844 | + if ($alter_table) |
|
845 | 845 | $columns[] = " INDEX $name ($fields)"; |
846 | 846 | else |
847 | 847 | $columns[] = " KEY $name ($fields)"; |
@@ -850,13 +850,13 @@ discard block |
||
850 | 850 | if ($this->full_text_indexing_installed()) |
851 | 851 | $columns[] = " FULLTEXT ($fields)"; |
852 | 852 | else |
853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:', $name); |
|
854 | 854 | break; |
855 | 855 | } |
856 | 856 | } |
857 | 857 | $columns = implode(", $alter_action ", $columns); |
858 | - if(!empty($alter_action)){ |
|
859 | - $columns = $alter_action . ' '. $columns; |
|
858 | + if (!empty($alter_action)) { |
|
859 | + $columns = $alter_action.' '.$columns; |
|
860 | 860 | } |
861 | 861 | return $columns; |
862 | 862 | } |
@@ -878,7 +878,7 @@ discard block |
||
878 | 878 | public function setAutoIncrementStart($table, $field_name, $start_value) |
879 | 879 | { |
880 | 880 | $start_value = (int)$start_value; |
881 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
881 | + return $this->query("ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -907,18 +907,18 @@ discard block |
||
907 | 907 | $result = $this->query("SHOW INDEX FROM $tablename"); |
908 | 908 | |
909 | 909 | $indices = array(); |
910 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
911 | - $index_type='index'; |
|
912 | - if ($row['Key_name'] =='PRIMARY') { |
|
913 | - $index_type='primary'; |
|
910 | + while (($row = $this->fetchByAssoc($result)) != null) { |
|
911 | + $index_type = 'index'; |
|
912 | + if ($row['Key_name'] == 'PRIMARY') { |
|
913 | + $index_type = 'primary'; |
|
914 | 914 | } |
915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
916 | - $index_type='unique'; |
|
915 | + elseif ($row['Non_unique'] == '0') { |
|
916 | + $index_type = 'unique'; |
|
917 | 917 | } |
918 | 918 | $name = strtolower($row['Key_name']); |
919 | - $indices[$name]['name']=$name; |
|
920 | - $indices[$name]['type']=$index_type; |
|
921 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
919 | + $indices[$name]['name'] = $name; |
|
920 | + $indices[$name]['type'] = $index_type; |
|
921 | + $indices[$name]['fields'][] = strtolower($row['Column_name']); |
|
922 | 922 | } |
923 | 923 | return $indices; |
924 | 924 | } |
@@ -929,11 +929,11 @@ discard block |
||
929 | 929 | public function add_drop_constraint($table, $definition, $drop = false) |
930 | 930 | { |
931 | 931 | $type = $definition['type']; |
932 | - $fields = implode(',',$definition['fields']); |
|
932 | + $fields = implode(',', $definition['fields']); |
|
933 | 933 | $name = $definition['name']; |
934 | 934 | $sql = ''; |
935 | 935 | |
936 | - switch ($type){ |
|
936 | + switch ($type) { |
|
937 | 937 | // generic indices |
938 | 938 | case 'index': |
939 | 939 | case 'alternate_key': |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | */ |
978 | 978 | public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
979 | 979 | { |
980 | - if(stripos($sql, ' LIMIT ') === false) { |
|
980 | + if (stripos($sql, ' LIMIT ') === false) { |
|
981 | 981 | // little optimization to just fetch one row |
982 | 982 | $sql .= " LIMIT 0,1"; |
983 | 983 | } |
@@ -997,13 +997,13 @@ discard block |
||
997 | 997 | */ |
998 | 998 | public function massageFieldDef(&$fieldDef, $tablename) |
999 | 999 | { |
1000 | - parent::massageFieldDef($fieldDef,$tablename); |
|
1000 | + parent::massageFieldDef($fieldDef, $tablename); |
|
1001 | 1001 | |
1002 | - if ( isset($fieldDef['default']) && |
|
1002 | + if (isset($fieldDef['default']) && |
|
1003 | 1003 | ($fieldDef['dbType'] == 'text' |
1004 | 1004 | || $fieldDef['dbType'] == 'blob' |
1005 | 1005 | || $fieldDef['dbType'] == 'longtext' |
1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
1006 | + || $fieldDef['dbType'] == 'longblob')) |
|
1007 | 1007 | unset($fieldDef['default']); |
1008 | 1008 | if ($fieldDef['dbType'] == 'uint') |
1009 | 1009 | $fieldDef['len'] = '10'; |
@@ -1011,22 +1011,22 @@ discard block |
||
1011 | 1011 | $fieldDef['len'] = '20'; |
1012 | 1012 | if ($fieldDef['dbType'] == 'bool') |
1013 | 1013 | $fieldDef['type'] = 'tinyint'; |
1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1014 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default'])) |
|
1015 | 1015 | $fieldDef['default'] = '0'; |
1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1016 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len'])) |
|
1017 | 1017 | $fieldDef['len'] = '255'; |
1018 | 1018 | if ($fieldDef['dbType'] == 'uint') |
1019 | 1019 | $fieldDef['len'] = '10'; |
1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1020 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len'])) |
|
1021 | 1021 | $fieldDef['len'] = '11'; |
1022 | 1022 | |
1023 | - if($fieldDef['dbType'] == 'decimal') { |
|
1024 | - if(isset($fieldDef['len'])) { |
|
1025 | - if(strstr($fieldDef['len'], ",") === false) { |
|
1023 | + if ($fieldDef['dbType'] == 'decimal') { |
|
1024 | + if (isset($fieldDef['len'])) { |
|
1025 | + if (strstr($fieldDef['len'], ",") === false) { |
|
1026 | 1026 | $fieldDef['len'] .= ",0"; |
1027 | 1027 | } |
1028 | 1028 | } else { |
1029 | - $fieldDef['len'] = '10,0'; |
|
1029 | + $fieldDef['len'] = '10,0'; |
|
1030 | 1030 | } |
1031 | 1031 | } |
1032 | 1032 | } |
@@ -1046,8 +1046,8 @@ discard block |
||
1046 | 1046 | { |
1047 | 1047 | $sql = array(); |
1048 | 1048 | foreach ($indexes as $index) { |
1049 | - $name =$index['name']; |
|
1050 | - if($execute) { |
|
1049 | + $name = $index['name']; |
|
1050 | + if ($execute) { |
|
1051 | 1051 | unset(self::$index_descriptions[$tablename][$name]); |
1052 | 1052 | } |
1053 | 1053 | if ($index['type'] == 'primary') { |
@@ -1057,8 +1057,8 @@ discard block |
||
1057 | 1057 | } |
1058 | 1058 | } |
1059 | 1059 | if (!empty($sql)) { |
1060 | - $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
|
1061 | - if($execute) |
|
1060 | + $sql = "ALTER TABLE $tablename ".join(",", $sql).";"; |
|
1061 | + if ($execute) |
|
1062 | 1062 | $this->query($sql); |
1063 | 1063 | } else { |
1064 | 1064 | $sql = ''; |
@@ -1084,7 +1084,7 @@ discard block |
||
1084 | 1084 | $q = "SHOW COLLATION LIKE 'utf8%'"; |
1085 | 1085 | $r = $this->query($q); |
1086 | 1086 | $res = array(); |
1087 | - while($a = $this->fetchByAssoc($r)) { |
|
1087 | + while ($a = $this->fetchByAssoc($r)) { |
|
1088 | 1088 | $res[] = $a['Collation']; |
1089 | 1089 | } |
1090 | 1090 | return $res; |
@@ -1104,13 +1104,13 @@ discard block |
||
1104 | 1104 | public function emptyValue($type) |
1105 | 1105 | { |
1106 | 1106 | $ctype = $this->getColumnType($type); |
1107 | - if($ctype == "datetime") { |
|
1107 | + if ($ctype == "datetime") { |
|
1108 | 1108 | return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
1109 | 1109 | } |
1110 | - if($ctype == "date") { |
|
1110 | + if ($ctype == "date") { |
|
1111 | 1111 | return $this->convert($this->quoted("0000-00-00"), "date"); |
1112 | 1112 | } |
1113 | - if($ctype == "time") { |
|
1113 | + if ($ctype == "time") { |
|
1114 | 1114 | return $this->convert($this->quoted("00:00:00"), "time"); |
1115 | 1115 | } |
1116 | 1116 | return parent::emptyValue($type); |
@@ -1122,13 +1122,13 @@ discard block |
||
1122 | 1122 | */ |
1123 | 1123 | public function lastDbError() |
1124 | 1124 | { |
1125 | - if($this->database) { |
|
1126 | - if(mysql_errno($this->database)) { |
|
1125 | + if ($this->database) { |
|
1126 | + if (mysql_errno($this->database)) { |
|
1127 | 1127 | return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
1128 | 1128 | } |
1129 | 1129 | } else { |
1130 | - $err = mysql_error(); |
|
1131 | - if($err) { |
|
1130 | + $err = mysql_error(); |
|
1131 | + if ($err) { |
|
1132 | 1132 | return $err; |
1133 | 1133 | } |
1134 | 1134 | } |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | */ |
1142 | 1142 | protected function quoteTerm($term) |
1143 | 1143 | { |
1144 | - if(strpos($term, ' ') !== false) { |
|
1144 | + if (strpos($term, ' ') !== false) { |
|
1145 | 1145 | return '"'.$term.'"'; |
1146 | 1146 | } |
1147 | 1147 | return $term; |
@@ -1157,16 +1157,16 @@ discard block |
||
1157 | 1157 | public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
1158 | 1158 | { |
1159 | 1159 | $condition = array(); |
1160 | - foreach($terms as $term) { |
|
1160 | + foreach ($terms as $term) { |
|
1161 | 1161 | $condition[] = $this->quoteTerm($term); |
1162 | 1162 | } |
1163 | - foreach($must_terms as $term) { |
|
1163 | + foreach ($must_terms as $term) { |
|
1164 | 1164 | $condition[] = "+".$this->quoteTerm($term); |
1165 | 1165 | } |
1166 | - foreach($exclude_terms as $term) { |
|
1166 | + foreach ($exclude_terms as $term) { |
|
1167 | 1167 | $condition[] = "-".$this->quoteTerm($term); |
1168 | 1168 | } |
1169 | - $condition = $this->quoted(join(" ",$condition)); |
|
1169 | + $condition = $this->quoted(join(" ", $condition)); |
|
1170 | 1170 | return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
1171 | 1171 | } |
1172 | 1172 | |
@@ -1178,7 +1178,7 @@ discard block |
||
1178 | 1178 | { |
1179 | 1179 | $charsets = array(); |
1180 | 1180 | $res = $this->query("show variables like 'character\\_set\\_%'"); |
1181 | - while($row = $this->fetchByAssoc($res)) { |
|
1181 | + while ($row = $this->fetchByAssoc($res)) { |
|
1182 | 1182 | $charsets[$row['Variable_name']] = $row['Value']; |
1183 | 1183 | } |
1184 | 1184 | return $charsets; |
@@ -1188,7 +1188,7 @@ discard block |
||
1188 | 1188 | { |
1189 | 1189 | $charsets = $this->getCharsetInfo(); |
1190 | 1190 | $charset_str = array(); |
1191 | - foreach($charsets as $name => $value) { |
|
1191 | + foreach ($charsets as $name => $value) { |
|
1192 | 1192 | $charset_str[] = "$name = $value"; |
1193 | 1193 | } |
1194 | 1194 | return array( |
@@ -1210,18 +1210,18 @@ discard block |
||
1210 | 1210 | { |
1211 | 1211 | $this->log->debug("creating temp table for [$table]..."); |
1212 | 1212 | $result = $this->query("SHOW CREATE TABLE {$table}"); |
1213 | - if(empty($result)) { |
|
1213 | + if (empty($result)) { |
|
1214 | 1214 | return false; |
1215 | 1215 | } |
1216 | 1216 | $row = $this->fetchByAssoc($result); |
1217 | - if(empty($row) || empty($row['Create Table'])) { |
|
1217 | + if (empty($row) || empty($row['Create Table'])) { |
|
1218 | 1218 | return false; |
1219 | 1219 | } |
1220 | 1220 | $create = $row['Create Table']; |
1221 | 1221 | // rewrite DDL with _temp name |
1222 | 1222 | $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
1223 | 1223 | $r2 = $this->query($tempTableQuery); |
1224 | - if(empty($r2)) { |
|
1224 | + if (empty($r2)) { |
|
1225 | 1225 | return false; |
1226 | 1226 | } |
1227 | 1227 | |
@@ -1243,11 +1243,11 @@ discard block |
||
1243 | 1243 | $this->log->debug("verifying ALTER TABLE"); |
1244 | 1244 | // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
1245 | 1245 | // over to the temp tables |
1246 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1246 | + if (strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1247 | 1247 | $this->log->debug("Skipping DROP PRIMARY KEY"); |
1248 | 1248 | return ''; |
1249 | 1249 | } |
1250 | - if(!$this->makeTempTableCopy($table)) { |
|
1250 | + if (!$this->makeTempTableCopy($table)) { |
|
1251 | 1251 | return 'Could not create temp table copy'; |
1252 | 1252 | } |
1253 | 1253 | |
@@ -1255,7 +1255,7 @@ discard block |
||
1255 | 1255 | $this->log->debug('testing query: ['.$query.']'); |
1256 | 1256 | $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
1257 | 1257 | if (strpos($tempTableTestQuery, 'idx') === false) { |
1258 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1258 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1259 | 1259 | return 'Could not use a temp table to test query!'; |
1260 | 1260 | } |
1261 | 1261 | |
@@ -1268,7 +1268,7 @@ discard block |
||
1268 | 1268 | $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
1269 | 1269 | } |
1270 | 1270 | $mysqlError = $this->getL(); |
1271 | - if(!empty($mysqlError)) { |
|
1271 | + if (!empty($mysqlError)) { |
|
1272 | 1272 | return $mysqlError; |
1273 | 1273 | } |
1274 | 1274 | $this->dropTableName("{$table}__uw_temp"); |
@@ -1280,13 +1280,13 @@ discard block |
||
1280 | 1280 | { |
1281 | 1281 | $this->log->debug("verifying $querytype statement"); |
1282 | 1282 | |
1283 | - if(!$this->makeTempTableCopy($table)) { |
|
1283 | + if (!$this->makeTempTableCopy($table)) { |
|
1284 | 1284 | return 'Could not create temp table copy'; |
1285 | 1285 | } |
1286 | 1286 | // test the query on the test table |
1287 | 1287 | $this->log->debug('testing query: ['.$query.']'); |
1288 | 1288 | $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
1289 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1289 | + if (strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1290 | 1290 | return 'Could not use a temp table to test query!'; |
1291 | 1291 | } |
1292 | 1292 | |
@@ -1366,11 +1366,11 @@ discard block |
||
1366 | 1366 | public function userExists($username) |
1367 | 1367 | { |
1368 | 1368 | $db = $this->getOne("SELECT DATABASE()"); |
1369 | - if(!$this->selectDb("mysql")) { |
|
1369 | + if (!$this->selectDb("mysql")) { |
|
1370 | 1370 | return false; |
1371 | 1371 | } |
1372 | 1372 | $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
1373 | - if(!$this->selectDb($db)) { |
|
1373 | + if (!$this->selectDb($db)) { |
|
1374 | 1374 | $this->checkError("Cannot select database $db", true); |
1375 | 1375 | } |
1376 | 1376 | return !empty($user); |
@@ -1392,7 +1392,7 @@ discard block |
||
1392 | 1392 | IDENTIFIED BY '{$qpassword}';", true); |
1393 | 1393 | |
1394 | 1394 | $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
1395 | - if($host_name != 'localhost') { |
|
1395 | + if ($host_name != 'localhost') { |
|
1396 | 1396 | $this->createDbUser($database_name, "localhost", $user, $password); |
1397 | 1397 | } |
1398 | 1398 | } |
@@ -1438,10 +1438,10 @@ discard block |
||
1438 | 1438 | public function canInstall() |
1439 | 1439 | { |
1440 | 1440 | $db_version = $this->version(); |
1441 | - if(empty($db_version)) { |
|
1441 | + if (empty($db_version)) { |
|
1442 | 1442 | return array('ERR_DB_VERSION_FAILURE'); |
1443 | 1443 | } |
1444 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
1444 | + if (version_compare($db_version, '4.1.2') < 0) { |
|
1445 | 1445 | return array('ERR_DB_MYSQL_VERSION', $db_version); |
1446 | 1446 | } |
1447 | 1447 | return true; |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
3 | + die('Not A Valid Entry Point'); |
|
4 | +} |
|
3 | 5 | /********************************************************************************* |
4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -185,8 +187,9 @@ discard block |
||
185 | 187 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
186 | 188 | |
187 | 189 | |
188 | - if($keepResult) |
|
189 | - $this->lastResult = $result; |
|
190 | + if($keepResult) { |
|
191 | + $this->lastResult = $result; |
|
192 | + } |
|
190 | 193 | |
191 | 194 | $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
192 | 195 | return $result; |
@@ -236,8 +239,9 @@ discard block |
||
236 | 239 | */ |
237 | 240 | protected function freeDbResult($dbResult) |
238 | 241 | { |
239 | - if(!empty($dbResult)) |
|
240 | - mysql_free_result($dbResult); |
|
242 | + if(!empty($dbResult)) { |
|
243 | + mysql_free_result($dbResult); |
|
244 | + } |
|
241 | 245 | } |
242 | 246 | |
243 | 247 | |
@@ -260,8 +264,9 @@ discard block |
||
260 | 264 | { |
261 | 265 | $start = (int)$start; |
262 | 266 | $count = (int)$count; |
263 | - if ($start < 0) |
|
264 | - $start = 0; |
|
267 | + if ($start < 0) { |
|
268 | + $start = 0; |
|
269 | + } |
|
265 | 270 | $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
266 | 271 | |
267 | 272 | $sql = "$sql LIMIT $start,$count"; |
@@ -286,21 +291,27 @@ discard block |
||
286 | 291 | $result = $this->query('EXPLAIN ' . $sql); |
287 | 292 | $badQuery = array(); |
288 | 293 | while ($row = $this->fetchByAssoc($result)) { |
289 | - if (empty($row['table'])) |
|
290 | - continue; |
|
294 | + if (empty($row['table'])) { |
|
295 | + continue; |
|
296 | + } |
|
291 | 297 | $badQuery[$row['table']] = ''; |
292 | - if (strtoupper($row['type']) == 'ALL') |
|
293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | - if (empty($row['key'])) |
|
295 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
296 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
297 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
298 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
299 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
298 | + if (strtoupper($row['type']) == 'ALL') { |
|
299 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
300 | + } |
|
301 | + if (empty($row['key'])) { |
|
302 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
303 | + } |
|
304 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) { |
|
305 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
306 | + } |
|
307 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) { |
|
308 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
309 | + } |
|
300 | 310 | } |
301 | 311 | |
302 | - if ( empty($badQuery) ) |
|
303 | - return true; |
|
312 | + if ( empty($badQuery) ) { |
|
313 | + return true; |
|
314 | + } |
|
304 | 315 | |
305 | 316 | foreach($badQuery as $table=>$data ){ |
306 | 317 | if(!empty($data)){ |
@@ -308,8 +319,7 @@ discard block |
||
308 | 319 | if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
309 | 320 | $GLOBALS['log']->fatal($sql); |
310 | 321 | $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
311 | - } |
|
312 | - else{ |
|
322 | + } else{ |
|
313 | 323 | $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
314 | 324 | } |
315 | 325 | } |
@@ -333,14 +343,18 @@ discard block |
||
333 | 343 | $matches = array(); |
334 | 344 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
335 | 345 | $columns[$name]['type']=strtolower($matches[1][0]); |
336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
339 | - $columns[$name]['auto_increment'] = '1'; |
|
340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
341 | - $columns[$name]['required'] = 'true'; |
|
342 | - if (!empty($row['Default']) ) |
|
343 | - $columns[$name]['default'] = $row['Default']; |
|
346 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) { |
|
347 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
348 | + } |
|
349 | + if ( stristr($row['Extra'],'auto_increment') ) { |
|
350 | + $columns[$name]['auto_increment'] = '1'; |
|
351 | + } |
|
352 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) { |
|
353 | + $columns[$name]['required'] = 'true'; |
|
354 | + } |
|
355 | + if (!empty($row['Default']) ) { |
|
356 | + $columns[$name]['default'] = $row['Default']; |
|
357 | + } |
|
344 | 358 | } |
345 | 359 | return $columns; |
346 | 360 | } |
@@ -352,17 +366,20 @@ discard block |
||
352 | 366 | { |
353 | 367 | $field_array = array(); |
354 | 368 | |
355 | - if(empty($result)) |
|
356 | - return 0; |
|
369 | + if(empty($result)) { |
|
370 | + return 0; |
|
371 | + } |
|
357 | 372 | |
358 | 373 | $fields = mysql_num_fields($result); |
359 | 374 | for ($i=0; $i < $fields; $i++) { |
360 | 375 | $meta = mysql_fetch_field($result, $i); |
361 | - if (!$meta) |
|
362 | - return array(); |
|
376 | + if (!$meta) { |
|
377 | + return array(); |
|
378 | + } |
|
363 | 379 | |
364 | - if($make_lower_case == true) |
|
365 | - $meta->name = strtolower($meta->name); |
|
380 | + if($make_lower_case == true) { |
|
381 | + $meta->name = strtolower($meta->name); |
|
382 | + } |
|
366 | 383 | |
367 | 384 | $field_array[] = $meta->name; |
368 | 385 | } |
@@ -375,7 +392,9 @@ discard block |
||
375 | 392 | */ |
376 | 393 | public function fetchRow($result) |
377 | 394 | { |
378 | - if (empty($result)) return false; |
|
395 | + if (empty($result)) { |
|
396 | + return false; |
|
397 | + } |
|
379 | 398 | |
380 | 399 | return mysql_fetch_assoc($result); |
381 | 400 | } |
@@ -419,7 +438,9 @@ discard block |
||
419 | 438 | |
420 | 439 | if ($this->getDatabase()) { |
421 | 440 | $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
422 | - if(empty($result)) return false; |
|
441 | + if(empty($result)) { |
|
442 | + return false; |
|
443 | + } |
|
423 | 444 | $row = $this->fetchByAssoc($result); |
424 | 445 | return !empty($row); |
425 | 446 | } |
@@ -474,8 +495,9 @@ discard block |
||
474 | 495 | { |
475 | 496 | global $sugar_config; |
476 | 497 | |
477 | - if(is_null($configOptions)) |
|
478 | - $configOptions = $sugar_config['dbconfig']; |
|
498 | + if(is_null($configOptions)) { |
|
499 | + $configOptions = $sugar_config['dbconfig']; |
|
500 | + } |
|
479 | 501 | |
480 | 502 | if ($this->getOption('persistent')) { |
481 | 503 | $this->database = @mysql_pconnect( |
@@ -528,8 +550,9 @@ discard block |
||
528 | 550 | } |
529 | 551 | mysql_query($names, $this->database); |
530 | 552 | |
531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | - $GLOBALS['log']->info("connected to db"); |
|
553 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) { |
|
554 | + $GLOBALS['log']->info("connected to db"); |
|
555 | + } |
|
533 | 556 | $this->connectOptions = $configOptions; |
534 | 557 | |
535 | 558 | $GLOBALS['log']->info("Connect:".$this->database); |
@@ -546,8 +569,9 @@ discard block |
||
546 | 569 | { |
547 | 570 | $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
548 | 571 | |
549 | - if ( $sql == '' ) |
|
550 | - return ''; |
|
572 | + if ( $sql == '' ) { |
|
573 | + return ''; |
|
574 | + } |
|
551 | 575 | |
552 | 576 | if ( stristr($sql,'create table') ) |
553 | 577 | { |
@@ -574,8 +598,9 @@ discard block |
||
574 | 598 | $sql = str_replace("\n","",$sql); |
575 | 599 | $sql = "ALTER TABLE $tablename $sql"; |
576 | 600 | |
577 | - if ( $execute ) |
|
578 | - $this->query($sql,'Error with MySQL repair table'); |
|
601 | + if ( $execute ) { |
|
602 | + $this->query($sql,'Error with MySQL repair table'); |
|
603 | + } |
|
579 | 604 | |
580 | 605 | // and re-add the comments at the beginning |
581 | 606 | $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
@@ -672,15 +697,18 @@ discard block |
||
672 | 697 | */ |
673 | 698 | protected function isEngineEnabled($engine) |
674 | 699 | { |
675 | - if(!is_string($engine)) return false; |
|
700 | + if(!is_string($engine)) { |
|
701 | + return false; |
|
702 | + } |
|
676 | 703 | |
677 | 704 | $engine = strtoupper($engine); |
678 | 705 | |
679 | 706 | $r = $this->query("SHOW ENGINES"); |
680 | 707 | |
681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
708 | + while ( $row = $this->fetchByAssoc($r) ) { |
|
709 | + if ( strtoupper($row['Engine']) == $engine ) |
|
683 | 710 | return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
711 | + } |
|
684 | 712 | |
685 | 713 | return false; |
686 | 714 | } |
@@ -708,18 +736,22 @@ discard block |
||
708 | 736 | */ |
709 | 737 | public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
710 | 738 | { |
711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
712 | - $engine = $fieldDefs['engine']; |
|
713 | - if ( !$this->isEngineEnabled($engine) ) |
|
714 | - $engine = ''; |
|
739 | + if ( empty($engine) && isset($fieldDefs['engine'])) { |
|
740 | + $engine = $fieldDefs['engine']; |
|
741 | + } |
|
742 | + if ( !$this->isEngineEnabled($engine) ) { |
|
743 | + $engine = ''; |
|
744 | + } |
|
715 | 745 | |
716 | 746 | $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
717 | - if (empty($columns)) |
|
718 | - return false; |
|
747 | + if (empty($columns)) { |
|
748 | + return false; |
|
749 | + } |
|
719 | 750 | |
720 | 751 | $keys = $this->keysSQL($indices); |
721 | - if (!empty($keys)) |
|
722 | - $keys = ",$keys"; |
|
752 | + if (!empty($keys)) { |
|
753 | + $keys = ",$keys"; |
|
754 | + } |
|
723 | 755 | |
724 | 756 | // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
725 | 757 | $collation = $this->getOption('collation'); |
@@ -728,8 +760,9 @@ discard block |
||
728 | 760 | } |
729 | 761 | $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
730 | 762 | |
731 | - if (!empty($engine)) |
|
732 | - $sql.= " ENGINE=$engine"; |
|
763 | + if (!empty($engine)) { |
|
764 | + $sql.= " ENGINE=$engine"; |
|
765 | + } |
|
733 | 766 | |
734 | 767 | return $sql; |
735 | 768 | } |
@@ -758,13 +791,15 @@ discard block |
||
758 | 791 | |
759 | 792 | // bug 22338 - don't set a default value on text or blob fields |
760 | 793 | if ( isset($ref['default']) && |
761 | - in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
|
762 | - $ref['default'] = ''; |
|
794 | + in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) { |
|
795 | + $ref['default'] = ''; |
|
796 | + } |
|
763 | 797 | |
764 | - if ( $return_as_array ) |
|
765 | - return $ref; |
|
766 | - else |
|
767 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
798 | + if ( $return_as_array ) { |
|
799 | + return $ref; |
|
800 | + } else { |
|
801 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
802 | + } |
|
768 | 803 | } |
769 | 804 | |
770 | 805 | /** |
@@ -775,16 +810,18 @@ discard block |
||
775 | 810 | $columns = array(); |
776 | 811 | if ($this->isFieldArray($fieldDefs)){ |
777 | 812 | foreach ($fieldDefs as $def){ |
778 | - if ($action == 'drop') |
|
779 | - $columns[] = $def['name']; |
|
780 | - else |
|
781 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
813 | + if ($action == 'drop') { |
|
814 | + $columns[] = $def['name']; |
|
815 | + } else { |
|
816 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
817 | + } |
|
782 | 818 | } |
783 | 819 | } else { |
784 | - if ($action == 'drop') |
|
785 | - $columns[] = $fieldDefs['name']; |
|
786 | - else |
|
787 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
820 | + if ($action == 'drop') { |
|
821 | + $columns[] = $fieldDefs['name']; |
|
822 | + } else { |
|
823 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
824 | + } |
|
788 | 825 | } |
789 | 826 | |
790 | 827 | return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
@@ -806,23 +843,27 @@ discard block |
||
806 | 843 | { |
807 | 844 | // check if the passed value is an array of fields. |
808 | 845 | // if not, convert it into an array |
809 | - if (!$this->isFieldArray($indices)) |
|
810 | - $indices[] = $indices; |
|
846 | + if (!$this->isFieldArray($indices)) { |
|
847 | + $indices[] = $indices; |
|
848 | + } |
|
811 | 849 | |
812 | 850 | $columns = array(); |
813 | 851 | foreach ($indices as $index) { |
814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | - continue; |
|
816 | - if (isset($index['source']) && $index['source'] != 'db') |
|
817 | - continue; |
|
852 | + if(!empty($index['db']) && $index['db'] != $this->dbType) { |
|
853 | + continue; |
|
854 | + } |
|
855 | + if (isset($index['source']) && $index['source'] != 'db') { |
|
856 | + continue; |
|
857 | + } |
|
818 | 858 | |
819 | 859 | $type = $index['type']; |
820 | 860 | $name = $index['name']; |
821 | 861 | |
822 | - if (is_array($index['fields'])) |
|
823 | - $fields = implode(", ", $index['fields']); |
|
824 | - else |
|
825 | - $fields = $index['fields']; |
|
862 | + if (is_array($index['fields'])) { |
|
863 | + $fields = implode(", ", $index['fields']); |
|
864 | + } else { |
|
865 | + $fields = $index['fields']; |
|
866 | + } |
|
826 | 867 | |
827 | 868 | switch ($type) { |
828 | 869 | case 'unique': |
@@ -841,16 +882,18 @@ discard block |
||
841 | 882 | * that this can easily be fixed by referring to db dictionary |
842 | 883 | * to find the correct primary field name |
843 | 884 | */ |
844 | - if ( $alter_table ) |
|
845 | - $columns[] = " INDEX $name ($fields)"; |
|
846 | - else |
|
847 | - $columns[] = " KEY $name ($fields)"; |
|
885 | + if ( $alter_table ) { |
|
886 | + $columns[] = " INDEX $name ($fields)"; |
|
887 | + } else { |
|
888 | + $columns[] = " KEY $name ($fields)"; |
|
889 | + } |
|
848 | 890 | break; |
849 | 891 | case 'fulltext': |
850 | - if ($this->full_text_indexing_installed()) |
|
851 | - $columns[] = " FULLTEXT ($fields)"; |
|
852 | - else |
|
853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
892 | + if ($this->full_text_indexing_installed()) { |
|
893 | + $columns[] = " FULLTEXT ($fields)"; |
|
894 | + } else { |
|
895 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
896 | + } |
|
854 | 897 | break; |
855 | 898 | } |
856 | 899 | } |
@@ -892,8 +935,9 @@ discard block |
||
892 | 935 | { |
893 | 936 | $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
894 | 937 | $row = $this->fetchByAssoc($result); |
895 | - if (!empty($row['Auto_increment'])) |
|
896 | - return $row['Auto_increment']; |
|
938 | + if (!empty($row['Auto_increment'])) { |
|
939 | + return $row['Auto_increment']; |
|
940 | + } |
|
897 | 941 | |
898 | 942 | return ""; |
899 | 943 | } |
@@ -911,8 +955,7 @@ discard block |
||
911 | 955 | $index_type='index'; |
912 | 956 | if ($row['Key_name'] =='PRIMARY') { |
913 | 957 | $index_type='primary'; |
914 | - } |
|
915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
958 | + } elseif ( $row['Non_unique'] == '0' ) { |
|
916 | 959 | $index_type='unique'; |
917 | 960 | } |
918 | 961 | $name = strtolower($row['Key_name']); |
@@ -938,29 +981,33 @@ discard block |
||
938 | 981 | case 'index': |
939 | 982 | case 'alternate_key': |
940 | 983 | case 'clustered': |
941 | - if ($drop) |
|
942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | - else |
|
944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
984 | + if ($drop) { |
|
985 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
986 | + } else { |
|
987 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
988 | + } |
|
945 | 989 | break; |
946 | 990 | // constraints as indices |
947 | 991 | case 'unique': |
948 | - if ($drop) |
|
949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | - else |
|
951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
992 | + if ($drop) { |
|
993 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
994 | + } else { |
|
995 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
996 | + } |
|
952 | 997 | break; |
953 | 998 | case 'primary': |
954 | - if ($drop) |
|
955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | - else |
|
957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
999 | + if ($drop) { |
|
1000 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
1001 | + } else { |
|
1002 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
1003 | + } |
|
958 | 1004 | break; |
959 | 1005 | case 'foreign': |
960 | - if ($drop) |
|
961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | - else |
|
963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
1006 | + if ($drop) { |
|
1007 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
1008 | + } else { |
|
1009 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
1010 | + } |
|
964 | 1011 | break; |
965 | 1012 | } |
966 | 1013 | return $sql; |
@@ -1003,22 +1050,30 @@ discard block |
||
1003 | 1050 | ($fieldDef['dbType'] == 'text' |
1004 | 1051 | || $fieldDef['dbType'] == 'blob' |
1005 | 1052 | || $fieldDef['dbType'] == 'longtext' |
1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
1007 | - unset($fieldDef['default']); |
|
1008 | - if ($fieldDef['dbType'] == 'uint') |
|
1009 | - $fieldDef['len'] = '10'; |
|
1010 | - if ($fieldDef['dbType'] == 'ulong') |
|
1011 | - $fieldDef['len'] = '20'; |
|
1012 | - if ($fieldDef['dbType'] == 'bool') |
|
1013 | - $fieldDef['type'] = 'tinyint'; |
|
1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1015 | - $fieldDef['default'] = '0'; |
|
1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1017 | - $fieldDef['len'] = '255'; |
|
1018 | - if ($fieldDef['dbType'] == 'uint') |
|
1019 | - $fieldDef['len'] = '10'; |
|
1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1021 | - $fieldDef['len'] = '11'; |
|
1053 | + || $fieldDef['dbType'] == 'longblob' )) { |
|
1054 | + unset($fieldDef['default']); |
|
1055 | + } |
|
1056 | + if ($fieldDef['dbType'] == 'uint') { |
|
1057 | + $fieldDef['len'] = '10'; |
|
1058 | + } |
|
1059 | + if ($fieldDef['dbType'] == 'ulong') { |
|
1060 | + $fieldDef['len'] = '20'; |
|
1061 | + } |
|
1062 | + if ($fieldDef['dbType'] == 'bool') { |
|
1063 | + $fieldDef['type'] = 'tinyint'; |
|
1064 | + } |
|
1065 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) { |
|
1066 | + $fieldDef['default'] = '0'; |
|
1067 | + } |
|
1068 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) { |
|
1069 | + $fieldDef['len'] = '255'; |
|
1070 | + } |
|
1071 | + if ($fieldDef['dbType'] == 'uint') { |
|
1072 | + $fieldDef['len'] = '10'; |
|
1073 | + } |
|
1074 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) { |
|
1075 | + $fieldDef['len'] = '11'; |
|
1076 | + } |
|
1022 | 1077 | |
1023 | 1078 | if($fieldDef['dbType'] == 'decimal') { |
1024 | 1079 | if(isset($fieldDef['len'])) { |
@@ -1058,8 +1113,9 @@ discard block |
||
1058 | 1113 | } |
1059 | 1114 | if (!empty($sql)) { |
1060 | 1115 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
1061 | - if($execute) |
|
1062 | - $this->query($sql); |
|
1116 | + if($execute) { |
|
1117 | + $this->query($sql); |
|
1118 | + } |
|
1063 | 1119 | } else { |
1064 | 1120 | $sql = ''; |
1065 | 1121 | } |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
3 | + die('Not A Valid Entry Point'); |
|
4 | +} |
|
3 | 5 | /********************************************************************************* |
4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -135,8 +137,9 @@ discard block |
||
135 | 137 | $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
136 | 138 | $md5 = md5($sql); |
137 | 139 | |
138 | - if (empty($queryMD5[$md5])) |
|
139 | - $queryMD5[$md5] = true; |
|
140 | + if (empty($queryMD5[$md5])) { |
|
141 | + $queryMD5[$md5] = true; |
|
142 | + } |
|
140 | 143 | |
141 | 144 | $this->query_time = microtime(true) - $this->query_time; |
142 | 145 | $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
@@ -154,8 +157,9 @@ discard block |
||
154 | 157 | */ |
155 | 158 | |
156 | 159 | |
157 | - if($keepResult) |
|
158 | - $this->lastResult = $result; |
|
160 | + if($keepResult) { |
|
161 | + $this->lastResult = $result; |
|
162 | + } |
|
159 | 163 | $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
160 | 164 | |
161 | 165 | return $result; |
@@ -208,8 +212,9 @@ discard block |
||
208 | 212 | */ |
209 | 213 | protected function freeDbResult($dbResult) |
210 | 214 | { |
211 | - if(!empty($dbResult)) |
|
212 | - mysqli_free_result($dbResult); |
|
215 | + if(!empty($dbResult)) { |
|
216 | + mysqli_free_result($dbResult); |
|
217 | + } |
|
213 | 218 | } |
214 | 219 | |
215 | 220 | /** |
@@ -219,17 +224,20 @@ discard block |
||
219 | 224 | { |
220 | 225 | $field_array = array(); |
221 | 226 | |
222 | - if (!isset($result) || empty($result)) |
|
223 | - return 0; |
|
227 | + if (!isset($result) || empty($result)) { |
|
228 | + return 0; |
|
229 | + } |
|
224 | 230 | |
225 | 231 | $i = 0; |
226 | 232 | while ($i < mysqli_num_fields($result)) { |
227 | 233 | $meta = mysqli_fetch_field_direct($result, $i); |
228 | - if (!$meta) |
|
229 | - return 0; |
|
234 | + if (!$meta) { |
|
235 | + return 0; |
|
236 | + } |
|
230 | 237 | |
231 | - if($make_lower_case == true) |
|
232 | - $meta->name = strtolower($meta->name); |
|
238 | + if($make_lower_case == true) { |
|
239 | + $meta->name = strtolower($meta->name); |
|
240 | + } |
|
233 | 241 | |
234 | 242 | $field_array[] = $meta->name; |
235 | 243 | |
@@ -244,10 +252,15 @@ discard block |
||
244 | 252 | */ |
245 | 253 | public function fetchRow($result) |
246 | 254 | { |
247 | - if (empty($result)) return false; |
|
255 | + if (empty($result)) { |
|
256 | + return false; |
|
257 | + } |
|
248 | 258 | |
249 | 259 | $row = mysqli_fetch_assoc($result); |
250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
260 | + if($row == null) { |
|
261 | + $row = false; |
|
262 | + } |
|
263 | + //Make sure MySQLi driver results are consistent with other database drivers |
|
251 | 264 | return $row; |
252 | 265 | } |
253 | 266 | |
@@ -266,8 +279,9 @@ discard block |
||
266 | 279 | { |
267 | 280 | global $sugar_config; |
268 | 281 | |
269 | - if (is_null($configOptions)) |
|
270 | - $configOptions = $sugar_config['dbconfig']; |
|
282 | + if (is_null($configOptions)) { |
|
283 | + $configOptions = $sugar_config['dbconfig']; |
|
284 | + } |
|
271 | 285 | |
272 | 286 | if(!isset($this->database)) { |
273 | 287 | |
@@ -318,8 +332,9 @@ discard block |
||
318 | 332 | } |
319 | 333 | mysqli_query($this->database,$names); |
320 | 334 | |
321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
322 | - $GLOBALS['log']->info("connected to db"); |
|
335 | + if($this->checkError('Could Not Connect', $dieOnError)) { |
|
336 | + $GLOBALS['log']->info("connected to db"); |
|
337 | + } |
|
323 | 338 | |
324 | 339 | $this->connectOptions = $configOptions; |
325 | 340 | return true; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -121,18 +121,18 @@ discard block |
||
121 | 121 | */ |
122 | 122 | public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
123 | 123 | { |
124 | - if(is_array($sql)) { |
|
124 | + if (is_array($sql)) { |
|
125 | 125 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
126 | 126 | } |
127 | 127 | |
128 | 128 | static $queryMD5 = array(); |
129 | 129 | |
130 | 130 | parent::countQuery($sql); |
131 | - $GLOBALS['log']->info('Query:' . $sql); |
|
131 | + $GLOBALS['log']->info('Query:'.$sql); |
|
132 | 132 | $this->checkConnection(); |
133 | 133 | $this->query_time = microtime(true); |
134 | 134 | $this->lastsql = $sql; |
135 | - $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
135 | + $result = $suppress ? @mysqli_query($this->database, $sql) : mysqli_query($this->database, $sql); |
|
136 | 136 | $md5 = md5($sql); |
137 | 137 | |
138 | 138 | if (empty($queryMD5[$md5])) |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | */ |
155 | 155 | |
156 | 156 | |
157 | - if($keepResult) |
|
157 | + if ($keepResult) |
|
158 | 158 | $this->lastResult = $result; |
159 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
159 | + $this->checkError($msg.' Query Failed: '.$sql, $dieOnError); |
|
160 | 160 | |
161 | 161 | return $result; |
162 | 162 | } |
@@ -193,10 +193,10 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function disconnect() |
195 | 195 | { |
196 | - if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
196 | + if (isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
197 | 197 | $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
198 | 198 | } |
199 | - if(!empty($this->database)){ |
|
199 | + if (!empty($this->database)) { |
|
200 | 200 | $this->freeResult(); |
201 | 201 | mysqli_close($this->database); |
202 | 202 | $this->database = null; |
@@ -208,7 +208,7 @@ discard block |
||
208 | 208 | */ |
209 | 209 | protected function freeDbResult($dbResult) |
210 | 210 | { |
211 | - if(!empty($dbResult)) |
|
211 | + if (!empty($dbResult)) |
|
212 | 212 | mysqli_free_result($dbResult); |
213 | 213 | } |
214 | 214 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | if (!$meta) |
229 | 229 | return 0; |
230 | 230 | |
231 | - if($make_lower_case == true) |
|
231 | + if ($make_lower_case == true) |
|
232 | 232 | $meta->name = strtolower($meta->name); |
233 | 233 | |
234 | 234 | $field_array[] = $meta->name; |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | if (empty($result)) return false; |
248 | 248 | |
249 | 249 | $row = mysqli_fetch_assoc($result); |
250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
250 | + if ($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
251 | 251 | return $row; |
252 | 252 | } |
253 | 253 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | */ |
257 | 257 | public function quote($string) |
258 | 258 | { |
259 | - return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
259 | + return mysqli_real_escape_string($this->getDatabase(), $this->quoteInternal($string)); |
|
260 | 260 | } |
261 | 261 | |
262 | 262 | /** |
@@ -269,23 +269,23 @@ discard block |
||
269 | 269 | if (is_null($configOptions)) |
270 | 270 | $configOptions = $sugar_config['dbconfig']; |
271 | 271 | |
272 | - if(!isset($this->database)) { |
|
272 | + if (!isset($this->database)) { |
|
273 | 273 | |
274 | 274 | //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
275 | - $dbhost=$configOptions['db_host_name']; |
|
276 | - $dbport=isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
|
275 | + $dbhost = $configOptions['db_host_name']; |
|
276 | + $dbport = isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
|
277 | 277 | |
278 | - $pos=strpos($configOptions['db_host_name'],':'); |
|
278 | + $pos = strpos($configOptions['db_host_name'], ':'); |
|
279 | 279 | if ($pos !== false) { |
280 | - $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
281 | - $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
280 | + $dbhost = substr($configOptions['db_host_name'], 0, $pos); |
|
281 | + $dbport = substr($configOptions['db_host_name'], $pos + 1); |
|
282 | 282 | } |
283 | 283 | |
284 | - $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
285 | - if(empty($this->database)) { |
|
286 | - $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
287 | - if($dieOnError) { |
|
288 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
284 | + $this->database = @mysqli_connect($dbhost, $configOptions['db_user_name'], $configOptions['db_password'], isset($configOptions['db_name']) ? $configOptions['db_name'] : '', $dbport); |
|
285 | + if (empty($this->database)) { |
|
286 | + $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port ".$dbport.": ".mysqli_connect_error()); |
|
287 | + if ($dieOnError) { |
|
288 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
289 | 289 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
290 | 290 | } else { |
291 | 291 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -296,10 +296,10 @@ discard block |
||
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
300 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
301 | - if($dieOnError) { |
|
302 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
299 | + if (!empty($configOptions['db_name']) && !@mysqli_select_db($this->database, $configOptions['db_name'])) { |
|
300 | + $GLOBALS['log']->fatal("Unable to select database {$configOptions['db_name']}: ".mysqli_connect_error()); |
|
301 | + if ($dieOnError) { |
|
302 | + if (isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
303 | 303 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
304 | 304 | } else { |
305 | 305 | sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
@@ -312,13 +312,13 @@ discard block |
||
312 | 312 | // cn: using direct calls to prevent this from spamming the Logs |
313 | 313 | |
314 | 314 | $collation = $this->getOption('collation'); |
315 | - if(!empty($collation)) { |
|
315 | + if (!empty($collation)) { |
|
316 | 316 | $names = "SET NAMES 'utf8' COLLATE '$collation'"; |
317 | - mysqli_query($this->database,$names); |
|
317 | + mysqli_query($this->database, $names); |
|
318 | 318 | } |
319 | - mysqli_set_charset ($this->database , "utf8" ); |
|
319 | + mysqli_set_charset($this->database, "utf8"); |
|
320 | 320 | |
321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
321 | + if ($this->checkError('Could Not Connect', $dieOnError)) |
|
322 | 322 | $GLOBALS['log']->info("connected to db"); |
323 | 323 | |
324 | 324 | $this->connectOptions = $configOptions; |
@@ -331,13 +331,13 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public function lastDbError() |
333 | 333 | { |
334 | - if($this->database) { |
|
335 | - if(mysqli_errno($this->database)) { |
|
334 | + if ($this->database) { |
|
335 | + if (mysqli_errno($this->database)) { |
|
336 | 336 | return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
337 | 337 | } |
338 | 338 | } else { |
339 | - $err = mysqli_connect_error(); |
|
340 | - if($err) { |
|
339 | + $err = mysqli_connect_error(); |
|
340 | + if ($err) { |
|
341 | 341 | return $err; |
342 | 342 | } |
343 | 343 | } |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | { |
350 | 350 | $charsets = $this->getCharsetInfo(); |
351 | 351 | $charset_str = array(); |
352 | - foreach($charsets as $name => $value) { |
|
352 | + foreach ($charsets as $name => $value) { |
|
353 | 353 | $charset_str[] = "$name = $value"; |
354 | 354 | } |
355 | 355 | return array( |
@@ -98,51 +98,51 @@ discard block |
||
98 | 98 | */ |
99 | 99 | class MysqliManager extends MysqlManager |
100 | 100 | { |
101 | - /** |
|
102 | - * @see DBManager::$dbType |
|
103 | - */ |
|
104 | - public $dbType = 'mysql'; |
|
105 | - public $variant = 'mysqli'; |
|
106 | - public $priority = 10; |
|
107 | - public $label = 'LBL_MYSQLI'; |
|
108 | - |
|
109 | - /** |
|
110 | - * @see DBManager::$backendFunctions |
|
111 | - */ |
|
112 | - protected $backendFunctions = array( |
|
113 | - 'free_result' => 'mysqli_free_result', |
|
114 | - 'close' => 'mysqli_close', |
|
115 | - 'row_count' => 'mysqli_num_rows', |
|
116 | - 'affected_row_count' => 'mysqli_affected_rows', |
|
117 | - ); |
|
118 | - |
|
119 | - /** |
|
120 | - * @see MysqlManager::query() |
|
121 | - */ |
|
122 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
123 | - { |
|
124 | - if(is_array($sql)) { |
|
125 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
101 | + /** |
|
102 | + * @see DBManager::$dbType |
|
103 | + */ |
|
104 | + public $dbType = 'mysql'; |
|
105 | + public $variant = 'mysqli'; |
|
106 | + public $priority = 10; |
|
107 | + public $label = 'LBL_MYSQLI'; |
|
108 | + |
|
109 | + /** |
|
110 | + * @see DBManager::$backendFunctions |
|
111 | + */ |
|
112 | + protected $backendFunctions = array( |
|
113 | + 'free_result' => 'mysqli_free_result', |
|
114 | + 'close' => 'mysqli_close', |
|
115 | + 'row_count' => 'mysqli_num_rows', |
|
116 | + 'affected_row_count' => 'mysqli_affected_rows', |
|
117 | + ); |
|
118 | + |
|
119 | + /** |
|
120 | + * @see MysqlManager::query() |
|
121 | + */ |
|
122 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
123 | + { |
|
124 | + if(is_array($sql)) { |
|
125 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
126 | 126 | } |
127 | 127 | |
128 | - static $queryMD5 = array(); |
|
128 | + static $queryMD5 = array(); |
|
129 | 129 | |
130 | - parent::countQuery($sql); |
|
131 | - $GLOBALS['log']->info('Query:' . $sql); |
|
132 | - $this->checkConnection(); |
|
133 | - $this->query_time = microtime(true); |
|
134 | - $this->lastsql = $sql; |
|
135 | - $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
136 | - $md5 = md5($sql); |
|
130 | + parent::countQuery($sql); |
|
131 | + $GLOBALS['log']->info('Query:' . $sql); |
|
132 | + $this->checkConnection(); |
|
133 | + $this->query_time = microtime(true); |
|
134 | + $this->lastsql = $sql; |
|
135 | + $result = $suppress?@mysqli_query($this->database,$sql):mysqli_query($this->database,$sql); |
|
136 | + $md5 = md5($sql); |
|
137 | 137 | |
138 | - if (empty($queryMD5[$md5])) |
|
139 | - $queryMD5[$md5] = true; |
|
138 | + if (empty($queryMD5[$md5])) |
|
139 | + $queryMD5[$md5] = true; |
|
140 | 140 | |
141 | - $this->query_time = microtime(true) - $this->query_time; |
|
142 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
141 | + $this->query_time = microtime(true) - $this->query_time; |
|
142 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
143 | 143 | |
144 | - // This is some heavy duty debugging, leave commented out unless you need this: |
|
145 | - /* |
|
144 | + // This is some heavy duty debugging, leave commented out unless you need this: |
|
145 | + /* |
|
146 | 146 | $bt = debug_backtrace(); |
147 | 147 | for ( $i = count($bt) ; $i-- ; $i > 0 ) { |
148 | 148 | if ( strpos('MysqliManager.php',$bt[$i]['file']) === false ) { |
@@ -154,228 +154,228 @@ discard block |
||
154 | 154 | */ |
155 | 155 | |
156 | 156 | |
157 | - if($keepResult) |
|
158 | - $this->lastResult = $result; |
|
159 | - $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
160 | - |
|
161 | - return $result; |
|
162 | - } |
|
163 | - |
|
164 | - /** |
|
165 | - * Returns the number of rows affected by the last query |
|
166 | - * |
|
167 | - * @return int |
|
168 | - */ |
|
169 | - public function getAffectedRowCount($result) |
|
170 | - { |
|
171 | - return mysqli_affected_rows($this->getDatabase()); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Returns the number of rows returned by the result |
|
176 | - * |
|
177 | - * This function can't be reliably implemented on most DB, do not use it. |
|
178 | - * @abstract |
|
179 | - * @deprecated |
|
180 | - * @param resource $result |
|
181 | - * @return int |
|
182 | - */ |
|
183 | - public function getRowCount($result) |
|
184 | - { |
|
185 | - return mysqli_num_rows($result); |
|
186 | - } |
|
157 | + if($keepResult) |
|
158 | + $this->lastResult = $result; |
|
159 | + $this->checkError($msg.' Query Failed: ' . $sql, $dieOnError); |
|
187 | 160 | |
161 | + return $result; |
|
162 | + } |
|
188 | 163 | |
189 | 164 | /** |
190 | - * Disconnects from the database |
|
191 | - * |
|
192 | - * Also handles any cleanup needed |
|
193 | - */ |
|
194 | - public function disconnect() |
|
195 | - { |
|
196 | - if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
197 | - $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
|
198 | - } |
|
199 | - if(!empty($this->database)){ |
|
200 | - $this->freeResult(); |
|
201 | - mysqli_close($this->database); |
|
202 | - $this->database = null; |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * @see DBManager::freeDbResult() |
|
208 | - */ |
|
209 | - protected function freeDbResult($dbResult) |
|
210 | - { |
|
211 | - if(!empty($dbResult)) |
|
212 | - mysqli_free_result($dbResult); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * @see DBManager::getFieldsArray() |
|
217 | - */ |
|
218 | - public function getFieldsArray($result, $make_lower_case = false) |
|
219 | - { |
|
220 | - $field_array = array(); |
|
221 | - |
|
222 | - if (!isset($result) || empty($result)) |
|
223 | - return 0; |
|
224 | - |
|
225 | - $i = 0; |
|
226 | - while ($i < mysqli_num_fields($result)) { |
|
227 | - $meta = mysqli_fetch_field_direct($result, $i); |
|
228 | - if (!$meta) |
|
229 | - return 0; |
|
230 | - |
|
231 | - if($make_lower_case == true) |
|
232 | - $meta->name = strtolower($meta->name); |
|
233 | - |
|
234 | - $field_array[] = $meta->name; |
|
235 | - |
|
236 | - $i++; |
|
237 | - } |
|
165 | + * Returns the number of rows affected by the last query |
|
166 | + * |
|
167 | + * @return int |
|
168 | + */ |
|
169 | + public function getAffectedRowCount($result) |
|
170 | + { |
|
171 | + return mysqli_affected_rows($this->getDatabase()); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Returns the number of rows returned by the result |
|
176 | + * |
|
177 | + * This function can't be reliably implemented on most DB, do not use it. |
|
178 | + * @abstract |
|
179 | + * @deprecated |
|
180 | + * @param resource $result |
|
181 | + * @return int |
|
182 | + */ |
|
183 | + public function getRowCount($result) |
|
184 | + { |
|
185 | + return mysqli_num_rows($result); |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Disconnects from the database |
|
191 | + * |
|
192 | + * Also handles any cleanup needed |
|
193 | + */ |
|
194 | + public function disconnect() |
|
195 | + { |
|
196 | + if(isset($GLOBALS['log']) && !is_null($GLOBALS['log'])) { |
|
197 | + $GLOBALS['log']->debug('Calling MySQLi::disconnect()'); |
|
198 | + } |
|
199 | + if(!empty($this->database)){ |
|
200 | + $this->freeResult(); |
|
201 | + mysqli_close($this->database); |
|
202 | + $this->database = null; |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * @see DBManager::freeDbResult() |
|
208 | + */ |
|
209 | + protected function freeDbResult($dbResult) |
|
210 | + { |
|
211 | + if(!empty($dbResult)) |
|
212 | + mysqli_free_result($dbResult); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * @see DBManager::getFieldsArray() |
|
217 | + */ |
|
218 | + public function getFieldsArray($result, $make_lower_case = false) |
|
219 | + { |
|
220 | + $field_array = array(); |
|
221 | + |
|
222 | + if (!isset($result) || empty($result)) |
|
223 | + return 0; |
|
224 | + |
|
225 | + $i = 0; |
|
226 | + while ($i < mysqli_num_fields($result)) { |
|
227 | + $meta = mysqli_fetch_field_direct($result, $i); |
|
228 | + if (!$meta) |
|
229 | + return 0; |
|
230 | + |
|
231 | + if($make_lower_case == true) |
|
232 | + $meta->name = strtolower($meta->name); |
|
233 | + |
|
234 | + $field_array[] = $meta->name; |
|
235 | + |
|
236 | + $i++; |
|
237 | + } |
|
238 | + |
|
239 | + return $field_array; |
|
240 | + } |
|
241 | + |
|
242 | + /** |
|
243 | + * @see DBManager::fetchRow() |
|
244 | + */ |
|
245 | + public function fetchRow($result) |
|
246 | + { |
|
247 | + if (empty($result)) return false; |
|
248 | + |
|
249 | + $row = mysqli_fetch_assoc($result); |
|
250 | + if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
251 | + return $row; |
|
252 | + } |
|
238 | 253 | |
239 | - return $field_array; |
|
240 | - } |
|
241 | - |
|
242 | - /** |
|
243 | - * @see DBManager::fetchRow() |
|
244 | - */ |
|
245 | - public function fetchRow($result) |
|
246 | - { |
|
247 | - if (empty($result)) return false; |
|
248 | - |
|
249 | - $row = mysqli_fetch_assoc($result); |
|
250 | - if($row == null) $row = false; //Make sure MySQLi driver results are consistent with other database drivers |
|
251 | - return $row; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * @see DBManager::quote() |
|
256 | - */ |
|
257 | - public function quote($string) |
|
258 | - { |
|
259 | - return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
260 | - } |
|
261 | - |
|
262 | - /** |
|
263 | - * @see DBManager::connect() |
|
264 | - */ |
|
265 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
266 | - { |
|
267 | - global $sugar_config; |
|
268 | - |
|
269 | - if (is_null($configOptions)) |
|
270 | - $configOptions = $sugar_config['dbconfig']; |
|
271 | - |
|
272 | - if(!isset($this->database)) { |
|
273 | - |
|
274 | - //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
|
275 | - $dbhost=$configOptions['db_host_name']; |
|
254 | + /** |
|
255 | + * @see DBManager::quote() |
|
256 | + */ |
|
257 | + public function quote($string) |
|
258 | + { |
|
259 | + return mysqli_real_escape_string($this->getDatabase(),$this->quoteInternal($string)); |
|
260 | + } |
|
261 | + |
|
262 | + /** |
|
263 | + * @see DBManager::connect() |
|
264 | + */ |
|
265 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
266 | + { |
|
267 | + global $sugar_config; |
|
268 | + |
|
269 | + if (is_null($configOptions)) |
|
270 | + $configOptions = $sugar_config['dbconfig']; |
|
271 | + |
|
272 | + if(!isset($this->database)) { |
|
273 | + |
|
274 | + //mysqli connector has a separate parameter for port.. We need to separate it out from the host name |
|
275 | + $dbhost=$configOptions['db_host_name']; |
|
276 | 276 | $dbport=isset($configOptions['db_port']) ? ($configOptions['db_port'] == '' ? null : $configOptions['db_port']) : null; |
277 | 277 | |
278 | - $pos=strpos($configOptions['db_host_name'],':'); |
|
279 | - if ($pos !== false) { |
|
280 | - $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
281 | - $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
282 | - } |
|
283 | - |
|
284 | - $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
285 | - if(empty($this->database)) { |
|
286 | - $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
287 | - if($dieOnError) { |
|
288 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
289 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
290 | - } else { |
|
291 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
292 | - } |
|
293 | - } else { |
|
294 | - return false; |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
278 | + $pos=strpos($configOptions['db_host_name'],':'); |
|
279 | + if ($pos !== false) { |
|
280 | + $dbhost=substr($configOptions['db_host_name'],0,$pos); |
|
281 | + $dbport=substr($configOptions['db_host_name'],$pos+1); |
|
282 | + } |
|
283 | + |
|
284 | + $this->database = @mysqli_connect($dbhost,$configOptions['db_user_name'],$configOptions['db_password'],isset($configOptions['db_name'])?$configOptions['db_name']:'',$dbport); |
|
285 | + if(empty($this->database)) { |
|
286 | + $GLOBALS['log']->fatal("Could not connect to DB server ".$dbhost." as ".$configOptions['db_user_name'].". port " .$dbport . ": " . mysqli_connect_error()); |
|
287 | + if($dieOnError) { |
|
288 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
289 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
290 | + } else { |
|
291 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
292 | + } |
|
293 | + } else { |
|
294 | + return false; |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | - if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
300 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
301 | - if($dieOnError) { |
|
302 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
303 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
304 | - } else { |
|
305 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
306 | - } |
|
307 | - } else { |
|
308 | - return false; |
|
309 | - } |
|
310 | - } |
|
299 | + if(!empty($configOptions['db_name']) && !@mysqli_select_db($this->database,$configOptions['db_name'])) { |
|
300 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysqli_connect_error()); |
|
301 | + if($dieOnError) { |
|
302 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
303 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
304 | + } else { |
|
305 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
306 | + } |
|
307 | + } else { |
|
308 | + return false; |
|
309 | + } |
|
310 | + } |
|
311 | 311 | |
312 | - // cn: using direct calls to prevent this from spamming the Logs |
|
312 | + // cn: using direct calls to prevent this from spamming the Logs |
|
313 | 313 | |
314 | - $collation = $this->getOption('collation'); |
|
315 | - if(!empty($collation)) { |
|
316 | - $names = "SET NAMES 'utf8' COLLATE '$collation'"; |
|
317 | - mysqli_query($this->database,$names); |
|
318 | - } |
|
319 | - mysqli_set_charset ($this->database , "utf8" ); |
|
320 | - |
|
321 | - if($this->checkError('Could Not Connect', $dieOnError)) |
|
322 | - $GLOBALS['log']->info("connected to db"); |
|
323 | - |
|
324 | - $this->connectOptions = $configOptions; |
|
325 | - return true; |
|
326 | - } |
|
327 | - |
|
328 | - /** |
|
329 | - * (non-PHPdoc) |
|
330 | - * @see MysqlManager::lastDbError() |
|
331 | - */ |
|
332 | - public function lastDbError() |
|
333 | - { |
|
334 | - if($this->database) { |
|
335 | - if(mysqli_errno($this->database)) { |
|
336 | - return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
|
337 | - } |
|
338 | - } else { |
|
339 | - $err = mysqli_connect_error(); |
|
340 | - if($err) { |
|
341 | - return $err; |
|
342 | - } |
|
343 | - } |
|
314 | + $collation = $this->getOption('collation'); |
|
315 | + if(!empty($collation)) { |
|
316 | + $names = "SET NAMES 'utf8' COLLATE '$collation'"; |
|
317 | + mysqli_query($this->database,$names); |
|
318 | + } |
|
319 | + mysqli_set_charset ($this->database , "utf8" ); |
|
344 | 320 | |
345 | - return false; |
|
346 | - } |
|
321 | + if($this->checkError('Could Not Connect', $dieOnError)) |
|
322 | + $GLOBALS['log']->info("connected to db"); |
|
347 | 323 | |
348 | - public function getDbInfo() |
|
349 | - { |
|
350 | - $charsets = $this->getCharsetInfo(); |
|
351 | - $charset_str = array(); |
|
352 | - foreach($charsets as $name => $value) { |
|
353 | - $charset_str[] = "$name = $value"; |
|
354 | - } |
|
355 | - return array( |
|
356 | - "MySQLi Version" => @mysqli_get_client_info(), |
|
357 | - "MySQLi Host Info" => @mysqli_get_host_info($this->database), |
|
358 | - "MySQLi Server Info" => @mysqli_get_server_info($this->database), |
|
359 | - "MySQLi Client Encoding" => @mysqli_character_set_name($this->database), |
|
360 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
361 | - ); |
|
362 | - } |
|
363 | - |
|
364 | - /** |
|
365 | - * Select database |
|
366 | - * @param string $dbname |
|
367 | - */ |
|
368 | - protected function selectDb($dbname) |
|
369 | - { |
|
370 | - return mysqli_select_db($this->getDatabase(), $dbname); |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Check if this driver can be used |
|
375 | - * @return bool |
|
376 | - */ |
|
377 | - public function valid() |
|
378 | - { |
|
379 | - return function_exists("mysqli_connect") && empty($GLOBALS['sugar_config']['mysqli_disabled']); |
|
380 | - } |
|
324 | + $this->connectOptions = $configOptions; |
|
325 | + return true; |
|
326 | + } |
|
327 | + |
|
328 | + /** |
|
329 | + * (non-PHPdoc) |
|
330 | + * @see MysqlManager::lastDbError() |
|
331 | + */ |
|
332 | + public function lastDbError() |
|
333 | + { |
|
334 | + if($this->database) { |
|
335 | + if(mysqli_errno($this->database)) { |
|
336 | + return "MySQL error ".mysqli_errno($this->database).": ".mysqli_error($this->database); |
|
337 | + } |
|
338 | + } else { |
|
339 | + $err = mysqli_connect_error(); |
|
340 | + if($err) { |
|
341 | + return $err; |
|
342 | + } |
|
343 | + } |
|
344 | + |
|
345 | + return false; |
|
346 | + } |
|
347 | + |
|
348 | + public function getDbInfo() |
|
349 | + { |
|
350 | + $charsets = $this->getCharsetInfo(); |
|
351 | + $charset_str = array(); |
|
352 | + foreach($charsets as $name => $value) { |
|
353 | + $charset_str[] = "$name = $value"; |
|
354 | + } |
|
355 | + return array( |
|
356 | + "MySQLi Version" => @mysqli_get_client_info(), |
|
357 | + "MySQLi Host Info" => @mysqli_get_host_info($this->database), |
|
358 | + "MySQLi Server Info" => @mysqli_get_server_info($this->database), |
|
359 | + "MySQLi Client Encoding" => @mysqli_character_set_name($this->database), |
|
360 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
361 | + ); |
|
362 | + } |
|
363 | + |
|
364 | + /** |
|
365 | + * Select database |
|
366 | + * @param string $dbname |
|
367 | + */ |
|
368 | + protected function selectDb($dbname) |
|
369 | + { |
|
370 | + return mysqli_select_db($this->getDatabase(), $dbname); |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Check if this driver can be used |
|
375 | + * @return bool |
|
376 | + */ |
|
377 | + public function valid() |
|
378 | + { |
|
379 | + return function_exists("mysqli_connect") && empty($GLOBALS['sugar_config']['mysqli_disabled']); |
|
380 | + } |
|
381 | 381 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | break; |
82 | 82 | case "mssql": |
83 | - if ( function_exists('sqlsrv_connect') |
|
83 | + if ( function_exists('sqlsrv_connect') |
|
84 | 84 | && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' )) { |
85 | 85 | $my_db_manager = 'SqlsrvManager'; |
86 | 86 | } elseif (self::isFreeTDS() |
@@ -122,20 +122,20 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | - * Returns a reference to the DB object for instance $instanceName, or the default |
|
125 | + * Returns a reference to the DB object for instance $instanceName, or the default |
|
126 | 126 | * instance if one is not specified |
127 | 127 | * |
128 | 128 | * @param string $instanceName optional, name of the instance |
129 | 129 | * @return object DBManager instance |
130 | 130 | */ |
131 | - public static function getInstance($instanceName = '') |
|
131 | + public static function getInstance($instanceName = '') |
|
132 | 132 | { |
133 | 133 | global $sugar_config; |
134 | 134 | static $count = 0, $old_count = 0; |
135 | 135 | |
136 | 136 | //fall back to the default instance name |
137 | 137 | if(empty($sugar_config['db'][$instanceName])){ |
138 | - $instanceName = ''; |
|
138 | + $instanceName = ''; |
|
139 | 139 | } |
140 | 140 | if(!isset(self::$instances[$instanceName])){ |
141 | 141 | $config = $sugar_config['dbconfig']; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | /** |
249 | 249 | * Check if we have freeTDS driver installed |
250 | 250 | * Invoked when connected to mssql. checks if we have freetds version of mssql library. |
251 | - * the response is put into a global variable. |
|
251 | + * the response is put into a global variable. |
|
252 | 252 | * @return bool |
253 | 253 | */ |
254 | 254 | public static function isFreeTDS() |
@@ -256,14 +256,14 @@ discard block |
||
256 | 256 | static $is_freetds = null; |
257 | 257 | |
258 | 258 | if($is_freetds === null) { |
259 | - ob_start(); |
|
260 | - phpinfo(INFO_MODULES); |
|
261 | - $info=ob_get_contents(); |
|
262 | - ob_end_clean(); |
|
259 | + ob_start(); |
|
260 | + phpinfo(INFO_MODULES); |
|
261 | + $info=ob_get_contents(); |
|
262 | + ob_end_clean(); |
|
263 | 263 | |
264 | - $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
264 | + $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $is_freetds; |
268 | - } |
|
268 | + } |
|
269 | 269 | } |
270 | 270 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
3 | 3 | /********************************************************************************* |
4 | 4 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 5 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -69,9 +69,9 @@ discard block |
||
69 | 69 | { |
70 | 70 | global $sugar_config; |
71 | 71 | |
72 | - if(empty($config['db_manager'])) { |
|
72 | + if (empty($config['db_manager'])) { |
|
73 | 73 | // standard types |
74 | - switch($type) { |
|
74 | + switch ($type) { |
|
75 | 75 | case "mysql": |
76 | 76 | if (empty($sugar_config['mysqli_disabled']) && function_exists('mysqli_connect')) { |
77 | 77 | $my_db_manager = 'MysqliManager'; |
@@ -80,11 +80,11 @@ discard block |
||
80 | 80 | } |
81 | 81 | break; |
82 | 82 | case "mssql": |
83 | - if ( function_exists('sqlsrv_connect') |
|
84 | - && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' )) { |
|
83 | + if (function_exists('sqlsrv_connect') |
|
84 | + && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv')) { |
|
85 | 85 | $my_db_manager = 'SqlsrvManager'; |
86 | 86 | } elseif (self::isFreeTDS() |
87 | - && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'freetds' )) { |
|
87 | + && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'freetds')) { |
|
88 | 88 | $my_db_manager = 'FreeTDSManager'; |
89 | 89 | } else { |
90 | 90 | $my_db_manager = 'MssqlManager'; |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | break; |
93 | 93 | default: |
94 | 94 | $my_db_manager = self::getManagerByType($type, false); |
95 | - if(empty($my_db_manager)) { |
|
95 | + if (empty($my_db_manager)) { |
|
96 | 96 | $GLOBALS['log']->fatal("unable to load DB manager for: $type"); |
97 | 97 | sugar_die("Cannot load DB manager"); |
98 | 98 | } |
@@ -104,17 +104,17 @@ discard block |
||
104 | 104 | // sanitize the name |
105 | 105 | $my_db_manager = preg_replace("/[^A-Za-z0-9_-]/", "", $my_db_manager); |
106 | 106 | |
107 | - if(!empty($config['db_manager_class'])){ |
|
107 | + if (!empty($config['db_manager_class'])) { |
|
108 | 108 | $my_db_manager = $config['db_manager_class']; |
109 | 109 | } else { |
110 | - if(file_exists("custom/include/database/{$my_db_manager}.php")) { |
|
110 | + if (file_exists("custom/include/database/{$my_db_manager}.php")) { |
|
111 | 111 | require_once("custom/include/database/{$my_db_manager}.php"); |
112 | 112 | } else { |
113 | 113 | require_once("include/database/{$my_db_manager}.php"); |
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
117 | - if(class_exists($my_db_manager)) { |
|
117 | + if (class_exists($my_db_manager)) { |
|
118 | 118 | return new $my_db_manager(); |
119 | 119 | } else { |
120 | 120 | return null; |
@@ -134,14 +134,14 @@ discard block |
||
134 | 134 | static $count = 0, $old_count = 0; |
135 | 135 | |
136 | 136 | //fall back to the default instance name |
137 | - if(empty($sugar_config['db'][$instanceName])){ |
|
137 | + if (empty($sugar_config['db'][$instanceName])) { |
|
138 | 138 | $instanceName = ''; |
139 | 139 | } |
140 | - if(!isset(self::$instances[$instanceName])){ |
|
140 | + if (!isset(self::$instances[$instanceName])) { |
|
141 | 141 | $config = $sugar_config['dbconfig']; |
142 | 142 | $count++; |
143 | 143 | self::$instances[$instanceName] = self::getTypeInstance($config['db_type'], $config); |
144 | - if(!empty($sugar_config['dbconfigoption'])) { |
|
144 | + if (!empty($sugar_config['dbconfigoption'])) { |
|
145 | 145 | self::$instances[$instanceName]->setOptions($sugar_config['dbconfigoption']); |
146 | 146 | } |
147 | 147 | self::$instances[$instanceName]->connect($config, true); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | */ |
160 | 160 | public static function disconnectAll() |
161 | 161 | { |
162 | - foreach(self::$instances as $instance) { |
|
162 | + foreach (self::$instances as $instance) { |
|
163 | 163 | $instance->disconnect(); |
164 | 164 | } |
165 | 165 | self::$instances = array(); |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | public static function getManagerByType($type, $validate = true) |
178 | 178 | { |
179 | 179 | $drivers = self::getDbDrivers($validate); |
180 | - if(!empty($drivers[$type])) { |
|
180 | + if (!empty($drivers[$type])) { |
|
181 | 181 | return get_class($drivers[$type]); |
182 | 182 | } |
183 | 183 | return false; |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | */ |
192 | 192 | protected static function scanDriverDir($dir, &$drivers, $validate = true) |
193 | 193 | { |
194 | - if(!is_dir($dir)) return; |
|
194 | + if (!is_dir($dir)) return; |
|
195 | 195 | $scandir = opendir($dir); |
196 | - if($scandir === false) return; |
|
197 | - while(($name = readdir($scandir)) !== false) { |
|
198 | - if(substr($name, -11) != "Manager.php") continue; |
|
199 | - if($name == "DBManager.php") continue; |
|
196 | + if ($scandir === false) return; |
|
197 | + while (($name = readdir($scandir)) !== false) { |
|
198 | + if (substr($name, -11) != "Manager.php") continue; |
|
199 | + if ($name == "DBManager.php") continue; |
|
200 | 200 | require_once("$dir/$name"); |
201 | 201 | $classname = substr($name, 0, -4); |
202 | - if(!class_exists($classname)) continue; |
|
202 | + if (!class_exists($classname)) continue; |
|
203 | 203 | $driver = new $classname; |
204 | - if(!$validate || $driver->valid()) { |
|
205 | - if(empty($drivers[$driver->dbType])) { |
|
206 | - $drivers[$driver->dbType] = array(); |
|
204 | + if (!$validate || $driver->valid()) { |
|
205 | + if (empty($drivers[$driver->dbType])) { |
|
206 | + $drivers[$driver->dbType] = array(); |
|
207 | 207 | } |
208 | 208 | $drivers[$driver->dbType][] = $driver; |
209 | 209 | } |
@@ -235,9 +235,9 @@ discard block |
||
235 | 235 | self::scanDriverDir("custom/include/database", $drivers, $validate); |
236 | 236 | |
237 | 237 | $result = array(); |
238 | - foreach($drivers as $type => $tdrivers) { |
|
239 | - if(empty($tdrivers)) continue; |
|
240 | - if(count($tdrivers) > 1) { |
|
238 | + foreach ($drivers as $type => $tdrivers) { |
|
239 | + if (empty($tdrivers)) continue; |
|
240 | + if (count($tdrivers) > 1) { |
|
241 | 241 | usort($tdrivers, array(__CLASS__, "_compareDrivers")); |
242 | 242 | } |
243 | 243 | $result[$type] = $tdrivers[0]; |
@@ -255,13 +255,13 @@ discard block |
||
255 | 255 | { |
256 | 256 | static $is_freetds = null; |
257 | 257 | |
258 | - if($is_freetds === null) { |
|
258 | + if ($is_freetds === null) { |
|
259 | 259 | ob_start(); |
260 | 260 | phpinfo(INFO_MODULES); |
261 | - $info=ob_get_contents(); |
|
261 | + $info = ob_get_contents(); |
|
262 | 262 | ob_end_clean(); |
263 | 263 | |
264 | - $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
264 | + $is_freetds = (strpos($info, 'FreeTDS') !== false); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $is_freetds; |
@@ -1,5 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | -if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); |
|
2 | +if(!defined('sugarEntry') || !sugarEntry) { |
|
3 | + die('Not A Valid Entry Point'); |
|
4 | +} |
|
3 | 5 | /********************************************************************************* |
4 | 6 | * SugarCRM Community Edition is a customer relationship management program developed by |
5 | 7 | * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc. |
@@ -191,15 +193,25 @@ discard block |
||
191 | 193 | */ |
192 | 194 | protected static function scanDriverDir($dir, &$drivers, $validate = true) |
193 | 195 | { |
194 | - if(!is_dir($dir)) return; |
|
196 | + if(!is_dir($dir)) { |
|
197 | + return; |
|
198 | + } |
|
195 | 199 | $scandir = opendir($dir); |
196 | - if($scandir === false) return; |
|
200 | + if($scandir === false) { |
|
201 | + return; |
|
202 | + } |
|
197 | 203 | while(($name = readdir($scandir)) !== false) { |
198 | - if(substr($name, -11) != "Manager.php") continue; |
|
199 | - if($name == "DBManager.php") continue; |
|
204 | + if(substr($name, -11) != "Manager.php") { |
|
205 | + continue; |
|
206 | + } |
|
207 | + if($name == "DBManager.php") { |
|
208 | + continue; |
|
209 | + } |
|
200 | 210 | require_once("$dir/$name"); |
201 | 211 | $classname = substr($name, 0, -4); |
202 | - if(!class_exists($classname)) continue; |
|
212 | + if(!class_exists($classname)) { |
|
213 | + continue; |
|
214 | + } |
|
203 | 215 | $driver = new $classname; |
204 | 216 | if(!$validate || $driver->valid()) { |
205 | 217 | if(empty($drivers[$driver->dbType])) { |
@@ -236,7 +248,9 @@ discard block |
||
236 | 248 | |
237 | 249 | $result = array(); |
238 | 250 | foreach($drivers as $type => $tdrivers) { |
239 | - if(empty($tdrivers)) continue; |
|
251 | + if(empty($tdrivers)) { |
|
252 | + continue; |
|
253 | + } |
|
240 | 254 | if(count($tdrivers) > 1) { |
241 | 255 | usort($tdrivers, array(__CLASS__, "_compareDrivers")); |
242 | 256 | } |