Completed
Push — develop ( 0c0e51 )
by Adam
26:01 queued 12:43
created
include/SugarObjects/SugarRegistry.php 1 patch
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@
 block discarded – undo
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.
Please login to merge, or discard this patch.
include/database/SqlsrvManager.php 1 patch
Braces   +43 added lines, -31 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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'])
Please login to merge, or discard this patch.
include/database/MssqlManager.php 1 patch
Braces   +202 added lines, -159 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
@@ -556,8 +560,7 @@  discard block
 block discarded – undo
556 560
                                                 group by " . $grpByStr . "
557 561
                                         ) AS a
558 562
                                         WHERE row_number > $start";
559
-                        }
560
-                        else {
563
+                        } else {
561 564
                         $newSQL = "SELECT TOP $count * FROM
562 565
                                     (
563 566
                                         " . $matches[1] . " ROW_NUMBER()
@@ -566,7 +569,7 @@  discard block
 block discarded – undo
566 569
                                     ) AS a
567 570
                                     WHERE row_number > $start";
568 571
                         }
569
-                    }else{
572
+                    } else{
570 573
                         //if there is a distinct clause, form query with rownumber after distinct
571 574
                         if ($hasDistinct) {
572 575
                              $newSQL = "SELECT TOP $count * FROM
@@ -577,8 +580,7 @@  discard block
 block discarded – undo
577 580
                                             )
578 581
                                             AS a
579 582
                                             WHERE row_number > $start";
580
-                        }
581
-                        else {
583
+                        } else {
582 584
                              $newSQL = "SELECT TOP $count * FROM
583 585
                                            (
584 586
                                   " . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3]. "
@@ -617,8 +619,9 @@  discard block
 block discarded – undo
617 619
         //strip all single quotes out
618 620
         $count = substr_count ( $p_sql, $strip_beg);
619 621
         $increment = 1;
620
-        if ($strip_beg != $strip_end)
621
-            $increment = 2;
622
+        if ($strip_beg != $strip_end) {
623
+                    $increment = 2;
624
+        }
622 625
 
623 626
         $i=0;
624 627
         $offset = 0;
@@ -780,9 +783,10 @@  discard block
 block discarded – undo
780 783
     {
781 784
         $sql = strtolower($sql);
782 785
         $orig_order_match = trim($orig_order_match);
783
-        if (strpos($orig_order_match, ".") != 0)
784
-            //this has a tablename defined, pass in the order match
786
+        if (strpos($orig_order_match, ".") != 0) {
787
+                    //this has a tablename defined, pass in the order match
785 788
             return $orig_order_match;
789
+        }
786 790
 
787 791
         // If there is no ordering direction (ASC/DESC), use ASC by default
788 792
         if (strpos($orig_order_match, " ") === false) {
@@ -824,15 +828,15 @@  discard block
 block discarded – undo
824 828
             //break out of here, log this
825 829
             $GLOBALS['log']->debug("No match was found for order by, pass string back untouched as: $orig_order_match");
826 830
             return $orig_order_match;
827
-        }
828
-        else {
831
+        } else {
829 832
             //if found, then parse and return
830 833
             //grab string up to the aliased column
831 834
             $GLOBALS['log']->debug("order by found, process sql string");
832 835
 
833 836
             $psql = (trim($this->getAliasFromSQL($sql, $orderMatch )));
834
-            if (empty($psql))
835
-                $psql = trim(substr($sql, 0, $found_in_sql));
837
+            if (empty($psql)) {
838
+                            $psql = trim(substr($sql, 0, $found_in_sql));
839
+            }
836 840
 
837 841
             //grab the last comma before the alias
838 842
             preg_match('/\s+' . trim($orderMatch). '/', $psql, $match, PREG_OFFSET_CAPTURE);
@@ -845,8 +849,9 @@  discard block
 block discarded – undo
845 849
             //this is especially true for unified search from home screen
846 850
 
847 851
             $alias_beg_pos = 0;
848
-            if(strpos($psql, " as "))
849
-                $alias_beg_pos = strpos($psql, " as ");
852
+            if(strpos($psql, " as ")) {
853
+                            $alias_beg_pos = strpos($psql, " as ");
854
+            }
850 855
 
851 856
             // Bug # 44923 - This breaks the query and does not properly filter isnull
852 857
             // as there are other functions such as ltrim and rtrim.
@@ -883,8 +888,9 @@  discard block
 block discarded – undo
883 888
         //correct table name.
884 889
         if (($module_str != 'Reports' && $module_str != 'SavedReport') && isset($beanList[$module_str])  &&  isset($beanFiles[$beanList[$module_str]])){
885 890
             //if the class is not already loaded, then load files
886
-            if (!class_exists($beanList[$module_str]))
887
-                require_once($beanFiles[$beanList[$module_str]]);
891
+            if (!class_exists($beanList[$module_str])) {
892
+                            require_once($beanFiles[$beanList[$module_str]]);
893
+            }
888 894
 
889 895
             //instantiate new bean
890 896
             $module_bean = new $beanList[$module_str]();
@@ -897,8 +903,7 @@  discard block
 block discarded – undo
897 903
                 $GLOBALS['log']->debug("Could not find table name for module $module_str. ");
898 904
                 $tbl_name = $module_str;
899 905
             }
900
-        }
901
-        else {
906
+        } else {
902 907
             //since the module does NOT exist in beanlist, then we have to parse the string
903 908
             //and grab the table name from the passed in sql
904 909
             $GLOBALS['log']->debug("Could not find table name from module in request, retrieve from passed in sql");
@@ -919,8 +924,9 @@  discard block
 block discarded – undo
919 924
                 // 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.
920 925
                 $carriage_ret = strpos($tableEnd,"\n");
921 926
                 $next_space = strpos($tableEnd," " );
922
-                if ($carriage_ret < $next_space)
923
-                    $next_space = $carriage_ret;
927
+                if ($carriage_ret < $next_space) {
928
+                                    $next_space = $carriage_ret;
929
+                }
924 930
                 if ($next_space > 0) {
925 931
                     $tbl_name= substr($tableEnd,0, $next_space);
926 932
                     if(empty($tbl_name)){
@@ -943,18 +949,17 @@  discard block
 block discarded – undo
943 949
                         || $alias_tbl_name == "outer"
944 950
                         || $alias_tbl_name == "right") {
945 951
                         //not aliased, do nothing
946
-                    }
947
-                    elseif ($alias_tbl_name == "as") {
952
+                    } elseif ($alias_tbl_name == "as") {
948 953
                             //the next word is the table name
949 954
                             $aliasTableEnd = trim(substr($aliasTableEnd, $alias_space));
950 955
                             $alias_space = strpos ($aliasTableEnd, " " );
951 956
                             if ($alias_space > 0) {
952 957
                                 $alias_tbl_name= trim(substr($aliasTableEnd,0, $alias_space));
953
-                                if (!empty($alias_tbl_name))
954
-                                    $tbl_name = $alias_tbl_name;
958
+                                if (!empty($alias_tbl_name)) {
959
+                                                                    $tbl_name = $alias_tbl_name;
960
+                                }
955 961
                             }
956
-                    }
957
-                    else {
962
+                    } else {
958 963
                         //this is table alias
959 964
                         $tbl_name = $alias_tbl_name;
960 965
                     }
@@ -974,16 +979,19 @@  discard block
 block discarded – undo
974 979
 	{
975 980
 		$field_array = array();
976 981
 
977
-		if(! isset($result) || empty($result))
978
-            return 0;
982
+		if(! isset($result) || empty($result)) {
983
+		            return 0;
984
+		}
979 985
 
980 986
         $i = 0;
981 987
         while ($i < mssql_num_fields($result)) {
982 988
             $meta = mssql_fetch_field($result, $i);
983
-            if (!$meta)
984
-                return 0;
985
-            if($make_lower_case==true)
986
-                $meta->name = strtolower($meta->name);
989
+            if (!$meta) {
990
+                            return 0;
991
+            }
992
+            if($make_lower_case==true) {
993
+                            $meta->name = strtolower($meta->name);
994
+            }
987 995
 
988 996
             $field_array[] = $meta->name;
989 997
 
@@ -1006,7 +1014,9 @@  discard block
 block discarded – undo
1006 1014
 	 */
1007 1015
 	public function fetchRow($result)
1008 1016
 	{
1009
-		if (empty($result))	return false;
1017
+		if (empty($result)) {
1018
+		    return false;
1019
+		}
1010 1020
 
1011 1021
         $row = mssql_fetch_assoc($result);
1012 1022
         //MSSQL returns a space " " when a varchar column is empty ("") and not null.
@@ -1088,8 +1098,9 @@  discard block
 block discarded – undo
1088 1098
             $tables = array();
1089 1099
             $r = $this->query('SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES');
1090 1100
             if (is_resource($r)) {
1091
-                while ($a = $this->fetchByAssoc($r))
1092
-                    $tables[] = $a['TABLE_NAME'];
1101
+                while ($a = $this->fetchByAssoc($r)) {
1102
+                                    $tables[] = $a['TABLE_NAME'];
1103
+                }
1093 1104
 
1094 1105
                 return $tables;
1095 1106
             }
@@ -1246,12 +1257,14 @@  discard block
 block discarded – undo
1246 1257
      */
1247 1258
 	public function createTableSQLParams($tablename, $fieldDefs, $indices)
1248 1259
     {
1249
-        if (empty($tablename) || empty($fieldDefs))
1250
-            return '';
1260
+        if (empty($tablename) || empty($fieldDefs)) {
1261
+                    return '';
1262
+        }
1251 1263
 
1252 1264
         $columns = $this->columnSQLRep($fieldDefs, false, $tablename);
1253
-        if (empty($columns))
1254
-            return '';
1265
+        if (empty($columns)) {
1266
+                    return '';
1267
+        }
1255 1268
 
1256 1269
         return "CREATE TABLE $tablename ($columns)";
1257 1270
     }
@@ -1263,7 +1276,9 @@  discard block
 block discarded – undo
1263 1276
     public function isTextType($type)
1264 1277
     {
1265 1278
         $type = strtolower($type);
1266
-        if(!isset($this->type_map[$type])) return false;
1279
+        if(!isset($this->type_map[$type])) {
1280
+            return false;
1281
+        }
1267 1282
         return in_array($this->type_map[$type], array('ntext','text','image', 'nvarchar(max)'));
1268 1283
     }
1269 1284
 
@@ -1316,8 +1331,9 @@  discard block
 block discarded – undo
1316 1331
             $f_def  = $this->oneColumnSQLRep($def, $ignoreRequired,$tablename, true);
1317 1332
             $f_stmt = "ALTER COLUMN ".$f_def['name'].' '.$f_def['colType'].' '.
1318 1333
                         $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'];
1334
+            if (!empty( $f_def['default'])) {
1335
+                            $f_stmt .= " ALTER TABLE " . $tablename .  " ADD  ". $f_def['default'] . " FOR " . $def['name'];
1336
+            }
1321 1337
             return $f_stmt;
1322 1338
             break;
1323 1339
         default:
@@ -1355,8 +1371,7 @@  discard block
 block discarded – undo
1355 1371
 
1356 1372
           		$columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename);
1357 1373
       		}
1358
-        }
1359
-        else {
1374
+        } else {
1360 1375
             //if the column is being modified drop the default value
1361 1376
       		//constraint if it exists. alterSQLRep will add the constraint back
1362 1377
       		if (!empty($constraints[$fieldDefs['name']])) {
@@ -1391,8 +1406,9 @@  discard block
 block discarded – undo
1391 1406
      */
1392 1407
     public function setAutoIncrementStart($table, $field_name, $start_value)
1393 1408
     {
1394
-        if($start_value > 1)
1395
-            $start_value -= 1;
1409
+        if($start_value > 1) {
1410
+                    $start_value -= 1;
1411
+        }
1396 1412
 		$this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS");
1397 1413
         return true;
1398 1414
     }
@@ -1428,10 +1444,11 @@  discard block
 block discarded – undo
1428 1444
         $indices = array();
1429 1445
         while (($row=$this->fetchByAssoc($result)) != null) {
1430 1446
             $index_type = 'index';
1431
-            if ($row['is_primary_key'] == '1')
1432
-                $index_type = 'primary';
1433
-            elseif ($row['is_unique'] == 1 )
1434
-                $index_type = 'unique';
1447
+            if ($row['is_primary_key'] == '1') {
1448
+                            $index_type = 'primary';
1449
+            } elseif ($row['is_unique'] == 1 ) {
1450
+                            $index_type = 'unique';
1451
+            }
1435 1452
             $name = strtolower($row['index_name']);
1436 1453
             $indices[$name]['name']     = $name;
1437 1454
             $indices[$name]['type']     = $index_type;
@@ -1456,18 +1473,19 @@  discard block
 block discarded – undo
1456 1473
             if ( $row['TYPE_NAME'] == 'decimal' ) {
1457 1474
                 $columns[$column_name]['len']=strtolower($row['PRECISION']);
1458 1475
                 $columns[$column_name]['len'].=','.strtolower($row['SCALE']);
1476
+            } elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) {
1477
+							$columns[$column_name]['len']=strtolower($row['PRECISION']);
1478
+			} elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) {
1479
+                            $columns[$column_name]['len']=strtolower($row['LENGTH']);
1459 1480
             }
1460
-			elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) )
1461
-				$columns[$column_name]['len']=strtolower($row['PRECISION']);
1462
-            elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) )
1463
-                $columns[$column_name]['len']=strtolower($row['LENGTH']);
1464 1481
             if ( stristr($row['TYPE_NAME'],'identity') ) {
1465 1482
                 $columns[$column_name]['auto_increment'] = '1';
1466 1483
                 $columns[$column_name]['type']=str_replace(' identity','',strtolower($row['TYPE_NAME']));
1467 1484
             }
1468 1485
 
1469
-            if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI')))
1470
-                $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true';
1486
+            if (!empty($row['IS_NULLABLE']) && $row['IS_NULLABLE'] == 'NO' && (empty($row['KEY']) || !stristr($row['KEY'],'PRI'))) {
1487
+                            $columns[strtolower($row['COLUMN_NAME'])]['required'] = 'true';
1488
+            }
1471 1489
 
1472 1490
             $column_def = 1;
1473 1491
             if ( strtolower($tablename) == 'relationships' ) {
@@ -1476,12 +1494,13 @@  discard block
 block discarded – undo
1476 1494
             if ( $column_def != 0 && ($row['COLUMN_DEF'] != null)) {	// NOTE Not using !empty as an empty string may be a viable default value.
1477 1495
                 $matches = array();
1478 1496
                 $row['COLUMN_DEF'] = html_entity_decode($row['COLUMN_DEF'],ENT_QUOTES);
1479
-                if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) )
1480
-                    $columns[$column_name]['default'] = $matches[1];
1481
-                elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) )
1482
-                    $columns[$column_name]['default'] = $matches[1];
1483
-                else
1484
-                    $columns[$column_name]['default'] = $row['COLUMN_DEF'];
1497
+                if ( preg_match('/\([\(|\'](.*)[\)|\']\)/i',$row['COLUMN_DEF'],$matches) ) {
1498
+                                    $columns[$column_name]['default'] = $matches[1];
1499
+                } elseif ( preg_match('/\(N\'(.*)\'\)/i',$row['COLUMN_DEF'],$matches) ) {
1500
+                                    $columns[$column_name]['default'] = $matches[1];
1501
+                } else {
1502
+                                    $columns[$column_name]['default'] = $row['COLUMN_DEF'];
1503
+                }
1485 1504
             }
