@@ -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. |
@@ -46,8 +48,9 @@ discard block |
||
46 | 48 | * theme basis. |
47 | 49 | ********************************************************************************/ |
48 | 50 | |
49 | -if(!defined('JSMIN_AS_LIB')) |
|
51 | +if(!defined('JSMIN_AS_LIB')) { |
|
50 | 52 | define('JSMIN_AS_LIB', true); |
53 | +} |
|
51 | 54 | |
52 | 55 | require_once("include/SugarTheme/cssmin.php"); |
53 | 56 | require_once("jssource/jsmin.php"); |
@@ -299,10 +302,11 @@ discard block |
||
299 | 302 | if ( property_exists(__CLASS__,$key) ) { |
300 | 303 | // For all arrays ( except colors and fonts ) you can just specify the items |
301 | 304 | // to change instead of all of the values |
302 | - if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) |
|
303 | - $this->$key = array_merge($this->$key,$value); |
|
304 | - else |
|
305 | - $this->$key = $value; |
|
305 | + if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) { |
|
306 | + $this->$key = array_merge($this->$key,$value); |
|
307 | + } else { |
|
308 | + $this->$key = $value; |
|
309 | + } |
|
306 | 310 | } |
307 | 311 | } |
308 | 312 | } |
@@ -310,23 +314,28 @@ discard block |
||
310 | 314 | if ( property_exists(__CLASS__,$key) ) { |
311 | 315 | // For all arrays ( except colors and fonts ) you can just specify the items |
312 | 316 | // to change instead of all of the values |
313 | - if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) |
|
314 | - $this->$key = array_merge($this->$key,$value); |
|
315 | - else |
|
316 | - $this->$key = $value; |
|
317 | + if ( is_array($this->$key) && !in_array($key,array('colors','fonts')) ) { |
|
318 | + $this->$key = array_merge($this->$key,$value); |
|
319 | + } else { |
|
320 | + $this->$key = $value; |
|
321 | + } |
|
317 | 322 | } |
318 | 323 | } |
319 | 324 | if ( !inDeveloperMode() ) { |
320 | 325 | if ( sugar_is_file($cachedfile = sugar_cached($this->getFilePath().'/pathCache.php'))) { |
321 | 326 | $caches = unserialize(file_get_contents($cachedfile)); |
322 | - if ( isset($caches['jsCache']) ) |
|
323 | - $this->_jsCache = $caches['jsCache']; |
|
324 | - if ( isset($caches['cssCache']) ) |
|
325 | - $this->_cssCache = $caches['cssCache']; |
|
326 | - if ( isset($caches['imageCache']) ) |
|
327 | - $this->_imageCache = $caches['imageCache']; |
|
328 | - if ( isset($caches['templateCache']) ) |
|
329 | - $this->_templateCache = $caches['templateCache']; |
|
327 | + if ( isset($caches['jsCache']) ) { |
|
328 | + $this->_jsCache = $caches['jsCache']; |
|
329 | + } |
|
330 | + if ( isset($caches['cssCache']) ) { |
|
331 | + $this->_cssCache = $caches['cssCache']; |
|
332 | + } |
|
333 | + if ( isset($caches['imageCache']) ) { |
|
334 | + $this->_imageCache = $caches['imageCache']; |
|
335 | + } |
|
336 | + if ( isset($caches['templateCache']) ) { |
|
337 | + $this->_templateCache = $caches['templateCache']; |
|
338 | + } |
|
330 | 339 | } |
331 | 340 | $cachedfile = sugar_cached($this->getFilePath().'/spriteCache.php'); |
332 | 341 | if(!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) { |
@@ -378,13 +387,14 @@ discard block |
||
378 | 387 | // clear out the cache on destroy if we are asked to |
379 | 388 | if ( $this->_clearCacheOnDestroy ) { |
380 | 389 | |
381 | - if (is_file("$cachedir/pathCache.php")) |
|
382 | - unlink("$cachedir/pathCache.php"); |
|
383 | - if (is_file("$cachedir/spriteCache.php")) |
|
384 | - unlink("$cachedir/spriteCache.php"); |
|
390 | + if (is_file("$cachedir/pathCache.php")) { |
|
391 | + unlink("$cachedir/pathCache.php"); |
|
392 | + } |
|
393 | + if (is_file("$cachedir/spriteCache.php")) { |
|
394 | + unlink("$cachedir/spriteCache.php"); |
|
395 | + } |
|
385 | 396 | |
386 | - } |
|
387 | - elseif ( !inDeveloperMode() ) { |
|
397 | + } elseif ( !inDeveloperMode() ) { |
|
388 | 398 | // only update the caches if they have been changed in this request |
389 | 399 | if ( count($this->_jsCache) != $this->_initialCacheSize['jsCache'] |
390 | 400 | || count($this->_cssCache) != $this->_initialCacheSize['cssCache'] |
@@ -433,8 +443,9 @@ discard block |
||
433 | 443 | $key |
434 | 444 | ) |
435 | 445 | { |
436 | - if ( isset($this->$key) ) |
|
437 | - return $this->$key; |
|
446 | + if ( isset($this->$key) ) { |
|
447 | + return $this->$key; |
|
448 | + } |
|
438 | 449 | } |
439 | 450 | |
440 | 451 | public function __isset($key){ |
@@ -607,38 +618,44 @@ discard block |
||
607 | 618 | if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
608 | 619 | |
609 | 620 | // system wide sprites |
610 | - if(file_exists("cache/sprites/default/sprites.css")) |
|
611 | - $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/default/sprites.css').'" />'; |
|
621 | + if(file_exists("cache/sprites/default/sprites.css")) { |
|
622 | + $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/default/sprites.css').'" />'; |
|
623 | + } |
|
612 | 624 | |
613 | 625 | // theme specific sprites |
614 | - if(file_exists("cache/sprites/{$this->dirName}/sprites.css")) |
|
615 | - $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$this->dirName.'/sprites.css').'" />'; |
|
626 | + if(file_exists("cache/sprites/{$this->dirName}/sprites.css")) { |
|
627 | + $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$this->dirName.'/sprites.css').'" />'; |
|
628 | + } |
|
616 | 629 | |
617 | 630 | // parent sprites |
618 | 631 | if($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
619 | - if(file_exists("cache/sprites/{$parent->dirName}/sprites.css")) |
|
620 | - $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$parent->dirName.'/sprites.css').'" />'; |
|
632 | + if(file_exists("cache/sprites/{$parent->dirName}/sprites.css")) { |
|
633 | + $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/'.$parent->dirName.'/sprites.css').'" />'; |
|
634 | + } |
|
621 | 635 | } |
622 | 636 | |
623 | 637 | // repeatable sprites |
624 | - if(file_exists("cache/sprites/Repeatable/sprites.css")) |
|
625 | - $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/Repeatable/sprites.css').'" />'; |
|
638 | + if(file_exists("cache/sprites/Repeatable/sprites.css")) { |
|
639 | + $html .= '<link rel="stylesheet" type="text/css" href="'.getJSPath('cache/sprites/Repeatable/sprites.css').'" />'; |
|
640 | + } |
|
626 | 641 | } |
627 | 642 | |
628 | 643 | // for BC during upgrade |
629 | 644 | if ( !empty($this->colors) ) { |
630 | - if ( isset($_SESSION['authenticated_user_theme_color']) && in_array($_SESSION['authenticated_user_theme_color'], $this->colors)) |
|
631 | - $color = $_SESSION['authenticated_user_theme_color']; |
|
632 | - else |
|
633 | - $color = $this->colors[0]; |
|
645 | + if ( isset($_SESSION['authenticated_user_theme_color']) && in_array($_SESSION['authenticated_user_theme_color'], $this->colors)) { |
|
646 | + $color = $_SESSION['authenticated_user_theme_color']; |
|
647 | + } else { |
|
648 | + $color = $this->colors[0]; |
|
649 | + } |
|
634 | 650 | $html .= '<link rel="stylesheet" type="text/css" href="'.$this->getCSSURL('colors.'.$color.'.css').'" id="current_color_style" />'; |
635 | 651 | } |
636 | 652 | |
637 | 653 | if ( !empty($this->fonts) ) { |
638 | - if ( isset($_SESSION['authenticated_user_theme_font']) && in_array($_SESSION['authenticated_user_theme_font'], $this->fonts)) |
|
639 | - $font = $_SESSION['authenticated_user_theme_font']; |
|
640 | - else |
|
641 | - $font = $this->fonts[0]; |
|
654 | + if ( isset($_SESSION['authenticated_user_theme_font']) && in_array($_SESSION['authenticated_user_theme_font'], $this->fonts)) { |
|
655 | + $font = $_SESSION['authenticated_user_theme_font']; |
|
656 | + } else { |
|
657 | + $font = $this->fonts[0]; |
|
658 | + } |
|
642 | 659 | $html .= '<link rel="stylesheet" type="text/css" href="'.$this->getCSSURL('fonts.'.$font.'.css').'" id="current_font_style" />'; |
643 | 660 | } |
644 | 661 | |
@@ -669,23 +686,24 @@ discard block |
||
669 | 686 | $templateName |
670 | 687 | ) |
671 | 688 | { |
672 | - if ( isset($this->_templateCache[$templateName]) ) |
|
673 | - return $this->_templateCache[$templateName]; |
|
689 | + if ( isset($this->_templateCache[$templateName]) ) { |
|
690 | + return $this->_templateCache[$templateName]; |
|
691 | + } |
|
674 | 692 | |
675 | 693 | $templatePath = ''; |
676 | - if (sugar_is_file('custom/'.$this->getTemplatePath().'/'.$templateName)) |
|
677 | - $templatePath = 'custom/'.$this->getTemplatePath().'/'.$templateName; |
|
678 | - elseif (sugar_is_file($this->getTemplatePath().'/'.$templateName)) |
|
679 | - $templatePath = $this->getTemplatePath().'/'.$templateName; |
|
680 | - elseif (isset($this->parentTheme) |
|
694 | + if (sugar_is_file('custom/'.$this->getTemplatePath().'/'.$templateName)) { |
|
695 | + $templatePath = 'custom/'.$this->getTemplatePath().'/'.$templateName; |
|
696 | + } elseif (sugar_is_file($this->getTemplatePath().'/'.$templateName)) { |
|
697 | + $templatePath = $this->getTemplatePath().'/'.$templateName; |
|
698 | + } elseif (isset($this->parentTheme) |
|
681 | 699 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
682 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getTemplate($templateName)) != '') |
|
683 | - $templatePath = $filename; |
|
684 | - elseif (sugar_is_file('custom/'.$this->getDefaultTemplatePath().'/'.$templateName)) |
|
685 | - $templatePath = 'custom/'.$this->getDefaultTemplatePath().'/'.$templateName; |
|
686 | - elseif (sugar_is_file($this->getDefaultTemplatePath().'/'.$templateName)) |
|
687 | - $templatePath = $this->getDefaultTemplatePath().'/'.$templateName; |
|
688 | - else { |
|
700 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getTemplate($templateName)) != '') { |
|
701 | + $templatePath = $filename; |
|
702 | + } elseif (sugar_is_file('custom/'.$this->getDefaultTemplatePath().'/'.$templateName)) { |
|
703 | + $templatePath = 'custom/'.$this->getDefaultTemplatePath().'/'.$templateName; |
|
704 | + } elseif (sugar_is_file($this->getDefaultTemplatePath().'/'.$templateName)) { |
|
705 | + $templatePath = $this->getDefaultTemplatePath().'/'.$templateName; |
|
706 | + } else { |
|
689 | 707 | $GLOBALS['log']->warn("Template $templateName not found"); |
690 | 708 | return false; |
691 | 709 | } |
@@ -721,15 +739,17 @@ discard block |
||
721 | 739 | // trap deprecated use of image extension |
722 | 740 | if(is_null($ext)) { |
723 | 741 | $imageNameExp = explode('.',$imageName); |
724 | - if(count($imageNameExp) == 1) |
|
725 | - $imageName .= '.gif'; |
|
742 | + if(count($imageNameExp) == 1) { |
|
743 | + $imageName .= '.gif'; |
|
744 | + } |
|
726 | 745 | } else { |
727 | 746 | $imageName .= $ext; |
728 | 747 | } |
729 | 748 | |
730 | 749 | // trap alt attributes in other_attributes |
731 | - if(preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) |
|
732 | - $GLOBALS['log']->debug("Sprites: alt attribute detected for $imageName"); |
|
750 | + if(preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) { |
|
751 | + $GLOBALS['log']->debug("Sprites: alt attribute detected for $imageName"); |
|
752 | + } |
|
733 | 753 | // sprite handler, makes use of own caching mechanism |
734 | 754 | if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
735 | 755 | // get sprite metadata |
@@ -751,8 +771,9 @@ discard block |
||
751 | 771 | // img caching |
752 | 772 | if(empty($cached_results[$imageName])) { |
753 | 773 | $imageURL = $this->getImageURL($imageName,false); |
754 | - if ( empty($imageURL) ) |
|
755 | - return false; |
|
774 | + if ( empty($imageURL) ) { |
|
775 | + return false; |
|
776 | + } |
|
756 | 777 | if(strpos($imageURL, '.svg', strlen($imageURL)-4)){ |
757 | 778 | $cached_results[$imageName] = file_get_contents($imageURL); |
758 | 779 | } else { |
@@ -779,8 +800,9 @@ discard block |
||
779 | 800 | public function getSpriteMeta($imageName) { |
780 | 801 | |
781 | 802 | // return from cache |
782 | - if(isset($this->_spriteCache[$imageName])) |
|
783 | - return $this->_spriteCache[$imageName]; |
|
803 | + if(isset($this->_spriteCache[$imageName])) { |
|
804 | + return $this->_spriteCache[$imageName]; |
|
805 | + } |
|
784 | 806 | |
785 | 807 | // sprite keys are base on imageURL |
786 | 808 | $imageURL = $this->getImageURL($imageName,false); |
@@ -832,8 +854,9 @@ discard block |
||
832 | 854 | $attr .= ' class="spr_'.$class.'"'; |
833 | 855 | } |
834 | 856 | |
835 | - if($title) |
|
836 | - $attr .= ' title="'.$title.'"'; |
|
857 | + if($title) { |
|
858 | + $attr .= ' title="'.$title.'"'; |
|
859 | + } |
|
837 | 860 | |
838 | 861 | // use </span> instead of /> to prevent weird UI results |
839 | 862 | $GLOBALS['log']->debug("Sprites: generated sprite -> $attr"); |
@@ -887,35 +910,37 @@ discard block |
||
887 | 910 | $addJSPath = true |
888 | 911 | ){ |
889 | 912 | if ( isset($this->_imageCache[$imageName]) ) { |
890 | - if ( $addJSPath ) |
|
891 | - return getJSPath($this->_imageCache[$imageName]); |
|
892 | - else |
|
893 | - return $this->_imageCache[$imageName]; |
|
913 | + if ( $addJSPath ) { |
|
914 | + return getJSPath($this->_imageCache[$imageName]); |
|
915 | + } else { |
|
916 | + return $this->_imageCache[$imageName]; |
|
917 | + } |
|
894 | 918 | } |
895 | 919 | $imagePath = ''; |
896 | - if (($filename = $this->_getImageFileName('custom/'.$this->getImagePath().'/'.$imageName)) != '') |
|
897 | - $imagePath = $filename; |
|
898 | - elseif (($filename = $this->_getImageFileName($this->getImagePath().'/'.$imageName)) != '') |
|
899 | - $imagePath = $filename; |
|
900 | - elseif (isset($this->parentTheme) |
|
920 | + if (($filename = $this->_getImageFileName('custom/'.$this->getImagePath().'/'.$imageName)) != '') { |
|
921 | + $imagePath = $filename; |
|
922 | + } elseif (($filename = $this->_getImageFileName($this->getImagePath().'/'.$imageName)) != '') { |
|
923 | + $imagePath = $filename; |
|
924 | + } elseif (isset($this->parentTheme) |
|
901 | 925 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
902 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getImageURL($imageName,false)) != '') |
|
903 | - $imagePath = $filename; |
|
904 | - elseif (($filename = $this->_getImageFileName('custom/'.$this->getDefaultImagePath().'/'.$imageName)) != '') |
|
905 | - $imagePath = $filename; |
|
906 | - elseif (($filename = $this->_getImageFileName($this->getDefaultImagePath().'/'.$imageName)) != '') |
|
907 | - $imagePath = $filename; |
|
908 | - elseif (($filename = $this->_getImageFileName('include/images/'.$imageName)) != '') |
|
909 | - $imagePath = $filename; |
|
910 | - else { |
|
926 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getImageURL($imageName,false)) != '') { |
|
927 | + $imagePath = $filename; |
|
928 | + } elseif (($filename = $this->_getImageFileName('custom/'.$this->getDefaultImagePath().'/'.$imageName)) != '') { |
|
929 | + $imagePath = $filename; |
|
930 | + } elseif (($filename = $this->_getImageFileName($this->getDefaultImagePath().'/'.$imageName)) != '') { |
|
931 | + $imagePath = $filename; |
|
932 | + } elseif (($filename = $this->_getImageFileName('include/images/'.$imageName)) != '') { |
|
933 | + $imagePath = $filename; |
|
934 | + } else { |
|
911 | 935 | $GLOBALS['log']->warn("Image $imageName not found"); |
912 | 936 | return false; |
913 | 937 | } |
914 | 938 | |
915 | 939 | $this->_imageCache[$imageName] = $imagePath; |
916 | 940 | |
917 | - if ( $addJSPath ) |
|
918 | - return getJSPath($imagePath); |
|
941 | + if ( $addJSPath ) { |
|
942 | + return getJSPath($imagePath); |
|
943 | + } |
|
919 | 944 | |
920 | 945 | return $imagePath; |
921 | 946 | } |
@@ -931,14 +956,16 @@ discard block |
||
931 | 956 | ) |
932 | 957 | { |
933 | 958 | // return now if the extension matches that of which we are looking for |
934 | - if ( sugar_is_file($imageName) ) |
|
935 | - return $imageName; |
|
959 | + if ( sugar_is_file($imageName) ) { |
|
960 | + return $imageName; |
|
961 | + } |
|
936 | 962 | $pathParts = pathinfo($imageName); |
937 | - foreach ( $this->imageExtensions as $extension ) |
|
938 | - if ( isset($pathParts['extension']) ) |
|
963 | + foreach ( $this->imageExtensions as $extension ) { |
|
964 | + if ( isset($pathParts['extension']) ) |
|
939 | 965 | if ( ( $extension != $pathParts['extension'] ) |
940 | 966 | && sugar_is_file($pathParts['dirname'].'/'.$pathParts['filename'].'.'.$extension) ) |
941 | 967 | return $pathParts['dirname'].'/'.$pathParts['filename'].'.'.$extension; |
968 | + } |
|
942 | 969 | |
943 | 970 | return ''; |
944 | 971 | } |
@@ -954,10 +981,11 @@ discard block |
||
954 | 981 | public function getCSSURL($cssFileName, $returnURL = true) |
955 | 982 | { |
956 | 983 | if ( isset($this->_cssCache[$cssFileName]) && sugar_is_file(sugar_cached($this->_cssCache[$cssFileName])) ) { |
957 | - if ( $returnURL ) |
|
958 | - return getJSPath("cache/".$this->_cssCache[$cssFileName]); |
|
959 | - else |
|
960 | - return sugar_cached($this->_cssCache[$cssFileName]); |
|
984 | + if ( $returnURL ) { |
|
985 | + return getJSPath("cache/".$this->_cssCache[$cssFileName]); |
|
986 | + } else { |
|
987 | + return sugar_cached($this->_cssCache[$cssFileName]); |
|
988 | + } |
|
961 | 989 | } |
962 | 990 | |
963 | 991 | $cssFileContents = ''; |
@@ -965,13 +993,15 @@ discard block |
||
965 | 993 | $fullFileName = $this->getCSSPath().'/'.$cssFileName; |
966 | 994 | if (isset($this->parentTheme) |
967 | 995 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
968 | - && ($filename = SugarThemeRegistry::get($this->parentTheme)->getCSSURL($cssFileName,false)) != '') |
|
969 | - $cssFileContents .= file_get_contents($filename); |
|
970 | - else { |
|
971 | - if (sugar_is_file($defaultFileName)) |
|
972 | - $cssFileContents .= file_get_contents($defaultFileName); |
|
973 | - if (sugar_is_file('custom/'.$defaultFileName)) |
|
974 | - $cssFileContents .= file_get_contents('custom/'.$defaultFileName); |
|
996 | + && ($filename = SugarThemeRegistry::get($this->parentTheme)->getCSSURL($cssFileName,false)) != '') { |
|
997 | + $cssFileContents .= file_get_contents($filename); |
|
998 | + } else { |
|
999 | + if (sugar_is_file($defaultFileName)) { |
|
1000 | + $cssFileContents .= file_get_contents($defaultFileName); |
|
1001 | + } |
|
1002 | + if (sugar_is_file('custom/'.$defaultFileName)) { |
|
1003 | + $cssFileContents .= file_get_contents('custom/'.$defaultFileName); |
|
1004 | + } |
|
975 | 1005 | } |
976 | 1006 | if (sugar_is_file($fullFileName)) { |
977 | 1007 | $cssFileContents .= file_get_contents($fullFileName); |
@@ -995,10 +1025,11 @@ discard block |
||
995 | 1025 | // if this is the style.css file, prepend the base.css and calendar-win2k-cold-1.css |
996 | 1026 | // files before the theme styles |
997 | 1027 | if ( $cssFileName == 'style.css' && !isset($this->parentTheme) ) { |
998 | - if ( inDeveloperMode() ) |
|
999 | - $cssFileContents = file_get_contents('include/javascript/yui/build/base/base.css') . $cssFileContents; |
|
1000 | - else |
|
1001 | - $cssFileContents = file_get_contents('include/javascript/yui/build/base/base-min.css') . $cssFileContents; |
|
1028 | + if ( inDeveloperMode() ) { |
|
1029 | + $cssFileContents = file_get_contents('include/javascript/yui/build/base/base.css') . $cssFileContents; |
|
1030 | + } else { |
|
1031 | + $cssFileContents = file_get_contents('include/javascript/yui/build/base/base-min.css') . $cssFileContents; |
|
1032 | + } |
|
1002 | 1033 | } |
1003 | 1034 | |
1004 | 1035 | // minify the css |
@@ -1011,8 +1042,9 @@ discard block |
||
1011 | 1042 | |
1012 | 1043 | $this->_cssCache[$cssFileName] = $fullFileName; |
1013 | 1044 | |
1014 | - if ( $returnURL ) |
|
1015 | - return getJSPath("cache/".$fullFileName); |
|
1045 | + if ( $returnURL ) { |
|
1046 | + return getJSPath("cache/".$fullFileName); |
|
1047 | + } |
|
1016 | 1048 | |
1017 | 1049 | return sugar_cached($fullFileName); |
1018 | 1050 | } |
@@ -1028,10 +1060,11 @@ discard block |
||
1028 | 1060 | public function getJSURL($jsFileName, $returnURL = true) |
1029 | 1061 | { |
1030 | 1062 | if ( isset($this->_jsCache[$jsFileName]) && sugar_is_file(sugar_cached($this->_jsCache[$jsFileName])) ) { |
1031 | - if ( $returnURL ) |
|
1032 | - return getJSPath("cache/".$this->_jsCache[$jsFileName]); |
|
1033 | - else |
|
1034 | - return sugar_cached($this->_jsCache[$jsFileName]); |
|
1063 | + if ( $returnURL ) { |
|
1064 | + return getJSPath("cache/".$this->_jsCache[$jsFileName]); |
|
1065 | + } else { |
|
1066 | + return sugar_cached($this->_jsCache[$jsFileName]); |
|
1067 | + } |
|
1035 | 1068 | } |
1036 | 1069 | |
1037 | 1070 | $jsFileContents = ''; |
@@ -1042,15 +1075,19 @@ discard block |
||
1042 | 1075 | && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName,false)) != '' && !in_array($jsFileName,$this->ignoreParentFiles)) { |
1043 | 1076 | $jsFileContents .= file_get_contents($filename); |
1044 | 1077 | } else { |
1045 | - if (sugar_is_file($defaultFileName)) |
|
1046 | - $jsFileContents .= file_get_contents($defaultFileName); |
|
1047 | - if (sugar_is_file('custom/'.$defaultFileName)) |
|
1048 | - $jsFileContents .= file_get_contents('custom/'.$defaultFileName); |
|
1078 | + if (sugar_is_file($defaultFileName)) { |
|
1079 | + $jsFileContents .= file_get_contents($defaultFileName); |
|
1080 | + } |
|
1081 | + if (sugar_is_file('custom/'.$defaultFileName)) { |
|
1082 | + $jsFileContents .= file_get_contents('custom/'.$defaultFileName); |
|
1083 | + } |
|
1084 | + } |
|
1085 | + if (sugar_is_file($fullFileName)) { |
|
1086 | + $jsFileContents .= file_get_contents($fullFileName); |
|
1087 | + } |
|
1088 | + if (sugar_is_file('custom/'.$fullFileName)) { |
|
1089 | + $jsFileContents .= file_get_contents('custom/'.$fullFileName); |
|
1049 | 1090 | } |
1050 | - if (sugar_is_file($fullFileName)) |
|
1051 | - $jsFileContents .= file_get_contents($fullFileName); |
|
1052 | - if (sugar_is_file('custom/'.$fullFileName)) |
|
1053 | - $jsFileContents .= file_get_contents('custom/'.$fullFileName); |
|
1054 | 1091 | if (empty($jsFileContents)) { |
1055 | 1092 | $GLOBALS['log']->warn("Javascript File $jsFileName not found"); |
1056 | 1093 | return false; |
@@ -1071,8 +1108,9 @@ discard block |
||
1071 | 1108 | |
1072 | 1109 | $this->_jsCache[$jsFileName] = $fullFileName; |
1073 | 1110 | |
1074 | - if ( $returnURL ) |
|
1075 | - return getJSPath("cache/".$fullFileName); |
|
1111 | + if ( $returnURL ) { |
|
1112 | + return getJSPath("cache/".$fullFileName); |
|
1113 | + } |
|
1076 | 1114 | |
1077 | 1115 | return sugar_cached($fullFileName); |
1078 | 1116 | } |
@@ -1097,7 +1135,9 @@ discard block |
||
1097 | 1135 | $imageArray = array(); |
1098 | 1136 | foreach ( $pathsToSearch as $path ) |
1099 | 1137 | { |
1100 | - if (!sugar_is_dir($path)) $path = "custom/$path"; |
|
1138 | + if (!sugar_is_dir($path)) { |
|
1139 | + $path = "custom/$path"; |
|
1140 | + } |
|
1101 | 1141 | if (sugar_is_dir($path) && is_readable($path) && $dir = opendir($path)) { |
1102 | 1142 | while (($file = readdir($dir)) !== false) { |
1103 | 1143 | if ($file == ".." |
@@ -1105,10 +1145,12 @@ discard block |
||
1105 | 1145 | || $file == ".svn" |
1106 | 1146 | || $file == "CVS" |
1107 | 1147 | || $file == "Attic" |
1108 | - ) |
|
1109 | - continue; |
|
1110 | - if ( !isset($imageArray[$file]) ) |
|
1111 | - $imageArray[$file] = $this->getImageURL($file,false); |
|
1148 | + ) { |
|
1149 | + continue; |
|
1150 | + } |
|
1151 | + if ( !isset($imageArray[$file]) ) { |
|
1152 | + $imageArray[$file] = $this->getImageURL($file,false); |
|
1153 | + } |
|
1112 | 1154 | } |
1113 | 1155 | closedir($dir); |
1114 | 1156 | } |
@@ -1189,8 +1231,9 @@ discard block |
||
1189 | 1231 | } |
1190 | 1232 | |
1191 | 1233 | // Assume theme is designed for 5.5.x if not specified otherwise |
1192 | - if ( !isset($themedef['version']) ) |
|
1193 | - $themedef['version']['regex_matches'] = array('5\.5\.*'); |
|
1234 | + if ( !isset($themedef['version']) ) { |
|
1235 | + $themedef['version']['regex_matches'] = array('5\.5\.*'); |
|
1236 | + } |
|
1194 | 1237 | |
1195 | 1238 | // Check to see if theme is valid for this version of Sugar; return false if not |
1196 | 1239 | $version_ok = false; |
@@ -1210,8 +1253,9 @@ discard block |
||
1210 | 1253 | } |
1211 | 1254 | } |
1212 | 1255 | } |
1213 | - if ( !$version_ok ) |
|
1214 | - return false; |
|
1256 | + if ( !$version_ok ) { |
|
1257 | + return false; |
|
1258 | + } |
|
1215 | 1259 | |
1216 | 1260 | $theme = new SugarTheme($themedef); |
1217 | 1261 | self::$_themes[$theme->dirName] = $theme; |
@@ -1226,8 +1270,9 @@ discard block |
||
1226 | 1270 | $themeName |
1227 | 1271 | ) |
1228 | 1272 | { |
1229 | - if ( self::exists($themeName) ) |
|
1230 | - unset(self::$_themes[$themeName]); |
|
1273 | + if ( self::exists($themeName) ) { |
|
1274 | + unset(self::$_themes[$themeName]); |
|
1275 | + } |
|
1231 | 1276 | } |
1232 | 1277 | |
1233 | 1278 | /** |
@@ -1239,8 +1284,9 @@ discard block |
||
1239 | 1284 | $themeName |
1240 | 1285 | ) |
1241 | 1286 | { |
1242 | - if ( isset(self::$_themes[$themeName]) ) |
|
1243 | - return self::$_themes[$themeName]; |
|
1287 | + if ( isset(self::$_themes[$themeName]) ) { |
|
1288 | + return self::$_themes[$themeName]; |
|
1289 | + } |
|
1244 | 1290 | } |
1245 | 1291 | |
1246 | 1292 | /** |
@@ -1250,8 +1296,9 @@ discard block |
||
1250 | 1296 | */ |
1251 | 1297 | public static function current() |
1252 | 1298 | { |
1253 | - if ( !isset(self::$_currentTheme) ) |
|
1254 | - self::buildRegistry(); |
|
1299 | + if ( !isset(self::$_currentTheme) ) { |
|
1300 | + self::buildRegistry(); |
|
1301 | + } |
|
1255 | 1302 | |
1256 | 1303 | return self::$_themes[self::$_currentTheme]; |
1257 | 1304 | } |
@@ -1263,8 +1310,9 @@ discard block |
||
1263 | 1310 | */ |
1264 | 1311 | public static function getDefault() |
1265 | 1312 | { |
1266 | - if ( !isset(self::$_currentTheme) ) |
|
1267 | - self::buildRegistry(); |
|
1313 | + if ( !isset(self::$_currentTheme) ) { |
|
1314 | + self::buildRegistry(); |
|
1315 | + } |
|
1268 | 1316 | |
1269 | 1317 | if ( isset($GLOBALS['sugar_config']['default_theme']) && self::exists($GLOBALS['sugar_config']['default_theme']) ) { |
1270 | 1318 | return self::get($GLOBALS['sugar_config']['default_theme']); |
@@ -1295,8 +1343,9 @@ discard block |
||
1295 | 1343 | $themeName |
1296 | 1344 | ) |
1297 | 1345 | { |
1298 | - if ( !self::exists($themeName) ) |
|
1299 | - return false; |
|
1346 | + if ( !self::exists($themeName) ) { |
|
1347 | + return false; |
|
1348 | + } |
|
1300 | 1349 | |
1301 | 1350 | self::$_currentTheme = $themeName; |
1302 | 1351 | |
@@ -1333,8 +1382,9 @@ discard block |
||
1333 | 1382 | || $file == "default" |
1334 | 1383 | || !sugar_is_dir("./$dirPath".$file) |
1335 | 1384 | || !sugar_is_file("./{$dirPath}{$file}/themedef.php") |
1336 | - ) |
|
1337 | - continue; |
|
1385 | + ) { |
|
1386 | + continue; |
|
1387 | + } |
|
1338 | 1388 | $themedef = array(); |
1339 | 1389 | require("./{$dirPath}{$file}/themedef.php"); |
1340 | 1390 | $themedef = array_merge($themedef,$themedefDefault); |
@@ -1343,9 +1393,10 @@ discard block |
||
1343 | 1393 | // if so, then it will override the current one |
1344 | 1394 | if ( self::exists($themedef['dirName']) ) { |
1345 | 1395 | $existingTheme = self::get($themedef['dirName']); |
1346 | - foreach ( SugarTheme::getThemeDefFields() as $field ) |
|
1347 | - if ( !isset($themedef[$field]) ) |
|
1396 | + foreach ( SugarTheme::getThemeDefFields() as $field ) { |
|
1397 | + if ( !isset($themedef[$field]) ) |
|
1348 | 1398 | $themedef[$field] = $existingTheme->$field; |
1399 | + } |
|
1349 | 1400 | self::remove($themedef['dirName']); |
1350 | 1401 | } |
1351 | 1402 | if ( isset($themedef['name']) ) { |
@@ -1400,12 +1451,14 @@ discard block |
||
1400 | 1451 | { |
1401 | 1452 | $themelist = array(); |
1402 | 1453 | $disabledThemes = array(); |
1403 | - if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) |
|
1404 | - $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1454 | + if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) { |
|
1455 | + $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1456 | + } |
|
1405 | 1457 | |
1406 | 1458 | foreach ( self::$_themes as $themename => $themeobject ) { |
1407 | - if ( in_array($themename,$disabledThemes) ) |
|
1408 | - continue; |
|
1459 | + if ( in_array($themename,$disabledThemes) ) { |
|
1460 | + continue; |
|
1461 | + } |
|
1409 | 1462 | $themelist[$themeobject->dirName] = $themeobject->name; |
1410 | 1463 | } |
1411 | 1464 | asort($themelist, SORT_STRING); |
@@ -1421,12 +1474,14 @@ discard block |
||
1421 | 1474 | { |
1422 | 1475 | $themelist = array(); |
1423 | 1476 | $disabledThemes = array(); |
1424 | - if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) |
|
1425 | - $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1477 | + if ( isset($GLOBALS['sugar_config']['disabled_themes']) ) { |
|
1478 | + $disabledThemes = explode(',',$GLOBALS['sugar_config']['disabled_themes']); |
|
1479 | + } |
|
1426 | 1480 | |
1427 | 1481 | foreach ( self::$_themes as $themename => $themeobject ) { |
1428 | - if ( in_array($themename,$disabledThemes) ) |
|
1429 | - $themelist[$themeobject->dirName] = $themeobject->name; |
|
1482 | + if ( in_array($themename,$disabledThemes) ) { |
|
1483 | + $themelist[$themeobject->dirName] = $themeobject->name; |
|
1484 | + } |
|
1430 | 1485 | } |
1431 | 1486 | |
1432 | 1487 | return $themelist; |
@@ -1441,8 +1496,9 @@ discard block |
||
1441 | 1496 | { |
1442 | 1497 | $themelist = array(); |
1443 | 1498 | |
1444 | - foreach ( self::$_themes as $themename => $themeobject ) |
|
1445 | - $themelist[$themeobject->dirName] = $themeobject->name; |
|
1499 | + foreach ( self::$_themes as $themename => $themeobject ) { |
|
1500 | + $themelist[$themeobject->dirName] = $themeobject->name; |
|
1501 | + } |
|
1446 | 1502 | |
1447 | 1503 | return $themelist; |
1448 | 1504 | } |
@@ -1456,8 +1512,9 @@ discard block |
||
1456 | 1512 | { |
1457 | 1513 | $themelist = array(); |
1458 | 1514 | $disabledThemes = array(); |
1459 | - if (isset($GLOBALS['sugar_config']['disabled_themes'])) |
|
1460 | - $disabledThemes = explode(',', $GLOBALS['sugar_config']['disabled_themes']); |
|
1515 | + if (isset($GLOBALS['sugar_config']['disabled_themes'])) { |
|
1516 | + $disabledThemes = explode(',', $GLOBALS['sugar_config']['disabled_themes']); |
|
1517 | + } |
|
1461 | 1518 | |
1462 | 1519 | foreach (self::$_themes as $themename => $themeobject) { |
1463 | 1520 | $themearray['name'] = $themeobject->name; |
@@ -1478,8 +1535,9 @@ discard block |
||
1478 | 1535 | { |
1479 | 1536 | global $sugar_config; |
1480 | 1537 | |
1481 | - if ( !self::exists($themeName) ) |
|
1482 | - return false; |
|
1538 | + if ( !self::exists($themeName) ) { |
|
1539 | + return false; |
|
1540 | + } |
|
1483 | 1541 | |
1484 | 1542 | $config = array(); |
1485 | 1543 |
@@ -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 | } |
@@ -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 ; |
@@ -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']) |
@@ -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 |
@@ -556,8 +560,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -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. |
@@ -403,13 +405,15 @@ discard block |
||
403 | 405 | $match = array(); |
404 | 406 | preg_match_all("'.* FROM ([^ ]*).* ORDER BY (.*)'is", $sql, $match); |
405 | 407 | $indices = false; |
406 | - if (!empty($match[1][0])) |
|
407 | - $table = $match[1][0]; |
|
408 | - else |
|
409 | - return false; |
|
408 | + if (!empty($match[1][0])) { |
|
409 | + $table = $match[1][0]; |
|
410 | + } else { |
|
411 | + return false; |
|
412 | + } |
|
410 | 413 | |
411 | - if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) |
|
412 | - $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
414 | + if (!empty($object_name) && !empty($GLOBALS['dictionary'][$object_name])) { |
|
415 | + $indices = $GLOBALS['dictionary'][$object_name]['indices']; |
|
416 | + } |
|
413 | 417 | |
414 | 418 | if (empty($indices)) { |
415 | 419 | foreach ( $GLOBALS['dictionary'] as $current ) { |
@@ -427,25 +431,29 @@ discard block |
||
427 | 431 | $orderBys = explode(' ', $match[2][0]); |
428 | 432 | foreach ($orderBys as $orderBy){ |
429 | 433 | $orderBy = trim($orderBy); |
430 | - if (empty($orderBy)) |
|
431 | - continue; |
|
434 | + if (empty($orderBy)) { |
|
435 | + continue; |
|
436 | + } |
|
432 | 437 | $orderBy = strtolower($orderBy); |
433 | - if ($orderBy == 'asc' || $orderBy == 'desc') |
|
434 | - continue; |
|
438 | + if ($orderBy == 'asc' || $orderBy == 'desc') { |
|
439 | + continue; |
|
440 | + } |
|
435 | 441 | |
436 | 442 | $orderBy = str_replace(array($table . '.', ','), '', $orderBy); |
437 | 443 | |
438 | - foreach ($indices as $index) |
|
439 | - if (empty($index['db']) || $index['db'] == $this->dbType) |
|
444 | + foreach ($indices as $index) { |
|
445 | + if (empty($index['db']) || $index['db'] == $this->dbType) |
|
440 | 446 | foreach ($index['fields'] as $field) |
441 | 447 | if ($field == $orderBy) |
442 | 448 | return true; |
449 | + } |
|
443 | 450 | |
444 | 451 | $warning = 'Missing Index For Order By Table: ' . $table . ' Order By:' . $orderBy ; |
445 | - if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) |
|
446 | - $this->log->fatal('CHECK QUERY:' .$warning); |
|
447 | - else |
|
448 | - $this->log->warn('CHECK QUERY:' .$warning); |
|
452 | + if (!empty($GLOBALS['sugar_config']['dump_slow_queries'])) { |
|
453 | + $this->log->fatal('CHECK QUERY:' .$warning); |
|
454 | + } else { |
|
455 | + $this->log->warn('CHECK QUERY:' .$warning); |
|
456 | + } |
|
449 | 457 | } |
450 | 458 | } |
451 | 459 | return false; |
@@ -467,8 +475,9 @@ discard block |
||
467 | 475 | public function checkConnection() |
468 | 476 | { |
469 | 477 | $this->last_error = ''; |
470 | - if (!isset($this->database)) |
|
471 | - $this->connect(); |
|
478 | + if (!isset($this->database)) { |
|
479 | + $this->connect(); |
|
480 | + } |
|
472 | 481 | } |
473 | 482 | |
474 | 483 | /** |
@@ -510,9 +519,13 @@ discard block |
||
510 | 519 | $values = array(); |
511 | 520 | foreach ($field_defs as $field => $fieldDef) |
512 | 521 | { |
513 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
522 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') { |
|
523 | + continue; |
|
524 | + } |
|
514 | 525 | //custom fields handle there save seperatley |
515 | - if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) continue; |
|
526 | + if(!empty($field_map) && !empty($field_map[$field]['custom_type'])) { |
|
527 | + continue; |
|
528 | + } |
|
516 | 529 | |
517 | 530 | if(isset($data[$field])) { |
518 | 531 | // clean the incoming value.. |
@@ -541,8 +554,10 @@ discard block |
||
541 | 554 | } |
542 | 555 | } |
543 | 556 | |
544 | - if (empty($values)) |
|
545 | - return $execute?true:''; // no columns set |
|
557 | + if (empty($values)) { |
|
558 | + return $execute?true:''; |
|
559 | + } |
|
560 | + // no columns set |
|
546 | 561 | |
547 | 562 | // get the entire sql |
548 | 563 | $query = "INSERT INTO $table (".implode(",", array_keys($values)).") |
@@ -642,9 +657,10 @@ discard block |
||
642 | 657 | if(!$this->supports("inline_keys")) { |
643 | 658 | // handle constraints and indices |
644 | 659 | $indicesArr = $this->createConstraintSql($bean); |
645 | - if (count($indicesArr) > 0) |
|
646 | - foreach ($indicesArr as $indexSql) |
|
660 | + if (count($indicesArr) > 0) { |
|
661 | + foreach ($indicesArr as $indexSql) |
|
647 | 662 | $this->query($indexSql, true, $msg); |
663 | + } |
|
648 | 664 | } |
649 | 665 | } |
650 | 666 | |
@@ -681,9 +697,10 @@ discard block |
||
681 | 697 | if(!$this->supports("inline_keys")) { |
682 | 698 | // handle constraints and indices |
683 | 699 | $indicesArr = $this->getConstraintSql($indices, $tablename); |
684 | - if (count($indicesArr) > 0) |
|
685 | - foreach ($indicesArr as $indexSql) |
|
700 | + if (count($indicesArr) > 0) { |
|
701 | + foreach ($indicesArr as $indexSql) |
|
686 | 702 | $res = ($res and $this->query($indexSql, true, "Error creating indexes")); |
703 | + } |
|
687 | 704 | } |
688 | 705 | return $res; |
689 | 706 | } |
@@ -710,13 +727,15 @@ discard block |
||
710 | 727 | } |
711 | 728 | //jc: added this for beans that do not actually have a table, namely |
712 | 729 | //ForecastOpportunities |
713 | - if($tablename == 'does_not_exist' || $tablename == '') |
|
714 | - return ''; |
|
730 | + if($tablename == 'does_not_exist' || $tablename == '') { |
|
731 | + return ''; |
|
732 | + } |
|
715 | 733 | |
716 | 734 | global $dictionary; |
717 | 735 | $engine=null; |
718 | - if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) |
|
719 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
736 | + if (isset($dictionary[$bean->getObjectName()]['engine']) && !empty($dictionary[$bean->getObjectName()]['engine']) ) { |
|
737 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
738 | + } |
|
720 | 739 | |
721 | 740 | return $this->repairTableParams($tablename, $fielddefs,$new_index,$execute,$engine); |
722 | 741 | } |
@@ -760,8 +779,9 @@ discard block |
||
760 | 779 | { |
761 | 780 | //jc: had a bug when running the repair if the tablename is blank the repair will |
762 | 781 | //fail when it tries to create a repair table |
763 | - if ($tablename == '' || empty($fielddefs)) |
|
764 | - return ''; |
|
782 | + if ($tablename == '' || empty($fielddefs)) { |
|
783 | + return ''; |
|
784 | + } |
|
765 | 785 | |
766 | 786 | //if the table does not exist create it and we are done |
767 | 787 | $sql = "/* Table : $tablename */\n"; |
@@ -784,16 +804,16 @@ discard block |
||
784 | 804 | // do column comparisons |
785 | 805 | $sql .= "/*COLUMNS*/\n"; |
786 | 806 | foreach ($fielddefs as $name => $value) { |
787 | - if (isset($value['source']) && $value['source'] != 'db') |
|
788 | - continue; |
|
807 | + if (isset($value['source']) && $value['source'] != 'db') { |
|
808 | + continue; |
|
809 | + } |
|
789 | 810 | |
790 | 811 | // Bug #42406. Skipping breaked vardef without type or name |
791 | 812 | if (isset($value['name']) == false || $value['name'] == false) |
792 | 813 | { |
793 | 814 | $sql .= "/* NAME IS MISSING IN VARDEF $tablename::$name */\n"; |
794 | 815 | continue; |
795 | - } |
|
796 | - else if (isset($value['type']) == false || $value['type'] == false) |
|
816 | + } else if (isset($value['type']) == false || $value['type'] == false) |
|
797 | 817 | { |
798 | 818 | $sql .= "/* TYPE IS MISSING IN VARDEF $tablename::$name */\n"; |
799 | 819 | continue; |
@@ -823,8 +843,9 @@ discard block |
||
823 | 843 | // ok we need this field lets create it |
824 | 844 | $sql .= "/*MISSING IN DATABASE - $name - ROW*/\n"; |
825 | 845 | $sql .= $this->addColumnSQL($tablename, $value) . "\n"; |
826 | - if ($execute) |
|
827 | - $this->addColumn($tablename, $value); |
|
846 | + if ($execute) { |
|
847 | + $this->addColumn($tablename, $value); |
|
848 | + } |
|
828 | 849 | $take_action = true; |
829 | 850 | } elseif ( !$this->compareVarDefs($compareFieldDefs[$name],$value)) { |
830 | 851 | //fields are different lets alter it |
@@ -880,8 +901,9 @@ discard block |
||
880 | 901 | unset($compareIndices_case_insensitive); |
881 | 902 | |
882 | 903 | foreach ($indices as $value) { |
883 | - if (isset($value['source']) && $value['source'] != 'db') |
|
884 | - continue; |
|
904 | + if (isset($value['source']) && $value['source'] != 'db') { |
|
905 | + continue; |
|
906 | + } |
|
885 | 907 | |
886 | 908 | |
887 | 909 | $validDBName = $this->getValidDBName($value['name'], true, 'index', true); |
@@ -891,19 +913,23 @@ discard block |
||
891 | 913 | $name = strtolower($value['name']); |
892 | 914 | |
893 | 915 | //Don't attempt to fix the same index twice in one pass; |
894 | - if (isset($correctedIndexs[$name])) |
|
895 | - continue; |
|
916 | + if (isset($correctedIndexs[$name])) { |
|
917 | + continue; |
|
918 | + } |
|
896 | 919 | |
897 | 920 | //don't bother checking primary nothing we can do about them |
898 | - if (isset($value['type']) && $value['type'] == 'primary') |
|
899 | - continue; |
|
921 | + if (isset($value['type']) && $value['type'] == 'primary') { |
|
922 | + continue; |
|
923 | + } |
|
900 | 924 | |
901 | 925 | //database helpers do not know how to handle full text indices |
902 | - if ($value['type']=='fulltext') |
|
903 | - continue; |
|
926 | + if ($value['type']=='fulltext') { |
|
927 | + continue; |
|
928 | + } |
|
904 | 929 | |
905 | - if ( in_array($value['type'],array('alternate_key','foreign')) ) |
|
906 | - $value['type'] = 'index'; |
|
930 | + if ( in_array($value['type'],array('alternate_key','foreign')) ) { |
|
931 | + $value['type'] = 'index'; |
|
932 | + } |
|
907 | 933 | |
908 | 934 | if ( !isset($compareIndices[$name]) ) { |
909 | 935 | //First check if an index exists that doesn't match our name, if so, try to rename it |
@@ -934,21 +960,23 @@ discard block |
||
934 | 960 | $sql .= "/*INDEX MISMATCH WITH DATABASE - $name - ROW "; |
935 | 961 | foreach ($compareIndices[$name] as $n1 => $t1) { |
936 | 962 | $sql .= "<$n1>"; |
937 | - if ( $n1 == 'fields' ) |
|
938 | - foreach($t1 as $rKey => $rValue) |
|
963 | + if ( $n1 == 'fields' ) { |
|
964 | + foreach($t1 as $rKey => $rValue) |
|
939 | 965 | $sql .= "[$rKey] => '$rValue' "; |
940 | - else |
|
941 | - $sql .= " $t1 "; |
|
966 | + } else { |
|
967 | + $sql .= " $t1 "; |
|
968 | + } |
|
942 | 969 | } |
943 | 970 | $sql .= "*/\n"; |
944 | 971 | $sql .= "/* VARDEF - $name - ROW"; |
945 | 972 | foreach ($value as $n1 => $t1) { |
946 | 973 | $sql .= "<$n1>"; |
947 | - if ( $n1 == 'fields' ) |
|
948 | - foreach ($t1 as $rKey => $rValue) |
|
974 | + if ( $n1 == 'fields' ) { |
|
975 | + foreach ($t1 as $rKey => $rValue) |
|
949 | 976 | $sql .= "[$rKey] => '$rValue' "; |
950 | - else |
|
951 | - $sql .= " $t1 "; |
|
977 | + } else { |
|
978 | + $sql .= " $t1 "; |
|
979 | + } |
|
952 | 980 | } |
953 | 981 | $sql .= "*/\n"; |
954 | 982 | $sql .= $this->modifyIndexes($tablename,array($value), $execute) . "\n"; |
@@ -971,8 +999,9 @@ discard block |
||
971 | 999 | public function compareVarDefs($fielddef1, $fielddef2, $ignoreName = false) |
972 | 1000 | { |
973 | 1001 | foreach ( $fielddef1 as $key => $value ) { |
974 | - if ($key == 'name' && $ignoreName) |
|
975 | - continue; |
|
1002 | + if ($key == 'name' && $ignoreName) { |
|
1003 | + continue; |
|
1004 | + } |
|
976 | 1005 | if (isset($fielddef2[$key])) |
977 | 1006 | { |
978 | 1007 | if (!is_array($fielddef1[$key]) && !is_array($fielddef2[$key])) |
@@ -981,8 +1010,7 @@ discard block |
||
981 | 1010 | { |
982 | 1011 | continue; |
983 | 1012 | } |
984 | - } |
|
985 | - else |
|
1013 | + } else |
|
986 | 1014 | { |
987 | 1015 | if (array_map('strtolower', $fielddef1[$key]) == array_map('strtolower',$fielddef2[$key])) |
988 | 1016 | { |
@@ -991,8 +1019,9 @@ discard block |
||
991 | 1019 | } |
992 | 1020 | } |
993 | 1021 | //Ignore len if its not set in the vardef |
994 | - if ($key == 'len' && empty($fielddef2[$key])) |
|
995 | - continue; |
|
1022 | + if ($key == 'len' && empty($fielddef2[$key])) { |
|
1023 | + continue; |
|
1024 | + } |
|
996 | 1025 | // if the length in db is greather than the vardef, ignore it |
997 | 1026 | if ($key == 'len' && ($fielddef1[$key] >= $fielddef2[$key])) { |
998 | 1027 | continue; |
@@ -1026,12 +1055,10 @@ discard block |
||
1026 | 1055 | if (!$row2) { |
1027 | 1056 | // Exists on table1 but not table2 |
1028 | 1057 | $returnArray['msg'] = 'not_exists_table2'; |
1029 | - } |
|
1030 | - else { |
|
1058 | + } else { |
|
1031 | 1059 | if (sizeof($row1) != sizeof($row2)) { |
1032 | 1060 | $returnArray['msg'] = 'no_match'; |
1033 | - } |
|
1034 | - else { |
|
1061 | + } else { |
|
1035 | 1062 | $returnArray['msg'] = 'match'; |
1036 | 1063 | foreach($row1 as $key => $value){ |
1037 | 1064 | //ignore keys when checking we will check them when we do the index check |
@@ -1041,8 +1068,7 @@ discard block |
||
1041 | 1068 | } |
1042 | 1069 | } |
1043 | 1070 | } |
1044 | - } |
|
1045 | - else { |
|
1071 | + } else { |
|
1046 | 1072 | $returnArray['msg'] = 'not_exists_table1'; |
1047 | 1073 | } |
1048 | 1074 | |
@@ -1122,16 +1148,19 @@ discard block |
||
1122 | 1148 | */ |
1123 | 1149 | public function getConstraintSql($indices, $table) |
1124 | 1150 | { |
1125 | - if (!$this->isFieldArray($indices)) |
|
1126 | - $indices = array($indices); |
|
1151 | + if (!$this->isFieldArray($indices)) { |
|
1152 | + $indices = array($indices); |
|
1153 | + } |
|
1127 | 1154 | |
1128 | 1155 | $columns = array(); |
1129 | 1156 | |
1130 | 1157 | foreach ($indices as $index) { |
1131 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
1132 | - continue; |
|
1133 | - if (isset($index['source']) && $index['source'] != 'db') |
|
1134 | - continue; |
|
1158 | + if(!empty($index['db']) && $index['db'] != $this->dbType) { |
|
1159 | + continue; |
|
1160 | + } |
|
1161 | + if (isset($index['source']) && $index['source'] != 'db') { |
|
1162 | + continue; |
|
1163 | + } |
|
1135 | 1164 | |
1136 | 1165 | $sql = $this->add_drop_constraint($table, $index); |
1137 | 1166 | |
@@ -1221,11 +1250,11 @@ discard block |
||
1221 | 1250 | $sql = $this->addColumnSQL($tablename, $fieldDefs); |
1222 | 1251 | if ($this->isFieldArray($fieldDefs)){ |
1223 | 1252 | $columns = array(); |
1224 | - foreach ($fieldDefs as $fieldDef) |
|
1225 | - $columns[] = $fieldDef['name']; |
|
1253 | + foreach ($fieldDefs as $fieldDef) { |
|
1254 | + $columns[] = $fieldDef['name']; |
|
1255 | + } |
|
1226 | 1256 | $columns = implode(",", $columns); |
1227 | - } |
|
1228 | - else { |
|
1257 | + } else { |
|
1229 | 1258 | $columns = $fieldDefs['name']; |
1230 | 1259 | } |
1231 | 1260 | $msg = "Error adding column(s) $columns on table: $tablename:"; |
@@ -1249,8 +1278,7 @@ discard block |
||
1249 | 1278 | $columns[] = $fieldDef['name']; |
1250 | 1279 | } |
1251 | 1280 | $columns = implode(",", $columns); |
1252 | - } |
|
1253 | - else { |
|
1281 | + } else { |
|
1254 | 1282 | $columns = $newFieldDef['name']; |
1255 | 1283 | } |
1256 | 1284 | |
@@ -1370,7 +1398,9 @@ discard block |
||
1370 | 1398 | if(!$is_related_query){ |
1371 | 1399 | foreach ($fields as $fieldDef) |
1372 | 1400 | { |
1373 | - if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') continue; |
|
1401 | + if(isset($fieldDef['source']) && $fieldDef['source'] != 'db' && $fieldDef['source'] != 'custom_fields') { |
|
1402 | + continue; |
|
1403 | + } |
|
1374 | 1404 | $val = $row[$fieldDef['name']]; |
1375 | 1405 | |
1376 | 1406 | //handle auto increment values here only need to do this on insert not create |
@@ -1379,8 +1409,7 @@ discard block |
||
1379 | 1409 | if(!$built_columns){ |
1380 | 1410 | $columns[] = 'deleted'; |
1381 | 1411 | } |
1382 | - } |
|
1383 | - else |
|
1412 | + } else |
|
1384 | 1413 | { |
1385 | 1414 | $type = $fieldDef['type']; |
1386 | 1415 | if(!empty($fieldDef['custom_type'])){ |
@@ -1388,28 +1417,32 @@ discard block |
||
1388 | 1417 | } |
1389 | 1418 | // need to do some thing about types of values |
1390 | 1419 | if($this->dbType == 'mysql' && $val == '' && ($type == 'datetime' || $type == 'date' || $type == 'int' || $type == 'currency' || $type == 'decimal')){ |
1391 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
1392 | - $cstm_values[$fieldDef['name']] = 'null'; |
|
1393 | - else |
|
1394 | - $values[$fieldDef['name']] = 'null'; |
|
1395 | - }else{ |
|
1420 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
1421 | + $cstm_values[$fieldDef['name']] = 'null'; |
|
1422 | + } else { |
|
1423 | + $values[$fieldDef['name']] = 'null'; |
|
1424 | + } |
|
1425 | + } else{ |
|
1396 | 1426 | if(isset($type) && $type=='int') { |
1397 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
1398 | - $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
1399 | - else |
|
1400 | - $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
1427 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
1428 | + $cstm_values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
1429 | + } else { |
|
1430 | + $values[$fieldDef['name']] = $GLOBALS['db']->quote(from_html($val)); |
|
1431 | + } |
|
1401 | 1432 | } else { |
1402 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
1403 | - $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
1404 | - else |
|
1405 | - $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
1433 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
1434 | + $cstm_values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
1435 | + } else { |
|
1436 | + $values[$fieldDef['name']] = "'".$GLOBALS['db']->quote(from_html($val))."'"; |
|
1437 | + } |
|
1406 | 1438 | } |
1407 | 1439 | } |
1408 | 1440 | if(!$built_columns){ |
1409 | - if(!empty($custom_fields[$fieldDef['name']])) |
|
1410 | - $cstm_columns[] = $fieldDef['name']; |
|
1411 | - else |
|
1412 | - $columns[] = $fieldDef['name']; |
|
1441 | + if(!empty($custom_fields[$fieldDef['name']])) { |
|
1442 | + $cstm_columns[] = $fieldDef['name']; |
|
1443 | + } else { |
|
1444 | + $columns[] = $fieldDef['name']; |
|
1445 | + } |
|
1413 | 1446 | } |
1414 | 1447 | } |
1415 | 1448 | |
@@ -1624,7 +1657,9 @@ discard block |
||
1624 | 1657 | $queryresult = $this->query($sql, $dieOnError, $msg); |
1625 | 1658 | } |
1626 | 1659 | $this->checkError($msg.' Get One Failed:' . $sql, $dieOnError); |
1627 | - if (!$queryresult) return false; |
|
1660 | + if (!$queryresult) { |
|
1661 | + return false; |
|
1662 | + } |
|
1628 | 1663 | $row = $this->fetchByAssoc($queryresult); |
1629 | 1664 | if(!empty($row)) { |
1630 | 1665 | return array_shift($row); |
@@ -1648,10 +1683,14 @@ discard block |
||
1648 | 1683 | $queryresult = $this->query($sql, $dieOnError, $msg); |
1649 | 1684 | $this->checkError($msg.' Fetch One Failed:' . $sql, $dieOnError); |
1650 | 1685 | |
1651 | - if (!$queryresult) return false; |
|
1686 | + if (!$queryresult) { |
|
1687 | + return false; |
|
1688 | + } |
|
1652 | 1689 | |
1653 | 1690 | $row = $this->fetchByAssoc($queryresult); |
1654 | - if ( !$row ) return false; |
|
1691 | + if ( !$row ) { |
|
1692 | + return false; |
|
1693 | + } |
|
1655 | 1694 | |
1656 | 1695 | $this->freeResult($queryresult); |
1657 | 1696 | return $row; |
@@ -1708,13 +1747,15 @@ discard block |
||
1708 | 1747 | protected function describeField($name, $tablename) |
1709 | 1748 | { |
1710 | 1749 | $table = $this->getTableDescription($tablename); |
1711 | - if(!empty($table) && isset($table[$name])) |
|
1712 | - return $table[$name]; |
|
1750 | + if(!empty($table) && isset($table[$name])) { |
|
1751 | + return $table[$name]; |
|
1752 | + } |
|
1713 | 1753 | |
1714 | 1754 | $table = $this->getTableDescription($tablename, true); |
1715 | 1755 | |
1716 | - if(isset($table[$name])) |
|
1717 | - return $table[$name]; |
|
1756 | + if(isset($table[$name])) { |
|
1757 | + return $table[$name]; |
|
1758 | + } |
|
1718 | 1759 | |
1719 | 1760 | return array(); |
1720 | 1761 | } |
@@ -1768,11 +1809,15 @@ discard block |
||
1768 | 1809 | */ |
1769 | 1810 | public function concat($table, array $fields, $space = ' ') |
1770 | 1811 | { |
1771 | - if(empty($fields)) return ''; |
|
1812 | + if(empty($fields)) { |
|
1813 | + return ''; |
|
1814 | + } |
|
1772 | 1815 | $elems = array(); |
1773 | 1816 | $space = $this->quoted($space); |
1774 | 1817 | foreach ( $fields as $field ) { |
1775 | - if(!empty($elems)) $elems[] = $space; |
|
1818 | + if(!empty($elems)) { |
|
1819 | + $elems[] = $space; |
|
1820 | + } |
|
1776 | 1821 | $elems[] = $this->convert("$table.$field", 'IFNULL', array("''")); |
1777 | 1822 | } |
1778 | 1823 | $first = array_shift($elems); |
@@ -1864,7 +1909,7 @@ discard block |
||
1864 | 1909 | }//switch |
1865 | 1910 | }//foreach |
1866 | 1911 | return $this->query($query); |
1867 | - }else{ |
|
1912 | + } else{ |
|
1868 | 1913 | return false; |
1869 | 1914 | } |
1870 | 1915 | } |
@@ -1926,20 +1971,30 @@ discard block |
||
1926 | 1971 | $fields = $bean->getFieldDefinitions(); |
1927 | 1972 | // get column names and values |
1928 | 1973 | foreach ($fields as $field => $fieldDef) { |
1929 | - if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') continue; |
|
1974 | + if (isset($fieldDef['source']) && $fieldDef['source'] != 'db') { |
|
1975 | + continue; |
|
1976 | + } |
|
1930 | 1977 | // Do not write out the id field on the update statement. |
1931 | 1978 | // We are not allowed to change ids. |
1932 | - if ($fieldDef['name'] == $primaryField['name']) continue; |
|
1979 | + if ($fieldDef['name'] == $primaryField['name']) { |
|
1980 | + continue; |
|
1981 | + } |
|
1933 | 1982 | |
1934 | 1983 | // If the field is an auto_increment field, then we shouldn't be setting it. This was added |
1935 | 1984 | // specially for Bugs and Cases which have a number associated with them. |
1936 | - if (!empty($bean->field_name_map[$field]['auto_increment'])) continue; |
|
1985 | + if (!empty($bean->field_name_map[$field]['auto_increment'])) { |
|
1986 | + continue; |
|
1987 | + } |
|
1937 | 1988 | |
1938 | 1989 | //custom fields handle their save separately |
1939 | - if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) continue; |
|
1990 | + if(isset($bean->field_name_map) && !empty($bean->field_name_map[$field]['custom_type'])) { |
|
1991 | + continue; |
|
1992 | + } |
|
1940 | 1993 | |
1941 | 1994 | // no need to clear deleted since we only update not deleted records anyway |
1942 | - if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) continue; |
|
1995 | + if($fieldDef['name'] == 'deleted' && empty($bean->deleted)) { |
|
1996 | + continue; |
|
1997 | + } |
|
1943 | 1998 | |
1944 | 1999 | if(isset($bean->$field)) { |
1945 | 2000 | $val = from_html($bean->$field); |
@@ -1972,8 +2027,10 @@ discard block |
||
1972 | 2027 | } |
1973 | 2028 | } |
1974 | 2029 | |
1975 | - if ( sizeof($columns) == 0 ) |
|
1976 | - return ""; // no columns set |
|
2030 | + if ( sizeof($columns) == 0 ) { |
|
2031 | + return ""; |
|
2032 | + } |
|
2033 | + // no columns set |
|
1977 | 2034 | |
1978 | 2035 | // build where clause |
1979 | 2036 | $where = $this->getWhereClause($bean, $this->updateWhereArray($bean, $where)); |
@@ -2039,8 +2096,9 @@ discard block |
||
2039 | 2096 | $where[] = " $table.$name $op $val"; |
2040 | 2097 | } |
2041 | 2098 | |
2042 | - if (!empty($where)) |
|
2043 | - return implode(" AND ", $where); |
|
2099 | + if (!empty($where)) { |
|
2100 | + return implode(" AND ", $where); |
|
2101 | + } |
|
2044 | 2102 | |
2045 | 2103 | return ''; |
2046 | 2104 | } |
@@ -2144,21 +2202,25 @@ discard block |
||
2144 | 2202 | public function massageFieldDef(&$fieldDef, $tablename) |
2145 | 2203 | { |
2146 | 2204 | if ( !isset($fieldDef['dbType']) ) { |
2147 | - if ( isset($fieldDef['dbtype']) ) |
|
2148 | - $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
2149 | - else |
|
2150 | - $fieldDef['dbType'] = $fieldDef['type']; |
|
2205 | + if ( isset($fieldDef['dbtype']) ) { |
|
2206 | + $fieldDef['dbType'] = $fieldDef['dbtype']; |
|
2207 | + } else { |
|
2208 | + $fieldDef['dbType'] = $fieldDef['type']; |
|
2209 | + } |
|
2151 | 2210 | } |
2152 | 2211 | $type = $this->getColumnType($fieldDef['dbType'],$fieldDef['name'],$tablename); |
2153 | 2212 | $matches = array(); |
2154 | 2213 | // len can be a number or a string like 'max', for example, nvarchar(max) |
2155 | 2214 | preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*|\w+)\)|)/i', $type, $matches); |
2156 | - if ( isset($matches[1][0]) ) |
|
2157 | - $fieldDef['type'] = $matches[1][0]; |
|
2158 | - if ( isset($matches[2][0]) && empty($fieldDef['len']) ) |
|
2159 | - $fieldDef['len'] = $matches[2][0]; |
|
2160 | - if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) |
|
2161 | - $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
2215 | + if ( isset($matches[1][0]) ) { |
|
2216 | + $fieldDef['type'] = $matches[1][0]; |
|
2217 | + } |
|
2218 | + if ( isset($matches[2][0]) && empty($fieldDef['len']) ) { |
|
2219 | + $fieldDef['len'] = $matches[2][0]; |
|
2220 | + } |
|
2221 | + if ( !empty($fieldDef['precision']) && is_numeric($fieldDef['precision']) && !strstr($fieldDef['len'],',') ) { |
|
2222 | + $fieldDef['len'] .= ",{$fieldDef['precision']}"; |
|
2223 | + } |
|
2162 | 2224 | if (!empty($fieldDef['required']) || ($fieldDef['name'] == 'id' && !isset($fieldDef['required'])) ) { |
2163 | 2225 | $fieldDef['required'] = 'true'; |
2164 | 2226 | } |
@@ -2172,8 +2234,9 @@ discard block |
||
2172 | 2234 | public function getSelectFieldsFromQuery($selectStatement) |
2173 | 2235 | { |
2174 | 2236 | $selectStatement = trim($selectStatement); |
2175 | - if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") |
|
2176 | - $selectStatement = trim(substr($selectStatement, 6)); |
|
2237 | + if (strtoupper(substr($selectStatement, 0, 6)) == "SELECT") { |
|
2238 | + $selectStatement = trim(substr($selectStatement, 6)); |
|
2239 | + } |
|
2177 | 2240 | |
2178 | 2241 | //Due to sql functions existing in many selects, we can't use php explode |
2179 | 2242 | $fields = array(); |
@@ -2189,17 +2252,15 @@ discard block |
||
2189 | 2252 | $field = $this->getFieldNameFromSelect(trim($selectField)); |
2190 | 2253 | $fields[$field] = $selectField; |
2191 | 2254 | $selectField = ""; |
2192 | - } |
|
2193 | - else if ($char == "("){ |
|
2255 | + } else if ($char == "("){ |
|
2194 | 2256 | $level++; |
2195 | 2257 | $selectField .= $char; |
2196 | - } |
|
2197 | - else if($char == ")"){ |
|
2258 | + } else if($char == ")"){ |
|
2198 | 2259 | $level--; |
2199 | 2260 | $selectField .= $char; |
2200 | 2261 | |
2201 | 2262 | |
2202 | - }else{ |
|
2263 | + } else{ |
|
2203 | 2264 | $selectField .= $char; |
2204 | 2265 | } |
2205 | 2266 | |
@@ -2218,18 +2279,19 @@ discard block |
||
2218 | 2279 | if(strncasecmp($string, "DISTINCT ", 9) == 0) { |
2219 | 2280 | $string = substr($string, 9); |
2220 | 2281 | } |
2221 | - if (stripos($string, " as ") !== false) |
|
2222 | - //"as" used for an alias |
|
2282 | + if (stripos($string, " as ") !== false) { |
|
2283 | + //"as" used for an alias |
|
2223 | 2284 | return trim(substr($string, strripos($string, " as ") + 4)); |
2224 | - else if (strrpos($string, " ") != 0) |
|
2225 | - //Space used as a delimiter for an alias |
|
2285 | + } else if (strrpos($string, " ") != 0) { |
|
2286 | + //Space used as a delimiter for an alias |
|
2226 | 2287 | return trim(substr($string, strrpos($string, " "))); |
2227 | - else if (strpos($string, ".") !== false) |
|
2228 | - //No alias, but a table.field format was used |
|
2288 | + } else if (strpos($string, ".") !== false) { |
|
2289 | + //No alias, but a table.field format was used |
|
2229 | 2290 | return substr($string, strpos($string, ".") + 1); |
2230 | - else |
|
2231 | - //Give up and assume the whole thing is the field name |
|
2291 | + } else { |
|
2292 | + //Give up and assume the whole thing is the field name |
|
2232 | 2293 | return $string; |
2294 | + } |
|
2233 | 2295 | } |
2234 | 2296 | |
2235 | 2297 | /** |
@@ -2289,8 +2351,9 @@ discard block |
||
2289 | 2351 | $aliases[$tableName][] = $table; |
2290 | 2352 | |
2291 | 2353 | // build part of select for this table |
2292 | - if (is_array($cols[$beanID])) |
|
2293 | - foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
2354 | + if (is_array($cols[$beanID])) { |
|
2355 | + foreach ($cols[$beanID] as $def) $select[] = $table.".".$def['name']; |
|
2356 | + } |
|
2294 | 2357 | |
2295 | 2358 | // build part of where clause |
2296 | 2359 | if (is_array($whereClause[$beanID])){ |
@@ -2322,7 +2385,10 @@ discard block |
||
2322 | 2385 | $separator = ""; |
2323 | 2386 | $from = ''; $table_used_in_from = array(); |
2324 | 2387 | foreach ($relations as $table1 => $rightsidearray){ |
2325 | - if ($table_used_in_from[$table1]) continue; // table has been joined |
|
2388 | + if ($table_used_in_from[$table1]) { |
|
2389 | + continue; |
|
2390 | + } |
|
2391 | + // table has been joined |
|
2326 | 2392 | |
2327 | 2393 | $from .= $separator." ".$table1; |
2328 | 2394 | $table_used_in_from[$table1] = true; |
@@ -2333,7 +2399,9 @@ discard block |
||
2333 | 2399 | //choose first alias that does not match |
2334 | 2400 | // we are doing this because of self joins. |
2335 | 2401 | // in case of self joins, the same table will have many aliases. |
2336 | - if ($table2 != $table1) break; |
|
2402 | + if ($table2 != $table1) { |
|
2403 | + break; |
|
2404 | + } |
|
2337 | 2405 | } |
2338 | 2406 | |
2339 | 2407 | $col = $tablearray['foreingColumn']; |
@@ -2362,11 +2430,13 @@ discard block |
||
2362 | 2430 | $tablename = $bean->getTableName(); |
2363 | 2431 | $columns = array(); |
2364 | 2432 | // get column names |
2365 | - foreach ($fields as $fieldDef) |
|
2366 | - $columns[] = $fieldDef['name']; |
|
2433 | + foreach ($fields as $fieldDef) { |
|
2434 | + $columns[] = $fieldDef['name']; |
|
2435 | + } |
|
2367 | 2436 | |
2368 | - if (empty($columns)) |
|
2369 | - return ""; |
|
2437 | + if (empty($columns)) { |
|
2438 | + return ""; |
|
2439 | + } |
|
2370 | 2440 | |
2371 | 2441 | $columns = implode(",", $columns); |
2372 | 2442 | |
@@ -2386,16 +2456,21 @@ discard block |
||
2386 | 2456 | // we do not have change a lot of existing code |
2387 | 2457 | // and add dbtype where type is being used for some special |
2388 | 2458 | // purposes like referring to foreign table etc. |
2389 | - if(!empty($fieldDef['dbType'])) |
|
2390 | - return $fieldDef['dbType']; |
|
2391 | - if(!empty($fieldDef['dbtype'])) |
|
2392 | - return $fieldDef['dbtype']; |
|
2393 | - if (!empty($fieldDef['type'])) |
|
2394 | - return $fieldDef['type']; |
|
2395 | - if (!empty($fieldDef['Type'])) |
|
2396 | - return $fieldDef['Type']; |
|
2397 | - if (!empty($fieldDef['data_type'])) |
|
2398 | - return $fieldDef['data_type']; |
|
2459 | + if(!empty($fieldDef['dbType'])) { |
|
2460 | + return $fieldDef['dbType']; |
|
2461 | + } |
|
2462 | + if(!empty($fieldDef['dbtype'])) { |
|
2463 | + return $fieldDef['dbtype']; |
|
2464 | + } |
|
2465 | + if (!empty($fieldDef['type'])) { |
|
2466 | + return $fieldDef['type']; |
|
2467 | + } |
|
2468 | + if (!empty($fieldDef['Type'])) { |
|
2469 | + return $fieldDef['Type']; |
|
2470 | + } |
|
2471 | + if (!empty($fieldDef['data_type'])) { |
|
2472 | + return $fieldDef['data_type']; |
|
2473 | + } |
|
2399 | 2474 | |
2400 | 2475 | return null; |
2401 | 2476 | } |
@@ -2453,14 +2528,15 @@ discard block |
||
2453 | 2528 | 'clob', 'blob', 'text'))) { |
2454 | 2529 | $colType = "$colBaseType(${fieldDef['len']})"; |
2455 | 2530 | } elseif(($colBaseType == 'decimal' || $colBaseType == 'float')){ |
2456 | - if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) |
|
2457 | - if(strpos($fieldDef['len'],',') === false){ |
|
2531 | + if(!empty($fieldDef['precision']) && is_numeric($fieldDef['precision'])) { |
|
2532 | + if(strpos($fieldDef['len'],',') === false){ |
|
2458 | 2533 | $colType = $colBaseType . "(".$fieldDef['len'].",".$fieldDef['precision'].")"; |
2459 | - }else{ |
|
2460 | - $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
2461 | - } |
|
2462 | - else |
|
2534 | + } |
|
2535 | + } else{ |
|
2463 | 2536 | $colType = $colBaseType . "(".$fieldDef['len'].")"; |
2537 | + } else { |
|
2538 | + $colType = $colBaseType . "(".$fieldDef['len'].")"; |
|
2539 | + } |
|
2464 | 2540 | } |
2465 | 2541 | } else { |
2466 | 2542 | if (in_array($colBaseType, array( 'nvarchar', 'nchar', 'varchar', 'varchar2', 'char'))) { |
@@ -2474,19 +2550,18 @@ discard block |
||
2474 | 2550 | if (!empty($fieldDef['no_default'])) |
2475 | 2551 | { |
2476 | 2552 | // nothing to do |
2477 | - } |
|
2478 | - elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
2553 | + } elseif (isset($fieldDef['default']) && strlen($fieldDef['default']) > 0) |
|
2479 | 2554 | { |
2480 | 2555 | $default = " DEFAULT ".$this->quoted($fieldDef['default']); |
2481 | - } |
|
2482 | - elseif (!isset($default) && $type == 'bool') |
|
2556 | + } elseif (!isset($default) && $type == 'bool') |
|
2483 | 2557 | { |
2484 | 2558 | $default = " DEFAULT 0 "; |
2485 | 2559 | } |
2486 | 2560 | |
2487 | 2561 | $auto_increment = ''; |
2488 | - if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) |
|
2489 | - $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
2562 | + if(!empty($fieldDef['auto_increment']) && $fieldDef['auto_increment']) { |
|
2563 | + $auto_increment = $this->setAutoIncrement($table , $fieldDef['name']); |
|
2564 | + } |
|
2490 | 2565 | |
2491 | 2566 | $required = 'NULL'; // MySQL defaults to NULL, SQL Server defaults to NOT NULL -- must specify |
2492 | 2567 | //Starting in 6.0, only ID and auto_increment fields will be NOT NULL in the DB. |
@@ -2500,8 +2575,9 @@ discard block |
||
2500 | 2575 | && !empty($fieldDef['required'])) { |
2501 | 2576 | $required = "NOT NULL"; |
2502 | 2577 | } |
2503 | - if ($ignoreRequired) |
|
2504 | - $required = ""; |
|
2578 | + if ($ignoreRequired) { |
|
2579 | + $required = ""; |
|
2580 | + } |
|
2505 | 2581 | |
2506 | 2582 | if ( $return_as_array ) { |
2507 | 2583 | return array( |
@@ -2537,8 +2613,7 @@ discard block |
||
2537 | 2613 | } |
2538 | 2614 | } |
2539 | 2615 | $columns = implode(",", $columns); |
2540 | - } |
|
2541 | - else { |
|
2616 | + } else { |
|
2542 | 2617 | $columns = $this->oneColumnSQLRep($fieldDefs,$ignoreRequired, $tablename); |
2543 | 2618 | } |
2544 | 2619 | |
@@ -2760,8 +2835,9 @@ discard block |
||
2760 | 2835 | */ |
2761 | 2836 | public function isFieldArray($defArray) |
2762 | 2837 | { |
2763 | - if ( !is_array($defArray) ) |
|
2764 | - return false; |
|
2838 | + if ( !is_array($defArray) ) { |
|
2839 | + return false; |
|
2840 | + } |
|
2765 | 2841 | |
2766 | 2842 | if ( isset($defArray['type']) ){ |
2767 | 2843 | // type key exists. May be an array of defs or a simple definition |
@@ -2872,11 +2948,9 @@ discard block |
||
2872 | 2948 | } else { |
2873 | 2949 | if (isset($properties['dbType'])) { |
2874 | 2950 | $field_type=$properties['dbType']; |
2875 | - } |
|
2876 | - else if(isset($properties['data_type'])) { |
|
2951 | + } else if(isset($properties['data_type'])) { |
|
2877 | 2952 | $field_type=$properties['data_type']; |
2878 | - } |
|
2879 | - else { |
|
2953 | + } else { |
|
2880 | 2954 | $field_type=$properties['dbtype']; |
2881 | 2955 | } |
2882 | 2956 | } |
@@ -2901,13 +2975,11 @@ discard block |
||
2901 | 2975 | if ($error >= 0.0000000001) { // Smaller than 10E-10 |
2902 | 2976 | $change = true; |
2903 | 2977 | } |
2904 | - } |
|
2905 | - else if ($this->isBooleanType($field_type)) { |
|
2978 | + } else if ($this->isBooleanType($field_type)) { |
|
2906 | 2979 | if ($this->_getBooleanValue($before_value) != $this->_getBooleanValue($after_value)) { |
2907 | 2980 | $change = true; |
2908 | 2981 | } |
2909 | - } |
|
2910 | - else { |
|
2982 | + } else { |
|
2911 | 2983 | $change = true; |
2912 | 2984 | } |
2913 | 2985 | if ($change) { |
@@ -3005,8 +3077,9 @@ discard block |
||
3005 | 3077 | protected function _getBooleanValue($val) |
3006 | 3078 | { |
3007 | 3079 | //need to put the === sign here otherwise true == 'non empty string' |
3008 | - if (empty($val) or $val==='off') |
|
3009 | - return false; |
|
3080 | + if (empty($val) or $val==='off') { |
|
3081 | + return false; |
|
3082 | + } |
|
3010 | 3083 | |
3011 | 3084 | return true; |
3012 | 3085 | } |
@@ -3032,8 +3105,9 @@ discard block |
||
3032 | 3105 | */ |
3033 | 3106 | protected function _emptyValue($val, $type) |
3034 | 3107 | { |
3035 | - if (empty($val)) |
|
3036 | - return true; |
|
3108 | + if (empty($val)) { |
|
3109 | + return true; |
|
3110 | + } |
|
3037 | 3111 | |
3038 | 3112 | if($this->emptyValue($type) == $val) { |
3039 | 3113 | return true; |
@@ -3050,10 +3124,12 @@ discard block |
||
3050 | 3124 | case 'short': |
3051 | 3125 | return ($val == 0); |
3052 | 3126 | case 'date': |
3053 | - if ($val == '0000-00-00') |
|
3054 | - return true; |
|
3055 | - if ($val == 'NULL') |
|
3056 | - return true; |
|
3127 | + if ($val == '0000-00-00') { |
|
3128 | + return true; |
|
3129 | + } |
|
3130 | + if ($val == 'NULL') { |
|
3131 | + return true; |
|
3132 | + } |
|
3057 | 3133 | return false; |
3058 | 3134 | } |
3059 | 3135 | |
@@ -3407,7 +3483,9 @@ discard block |
||
3407 | 3483 | */ |
3408 | 3484 | public function fetchByAssoc($result, $encode = true) |
3409 | 3485 | { |
3410 | - if (empty($result)) return false; |
|
3486 | + if (empty($result)) { |
|
3487 | + return false; |
|
3488 | + } |
|
3411 | 3489 | |
3412 | 3490 | if(is_int($encode) && func_num_args() == 3) { |
3413 | 3491 | // old API: $result, $rowNum, $encode |
@@ -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,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 | } |