1486 1505
         }
1487 1506
         return $columns;
@@ -1513,53 +1532,61 @@  discard block
 block discarded – undo
1513 1532
         // generic indices
1514 1533
         case 'index':
1515 1534
         case 'alternate_key':
1516
-            if ($drop)
1517
-                $sql = "DROP INDEX {$name} ON {$table}";
1518
-            else
1519
-                $sql = "CREATE INDEX {$name} ON {$table} ({$fields})";
1535
+            if ($drop) {
1536
+                            $sql = "DROP INDEX {$name} ON {$table}";
1537
+            } else {
1538
+                            $sql = "CREATE INDEX {$name} ON {$table} ({$fields})";
1539
+            }
1520 1540
             break;
1521 1541
         case 'clustered':
1522
-            if ($drop)
1523
-                $sql = "DROP INDEX {$name} ON {$table}";
1524
-            else
1525
-                $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)";
1542
+            if ($drop) {
1543
+                            $sql = "DROP INDEX {$name} ON {$table}";
1544
+            } else {
1545
+                            $sql = "CREATE CLUSTERED INDEX $name ON $table ($fields)";
1546
+            }
1526 1547
             break;
1527 1548
             // constraints as indices
1528 1549
         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})";
1550
+            if ($drop) {
1551
+                            $sql = "ALTER TABLE {$table} DROP CONSTRAINT $name";
1552
+            } else {
1553
+                            $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} UNIQUE ({$fields})";
1554
+            }
1533 1555
             break;
1534 1556
         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})";
1557
+            if ($drop) {
1558
+                            $sql = "ALTER TABLE {$table} DROP CONSTRAINT {$name}";
1559
+            } else {
1560
+                            $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name} PRIMARY KEY ({$fields})";
1561
+            }
1539 1562
             break;
1540 1563
         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']})";
1564
+            if ($drop) {
1565
+                            $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})";
1566
+            } else {
1567
+                            $sql = "ALTER TABLE {$table} ADD CONSTRAINT {$name}  FOREIGN KEY ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignFields']})";
1568
+            }
1545 1569
             break;
1546 1570
         case 'fulltext':
1547 1571
             if ($this->full_text_indexing_enabled() && $drop) {
1548 1572
                 $sql = "DROP FULLTEXT INDEX ON {$table}";
1549 1573
             } elseif ($this->full_text_indexing_enabled()) {
1550 1574
                 $catalog_name=$this->ftsCatalogName();
1551
-                if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default')
1552
-                    $catalog_name = $definition['catalog_name'];
1575
+                if ( isset($definition['catalog_name']) && $definition['catalog_name'] != 'default') {
1576
+                                    $catalog_name = $definition['catalog_name'];
1577
+                }
1553 1578
 
1554 1579
                 $language = "Language 1033";
1555
-                if (isset($definition['language']) && !empty($definition['language']))
1556
-                    $language = "Language " . $definition['language'];
1580
+                if (isset($definition['language']) && !empty($definition['language'])) {
1581
+                                    $language = "Language " . $definition['language'];
1582
+                }
1557 1583
 
1558 1584
                 $key_index = $definition['key_index'];
1559 1585
 
1560 1586
                 $change_tracking = "auto";
1561
-                if (isset($definition['change_tracking']) && !empty($definition['change_tracking']))
1562
-                    $change_tracking = $definition['change_tracking'];
1587
+                if (isset($definition['change_tracking']) && !empty($definition['change_tracking'])) {
1588
+                                    $change_tracking = $definition['change_tracking'];
1589
+                }
1563 1590
 
1564 1591
                 $sql = " CREATE FULLTEXT INDEX ON $table ($fields $language) KEY INDEX $key_index ON $catalog_name WITH CHANGE_TRACKING $change_tracking" ;
1565 1592
             }
@@ -1585,12 +1612,14 @@  discard block
 block discarded – undo
1585 1612
     protected function full_text_indexing_enabled($dbname = null)
1586 1613
     {
1587 1614
         // check to see if we already have install setting in session
1588
-    	if(!isset($_SESSION['IsFulltextInstalled']))
1589
-            $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed();
1615
+    	if(!isset($_SESSION['IsFulltextInstalled'])) {
1616
+    	            $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed();
1617
+    	}
1590 1618
 
1591 1619
         // check to see if FTS Indexing service is installed
1592
-        if(empty($_SESSION['IsFulltextInstalled']))
1593
-            return false;
1620
+        if(empty($_SESSION['IsFulltextInstalled'])) {
1621
+                    return false;
1622
+        }
1594 1623
 
1595 1624
         // grab the dbname if it was not passed through
1596 1625
 		if (empty($dbname)) {
@@ -1639,8 +1668,9 @@  discard block
 block discarded – undo
1639 1668
     {
1640 1669
         static $results = array();
1641 1670
 
1642
-        if ( empty($column) && isset($results[$table]) )
1643
-            return $results[$table];
1671
+        if ( empty($column) && isset($results[$table]) ) {
1672
+                    return $results[$table];
1673
+        }
1644 1674
 
1645 1675
         $query = <<<EOQ
1646 1676
 select s.name, o.name, c.name dtrt, d.name ctrt
@@ -1653,18 +1683,20 @@  discard block
 block discarded – undo
1653 1683
             on s.schema_id = o.schema_id
1654 1684
     where o.name = '$table'
1655 1685
 EOQ;
1656
-        if ( !empty($column) )
1657
-            $query .= " and c.name = '$column'";
1686
+        if ( !empty($column) ) {
1687
+                    $query .= " and c.name = '$column'";
1688
+        }
1658 1689
         $res = $this->query($query);
1659 1690
         if ( !empty($column) ) {
1660 1691
             $row = $this->fetchByAssoc($res);
1661
-            if (!empty($row))
1662
-                return $row['ctrt'];
1663
-        }
1664
-        else {
1692
+            if (!empty($row)) {
1693
+                            return $row['ctrt'];
1694
+            }
1695
+        } else {
1665 1696
             $returnResult = array();
1666
-            while ( $row = $this->fetchByAssoc($res) )
1667
-                $returnResult[$row['dtrt']] = $row['ctrt'];
1697
+            while ( $row = $this->fetchByAssoc($res) ) {
1698
+                            $returnResult[$row['dtrt']] = $row['ctrt'];
1699
+            }
1668 1700
             $results[$table] = $returnResult;
1669 1701
             return $returnResult;
1670 1702
         }
@@ -1679,8 +1711,9 @@  discard block
 block discarded – undo
1679 1711
     {
1680 1712
         parent::massageFieldDef($fieldDef,$tablename);
1681 1713
 
1682
-        if ($fieldDef['type'] == 'int')
1683
-            $fieldDef['len'] = '4';
1714
+        if ($fieldDef['type'] == 'int') {
1715
+                    $fieldDef['len'] = '4';
1716
+        }
1684 1717
 
1685 1718
         if(empty($fieldDef['len']))
1686 1719
         {
@@ -1709,9 +1742,10 @@  discard block
 block discarded – undo
1709 1742
         {
1710 1743
             $fieldDef['default'] = '0';
1711 1744
         }
1712
-		if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) )
1713
-			$fieldDef['default'] = '';
1714
-//        if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) )
1745
+		if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) {
1746
+					$fieldDef['default'] = '';
1747
+		}
1748
+		//        if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) )
1715 1749
 //            $fieldDef['len'] = '1';
1716 1750
 //		if ($fieldDef['type'] == 'bool' && empty($fieldDef['len']) )
1717 1751
 //            $fieldDef['len'] = '1';
@@ -1755,13 +1789,15 @@  discard block
 block discarded – undo
1755 1789
 		$ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true);
1756 1790
 
1757 1791
 		// Bug 24307 - Don't add precision for float fields.
1758
-		if ( stristr($ref['colType'],'float') )
1759
-			$ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']);
1792
+		if ( stristr($ref['colType'],'float') ) {
1793
+					$ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']);
1794
+		}
1760 1795
 
1761
-        if ( $return_as_array )
1762
-            return $ref;
1763
-        else
1764
-            return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}";
1796
+        if ( $return_as_array ) {
1797
+                    return $ref;
1798
+        } else {
1799
+                    return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}";
1800
+        }
1765 1801
 	}
1766 1802
 
1767 1803
     /**
@@ -1799,8 +1835,9 @@  discard block
 block discarded – undo
1799 1835
      */
1800 1836
     protected function freeDbResult($dbResult)
1801 1837
     {
1802
-        if(!empty($dbResult))
1803
-            mssql_free_result($dbResult);
1838
+        if(!empty($dbResult)) {
1839
+                    mssql_free_result($dbResult);
1840
+        }
1804 1841
     }
1805 1842
 
1806 1843
 	/**
@@ -1810,7 +1847,9 @@  discard block
 block discarded – undo
1810 1847
     public function lastDbError()
1811 1848
     {
1812 1849
         $sqlmsg = mssql_get_last_message();
1813
-        if(empty($sqlmsg)) return false;
1850
+        if(empty($sqlmsg)) {
1851
+            return false;
1852
+        }
1814 1853
         global $app_strings;
1815 1854
         if (empty($app_strings)
1816 1855
 		    or !isset($app_strings['ERR_MSSQL_DB_CONTEXT'])
@@ -1833,11 +1872,11 @@  discard block
 block discarded – undo
1833 1872
                 //only if connection if made before languge is set.
1834 1873
                 $GLOBALS['log']->debug("Ignoring this database message: " . $sqlmsg);
1835 1874
                 return false;
1836
-            }
1837
-            else {
1875
+            } else {
1838 1876
                 $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']);
1839
-                if ( $sqlpos !== false )
1840
-                    return false;
1877
+                if ( $sqlpos !== false ) {
1878
+                                    return false;
1879
+                }
1841 1880
             }
1842 1881
         }
1843 1882
 
@@ -1882,8 +1921,9 @@  discard block
 block discarded – undo
1882 1921
     protected function _appendN($sql)
1883 1922
     {
1884 1923
         // If there are no single quotes, don't bother, will just assume there is no character data
1885
-        if (strpos($sql, "'") === false)
1886
-            return $sql;
1924
+        if (strpos($sql, "'") === false) {
1925
+                    return $sql;
1926
+        }
1887 1927
 
1888 1928
         // Flag if there are odd number of single quotes, just continue without trying to append N
1889 1929
         if ((substr_count($sql, "'") & 1)) {
@@ -1922,14 +1962,17 @@  discard block
 block discarded – undo
1922 1962
             }
1923 1963
         }
1924 1964
 
1925
-        if (!empty($replace))
1926
-            $sql = str_replace(array_keys($replace), $replace, $sql);
1965
+        if (!empty($replace)) {
1966
+                    $sql = str_replace(array_keys($replace), $replace, $sql);
1967
+        }
1927 1968
 
1928
-        if (!empty($pairs))
1929
-            $sql = str_replace(array_keys($pairs), $pairs, $sql);
1969
+        if (!empty($pairs)) {
1970
+                    $sql = str_replace(array_keys($pairs), $pairs, $sql);
1971
+        }
1930 1972
 
1931
-        if(strpos($sql, "<@#@#@PAIR@#@#@>"))
1932
-            $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql);
1973
+        if(strpos($sql, "<@#@#@PAIR@#@#@>")) {
1974
+                    $sql = str_replace(array('<@#@#@PAIR@#@#@>'), array("''"), $sql);
1975
+        }
1933 1976
 
1934 1977
         return $sql;
1935 1978
     }
Please login to merge, or discard this patch.
include/database/MysqlManager.php 1 patch
Braces   +184 added lines, -128 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.
include/database/DBManagerFactory.php 1 patch
Braces   +21 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
             }
Please login to merge, or discard this patch.
include/utils/sugar_file_utils.php 1 patch
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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.
@@ -56,12 +58,14 @@  discard block
 block discarded – undo
56 58
 function sugar_mkdir($pathname, $mode=null, $recursive=false, $context='') {
57 59
 	$mode = get_mode('dir_mode', $mode);
58 60
 
59
-	if ( sugar_is_dir($pathname,$mode) )
60
-	    return true;
61
+	if ( sugar_is_dir($pathname,$mode) ) {
62
+		    return true;
63
+	}
61 64
 
62 65
 	$result = false;
63
-	if(empty($mode))
64
-		$mode = 0777;
66
+	if(empty($mode)) {
67
+			$mode = 0777;
68
+	}
65 69
 	if(empty($context)) {
66 70
 		$result = @mkdir($pathname, $mode, $recursive);
67 71
 	} else {
@@ -82,8 +86,7 @@  discard block
 block discarded – undo
82 86
    				return false;
83 87
    			}
84 88
 		}
85
-	}
86
-	else {
89
+	} else {
87 90
 		$errorMessage = "Cannot create directory $pathname cannot be touched";
88 91
 		if(is_null($GLOBALS['log'])) {
89 92
 			throw new Exception("Error occurred but the system doesn't have logger. Error message: \"$errorMessage\"");
@@ -285,15 +288,16 @@  discard block
 block discarded – undo
285 288
  * @return boolean   Returns TRUE on success or FALSE on failure.
286 289
  */
287 290
 function sugar_chmod($filename, $mode=null) {
288
-    if ( !is_int($mode) )
289
-        $mode = (int) $mode;
291
+    if ( !is_int($mode) ) {
292
+            $mode = (int) $mode;
293
+    }
290 294
 	if(!is_windows()){
291 295
 		if(!isset($mode)){
292 296
 			$mode = get_mode('file_mode', $mode);
293 297
 		}
294 298
         if(isset($mode) && $mode > 0){
295 299
 		   return @chmod($filename, $mode);
296
-		}else{
300
+		} else{
297 301
 	    	return false;
298 302
 		}
299 303
 	}
@@ -313,11 +317,11 @@  discard block
 block discarded – undo
313 317
 	if(!is_windows()){
314 318
 		if(strlen($user)){
315 319
 			return chown($filename, $user);
316
-		}else{
320
+		} else{
317 321
 			if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){
318 322
 				$user = $GLOBALS['sugar_config']['default_permissions']['user'];
319 323
 				return chown($filename, $user);
320
-			}else{
324
+			} else{
321 325
 				return false;
322 326
 			}
323 327
 		}
@@ -338,11 +342,11 @@  discard block
 block discarded – undo
338 342
 	if(!is_windows()){
339 343
 		if(!empty($group)){
340 344
 			return chgrp($filename, $group);
341
-		}else{
345
+		} else{
342 346
 			if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){
343 347
 				$group = $GLOBALS['sugar_config']['default_permissions']['group'];
344 348
 				return chgrp($filename, $group);
345
-			}else{
349
+			} else{
346 350
 				return false;
347 351
 			}
348 352
 		}
@@ -361,8 +365,9 @@  discard block
 block discarded – undo
361 365
  * @return int - the mode either found in the config file or passed in via the input parameter
362 366
  */
363 367
 function get_mode($key = 'dir_mode', $mode=null) {
364
-	if ( !is_int($mode) )
365
-        $mode = (int) $mode;
368
+	if ( !is_int($mode) ) {
369
+	        $mode = (int) $mode;
370
+	}
366 371
     if(!class_exists('SugarConfig', true)) {
367 372
 		require 'include/SugarObjects/SugarConfig.php';
368 373
 	}
@@ -374,12 +379,16 @@  discard block
 block discarded – undo
374 379
 }
375 380
 
376 381
 function sugar_is_dir($path, $mode='r'){
377
-		if(defined('TEMPLATE_URL'))return is_dir($path, $mode);
382
+		if(defined('TEMPLATE_URL')) {
383
+		    return is_dir($path, $mode);
384
+		}
378 385
 		return is_dir($path);
379 386
 }
380 387
 
381 388
 function sugar_is_file($path, $mode='r'){
382
-		if(defined('TEMPLATE_URL'))return is_file($path, $mode);
389
+		if(defined('TEMPLATE_URL')) {
390
+		    return is_file($path, $mode);
391
+		}
383 392
 		return is_file($path);
384 393
 }
385 394
 
Please login to merge, or discard this patch.
include/MVC/Controller/ControllerFactory.php 1 patch
Braces   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -57,23 +57,23 @@
 block discarded – undo
57 57
 			require_once('custom/modules/'.$module.'/controller.php');
58 58
 			if(class_exists($customClass)){
59 59
 				$controller = new $customClass();
60
-			}else if(class_exists($class)){
60
+			} else if(class_exists($class)){
61 61
 				$controller = new $class();
62 62
 			}
63
-		}elseif(file_exists('modules/'.$module.'/controller.php')){
63
+		} elseif(file_exists('modules/'.$module.'/controller.php')){
64 64
 			require_once('modules/'.$module.'/controller.php');
65 65
 			if(class_exists($customClass)){
66 66
 				$controller = new $customClass();
67
-			}else if(class_exists($class)){
67
+			} else if(class_exists($class)){
68 68
 				$controller = new $class();
69 69
 			}
70
-		}else{
70
+		} else{
71 71
 			if(file_exists('custom/include/MVC/Controller/SugarController.php')){
72 72
 				require_once('custom/include/MVC/Controller/SugarController.php');
73 73
 			}
74 74
 			if(class_exists('CustomSugarController')){
75 75
 				$controller = new CustomSugarController();
76
-			}else{
76
+			} else{
77 77
 			$controller = new SugarController();
78 78
 			}
79 79
 		}
Please login to merge, or discard this patch.
include/javascript/getYUIComboFile.php 1 patch
Braces   +15 added lines, -7 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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.
@@ -38,7 +40,9 @@  discard block
 block discarded – undo
38 40
  * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39 41
  ********************************************************************************/
40 42
 
41
-if (empty($_REQUEST)) die();
43
+if (empty($_REQUEST)) {
44
+    die();
45
+}
42 46
 
43 47
 $yui_path = array(
44 48
     "2.9.0" => "include/javascript/yui",
@@ -58,20 +62,24 @@  discard block
 block discarded – undo
58 62
 foreach ($_REQUEST as $param => $val)
59 63
 {
60 64
 	//No backtracking in the path
61
-	if (strpos($param, "..") !== false)
62
-        continue;
65
+	if (strpos($param, "..") !== false) {
66
+	        continue;
67
+	}
63 68
 
64 69
 	$version = explode("/", $param);
65 70
 	$version = $version[0];
66
-    if (empty($yui_path[$version])) continue;
71
+    if (empty($yui_path[$version])) {
72
+        continue;
73
+    }
67 74
 
68 75
     $path = $yui_path[$version] . substr($param, strlen($version));
69 76
 
70 77
 	$extension = substr($path, strrpos($path, "_") + 1);
71 78
 
72 79
 	//Only allowed file extensions
73
-	if (empty($types[$extension]))
74
-	   continue;
80
+	if (empty($types[$extension])) {
81
+		   continue;
82
+	}
75 83
 
76 84
 	if (empty($contentType))
77 85
     {
Please login to merge, or discard this patch.
include/Dashlets/DashletGenericChart.php 1 patch
Braces   +59 added lines, -36 removed lines patch added patch discarded remove patch
@@ -1,5 +1,7 @@  discard block
 block discarded – undo
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.
@@ -121,10 +123,12 @@  discard block
 block discarded – undo
121 123
         // load language files
122 124
         $this->loadLanguage($classname, 'modules/Charts/Dashlets/');
123 125
 
124
-        if ( empty($options['title']) )
125
-            $this->title = $this->dashletStrings['LBL_TITLE'];
126
-        if ( isset($options['autoRefresh']) )
127
-            $this->autoRefresh = $options['autoRefresh'];
126
+        if ( empty($options['title']) ) {
127
+                    $this->title = $this->dashletStrings['LBL_TITLE'];
128
+        }
129
+        if ( isset($options['autoRefresh']) ) {
130
+                    $this->autoRefresh = $options['autoRefresh'];
131
+        }
128 132
 
129 133
         $this->layoutManager = new LayoutManager();
130 134
         $this->layoutManager->setAttribute('context', 'Report');
@@ -140,8 +144,8 @@  discard block
 block discarded – undo
140 144
     public function setRefreshIcon()
141 145
     {
142 146
     	$additionalTitle = '';
143
-        if($this->isRefreshable)
144
-
147
+        if($this->isRefreshable) {
148
+        
145 149
             $additionalTitle .= '<a href="#" onclick="SUGAR.mySugar.retrieveDashlet(\''
146 150
                 . $this->id
147 151
                 . '\',\'predefined_chart\'); return false;"><!--not_in_theme!-->'
@@ -154,6 +158,7 @@  discard block
 block discarded – undo
154 158
                     translate('LBL_DASHLET_REFRESH', 'Home')
155 159
                 )
156 160
                 . '</a>';
161
+        }
157 162
         return $additionalTitle;
158 163
     }
159 164
 
@@ -200,25 +205,32 @@  discard block
 block discarded – undo
200 205
 
201 206
         $options = array();
202 207
 
203
-        foreach($req as $name => $value)
204
-            if(!is_array($value)) $req[$name] = trim($value);
208
+        foreach($req as $name => $value) {
209
+                    if(!is_array($value)) $req[$name] = trim($value);
210
+        }
205 211
 
206 212
         foreach($this->_searchFields as $name => $params) {
207 213
             $widgetDef = $params;
208
-            if ( isset($this->getSeedBean()->field_defs[$name]) )
209
-                $widgetDef = $this->getSeedBean()->field_defs[$name];
210
-            if ( $widgetDef['type'] == 'date')           // special case date types
214
+            if ( isset($this->getSeedBean()->field_defs[$name]) ) {
215
+                            $widgetDef = $this->getSeedBean()->field_defs[$name];
216
+            }
217
+            if ( $widgetDef['type'] == 'date') {
218
+                // special case date types
211 219
                 $options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
212
-            elseif ( $widgetDef['type'] == 'time')       // special case time types
220
+            } elseif ( $widgetDef['type'] == 'time') {
221
+                // special case time types
213 222
                 $options[$widgetDef['name']] = $timedate->swap_formats($req['type_'.$widgetDef['name']], $timedate->get_time_format(), $timedate->dbTimeFormat);
214
-            elseif ( $widgetDef['type'] == 'datepicker') // special case datepicker types
223
+            } elseif ( $widgetDef['type'] == 'datepicker') {
224
+                // special case datepicker types
215 225
                 $options[$widgetDef['name']] = $timedate->swap_formats($req[$widgetDef['name']], $timedate->get_date_format(), $timedate->dbDayFormat);
216
-            elseif (!empty($req[$widgetDef['name']]))
217
-                $options[$widgetDef['name']] = $req[$widgetDef['name']];
226
+            } elseif (!empty($req[$widgetDef['name']])) {
227
+                            $options[$widgetDef['name']] = $req[$widgetDef['name']];
228
+            }
218 229
         }
219 230
 
220
-        if (!empty($req['dashletTitle']))
221
-            $options['title'] = $req['dashletTitle'];
231
+        if (!empty($req['dashletTitle'])) {
232
+                    $options['title'] = $req['dashletTitle'];
233
+        }
222 234
 
223 235
         $options['autoRefresh'] = empty($req['autoRefresh']) ? '0' : $req['autoRefresh'];
224 236
 
@@ -241,19 +253,24 @@  discard block
 block discarded – undo
241 253
                     $currentSearchFields[$name] = array();
242 254
 
243 255
                     $widgetDef = $params;
244
-                    if ( isset($this->getSeedBean()->field_defs[$name]) )
245
-                        $widgetDef = $this->getSeedBean()->field_defs[$name];
256
+                    if ( isset($this->getSeedBean()->field_defs[$name]) ) {
257
+                                            $widgetDef = $this->getSeedBean()->field_defs[$name];
258
+                    }
246 259
 
247
-                    if($widgetDef['type'] == 'enum' || $widgetDef['type'] == 'singleenum') $widgetDef['remove_blank'] = true; // remove the blank option for the dropdown
260
+                    if($widgetDef['type'] == 'enum' || $widgetDef['type'] == 'singleenum') {
261
+                        $widgetDef['remove_blank'] = true;
262
+                    }
263
+                    // remove the blank option for the dropdown
248 264
 
249
-                    if ( empty($widgetDef['input_name0']) )
250
-                        $widgetDef['input_name0'] = empty($this->$name) ? '' : $this->$name;
265
+                    if ( empty($widgetDef['input_name0']) ) {
266
+                                            $widgetDef['input_name0'] = empty($this->$name) ? '' : $this->$name;
267
+                    }
251 268
                     $currentSearchFields[$name]['label'] = translate($widgetDef['vname'], $this->getSeedBean()->module_dir);
252
-                    if ( $currentSearchFields[$name]['label'] == $widgetDef['vname'] )
253
-                        $currentSearchFields[$name]['label'] = translate($widgetDef['vname'], 'Charts');
269
+                    if ( $currentSearchFields[$name]['label'] == $widgetDef['vname'] ) {
270
+                                            $currentSearchFields[$name]['label'] = translate($widgetDef['vname'], 'Charts');
271
+                    }
254 272
                     $currentSearchFields[$name]['input'] = $this->layoutManager->widgetDisplayInput($widgetDef, true, (empty($this->$name) ? '' : $this->$name));
255
-                }
256
-                else { // ability to create spacers in input fields
273
+                } else { // ability to create spacers in input fields
257 274
                     $currentSearchFields['blank' + $count]['label'] = '';
258 275
                     $currentSearchFields['blank' + $count]['input'] = '';
259 276
                     $count++;
@@ -289,8 +306,9 @@  discard block
 block discarded – undo
289 306
      */
290 307
     protected function getSeedBean()
291 308
     {
292
-        if ( !($this->_seedBean instanceof SugarBean) )
293
-            $this->_seedBean = SugarModule::get($this->_seedName)->loadBean();
309
+        if ( !($this->_seedBean instanceof SugarBean) ) {
310
+                    $this->_seedBean = SugarModule::get($this->_seedName)->loadBean();
311
+        }
294 312
 
295 313
         return $this->_seedBean;
296 314
     }
@@ -412,9 +430,14 @@  discard block
 block discarded – undo
412 430
         }
413 431
 
414 432
         //if(isset($sortby1[0]) && $sortby1[0]=='') unset($sortby1[0]);//the beginning of lead_source_dom is blank.
415
-        if(isset($sortby1[0]) && $sortby1[0]==array()) unset($sortby1[0]);//the beginning of month after search is blank.
433
+        if(isset($sortby1[0]) && $sortby1[0]==array()) {
434
+            unset($sortby1[0]);
435
+        }
436
+        //the beginning of month after search is blank.
416 437
 
417
-        if($ifsort2==false) $sortby2=array(0);
438
+        if($ifsort2==false) {
439
+            $sortby2=array(0);
440
+        }
418 441
 
419 442
         if($keycolname2!=null) {
420 443
             $sortby2 = array();
@@ -438,7 +461,9 @@  discard block
 block discarded – undo
438 461
 
439 462
         foreach($sortby1 as $sort1) {
440 463
             foreach($sortby2 as $sort2) {
441
-                if($ifsort2) $a=0;
464
+                if($ifsort2) {
465
+                    $a=0;
466
+                }
442 467
                 foreach($data_set as $key => $value){
443 468
                     if($value[$keycolname1] == $sort1 && (!$ifsort2 || $value[$keycolname2]== $sort2)) {
444 469
                         if($translate1) {
@@ -461,15 +486,13 @@  discard block
 block discarded – undo
461 486
                     if($translate1) {
462 487
                         $val[$keycolname1] = $app_list_strings[$keycolname1.'_dom'][$sort1];
463 488
                         $val[$keycolname1.'_dom_option'] = $sort1;
464
-                    }
465
-                    else {
489
+                    } else {
466 490
                         $val[$keycolname1] = $sort1;
467 491
                     }
468 492
                     if($translate2) {
469 493
                         $val[$keycolname2] = $app_list_strings[$keycolname2.'_dom'][$sort2];
470 494
                         $val[$keycolname2.'_dom_option'] = $sort2;
471
-                    }
472
-                    elseif($keycolname2!=null) {
495
+                    } elseif($keycolname2!=null) {
473 496
                         $val[$keycolname2] = $sort2;
474 497
                     }
475 498
                     array_push($data, $val);
Please login to merge, or discard this patch.