@@ -246,12 +246,12 @@ discard block |
||
246 | 246 | */ |
247 | 247 | private $_templateCache = array(); |
248 | 248 | |
249 | - /** |
|
250 | - * Cache built of sprite meta data |
|
251 | - * |
|
252 | - * @var array |
|
253 | - */ |
|
254 | - private $_spriteCache = array(); |
|
249 | + /** |
|
250 | + * Cache built of sprite meta data |
|
251 | + * |
|
252 | + * @var array |
|
253 | + */ |
|
254 | + private $_spriteCache = array(); |
|
255 | 255 | |
256 | 256 | /** |
257 | 257 | * Size of the caches after the are initialized in the constructor |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | 'imageCache' => 0, |
264 | 264 | 'jsCache' => 0, |
265 | 265 | 'templateCache' => 0, |
266 | - 'spriteCache' => 0, |
|
266 | + 'spriteCache' => 0, |
|
267 | 267 | ); |
268 | 268 | |
269 | 269 | /** |
@@ -329,21 +329,21 @@ discard block |
||
329 | 329 | $this->_templateCache = $caches['templateCache']; |
330 | 330 | } |
331 | 331 | $cachedfile = sugar_cached($this->getFilePath().'/spriteCache.php'); |
332 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) { |
|
333 | - $this->_spriteCache = unserialize(sugar_file_get_contents($cachedfile)); |
|
334 | - } |
|
332 | + if(!empty($GLOBALS['sugar_config']['use_sprites']) && sugar_is_file($cachedfile)) { |
|
333 | + $this->_spriteCache = unserialize(sugar_file_get_contents($cachedfile)); |
|
334 | + } |
|
335 | 335 | } |
336 | 336 | $this->_initialCacheSize = array( |
337 | 337 | 'jsCache' => count($this->_jsCache), |
338 | 338 | 'cssCache' => count($this->_cssCache), |
339 | 339 | 'imageCache' => count($this->_imageCache), |
340 | 340 | 'templateCache' => count($this->_templateCache), |
341 | - 'spriteCache' => count($this->_spriteCache), |
|
341 | + 'spriteCache' => count($this->_spriteCache), |
|
342 | 342 | ); |
343 | 343 | } |
344 | 344 | |
345 | 345 | /** |
346 | - * This is needed to prevent unserialize vulnerability |
|
346 | + * This is needed to prevent unserialize vulnerability |
|
347 | 347 | */ |
348 | 348 | public function __wakeup() |
349 | 349 | { |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | |
381 | 381 | if (is_file("$cachedir/pathCache.php")) |
382 | 382 | unlink("$cachedir/pathCache.php"); |
383 | - if (is_file("$cachedir/spriteCache.php")) |
|
384 | - unlink("$cachedir/spriteCache.php"); |
|
383 | + if (is_file("$cachedir/spriteCache.php")) |
|
384 | + unlink("$cachedir/spriteCache.php"); |
|
385 | 385 | |
386 | 386 | } |
387 | 387 | elseif ( !inDeveloperMode() ) { |
@@ -404,12 +404,12 @@ discard block |
||
404 | 404 | ); |
405 | 405 | |
406 | 406 | } |
407 | - if ( count($this->_spriteCache) != $this->_initialCacheSize['spriteCache']) { |
|
408 | - sugar_file_put_contents( |
|
409 | - "$cachedir/spriteCache.php", |
|
410 | - serialize($this->_spriteCache) |
|
411 | - ); |
|
412 | - } |
|
407 | + if ( count($this->_spriteCache) != $this->_initialCacheSize['spriteCache']) { |
|
408 | + sugar_file_put_contents( |
|
409 | + "$cachedir/spriteCache.php", |
|
410 | + serialize($this->_spriteCache) |
|
411 | + ); |
|
412 | + } |
|
413 | 413 | } |
414 | 414 | } |
415 | 415 | |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | } |
439 | 439 | |
440 | 440 | public function __isset($key){ |
441 | - return isset($this->$key); |
|
441 | + return isset($this->$key); |
|
442 | 442 | |
443 | 443 | } |
444 | 444 | |
@@ -603,27 +603,27 @@ discard block |
||
603 | 603 | $html .= '<link rel="stylesheet" type="text/css" href="'.$this->getCSSURL('style.css').'" />'; |
604 | 604 | |
605 | 605 | |
606 | - // sprites |
|
607 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
606 | + // sprites |
|
607 | + if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
608 | 608 | |
609 | - // 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').'" />'; |
|
609 | + // 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').'" />'; |
|
612 | 612 | |
613 | - // 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').'" />'; |
|
613 | + // 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').'" />'; |
|
616 | 616 | |
617 | - // parent sprites |
|
618 | - 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').'" />'; |
|
621 | - } |
|
617 | + // parent sprites |
|
618 | + 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').'" />'; |
|
621 | + } |
|
622 | 622 | |
623 | - // 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').'" />'; |
|
626 | - } |
|
623 | + // 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').'" />'; |
|
626 | + } |
|
627 | 627 | |
628 | 628 | // for BC during upgrade |
629 | 629 | if ( !empty($this->colors) ) { |
@@ -700,180 +700,180 @@ discard block |
||
700 | 700 | * |
701 | 701 | * @param string $image image name |
702 | 702 | * @param string $other_attributes optional, other attributes to add to the image tag, not cached |
703 | - * @param string $width optional, defaults to the actual image's width |
|
704 | - * @param string $height optional, defaults to the actual image's height |
|
705 | - * @param string $ext optional, image extension (TODO can we deprecate this one ?) |
|
703 | + * @param string $width optional, defaults to the actual image's width |
|
704 | + * @param string $height optional, defaults to the actual image's height |
|
705 | + * @param string $ext optional, image extension (TODO can we deprecate this one ?) |
|
706 | 706 | * @param string $alt optional, only used when image contains something useful, i.e. "Sally's profile pic" |
707 | 707 | * @return string HTML image tag or sprite |
708 | 708 | */ |
709 | 709 | public function getImage( |
710 | 710 | $imageName, |
711 | 711 | $other_attributes = '', |
712 | - $width = null, |
|
713 | - $height = null, |
|
714 | - $ext = null, |
|
712 | + $width = null, |
|
713 | + $height = null, |
|
714 | + $ext = null, |
|
715 | 715 | $alt = '' |
716 | 716 | ) |
717 | 717 | { |
718 | 718 | |
719 | 719 | static $cached_results = array(); |
720 | 720 | |
721 | - // trap deprecated use of image extension |
|
722 | - if(is_null($ext)) { |
|
723 | - $imageNameExp = explode('.',$imageName); |
|
724 | - if(count($imageNameExp) == 1) |
|
725 | - $imageName .= '.gif'; |
|
726 | - } else { |
|
727 | - $imageName .= $ext; |
|
728 | - } |
|
729 | - |
|
730 | - // trap alt attributes in other_attributes |
|
731 | - if(preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) |
|
732 | - $GLOBALS['log']->debug("Sprites: alt attribute detected for $imageName"); |
|
733 | - // sprite handler, makes use of own caching mechanism |
|
734 | - if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
735 | - // get sprite metadata |
|
736 | - if($sp = $this->getSpriteMeta($imageName)) { |
|
737 | - // requested size should match |
|
738 | - if( (!is_null($width) && $sp['width'] == $width) || (is_null($width)) && |
|
739 | - (!is_null($height) && $sp['height'] == $height) || (is_null($height)) ) |
|
740 | - { |
|
721 | + // trap deprecated use of image extension |
|
722 | + if(is_null($ext)) { |
|
723 | + $imageNameExp = explode('.',$imageName); |
|
724 | + if(count($imageNameExp) == 1) |
|
725 | + $imageName .= '.gif'; |
|
726 | + } else { |
|
727 | + $imageName .= $ext; |
|
728 | + } |
|
729 | + |
|
730 | + // trap alt attributes in other_attributes |
|
731 | + if(preg_match('/alt=["\']([^\'"]+)["\']/i', $other_attributes)) |
|
732 | + $GLOBALS['log']->debug("Sprites: alt attribute detected for $imageName"); |
|
733 | + // sprite handler, makes use of own caching mechanism |
|
734 | + if(!empty($GLOBALS['sugar_config']['use_sprites']) && $GLOBALS['sugar_config']['use_sprites']) { |
|
735 | + // get sprite metadata |
|
736 | + if($sp = $this->getSpriteMeta($imageName)) { |
|
737 | + // requested size should match |
|
738 | + if( (!is_null($width) && $sp['width'] == $width) || (is_null($width)) && |
|
739 | + (!is_null($height) && $sp['height'] == $height) || (is_null($height)) ) |
|
740 | + { |
|
741 | 741 | $other_attributes .= ' data-orig="'.$imageName.'"'; |
742 | 742 | |
743 | - if($sprite = $this->getSprite($sp['class'], $other_attributes, $alt)) |
|
744 | - { |
|
745 | - return $sprite; |
|
746 | - } |
|
747 | - } |
|
748 | - } |
|
749 | - } |
|
750 | - |
|
751 | - // img caching |
|
752 | - if(empty($cached_results[$imageName])) { |
|
753 | - $imageURL = $this->getImageURL($imageName,false); |
|
754 | - if ( empty($imageURL) ) |
|
755 | - return false; |
|
743 | + if($sprite = $this->getSprite($sp['class'], $other_attributes, $alt)) |
|
744 | + { |
|
745 | + return $sprite; |
|
746 | + } |
|
747 | + } |
|
748 | + } |
|
749 | + } |
|
750 | + |
|
751 | + // img caching |
|
752 | + if(empty($cached_results[$imageName])) { |
|
753 | + $imageURL = $this->getImageURL($imageName,false); |
|
754 | + if ( empty($imageURL) ) |
|
755 | + return false; |
|
756 | 756 | if(strpos($imageURL, '.svg', strlen($imageURL)-4)){ |
757 | 757 | $cached_results[$imageName] = file_get_contents($imageURL); |
758 | 758 | } else { |
759 | 759 | $cached_results[$imageName] = '<img src="'.getJSPath($imageURL).'" '; |
760 | 760 | } |
761 | 761 | |
762 | - } |
|
762 | + } |
|
763 | 763 | |
764 | - $attr_width = (is_null($width)) ? "" : "width=\"$width\""; |
|
765 | - $attr_height = (is_null($height)) ? "" : "height=\"$height\""; |
|
764 | + $attr_width = (is_null($width)) ? "" : "width=\"$width\""; |
|
765 | + $attr_height = (is_null($height)) ? "" : "height=\"$height\""; |
|
766 | 766 | |
767 | 767 | if(strpos($cached_results[$imageName], 'svg') !== false){ |
768 | 768 | return $cached_results[$imageName]; |
769 | 769 | } |
770 | - return $cached_results[$imageName] . " $attr_width $attr_height $other_attributes alt=\"$alt\" />"; |
|
770 | + return $cached_results[$imageName] . " $attr_width $attr_height $other_attributes alt=\"$alt\" />"; |
|
771 | + } |
|
772 | + |
|
773 | + /** |
|
774 | + * Returns sprite meta data |
|
775 | + * |
|
776 | + * @param string $imageName Image filename including extension |
|
777 | + * @return array Sprite meta data |
|
778 | + */ |
|
779 | + public function getSpriteMeta($imageName) { |
|
780 | + |
|
781 | + // return from cache |
|
782 | + if(isset($this->_spriteCache[$imageName])) |
|
783 | + return $this->_spriteCache[$imageName]; |
|
784 | + |
|
785 | + // sprite keys are base on imageURL |
|
786 | + $imageURL = $this->getImageURL($imageName,false); |
|
787 | + if(empty($imageURL)) { |
|
788 | + $this->_spriteCache[$imageName] = false; |
|
789 | + return false; |
|
790 | + } |
|
791 | + |
|
792 | + // load meta data, includes default images |
|
793 | + require_once("include/SugarTheme/SugarSprites.php"); |
|
794 | + $meta = SugarSprites::getInstance(); |
|
795 | + // add current theme dir |
|
796 | + $meta->loadSpriteMeta($this->dirName); |
|
797 | + // add parent theme dir |
|
798 | + if($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
799 | + $meta->loadSpriteMeta($parent->dirName); |
|
800 | + } |
|
801 | + |
|
802 | + // add to cache |
|
803 | + if(isset($meta->sprites[$imageURL])) { |
|
804 | + $this->_spriteCache[$imageName] = $meta->sprites[$imageURL]; |
|
805 | + // add imageURL to cache |
|
806 | + //$this->_spriteCache[$imageName]['imageURL'] = $imageURL; |
|
807 | + } else { |
|
808 | + $this->_spriteCache[$imageName] = false; |
|
809 | + $GLOBALS['log']->debug("Sprites: miss for $imageURL"); |
|
810 | + } |
|
811 | + return $this->_spriteCache[$imageName]; |
|
812 | + } |
|
813 | + |
|
814 | + /** |
|
815 | + * Returns sprite HTML span tag |
|
816 | + * |
|
817 | + * @param string class The md5 id used in the CSS sprites class |
|
818 | + * @param string attr optional, list of additional html attributes |
|
819 | + * @param string title optional, the title (equivalent to alt on img) |
|
820 | + * @return string HTML span tag |
|
821 | + */ |
|
822 | + public function getSprite($class, $attr, $title) { |
|
823 | + |
|
824 | + // handle multiple class tags |
|
825 | + $class_regex = '/class=["\']([^\'"]+)["\']/i'; |
|
826 | + preg_match($class_regex, $attr, $match); |
|
827 | + if(isset($match[1])) { |
|
828 | + $attr = preg_replace($class_regex, 'class="spr_'.$class.' ${1}"', $attr); |
|
829 | + |
|
830 | + // single class |
|
831 | + } else { |
|
832 | + $attr .= ' class="spr_'.$class.'"'; |
|
833 | + } |
|
834 | + |
|
835 | + if($title) |
|
836 | + $attr .= ' title="'.$title.'"'; |
|
837 | + |
|
838 | + // use </span> instead of /> to prevent weird UI results |
|
839 | + $GLOBALS['log']->debug("Sprites: generated sprite -> $attr"); |
|
840 | + return "<span {$attr}></span>"; |
|
771 | 841 | } |
772 | 842 | |
773 | - /** |
|
774 | - * Returns sprite meta data |
|
775 | - * |
|
776 | - * @param string $imageName Image filename including extension |
|
777 | - * @return array Sprite meta data |
|
778 | - */ |
|
779 | - public function getSpriteMeta($imageName) { |
|
780 | - |
|
781 | - // return from cache |
|
782 | - if(isset($this->_spriteCache[$imageName])) |
|
783 | - return $this->_spriteCache[$imageName]; |
|
784 | - |
|
785 | - // sprite keys are base on imageURL |
|
786 | - $imageURL = $this->getImageURL($imageName,false); |
|
787 | - if(empty($imageURL)) { |
|
788 | - $this->_spriteCache[$imageName] = false; |
|
789 | - return false; |
|
790 | - } |
|
791 | - |
|
792 | - // load meta data, includes default images |
|
793 | - require_once("include/SugarTheme/SugarSprites.php"); |
|
794 | - $meta = SugarSprites::getInstance(); |
|
795 | - // add current theme dir |
|
796 | - $meta->loadSpriteMeta($this->dirName); |
|
797 | - // add parent theme dir |
|
798 | - if($this->parentTheme && $parent = SugarThemeRegistry::get($this->parentTheme)) { |
|
799 | - $meta->loadSpriteMeta($parent->dirName); |
|
800 | - } |
|
801 | - |
|
802 | - // add to cache |
|
803 | - if(isset($meta->sprites[$imageURL])) { |
|
804 | - $this->_spriteCache[$imageName] = $meta->sprites[$imageURL]; |
|
805 | - // add imageURL to cache |
|
806 | - //$this->_spriteCache[$imageName]['imageURL'] = $imageURL; |
|
807 | - } else { |
|
808 | - $this->_spriteCache[$imageName] = false; |
|
809 | - $GLOBALS['log']->debug("Sprites: miss for $imageURL"); |
|
810 | - } |
|
811 | - return $this->_spriteCache[$imageName]; |
|
812 | - } |
|
813 | - |
|
814 | - /** |
|
815 | - * Returns sprite HTML span tag |
|
816 | - * |
|
817 | - * @param string class The md5 id used in the CSS sprites class |
|
818 | - * @param string attr optional, list of additional html attributes |
|
819 | - * @param string title optional, the title (equivalent to alt on img) |
|
820 | - * @return string HTML span tag |
|
821 | - */ |
|
822 | - public function getSprite($class, $attr, $title) { |
|
823 | - |
|
824 | - // handle multiple class tags |
|
825 | - $class_regex = '/class=["\']([^\'"]+)["\']/i'; |
|
826 | - preg_match($class_regex, $attr, $match); |
|
827 | - if(isset($match[1])) { |
|
828 | - $attr = preg_replace($class_regex, 'class="spr_'.$class.' ${1}"', $attr); |
|
829 | - |
|
830 | - // single class |
|
831 | - } else { |
|
832 | - $attr .= ' class="spr_'.$class.'"'; |
|
833 | - } |
|
834 | - |
|
835 | - if($title) |
|
836 | - $attr .= ' title="'.$title.'"'; |
|
837 | - |
|
838 | - // use </span> instead of /> to prevent weird UI results |
|
839 | - $GLOBALS['log']->debug("Sprites: generated sprite -> $attr"); |
|
840 | - return "<span {$attr}></span>"; |
|
841 | - } |
|
842 | - |
|
843 | - /** |
|
844 | - * Returns a link HTML tag with or without an embedded image |
|
845 | - */ |
|
843 | + /** |
|
844 | + * Returns a link HTML tag with or without an embedded image |
|
845 | + */ |
|
846 | 846 | public function getLink( |
847 | - $url, |
|
848 | - $title, |
|
849 | - $other_attributes = '', |
|
847 | + $url, |
|
848 | + $title, |
|
849 | + $other_attributes = '', |
|
850 | 850 | $img_name = '', |
851 | 851 | $img_other_attributes = '', |
852 | - $img_width = null, |
|
853 | - $img_height = null, |
|
854 | - $img_alt = '', |
|
855 | - $img_placement = 'imageonly' |
|
852 | + $img_width = null, |
|
853 | + $img_height = null, |
|
854 | + $img_alt = '', |
|
855 | + $img_placement = 'imageonly' |
|
856 | 856 | ) |
857 | 857 | { |
858 | 858 | |
859 | - if($img_name) { |
|
860 | - $img = $this->getImage($img_name, $img_other_attributes, $img_width, $img_height, null, $img_alt); |
|
861 | - if($img == false) { |
|
862 | - $GLOBALS['log']->debug('Sprites: unknown image getLink'); |
|
863 | - $img = 'unknown'; |
|
864 | - } |
|
865 | - switch($img_placement) { |
|
866 | - case 'left': $inner_html = $img."<span class='title'>".$title."</span>"; break; |
|
867 | - case 'right': $inner_html = "<span class='title'>".$title."</span>".$img; break; |
|
868 | - default: $inner_html = $img; break; |
|
869 | - } |
|
870 | - } else { |
|
871 | - $inner_html = $title; |
|
872 | - } |
|
859 | + if($img_name) { |
|
860 | + $img = $this->getImage($img_name, $img_other_attributes, $img_width, $img_height, null, $img_alt); |
|
861 | + if($img == false) { |
|
862 | + $GLOBALS['log']->debug('Sprites: unknown image getLink'); |
|
863 | + $img = 'unknown'; |
|
864 | + } |
|
865 | + switch($img_placement) { |
|
866 | + case 'left': $inner_html = $img."<span class='title'>".$title."</span>"; break; |
|
867 | + case 'right': $inner_html = "<span class='title'>".$title."</span>".$img; break; |
|
868 | + default: $inner_html = $img; break; |
|
869 | + } |
|
870 | + } else { |
|
871 | + $inner_html = $title; |
|
872 | + } |
|
873 | 873 | |
874 | - return '<a href="'.$url.'" title="'.$title.'" '.$other_attributes.'>'.$inner_html.'</a>'; |
|
874 | + return '<a href="'.$url.'" title="'.$title.'" '.$other_attributes.'>'.$inner_html.'</a>'; |
|
875 | 875 | |
876 | - } |
|
876 | + } |
|
877 | 877 | |
878 | 878 | /** |
879 | 879 | * Returns the URL for an image in the current theme. If not found in the current theme, will revert |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | $imagePath = $filename; |
906 | 906 | elseif (($filename = $this->_getImageFileName($this->getDefaultImagePath().'/'.$imageName)) != '') |
907 | 907 | $imagePath = $filename; |
908 | - elseif (($filename = $this->_getImageFileName('include/images/'.$imageName)) != '') |
|
909 | - $imagePath = $filename; |
|
908 | + elseif (($filename = $this->_getImageFileName('include/images/'.$imageName)) != '') |
|
909 | + $imagePath = $filename; |
|
910 | 910 | else { |
911 | 911 | $GLOBALS['log']->warn("Image $imageName not found"); |
912 | 912 | return false; |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | if (isset($this->parentTheme) |
1041 | 1041 | && SugarThemeRegistry::get($this->parentTheme) instanceOf SugarTheme |
1042 | 1042 | && ($filename = SugarThemeRegistry::get($this->parentTheme)->getJSURL($jsFileName,false)) != '' && !in_array($jsFileName,$this->ignoreParentFiles)) { |
1043 | - $jsFileContents .= file_get_contents($filename); |
|
1044 | - } else { |
|
1043 | + $jsFileContents .= file_get_contents($filename); |
|
1044 | + } else { |
|
1045 | 1045 | if (sugar_is_file($defaultFileName)) |
1046 | 1046 | $jsFileContents .= file_get_contents($defaultFileName); |
1047 | 1047 | if (sugar_is_file('custom/'.$defaultFileName)) |
@@ -44,226 +44,226 @@ discard block |
||
44 | 44 | class LanguageManager |
45 | 45 | { |
46 | 46 | |
47 | - /** |
|
48 | - * Called from VardefManager to allow for caching a lang file for a module |
|
49 | - * @param module - the name of the module we are working with |
|
50 | - * @param templates - an array of templates this module uses |
|
51 | - */ |
|
52 | - static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
53 | - global $mod_strings, $current_language; |
|
54 | - if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
55 | - $refresh = true; |
|
56 | - } |
|
57 | - $temp_mod_strings = $mod_strings; |
|
58 | - $lang = $current_language; |
|
47 | + /** |
|
48 | + * Called from VardefManager to allow for caching a lang file for a module |
|
49 | + * @param module - the name of the module we are working with |
|
50 | + * @param templates - an array of templates this module uses |
|
51 | + */ |
|
52 | + static function createLanguageFile($module , $templates=array('default'), $refresh = false){ |
|
53 | + global $mod_strings, $current_language; |
|
54 | + if(inDeveloperMode() || !empty($_SESSION['developerMode'])){ |
|
55 | + $refresh = true; |
|
56 | + } |
|
57 | + $temp_mod_strings = $mod_strings; |
|
58 | + $lang = $current_language; |
|
59 | 59 | if(empty($lang)) |
60 | 60 | $lang = $GLOBALS['sugar_config']['default_language']; |
61 | - static $createdModules = array(); |
|
62 | - if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
63 | - $loaded_mod_strings = array(); |
|
64 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
65 | - $createdModules[$module] = true; |
|
66 | - LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
67 | - } |
|
68 | - } |
|
61 | + static $createdModules = array(); |
|
62 | + if(empty($createdModules[$module]) && ($refresh || !file_exists(sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'))){ |
|
63 | + $loaded_mod_strings = array(); |
|
64 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
65 | + $createdModules[$module] = true; |
|
66 | + LanguageManager::refreshLanguage($module,$lang, $loaded_mod_strings); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Load the module tempalte lauguage files |
|
72 | - * @param module - the name of the module we are working with |
|
73 | - * @param templates - an array of templates this module uses |
|
74 | - * @param lang - current language this module use |
|
75 | - * @param loaded_mod_strings - the string that we will add the module template language into |
|
76 | - */ |
|
77 | - static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
78 | - $templates = array_reverse($templates); |
|
79 | - foreach($templates as $template){ |
|
80 | - $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
81 | - $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
|
82 | - } |
|
83 | - return $loaded_mod_strings; |
|
84 | - } |
|
70 | + /** |
|
71 | + * Load the module tempalte lauguage files |
|
72 | + * @param module - the name of the module we are working with |
|
73 | + * @param templates - an array of templates this module uses |
|
74 | + * @param lang - current language this module use |
|
75 | + * @param loaded_mod_strings - the string that we will add the module template language into |
|
76 | + */ |
|
77 | + static function loadTemplateLanguage($module , $templates , $lang, $loaded_mod_strings){ |
|
78 | + $templates = array_reverse($templates); |
|
79 | + foreach($templates as $template){ |
|
80 | + $temp = LanguageManager::addTemplate($module,$lang, $template); |
|
81 | + $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $temp); |
|
82 | + } |
|
83 | + return $loaded_mod_strings; |
|
84 | + } |
|
85 | 85 | |
86 | - static function addTemplate($module, $lang, $template){ |
|
87 | - if($template == 'default')$template = 'basic'; |
|
88 | - $templates = array(); |
|
89 | - $fields = array(); |
|
90 | - if(empty($templates[$template])){ |
|
91 | - $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | - if(file_exists($path)){ |
|
93 | - require($path); |
|
94 | - $templates[$template] = $mod_strings; |
|
95 | - }else{ |
|
96 | - $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | - if(file_exists($path)){ |
|
98 | - require($path); |
|
99 | - $templates[$template] = $mod_strings; |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - if(!empty($templates[$template])){ |
|
104 | - return $templates[$template]; |
|
105 | - } |
|
106 | - } |
|
86 | + static function addTemplate($module, $lang, $template){ |
|
87 | + if($template == 'default')$template = 'basic'; |
|
88 | + $templates = array(); |
|
89 | + $fields = array(); |
|
90 | + if(empty($templates[$template])){ |
|
91 | + $path = 'include/SugarObjects/templates/' . $template . '/language/'.$lang.'.lang.php'; |
|
92 | + if(file_exists($path)){ |
|
93 | + require($path); |
|
94 | + $templates[$template] = $mod_strings; |
|
95 | + }else{ |
|
96 | + $path = 'include/SugarObjects/implements/' . $template . '/language/'.$lang.'.lang.php'; |
|
97 | + if(file_exists($path)){ |
|
98 | + require($path); |
|
99 | + $templates[$template] = $mod_strings; |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + if(!empty($templates[$template])){ |
|
104 | + return $templates[$template]; |
|
105 | + } |
|
106 | + } |
|
107 | 107 | |
108 | - static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | - if(empty($lang)) |
|
110 | - $lang = $GLOBALS['sugar_config']['default_language']; |
|
108 | + static function saveCache($module,$lang, $loaded_mod_strings, $additonal_objects= array()){ |
|
109 | + if(empty($lang)) |
|
110 | + $lang = $GLOBALS['sugar_config']['default_language']; |
|
111 | 111 | |
112 | - $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | - write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
114 | - include($file); |
|
112 | + $file = create_cache_directory('modules/' . $module . '/language/'.$lang.'.lang.php'); |
|
113 | + write_array_to_file('mod_strings',$loaded_mod_strings, $file); |
|
114 | + include($file); |
|
115 | 115 | |
116 | - // put the item in the sugar cache. |
|
117 | - $key = self::getLanguageCacheKey($module,$lang); |
|
118 | - sugar_cache_put($key,$loaded_mod_strings); |
|
119 | - } |
|
116 | + // put the item in the sugar cache. |
|
117 | + $key = self::getLanguageCacheKey($module,$lang); |
|
118 | + sugar_cache_put($key,$loaded_mod_strings); |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * clear out the language cache. |
|
123 | - * @param string module_dir the module_dir to clear, if not specified then clear |
|
124 | - * clear language cache for all modules. |
|
125 | - * @param string lang the name of the object we are clearing this is for sugar_cache |
|
126 | - */ |
|
127 | - static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | - if(empty($lang)) { |
|
129 | - $languages = array_keys($GLOBALS['sugar_config']['languages']); |
|
130 | - } else { |
|
131 | - $languages = array($lang); |
|
132 | - } |
|
133 | - //if we have a module name specified then just remove that language file |
|
134 | - //otherwise go through each module and clean up the language |
|
135 | - if(!empty($module_dir)) { |
|
136 | - foreach($languages as $clean_lang) { |
|
137 | - LanguageManager::_clearCache($module_dir, $clean_lang); |
|
138 | - } |
|
139 | - } else { |
|
140 | - $cache_dir = sugar_cached('modules/'); |
|
141 | - if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | - while(($entry = readdir($dir)) !== false) { |
|
143 | - if ($entry == "." || $entry == "..") continue; |
|
144 | - foreach($languages as $clean_lang) { |
|
145 | - LanguageManager::_clearCache($entry, $clean_lang); |
|
146 | - } |
|
147 | - } |
|
148 | - closedir($dir); |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
121 | + /** |
|
122 | + * clear out the language cache. |
|
123 | + * @param string module_dir the module_dir to clear, if not specified then clear |
|
124 | + * clear language cache for all modules. |
|
125 | + * @param string lang the name of the object we are clearing this is for sugar_cache |
|
126 | + */ |
|
127 | + static function clearLanguageCache($module_dir = '', $lang = ''){ |
|
128 | + if(empty($lang)) { |
|
129 | + $languages = array_keys($GLOBALS['sugar_config']['languages']); |
|
130 | + } else { |
|
131 | + $languages = array($lang); |
|
132 | + } |
|
133 | + //if we have a module name specified then just remove that language file |
|
134 | + //otherwise go through each module and clean up the language |
|
135 | + if(!empty($module_dir)) { |
|
136 | + foreach($languages as $clean_lang) { |
|
137 | + LanguageManager::_clearCache($module_dir, $clean_lang); |
|
138 | + } |
|
139 | + } else { |
|
140 | + $cache_dir = sugar_cached('modules/'); |
|
141 | + if(file_exists($cache_dir) && $dir = @opendir($cache_dir)) { |
|
142 | + while(($entry = readdir($dir)) !== false) { |
|
143 | + if ($entry == "." || $entry == "..") continue; |
|
144 | + foreach($languages as $clean_lang) { |
|
145 | + LanguageManager::_clearCache($entry, $clean_lang); |
|
146 | + } |
|
147 | + } |
|
148 | + closedir($dir); |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | 152 | |
153 | - /** |
|
154 | - * PRIVATE function used within clearLanguageCache so we do not repeat logic |
|
155 | - * @param string module_dir the module_dir to clear |
|
156 | - * @param string lang the name of the language file we are clearing this is for sugar_cache |
|
157 | - */ |
|
158 | - static function _clearCache($module_dir = '', $lang){ |
|
159 | - if(!empty($module_dir) && !empty($lang)){ |
|
160 | - $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
|
161 | - if(file_exists($file)){ |
|
162 | - unlink($file); |
|
163 | - $key = self::getLanguageCacheKey($module_dir,$lang); |
|
164 | - sugar_cache_clear($key); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
153 | + /** |
|
154 | + * PRIVATE function used within clearLanguageCache so we do not repeat logic |
|
155 | + * @param string module_dir the module_dir to clear |
|
156 | + * @param string lang the name of the language file we are clearing this is for sugar_cache |
|
157 | + */ |
|
158 | + static function _clearCache($module_dir = '', $lang){ |
|
159 | + if(!empty($module_dir) && !empty($lang)){ |
|
160 | + $file = sugar_cached('modules/').$module_dir.'/language/'.$lang.'.lang.php'; |
|
161 | + if(file_exists($file)){ |
|
162 | + unlink($file); |
|
163 | + $key = self::getLanguageCacheKey($module_dir,$lang); |
|
164 | + sugar_cache_clear($key); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Given a module, search all of the specified locations, and any others as specified |
|
171 | - * in order to refresh the cache file |
|
172 | - * |
|
173 | - * @param string $module the given module we want to load the vardefs for |
|
174 | - * @param string $lang the given language we wish to load |
|
175 | - * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
|
176 | - */ |
|
177 | - static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
178 | - // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
179 | - $lang_paths = array( |
|
180 | - 'modules/'.$module.'/language/'.$lang.'.lang.php', |
|
181 | - 'modules/'.$module.'/language/'.$lang.'.lang.override.php', |
|
182 | - 'custom/modules/'.$module.'/language/'.$lang.'.lang.php', |
|
183 | - 'custom/modules/'.$module.'/Ext/Language/'.$lang.'.lang.ext.php', |
|
184 | - ); |
|
169 | + /** |
|
170 | + * Given a module, search all of the specified locations, and any others as specified |
|
171 | + * in order to refresh the cache file |
|
172 | + * |
|
173 | + * @param string $module the given module we want to load the vardefs for |
|
174 | + * @param string $lang the given language we wish to load |
|
175 | + * @param array $additional_search_paths an array which allows a consumer to pass in additional vardef locations to search |
|
176 | + */ |
|
177 | + static function refreshLanguage($module, $lang, $loaded_mod_strings = array(), $additional_search_paths = null){ |
|
178 | + // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
179 | + $lang_paths = array( |
|
180 | + 'modules/'.$module.'/language/'.$lang.'.lang.php', |
|
181 | + 'modules/'.$module.'/language/'.$lang.'.lang.override.php', |
|
182 | + 'custom/modules/'.$module.'/language/'.$lang.'.lang.php', |
|
183 | + 'custom/modules/'.$module.'/Ext/Language/'.$lang.'.lang.ext.php', |
|
184 | + ); |
|
185 | 185 | |
186 | - #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
|
187 | - static $createdModules; |
|
188 | - if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
189 | - $object = $GLOBALS['beanList'][$module]; |
|
186 | + #27023, if this module template language file was not attached , get the template from this module vardef cache file if exsits and load the template language files. |
|
187 | + static $createdModules; |
|
188 | + if(empty($createdModules[$module]) && isset($GLOBALS['beanList'][$module])){ |
|
189 | + $object = $GLOBALS['beanList'][$module]; |
|
190 | 190 | |
191 | - if ($object == 'aCase') |
|
192 | - $object = 'Case'; |
|
191 | + if ($object == 'aCase') |
|
192 | + $object = 'Case'; |
|
193 | 193 | |
194 | - if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
195 | - $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
|
196 | - $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
197 | - $createdModules[$module] = true; |
|
198 | - } |
|
199 | - } |
|
200 | - //end of fix #27023 |
|
194 | + if(!empty($GLOBALS["dictionary"]["$object"]["templates"])){ |
|
195 | + $templates = $GLOBALS["dictionary"]["$object"]["templates"]; |
|
196 | + $loaded_mod_strings = LanguageManager::loadTemplateLanguage($module , $templates, $lang , $loaded_mod_strings); |
|
197 | + $createdModules[$module] = true; |
|
198 | + } |
|
199 | + } |
|
200 | + //end of fix #27023 |
|
201 | 201 | |
202 | - // Add in additional search paths if they were provided. |
|
203 | - if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | - { |
|
205 | - $lang_paths = array_merge($lang_paths, $additional_search_paths); |
|
206 | - } |
|
202 | + // Add in additional search paths if they were provided. |
|
203 | + if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
|
204 | + { |
|
205 | + $lang_paths = array_merge($lang_paths, $additional_search_paths); |
|
206 | + } |
|
207 | 207 | |
208 | - //search a predefined set of locations for the vardef files |
|
209 | - foreach($lang_paths as $path){ |
|
210 | - if(file_exists($path)){ |
|
211 | - require($path); |
|
212 | - if(!empty($mod_strings)){ |
|
213 | - if (function_exists('sugarArrayMergeRecursive')){ |
|
214 | - $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
|
215 | - } |
|
216 | - else{ |
|
217 | - $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - } |
|
208 | + //search a predefined set of locations for the vardef files |
|
209 | + foreach($lang_paths as $path){ |
|
210 | + if(file_exists($path)){ |
|
211 | + require($path); |
|
212 | + if(!empty($mod_strings)){ |
|
213 | + if (function_exists('sugarArrayMergeRecursive')){ |
|
214 | + $loaded_mod_strings = sugarArrayMergeRecursive($loaded_mod_strings, $mod_strings); |
|
215 | + } |
|
216 | + else{ |
|
217 | + $loaded_mod_strings = sugarLangArrayMerge($loaded_mod_strings, $mod_strings); |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + } |
|
222 | 222 | |
223 | - //great! now that we have loaded all of our vardefs. |
|
224 | - //let's go save them to the cache file. |
|
225 | - if(!empty($loaded_mod_strings)) |
|
226 | - LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
227 | - } |
|
223 | + //great! now that we have loaded all of our vardefs. |
|
224 | + //let's go save them to the cache file. |
|
225 | + if(!empty($loaded_mod_strings)) |
|
226 | + LanguageManager::saveCache($module, $lang, $loaded_mod_strings); |
|
227 | + } |
|
228 | 228 | |
229 | - static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
230 | - //here check if the cache file exists, if it does then load it, if it doesn't |
|
231 | - //then call refreshVardef |
|
232 | - //if either our session or the system is set to developerMode then refresh is set to true |
|
229 | + static function loadModuleLanguage($module, $lang, $refresh=false){ |
|
230 | + //here check if the cache file exists, if it does then load it, if it doesn't |
|
231 | + //then call refreshVardef |
|
232 | + //if either our session or the system is set to developerMode then refresh is set to true |
|
233 | 233 | |
234 | - // Retrieve the vardefs from cache. |
|
235 | - $key = self::getLanguageCacheKey($module,$lang); |
|
234 | + // Retrieve the vardefs from cache. |
|
235 | + $key = self::getLanguageCacheKey($module,$lang); |
|
236 | 236 | |
237 | - if(!$refresh) |
|
238 | - { |
|
239 | - $return_result = sugar_cache_retrieve($key); |
|
240 | - if(!empty($return_result) && is_array($return_result)){ |
|
241 | - return $return_result; |
|
242 | - } |
|
243 | - } |
|
237 | + if(!$refresh) |
|
238 | + { |
|
239 | + $return_result = sugar_cache_retrieve($key); |
|
240 | + if(!empty($return_result) && is_array($return_result)){ |
|
241 | + return $return_result; |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
246 | - $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
|
247 | - if($refresh || !file_exists($cachedfile)){ |
|
248 | - LanguageManager::refreshLanguage($module, $lang); |
|
249 | - } |
|
245 | + // Some of the vardefs do not correctly define dictionary as global. Declare it first. |
|
246 | + $cachedfile = sugar_cached('modules/').$module.'/language/'.$lang.'.lang.php'; |
|
247 | + if($refresh || !file_exists($cachedfile)){ |
|
248 | + LanguageManager::refreshLanguage($module, $lang); |
|
249 | + } |
|
250 | 250 | |
251 | - //at this point we should have the cache/modules/... file |
|
252 | - //which was created from the refreshVardefs so let's try to load it. |
|
253 | - if(file_exists($cachedfile)){ |
|
254 | - global $mod_strings; |
|
251 | + //at this point we should have the cache/modules/... file |
|
252 | + //which was created from the refreshVardefs so let's try to load it. |
|
253 | + if(file_exists($cachedfile)){ |
|
254 | + global $mod_strings; |
|
255 | 255 | |
256 | - require $cachedfile; |
|
256 | + require $cachedfile; |
|
257 | 257 | |
258 | - // now that we hae loaded the data from disk, put it in the cache. |
|
259 | - if(!empty($mod_strings)) |
|
260 | - sugar_cache_put($key,$mod_strings); |
|
261 | - if(!empty($_SESSION['translation_mode'])){ |
|
262 | - $mod_strings = array_map('translated_prefix', $mod_strings); |
|
263 | - } |
|
264 | - return $mod_strings; |
|
265 | - } |
|
266 | - } |
|
258 | + // now that we hae loaded the data from disk, put it in the cache. |
|
259 | + if(!empty($mod_strings)) |
|
260 | + sugar_cache_put($key,$mod_strings); |
|
261 | + if(!empty($_SESSION['translation_mode'])){ |
|
262 | + $mod_strings = array_map('translated_prefix', $mod_strings); |
|
263 | + } |
|
264 | + return $mod_strings; |
|
265 | + } |
|
266 | + } |
|
267 | 267 | |
268 | 268 | /** |
269 | 269 | * Return the cache key for the module language definition |
@@ -274,9 +274,9 @@ discard block |
||
274 | 274 | * @return string |
275 | 275 | */ |
276 | 276 | public static function getLanguageCacheKey($module, $lang) |
277 | - { |
|
278 | - return "LanguageManager.$module.$lang"; |
|
279 | - } |
|
277 | + { |
|
278 | + return "LanguageManager.$module.$lang"; |
|
279 | + } |
|
280 | 280 | |
281 | 281 | /** |
282 | 282 | * Remove any cached js language strings. |
@@ -302,5 +302,5 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | function translated_prefix($key){ |
305 | - return '[translated]' . $key; |
|
305 | + return '[translated]' . $key; |
|
306 | 306 | } |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | */ |
90 | 90 | public static function setCustomAllowedForModule($module, $enable) { |
91 | 91 | if ($enable && isset($custom_disabled_modules[$module])) { |
92 | - unset($custom_disabled_modules[$module]); |
|
92 | + unset($custom_disabled_modules[$module]); |
|
93 | 93 | } else if (!$enable) { |
94 | - $custom_disabled_modules[$module] = true; |
|
94 | + $custom_disabled_modules[$module] = true; |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | 'modules/'.$module.'/vardefs.php', |
237 | 237 | 'custom/modules/'.$module.'/Ext/Vardefs/vardefs.ext.php', |
238 | 238 | 'custom/Extension/modules/'.$module.'/Ext/Vardefs/vardefs.php' |
239 | - ); |
|
239 | + ); |
|
240 | 240 | |
241 | 241 | // Add in additional search paths if they were provided. |
242 | 242 | if(!empty($additional_search_paths) && is_array($additional_search_paths)) |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | //if the consumer has demanded a refresh or the cache/modules... file |
427 | 427 | //does not exist, then we should do out and try to reload things |
428 | 428 | |
429 | - $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
430 | - if($refresh || !file_exists($cachedfile)){ |
|
431 | - VardefManager::refreshVardefs($module, $object, null, true, $params); |
|
432 | - } |
|
429 | + $cachedfile = sugar_cached('modules/'). $module . '/' . $object . 'vardefs.php'; |
|
430 | + if($refresh || !file_exists($cachedfile)){ |
|
431 | + VardefManager::refreshVardefs($module, $object, null, true, $params); |
|
432 | + } |
|
433 | 433 | |
434 | 434 | //at this point we should have the cache/modules/... file |
435 | 435 | //which was created from the refreshVardefs so let's try to load it. |
@@ -39,141 +39,141 @@ discard block |
||
39 | 39 | |
40 | 40 | $vardefs = array( |
41 | 41 | 'fields' => array ( |
42 | - 'id' => |
|
43 | - array ( |
|
44 | - 'name' => 'id', |
|
45 | - 'vname' => 'LBL_ID', |
|
46 | - 'type' => 'id', |
|
47 | - 'required'=>true, |
|
48 | - 'reportable'=>true, |
|
49 | - 'comment' => 'Unique identifier', |
|
50 | - 'inline_edit' => false, |
|
51 | - ), |
|
52 | - 'name'=> |
|
53 | - array( |
|
54 | - 'name'=>'name', |
|
55 | - 'vname'=> 'LBL_NAME', |
|
56 | - 'type'=>'name', |
|
57 | - 'link' => true, // bug 39288 |
|
58 | - 'dbType' => 'varchar', |
|
59 | - 'len'=>255, |
|
42 | + 'id' => |
|
43 | + array ( |
|
44 | + 'name' => 'id', |
|
45 | + 'vname' => 'LBL_ID', |
|
46 | + 'type' => 'id', |
|
47 | + 'required'=>true, |
|
48 | + 'reportable'=>true, |
|
49 | + 'comment' => 'Unique identifier', |
|
50 | + 'inline_edit' => false, |
|
51 | + ), |
|
52 | + 'name'=> |
|
53 | + array( |
|
54 | + 'name'=>'name', |
|
55 | + 'vname'=> 'LBL_NAME', |
|
56 | + 'type'=>'name', |
|
57 | + 'link' => true, // bug 39288 |
|
58 | + 'dbType' => 'varchar', |
|
59 | + 'len'=>255, |
|
60 | 60 | 'unified_search' => true, |
61 | 61 | 'full_text_search' => array('boost' => 3), |
62 | 62 | 'required'=>true, |
63 | - 'importable' => 'required', |
|
63 | + 'importable' => 'required', |
|
64 | 64 | 'duplicate_merge' => 'enabled', |
65 | 65 | //'duplicate_merge_dom_value' => '3', |
66 | 66 | 'merge_filter' => 'selected', |
67 | - ), |
|
68 | - 'date_entered' => |
|
69 | - array ( |
|
70 | - 'name' => 'date_entered', |
|
71 | - 'vname' => 'LBL_DATE_ENTERED', |
|
72 | - 'type' => 'datetime', |
|
73 | - 'group'=>'created_by_name', |
|
74 | - 'comment' => 'Date record created', |
|
75 | - 'enable_range_search' => true, |
|
76 | - 'options' => 'date_range_search_dom', |
|
77 | - 'inline_edit' => false, |
|
78 | - ), |
|
79 | - 'date_modified' => |
|
80 | - array ( |
|
81 | - 'name' => 'date_modified', |
|
82 | - 'vname' => 'LBL_DATE_MODIFIED', |
|
83 | - 'type' => 'datetime', |
|
84 | - 'group'=>'modified_by_name', |
|
85 | - 'comment' => 'Date record last modified', |
|
86 | - 'enable_range_search' => true, |
|
87 | - 'options' => 'date_range_search_dom', |
|
88 | - 'inline_edit' => false, |
|
89 | - ), |
|
90 | - 'modified_user_id' => |
|
91 | - array ( |
|
92 | - 'name' => 'modified_user_id', |
|
93 | - 'rname' => 'user_name', |
|
94 | - 'id_name' => 'modified_user_id', |
|
95 | - 'vname' => 'LBL_MODIFIED', |
|
96 | - 'type' => 'assigned_user_name', |
|
97 | - 'table' => 'users', |
|
98 | - 'isnull' => 'false', |
|
99 | - 'group'=>'modified_by_name', |
|
100 | - 'dbType' => 'id', |
|
101 | - 'reportable'=>true, |
|
102 | - 'comment' => 'User who last modified record', |
|
67 | + ), |
|
68 | + 'date_entered' => |
|
69 | + array ( |
|
70 | + 'name' => 'date_entered', |
|
71 | + 'vname' => 'LBL_DATE_ENTERED', |
|
72 | + 'type' => 'datetime', |
|
73 | + 'group'=>'created_by_name', |
|
74 | + 'comment' => 'Date record created', |
|
75 | + 'enable_range_search' => true, |
|
76 | + 'options' => 'date_range_search_dom', |
|
77 | + 'inline_edit' => false, |
|
78 | + ), |
|
79 | + 'date_modified' => |
|
80 | + array ( |
|
81 | + 'name' => 'date_modified', |
|
82 | + 'vname' => 'LBL_DATE_MODIFIED', |
|
83 | + 'type' => 'datetime', |
|
84 | + 'group'=>'modified_by_name', |
|
85 | + 'comment' => 'Date record last modified', |
|
86 | + 'enable_range_search' => true, |
|
87 | + 'options' => 'date_range_search_dom', |
|
88 | + 'inline_edit' => false, |
|
89 | + ), |
|
90 | + 'modified_user_id' => |
|
91 | + array ( |
|
92 | + 'name' => 'modified_user_id', |
|
93 | + 'rname' => 'user_name', |
|
94 | + 'id_name' => 'modified_user_id', |
|
95 | + 'vname' => 'LBL_MODIFIED', |
|
96 | + 'type' => 'assigned_user_name', |
|
97 | + 'table' => 'users', |
|
98 | + 'isnull' => 'false', |
|
99 | + 'group'=>'modified_by_name', |
|
100 | + 'dbType' => 'id', |
|
101 | + 'reportable'=>true, |
|
102 | + 'comment' => 'User who last modified record', |
|
103 | 103 | 'massupdate' => false, |
104 | - 'inline_edit' => false, |
|
105 | - ), |
|
106 | - 'modified_by_name' => |
|
107 | - array ( |
|
108 | - 'name' => 'modified_by_name', |
|
109 | - 'vname' => 'LBL_MODIFIED_NAME', |
|
110 | - 'type' => 'relate', |
|
111 | - 'reportable'=>false, |
|
112 | - 'source'=>'non-db', |
|
113 | - 'rname'=>'user_name', |
|
114 | - 'table' => 'users', |
|
115 | - 'id_name' => 'modified_user_id', |
|
116 | - 'module'=>'Users', |
|
117 | - 'link'=>'modified_user_link', |
|
118 | - 'duplicate_merge'=>'disabled', |
|
104 | + 'inline_edit' => false, |
|
105 | + ), |
|
106 | + 'modified_by_name' => |
|
107 | + array ( |
|
108 | + 'name' => 'modified_by_name', |
|
109 | + 'vname' => 'LBL_MODIFIED_NAME', |
|
110 | + 'type' => 'relate', |
|
111 | + 'reportable'=>false, |
|
112 | + 'source'=>'non-db', |
|
113 | + 'rname'=>'user_name', |
|
114 | + 'table' => 'users', |
|
115 | + 'id_name' => 'modified_user_id', |
|
116 | + 'module'=>'Users', |
|
117 | + 'link'=>'modified_user_link', |
|
118 | + 'duplicate_merge'=>'disabled', |
|
119 | 119 | 'massupdate' => false, |
120 | - 'inline_edit' => false, |
|
121 | - ), |
|
122 | - 'created_by' => |
|
123 | - array ( |
|
124 | - 'name' => 'created_by', |
|
125 | - 'rname' => 'user_name', |
|
126 | - 'id_name' => 'modified_user_id', |
|
127 | - 'vname' => 'LBL_CREATED', |
|
128 | - 'type' => 'assigned_user_name', |
|
129 | - 'table' => 'users', |
|
130 | - 'isnull' => 'false', |
|
131 | - 'dbType' => 'id', |
|
132 | - 'group'=>'created_by_name', |
|
133 | - 'comment' => 'User who created record', |
|
120 | + 'inline_edit' => false, |
|
121 | + ), |
|
122 | + 'created_by' => |
|
123 | + array ( |
|
124 | + 'name' => 'created_by', |
|
125 | + 'rname' => 'user_name', |
|
126 | + 'id_name' => 'modified_user_id', |
|
127 | + 'vname' => 'LBL_CREATED', |
|
128 | + 'type' => 'assigned_user_name', |
|
129 | + 'table' => 'users', |
|
130 | + 'isnull' => 'false', |
|
131 | + 'dbType' => 'id', |
|
132 | + 'group'=>'created_by_name', |
|
133 | + 'comment' => 'User who created record', |
|
134 | 134 | 'massupdate' => false, |
135 | - 'inline_edit' => false, |
|
136 | - ), |
|
137 | - 'created_by_name' => |
|
138 | - array ( |
|
139 | - 'name' => 'created_by_name', |
|
140 | - 'vname' => 'LBL_CREATED', |
|
141 | - 'type' => 'relate', |
|
142 | - 'reportable'=>false, |
|
143 | - 'link' => 'created_by_link', |
|
144 | - 'rname' => 'user_name', |
|
145 | - 'source'=>'non-db', |
|
146 | - 'table' => 'users', |
|
147 | - 'id_name' => 'created_by', |
|
148 | - 'module'=>'Users', |
|
149 | - 'duplicate_merge'=>'disabled', |
|
135 | + 'inline_edit' => false, |
|
136 | + ), |
|
137 | + 'created_by_name' => |
|
138 | + array ( |
|
139 | + 'name' => 'created_by_name', |
|
140 | + 'vname' => 'LBL_CREATED', |
|
141 | + 'type' => 'relate', |
|
142 | + 'reportable'=>false, |
|
143 | + 'link' => 'created_by_link', |
|
144 | + 'rname' => 'user_name', |
|
145 | + 'source'=>'non-db', |
|
146 | + 'table' => 'users', |
|
147 | + 'id_name' => 'created_by', |
|
148 | + 'module'=>'Users', |
|
149 | + 'duplicate_merge'=>'disabled', |
|
150 | 150 | 'importable' => 'false', |
151 | 151 | 'massupdate' => false, |
152 | - 'inline_edit' => false, |
|
153 | - ), |
|
154 | - 'description' => |
|
155 | - array ( |
|
156 | - 'name' => 'description', |
|
157 | - 'vname' => 'LBL_DESCRIPTION', |
|
158 | - 'type' => 'text', |
|
159 | - 'comment' => 'Full text of the note', |
|
160 | - 'rows' => 6, |
|
161 | - 'cols' => 80, |
|
162 | - ), |
|
163 | - 'deleted' => |
|
164 | - array ( |
|
165 | - 'name' => 'deleted', |
|
166 | - 'vname' => 'LBL_DELETED', |
|
167 | - 'type' => 'bool', |
|
168 | - 'default' => '0', |
|
169 | - 'reportable'=>false, |
|
170 | - 'comment' => 'Record deletion indicator' |
|
171 | - ), |
|
152 | + 'inline_edit' => false, |
|
153 | + ), |
|
154 | + 'description' => |
|
155 | + array ( |
|
156 | + 'name' => 'description', |
|
157 | + 'vname' => 'LBL_DESCRIPTION', |
|
158 | + 'type' => 'text', |
|
159 | + 'comment' => 'Full text of the note', |
|
160 | + 'rows' => 6, |
|
161 | + 'cols' => 80, |
|
162 | + ), |
|
163 | + 'deleted' => |
|
164 | + array ( |
|
165 | + 'name' => 'deleted', |
|
166 | + 'vname' => 'LBL_DELETED', |
|
167 | + 'type' => 'bool', |
|
168 | + 'default' => '0', |
|
169 | + 'reportable'=>false, |
|
170 | + 'comment' => 'Record deletion indicator' |
|
171 | + ), |
|
172 | 172 | |
173 | 173 | /////////////////RELATIONSHIP LINKS//////////////////////////// |
174 | - 'created_by_link' => |
|
175 | - array ( |
|
176 | - 'name' => 'created_by_link', |
|
174 | + 'created_by_link' => |
|
175 | + array ( |
|
176 | + 'name' => 'created_by_link', |
|
177 | 177 | 'type' => 'link', |
178 | 178 | 'relationship' => strtolower($module) . '_created_by', |
179 | 179 | 'vname' => 'LBL_CREATED_USER', |
@@ -181,9 +181,9 @@ discard block |
||
181 | 181 | 'module'=>'Users', |
182 | 182 | 'bean_name'=>'User', |
183 | 183 | 'source'=>'non-db', |
184 | - ), |
|
185 | - 'modified_user_link' => |
|
186 | - array ( |
|
184 | + ), |
|
185 | + 'modified_user_link' => |
|
186 | + array ( |
|
187 | 187 | 'name' => 'modified_user_link', |
188 | 188 | 'type' => 'link', |
189 | 189 | 'relationship' => strtolower($module). '_modified_user', |
@@ -192,21 +192,21 @@ discard block |
||
192 | 192 | 'module'=>'Users', |
193 | 193 | 'bean_name'=>'User', |
194 | 194 | 'source'=>'non-db', |
195 | - ), |
|
195 | + ), |
|
196 | 196 | |
197 | 197 | ), |
198 | 198 | 'indices' => array ( |
199 | - 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
|
200 | - ), |
|
199 | + 'id'=>array('name' =>strtolower($module).'pk', 'type' =>'primary', 'fields'=>array('id')), |
|
200 | + ), |
|
201 | 201 | 'relationships'=>array( |
202 | - strtolower($module).'_modified_user' => |
|
203 | - array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
204 | - 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'modified_user_id', |
|
205 | - 'relationship_type'=>'one-to-many') |
|
206 | - ,strtolower($module).'_created_by' => |
|
207 | - array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
208 | - 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'created_by', |
|
209 | - 'relationship_type'=>'one-to-many') |
|
202 | + strtolower($module).'_modified_user' => |
|
203 | + array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
204 | + 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'modified_user_id', |
|
205 | + 'relationship_type'=>'one-to-many') |
|
206 | + ,strtolower($module).'_created_by' => |
|
207 | + array('lhs_module'=> 'Users', 'lhs_table'=> 'users', 'lhs_key' => 'id', |
|
208 | + 'rhs_module'=> $module, 'rhs_table'=> strtolower($module), 'rhs_key' => 'created_by', |
|
209 | + 'relationship_type'=>'one-to-many') |
|
210 | 210 | ), |
211 | 211 | |
212 | 212 |
@@ -54,7 +54,7 @@ |
||
54 | 54 | 'LBL_MODIFIED_USER'=>'Modified by User', |
55 | 55 | 'LBL_LIST_NAME'=>'Name', |
56 | 56 | 'LBL_EDIT_BUTTON' => 'Edit', |
57 | - 'LBL_REMOVE' => 'Remove', |
|
57 | + 'LBL_REMOVE' => 'Remove', |
|
58 | 58 | |
59 | 59 | |
60 | 60 | ); |
61 | 61 | \ No newline at end of file |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | 'url' => 'nvarchar', |
144 | 144 | 'encrypt' => 'nvarchar', |
145 | 145 | 'file' => 'nvarchar', |
146 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
146 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | 147 | ); |
148 | 148 | |
149 | - /** |
|
149 | + /** |
|
150 | 150 | * @see DBManager::connect() |
151 | 151 | */ |
152 | 152 | public function connect(array $configOptions = null, $dieOnError = false) |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | return true; |
204 | 204 | } |
205 | 205 | |
206 | - /** |
|
206 | + /** |
|
207 | 207 | * @see DBManager::query() |
208 | - */ |
|
209 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
208 | + */ |
|
209 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
210 | 210 | { |
211 | 211 | if(is_array($sql)) { |
212 | 212 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
@@ -232,15 +232,15 @@ discard block |
||
232 | 232 | return $result; |
233 | 233 | } |
234 | 234 | |
235 | - /** |
|
235 | + /** |
|
236 | 236 | * @see DBManager::getFieldsArray() |
237 | 237 | */ |
238 | - public function getFieldsArray($result, $make_lower_case = false) |
|
239 | - { |
|
238 | + public function getFieldsArray($result, $make_lower_case = false) |
|
239 | + { |
|
240 | 240 | $field_array = array(); |
241 | 241 | |
242 | 242 | if ( !$result ) { |
243 | - return false; |
|
243 | + return false; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | foreach ( sqlsrv_field_metadata($result) as $fieldMetadata ) { |
@@ -252,16 +252,16 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | return $field_array; |
255 | - } |
|
255 | + } |
|
256 | 256 | |
257 | - /** |
|
258 | - * @see DBManager::fetchRow() |
|
259 | - */ |
|
260 | - public function fetchRow($result) |
|
261 | - { |
|
262 | - if (empty($result)) return false; |
|
257 | + /** |
|
258 | + * @see DBManager::fetchRow() |
|
259 | + */ |
|
260 | + public function fetchRow($result) |
|
261 | + { |
|
262 | + if (empty($result)) return false; |
|
263 | 263 | |
264 | - $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
264 | + $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC); |
|
265 | 265 | if (empty($row)) { |
266 | 266 | return false; |
267 | 267 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | return $row; |
280 | - } |
|
280 | + } |
|
281 | 281 | |
282 | 282 | /** |
283 | 283 | * @see DBManager::convert() |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | return parent::convert($string, $type, $additional_parameters); |
292 | 292 | } |
293 | 293 | |
294 | - /** |
|
294 | + /** |
|
295 | 295 | * Compares two vardefs. Overriding 39098 due to bug: 39098 . IN 6.0 we changed the id columns to dbType = 'id' |
296 | 296 | * for example emails_beans. In 554 the field email_id was nvarchar but in 6.0 since it id dbType = 'id' we would want to alter |
297 | 297 | * it to varchar. This code will prevent it. |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | */ |
318 | 318 | public function disconnect() |
319 | 319 | { |
320 | - $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
320 | + $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
321 | 321 | if(!empty($this->database)){ |
322 | 322 | $this->freeResult(); |
323 | 323 | sqlsrv_close($this->database); |
@@ -335,10 +335,10 @@ discard block |
||
335 | 335 | } |
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * Detect if no clustered index has been created for a table; if none created then just pick the first index and make it that |
|
340 | - * |
|
341 | - * @see MssqlHelper::indexSQL() |
|
338 | + /** |
|
339 | + * Detect if no clustered index has been created for a table; if none created then just pick the first index and make it that |
|
340 | + * |
|
341 | + * @see MssqlHelper::indexSQL() |
|
342 | 342 | */ |
343 | 343 | public function getConstraintSql($indices, $table) |
344 | 344 | { |
@@ -378,12 +378,12 @@ discard block |
||
378 | 378 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
379 | 379 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
380 | 380 | } |
381 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | - if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | - $columns[$column_name]['len']='max'; |
|
385 | - } |
|
386 | - } |
|
381 | + elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) { |
|
382 | + $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
383 | + if ( $row['TYPE_NAME'] == 'nvarchar' && $row['PRECISION'] == '0' ) { |
|
384 | + $columns[$column_name]['len']='max'; |
|
385 | + } |
|
386 | + } |
|
387 | 387 | elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) { |
388 | 388 | $columns[$column_name]['len']=strtolower($row['LENGTH']); |
389 | 389 | } |
@@ -488,21 +488,21 @@ discard block |
||
488 | 488 | return "TRUNCATE TABLE $name"; |
489 | 489 | } |
490 | 490 | |
491 | - /** |
|
492 | - * (non-PHPdoc) |
|
493 | - * @see DBManager::lastDbError() |
|
494 | - */ |
|
491 | + /** |
|
492 | + * (non-PHPdoc) |
|
493 | + * @see DBManager::lastDbError() |
|
494 | + */ |
|
495 | 495 | public function lastDbError() |
496 | 496 | { |
497 | 497 | $errors = sqlsrv_errors(SQLSRV_ERR_ERRORS); |
498 | 498 | if(empty($errors)) return false; |
499 | 499 | global $app_strings; |
500 | 500 | if (empty($app_strings) |
501 | - or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
502 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
501 | + or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
502 | + or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
503 | 503 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
504 | 504 | //only if connection if made before languge is set. |
505 | - return false; |
|
505 | + return false; |
|
506 | 506 | } |
507 | 507 | $messages = array(); |
508 | 508 | foreach($errors as $error) { |
@@ -515,7 +515,7 @@ discard block |
||
515 | 515 | } |
516 | 516 | $sqlpos = strpos($sqlmsg, $app_strings['ERR_MSSQL_DB_CONTEXT']); |
517 | 517 | $sqlpos2 = strpos($sqlmsg, $app_strings['ERR_MSSQL_WARNING']); |
518 | - if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
518 | + if ( $sqlpos !== false || $sqlpos2 !== false) { |
|
519 | 519 | continue; |
520 | 520 | } |
521 | 521 | $messages[] = $sqlmsg; |
@@ -140,8 +140,8 @@ discard block |
||
140 | 140 | 'relate' => 'varchar', |
141 | 141 | 'multienum'=> 'text', |
142 | 142 | 'html' => 'text', |
143 | - 'longhtml' => 'text', |
|
144 | - 'datetime' => 'datetime', |
|
143 | + 'longhtml' => 'text', |
|
144 | + 'datetime' => 'datetime', |
|
145 | 145 | 'datetimecombo' => 'datetime', |
146 | 146 | 'time' => 'datetime', |
147 | 147 | 'bool' => 'bit', |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | 'url' => 'varchar', |
157 | 157 | 'encrypt' => 'varchar', |
158 | 158 | 'file' => 'varchar', |
159 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
159 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
160 | 160 | ); |
161 | 161 | |
162 | 162 | protected $connectOptions = null; |
@@ -236,16 +236,16 @@ discard block |
||
236 | 236 | //it will throw an Unable to select database message. |
237 | 237 | |
238 | 238 | if(!empty($configOptions['db_name']) && !@mssql_select_db($configOptions['db_name'], $this->database)){ |
239 | - $connected = false; |
|
240 | - for($i=0;$i<5;$i++){ |
|
241 | - usleep(200000); |
|
242 | - if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
243 | - $connected = true; |
|
244 | - break; |
|
245 | - } |
|
246 | - } |
|
247 | - if(!$connected){ |
|
248 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
239 | + $connected = false; |
|
240 | + for($i=0;$i<5;$i++){ |
|
241 | + usleep(200000); |
|
242 | + if(@mssql_select_db($configOptions['db_name'], $this->database)){ |
|
243 | + $connected = true; |
|
244 | + break; |
|
245 | + } |
|
246 | + } |
|
247 | + if(!$connected){ |
|
248 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}"); |
|
249 | 249 | if($dieOnError) { |
250 | 250 | if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
251 | 251 | sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
@@ -255,8 +255,8 @@ discard block |
||
255 | 255 | } else { |
256 | 256 | return false; |
257 | 257 | } |
258 | - } |
|
259 | - } |
|
258 | + } |
|
259 | + } |
|
260 | 260 | |
261 | 261 | if(!$this->checkError('Could Not Connect', $dieOnError)) |
262 | 262 | $GLOBALS['log']->info("connected to db"); |
@@ -267,18 +267,18 @@ discard block |
||
267 | 267 | return true; |
268 | 268 | } |
269 | 269 | |
270 | - /** |
|
270 | + /** |
|
271 | 271 | * @see DBManager::version() |
272 | 272 | */ |
273 | 273 | public function version() |
274 | 274 | { |
275 | 275 | return $this->getOne("SELECT @@VERSION as version"); |
276 | - } |
|
276 | + } |
|
277 | 277 | |
278 | - /** |
|
278 | + /** |
|
279 | 279 | * @see DBManager::query() |
280 | - */ |
|
281 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
280 | + */ |
|
281 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
282 | 282 | { |
283 | 283 | if(is_array($sql)) { |
284 | 284 | return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | if ((substr_count($sql, "'") & 1)) |
288 | 288 | $GLOBALS['log']->error("SQL statement[" . $sql . "] has odd number of single quotes."); |
289 | 289 | |
290 | - $sql = $this->_appendN($sql); |
|
290 | + $sql = $this->_appendN($sql); |
|
291 | 291 | |
292 | 292 | $GLOBALS['log']->info('Query:' . $sql); |
293 | 293 | $this->checkConnection(); |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | $this->query_time = microtime(true); |
296 | 296 | |
297 | 297 | // Bug 34892 - Clear out previous error message by checking the @@ERROR global variable |
298 | - @mssql_query("SELECT @@ERROR", $this->database); |
|
298 | + @mssql_query("SELECT @@ERROR", $this->database); |
|
299 | 299 | |
300 | 300 | $result = $suppress?@mssql_query($sql, $this->database):mssql_query($sql, $this->database); |
301 | 301 | |
@@ -305,18 +305,18 @@ discard block |
||
305 | 305 | // not affect the functionality of the query |
306 | 306 | $sqlmsg = mssql_get_last_message(); |
307 | 307 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
308 | - $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
|
309 | - $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
|
308 | + $sqlpos2 = strpos($sqlmsg, 'Warning:'); |
|
309 | + $sqlpos3 = strpos($sqlmsg, 'Checking identity information:'); |
|
310 | 310 | |
311 | - if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
|
312 | - $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
313 | - else { |
|
314 | - $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | - if($dieOnError) |
|
316 | - sugar_die('SQL Error : ' . $sqlmsg); |
|
317 | - else |
|
318 | - echo 'SQL Error : ' . $sqlmsg; |
|
319 | - } |
|
311 | + if ($sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false) // if sqlmsg has 'Changed database context to', just log it |
|
312 | + $GLOBALS['log']->debug($sqlmsg . ": " . $sql ); |
|
313 | + else { |
|
314 | + $GLOBALS['log']->fatal($sqlmsg . ": " . $sql ); |
|
315 | + if($dieOnError) |
|
316 | + sugar_die('SQL Error : ' . $sqlmsg); |
|
317 | + else |
|
318 | + echo 'SQL Error : ' . $sqlmsg; |
|
319 | + } |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | $this->query_time = microtime(true) - $this->query_time; |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | return $limitUnionSQL; |
427 | 427 | } |
428 | 428 | |
429 | - /** |
|
430 | - * FIXME: verify and thoroughly test this code, these regexps look fishy |
|
429 | + /** |
|
430 | + * FIXME: verify and thoroughly test this code, these regexps look fishy |
|
431 | 431 | * @see DBManager::limitQuery() |
432 | 432 | */ |
433 | 433 | public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
@@ -569,7 +569,7 @@ discard block |
||
569 | 569 | }else{ |
570 | 570 | //if there is a distinct clause, form query with rownumber after distinct |
571 | 571 | if ($hasDistinct) { |
572 | - $newSQL = "SELECT TOP $count * FROM |
|
572 | + $newSQL = "SELECT TOP $count * FROM |
|
573 | 573 | ( |
574 | 574 | SELECT ROW_NUMBER() OVER (ORDER BY ".$grpByStr.") AS row_number, count(*) counter, " . $distinctSQLARRAY[0] . " |
575 | 575 | " . $distinctSQLARRAY[1] . " |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | WHERE row_number > $start"; |
580 | 580 | } |
581 | 581 | else { |
582 | - $newSQL = "SELECT TOP $count * FROM |
|
582 | + $newSQL = "SELECT TOP $count * FROM |
|
583 | 583 | ( |
584 | 584 | " . $matches[1] . " ROW_NUMBER() OVER (ORDER BY " . $sqlArray['FROM'][0]['alias'] . ".id) AS row_number, " . $matches[2] . $matches[3]. " |
585 | 585 | ) |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | while ($i<$count && $offset<strlen($p_sql)) { |
627 | 627 | if ($offset > strlen($p_sql)) |
628 | 628 | { |
629 | - break; |
|
629 | + break; |
|
630 | 630 | } |
631 | 631 | |
632 | 632 | $beg_sin = strpos($p_sql, $strip_beg, $offset); |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | * @param array $pattern_array |
666 | 666 | * @return string |
667 | 667 | */ |
668 | - private function addPatternToSQL($token, array $pattern_array) |
|
668 | + private function addPatternToSQL($token, array $pattern_array) |
|
669 | 669 | { |
670 | 670 | //strip all single quotes out |
671 | 671 | $pattern_array = array_reverse($pattern_array); |
@@ -684,7 +684,7 @@ discard block |
||
684 | 684 | * @param string $alias |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - private function getAliasFromSQL($sql, $alias) |
|
687 | + private function getAliasFromSQL($sql, $alias) |
|
688 | 688 | { |
689 | 689 | $matches = array(); |
690 | 690 | preg_match('/^(.*SELECT)(.*?FROM.*WHERE)(.*)$/isU',$sql, $matches); |
@@ -786,7 +786,7 @@ discard block |
||
786 | 786 | |
787 | 787 | // If there is no ordering direction (ASC/DESC), use ASC by default |
788 | 788 | if (strpos($orig_order_match, " ") === false) { |
789 | - $orig_order_match .= " ASC"; |
|
789 | + $orig_order_match .= " ASC"; |
|
790 | 790 | } |
791 | 791 | |
792 | 792 | //grab first space in order by |
@@ -810,11 +810,11 @@ discard block |
||
810 | 810 | $lastSpacePos = strrpos($containsColStr, " "); |
811 | 811 | //use positions of column name, space before name, and length of column to find the correct column name |
812 | 812 | $col_name = substr($sql, $lastSpacePos, $colMatchPos-$lastSpacePos+strlen($orderMatch)); |
813 | - //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
|
814 | - $containsCommaPos = strpos($col_name, ","); |
|
815 | - if($containsCommaPos !== false) { |
|
816 | - $col_name = substr($col_name, $containsCommaPos+1); |
|
817 | - } |
|
813 | + //bug 25485. When sorting by a custom field in Account List and then pressing NEXT >, system gives an error |
|
814 | + $containsCommaPos = strpos($col_name, ","); |
|
815 | + if($containsCommaPos !== false) { |
|
816 | + $col_name = substr($col_name, $containsCommaPos+1); |
|
817 | + } |
|
818 | 818 | //add the "asc/desc" order back |
819 | 819 | $col_name = $col_name. " ". $asc_desc; |
820 | 820 | |
@@ -967,14 +967,14 @@ discard block |
||
967 | 967 | } |
968 | 968 | |
969 | 969 | |
970 | - /** |
|
970 | + /** |
|
971 | 971 | * @see DBManager::getFieldsArray() |
972 | 972 | */ |
973 | - public function getFieldsArray($result, $make_lower_case = false) |
|
974 | - { |
|
975 | - $field_array = array(); |
|
973 | + public function getFieldsArray($result, $make_lower_case = false) |
|
974 | + { |
|
975 | + $field_array = array(); |
|
976 | 976 | |
977 | - if(! isset($result) || empty($result)) |
|
977 | + if(! isset($result) || empty($result)) |
|
978 | 978 | return 0; |
979 | 979 | |
980 | 980 | $i = 0; |
@@ -991,37 +991,37 @@ discard block |
||
991 | 991 | } |
992 | 992 | |
993 | 993 | return $field_array; |
994 | - } |
|
994 | + } |
|
995 | 995 | |
996 | 996 | /** |
997 | 997 | * @see DBManager::getAffectedRowCount() |
998 | 998 | */ |
999 | - public function getAffectedRowCount($result) |
|
999 | + public function getAffectedRowCount($result) |
|
1000 | 1000 | { |
1001 | 1001 | return $this->getOne("SELECT @@ROWCOUNT"); |
1002 | 1002 | } |
1003 | 1003 | |
1004 | - /** |
|
1005 | - * @see DBManager::fetchRow() |
|
1006 | - */ |
|
1007 | - public function fetchRow($result) |
|
1008 | - { |
|
1009 | - if (empty($result)) return false; |
|
1004 | + /** |
|
1005 | + * @see DBManager::fetchRow() |
|
1006 | + */ |
|
1007 | + public function fetchRow($result) |
|
1008 | + { |
|
1009 | + if (empty($result)) return false; |
|
1010 | 1010 | |
1011 | 1011 | $row = mssql_fetch_assoc($result); |
1012 | 1012 | //MSSQL returns a space " " when a varchar column is empty ("") and not null. |
1013 | 1013 | //We need to iterate through the returned row array and strip empty spaces |
1014 | 1014 | if(!empty($row)){ |
1015 | 1015 | foreach($row as $key => $column) { |
1016 | - //notice we only strip if one space is returned. we do not want to strip |
|
1017 | - //strings with intentional spaces (" foo ") |
|
1018 | - if (!empty($column) && $column ==" ") { |
|
1019 | - $row[$key] = ''; |
|
1020 | - } |
|
1016 | + //notice we only strip if one space is returned. we do not want to strip |
|
1017 | + //strings with intentional spaces (" foo ") |
|
1018 | + if (!empty($column) && $column ==" ") { |
|
1019 | + $row[$key] = ''; |
|
1020 | + } |
|
1021 | 1021 | } |
1022 | 1022 | } |
1023 | 1023 | return $row; |
1024 | - } |
|
1024 | + } |
|
1025 | 1025 | |
1026 | 1026 | /** |
1027 | 1027 | * @see DBManager::quote() |
@@ -1069,7 +1069,7 @@ discard block |
||
1069 | 1069 | if (!empty($r)) { |
1070 | 1070 | while ($a = $this->fetchByAssoc($r)) { |
1071 | 1071 | $row = array_values($a); |
1072 | - $tables[]=$row[0]; |
|
1072 | + $tables[]=$row[0]; |
|
1073 | 1073 | } |
1074 | 1074 | return $tables; |
1075 | 1075 | } |
@@ -1126,7 +1126,7 @@ discard block |
||
1126 | 1126 | ) |
1127 | 1127 | "; |
1128 | 1128 | //create full text index |
1129 | - $FTSqry[] = "CREATE FULLTEXT INDEX ON fts_wakeup |
|
1129 | + $FTSqry[] = "CREATE FULLTEXT INDEX ON fts_wakeup |
|
1130 | 1130 | ( |
1131 | 1131 | body |
1132 | 1132 | Language 0X0 |
@@ -1195,7 +1195,7 @@ discard block |
||
1195 | 1195 | $len = $this->date_formats[$additional_parameters[0]]; |
1196 | 1196 | return "LEFT(CONVERT(varchar($len),". $string . ",120),$len)"; |
1197 | 1197 | } else { |
1198 | - return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1198 | + return "LEFT(CONVERT(varchar(10),". $string . ",120),10)"; |
|
1199 | 1199 | } |
1200 | 1200 | case 'ifnull': |
1201 | 1201 | if(empty($additional_parameters_string)) { |
@@ -1237,14 +1237,14 @@ discard block |
||
1237 | 1237 | case 'datetime': return substr($string, 0,19); |
1238 | 1238 | case 'date': return substr($string, 0, 10); |
1239 | 1239 | case 'time': return substr($string, 11); |
1240 | - } |
|
1241 | - return $string; |
|
1240 | + } |
|
1241 | + return $string; |
|
1242 | 1242 | } |
1243 | 1243 | |
1244 | 1244 | /** |
1245 | 1245 | * @see DBManager::createTableSQLParams() |
1246 | 1246 | */ |
1247 | - public function createTableSQLParams($tablename, $fieldDefs, $indices) |
|
1247 | + public function createTableSQLParams($tablename, $fieldDefs, $indices) |
|
1248 | 1248 | { |
1249 | 1249 | if (empty($tablename) || empty($fieldDefs)) |
1250 | 1250 | return ''; |
@@ -1322,7 +1322,7 @@ discard block |
||
1322 | 1322 | break; |
1323 | 1323 | default: |
1324 | 1324 | return ''; |
1325 | - } |
|
1325 | + } |
|
1326 | 1326 | } |
1327 | 1327 | |
1328 | 1328 | /** |
@@ -1338,14 +1338,14 @@ discard block |
||
1338 | 1338 | $columns = array(); |
1339 | 1339 | if ($this->isFieldArray($fieldDefs)) { |
1340 | 1340 | foreach ($fieldDefs as $def) |
1341 | - { |
|
1342 | - //if the column is being modified drop the default value |
|
1343 | - //constraint if it exists. alterSQLRep will add the constraint back |
|
1344 | - if (!empty($constraints[$def['name']])) { |
|
1345 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1346 | - } |
|
1347 | - //check to see if we need to drop related indexes before the alter |
|
1348 | - $indices = $this->get_indices($tablename); |
|
1341 | + { |
|
1342 | + //if the column is being modified drop the default value |
|
1343 | + //constraint if it exists. alterSQLRep will add the constraint back |
|
1344 | + if (!empty($constraints[$def['name']])) { |
|
1345 | + $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$def['name']]; |
|
1346 | + } |
|
1347 | + //check to see if we need to drop related indexes before the alter |
|
1348 | + $indices = $this->get_indices($tablename); |
|
1349 | 1349 | foreach ( $indices as $index ) { |
1350 | 1350 | if ( in_array($def['name'],$index['fields']) ) { |
1351 | 1351 | $sql .= ' ' . $this->add_drop_constraint($tablename,$index,true).' '; |
@@ -1353,16 +1353,16 @@ discard block |
||
1353 | 1353 | } |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1357 | - } |
|
1356 | + $columns[] = $this->alterSQLRep($action, $def, $ignoreRequired,$tablename); |
|
1357 | + } |
|
1358 | 1358 | } |
1359 | 1359 | else { |
1360 | 1360 | //if the column is being modified drop the default value |
1361 | - //constraint if it exists. alterSQLRep will add the constraint back |
|
1362 | - if (!empty($constraints[$fieldDefs['name']])) { |
|
1363 | - $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1364 | - } |
|
1365 | - //check to see if we need to drop related indexes before the alter |
|
1361 | + //constraint if it exists. alterSQLRep will add the constraint back |
|
1362 | + if (!empty($constraints[$fieldDefs['name']])) { |
|
1363 | + $sql.=" ALTER TABLE " . $tablename . " DROP CONSTRAINT " . $constraints[$fieldDefs['name']]; |
|
1364 | + } |
|
1365 | + //check to see if we need to drop related indexes before the alter |
|
1366 | 1366 | $indices = $this->get_indices($tablename); |
1367 | 1367 | foreach ( $indices as $index ) { |
1368 | 1368 | if ( in_array($fieldDefs['name'],$index['fields']) ) { |
@@ -1372,7 +1372,7 @@ discard block |
||
1372 | 1372 | } |
1373 | 1373 | |
1374 | 1374 | |
1375 | - $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1375 | + $columns[] = $this->alterSQLRep($action, $fieldDefs, $ignoreRequired,$tablename); |
|
1376 | 1376 | } |
1377 | 1377 | |
1378 | 1378 | $columns = implode(", ", $columns); |
@@ -1383,8 +1383,8 @@ discard block |
||
1383 | 1383 | |
1384 | 1384 | protected function setAutoIncrement($table, $field_name) |
1385 | 1385 | { |
1386 | - return "identity(1,1)"; |
|
1387 | - } |
|
1386 | + return "identity(1,1)"; |
|
1387 | + } |
|
1388 | 1388 | |
1389 | 1389 | /** |
1390 | 1390 | * @see DBManager::setAutoIncrementStart() |
@@ -1393,16 +1393,16 @@ discard block |
||
1393 | 1393 | { |
1394 | 1394 | if($start_value > 1) |
1395 | 1395 | $start_value -= 1; |
1396 | - $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
|
1396 | + $this->query("DBCC CHECKIDENT ('$table', RESEED, $start_value) WITH NO_INFOMSGS"); |
|
1397 | 1397 | return true; |
1398 | 1398 | } |
1399 | 1399 | |
1400 | - /** |
|
1400 | + /** |
|
1401 | 1401 | * @see DBManager::getAutoIncrement() |
1402 | 1402 | */ |
1403 | 1403 | public function getAutoIncrement($table, $field_name) |
1404 | 1404 | { |
1405 | - $result = $this->getOne("select IDENT_CURRENT('$table') + IDENT_INCR ( '$table' ) as 'Auto_increment'"); |
|
1405 | + $result = $this->getOne("select IDENT_CURRENT('$table') + IDENT_INCR ( '$table' ) as 'Auto_increment'"); |
|
1406 | 1406 | return $result; |
1407 | 1407 | } |
1408 | 1408 | |
@@ -1457,8 +1457,8 @@ discard block |
||
1457 | 1457 | $columns[$column_name]['len']=strtolower($row['PRECISION']); |
1458 | 1458 | $columns[$column_name]['len'].=','.strtolower($row['SCALE']); |
1459 | 1459 | } |
1460 | - elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1461 | - $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1460 | + elseif ( in_array($row['TYPE_NAME'],array('nchar','nvarchar')) ) |
|
1461 | + $columns[$column_name]['len']=strtolower($row['PRECISION']); |
|
1462 | 1462 | elseif ( !in_array($row['TYPE_NAME'],array('datetime','text')) ) |
1463 | 1463 | $columns[$column_name]['len']=strtolower($row['LENGTH']); |
1464 | 1464 | if ( stristr($row['TYPE_NAME'],'identity') ) { |
@@ -1585,7 +1585,7 @@ discard block |
||
1585 | 1585 | protected function full_text_indexing_enabled($dbname = null) |
1586 | 1586 | { |
1587 | 1587 | // check to see if we already have install setting in session |
1588 | - if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1588 | + if(!isset($_SESSION['IsFulltextInstalled'])) |
|
1589 | 1589 | $_SESSION['IsFulltextInstalled'] = $this->full_text_indexing_installed(); |
1590 | 1590 | |
1591 | 1591 | // check to see if FTS Indexing service is installed |
@@ -1593,27 +1593,27 @@ discard block |
||
1593 | 1593 | return false; |
1594 | 1594 | |
1595 | 1595 | // grab the dbname if it was not passed through |
1596 | - if (empty($dbname)) { |
|
1597 | - global $sugar_config; |
|
1598 | - $dbname = $sugar_config['dbconfig']['db_name']; |
|
1599 | - } |
|
1596 | + if (empty($dbname)) { |
|
1597 | + global $sugar_config; |
|
1598 | + $dbname = $sugar_config['dbconfig']['db_name']; |
|
1599 | + } |
|
1600 | 1600 | //we already know that Indexing service is installed, now check |
1601 | 1601 | //to see if it is enabled |
1602 | - $res = $this->getOne("SELECT DATABASEPROPERTY('$dbname', 'IsFulltextEnabled') ftext"); |
|
1602 | + $res = $this->getOne("SELECT DATABASEPROPERTY('$dbname', 'IsFulltextEnabled') ftext"); |
|
1603 | 1603 | return !empty($res); |
1604 | - } |
|
1604 | + } |
|
1605 | 1605 | |
1606 | 1606 | /** |
1607 | 1607 | * Creates default full text catalog |
1608 | 1608 | */ |
1609 | - protected function create_default_full_text_catalog() |
|
1609 | + protected function create_default_full_text_catalog() |
|
1610 | 1610 | { |
1611 | - if ($this->full_text_indexing_enabled()) { |
|
1612 | - $catalog = $this->ftsCatalogName(); |
|
1611 | + if ($this->full_text_indexing_enabled()) { |
|
1612 | + $catalog = $this->ftsCatalogName(); |
|
1613 | 1613 | $GLOBALS['log']->debug("Creating the default catalog for full-text indexing, $catalog"); |
1614 | 1614 | |
1615 | 1615 | //drop catalog if exists. |
1616 | - $ret = $this->query(" |
|
1616 | + $ret = $this->query(" |
|
1617 | 1617 | if not exists( |
1618 | 1618 | select * |
1619 | 1619 | from sys.fulltext_catalogs |
@@ -1621,11 +1621,11 @@ discard block |
||
1621 | 1621 | ) |
1622 | 1622 | CREATE FULLTEXT CATALOG $catalog"); |
1623 | 1623 | |
1624 | - if (empty($ret)) { |
|
1625 | - $GLOBALS['log']->error("Error creating default full-text catalog, $catalog"); |
|
1626 | - } |
|
1627 | - } |
|
1628 | - } |
|
1624 | + if (empty($ret)) { |
|
1625 | + $GLOBALS['log']->error("Error creating default full-text catalog, $catalog"); |
|
1626 | + } |
|
1627 | + } |
|
1628 | + } |
|
1629 | 1629 | |
1630 | 1630 | /** |
1631 | 1631 | * Function returns name of the constraint automatically generated by sql-server. |
@@ -1635,7 +1635,7 @@ discard block |
||
1635 | 1635 | * @param string $column |
1636 | 1636 | * @return string |
1637 | 1637 | */ |
1638 | - private function get_field_default_constraint_name($table, $column = null) |
|
1638 | + private function get_field_default_constraint_name($table, $column = null) |
|
1639 | 1639 | { |
1640 | 1640 | static $results = array(); |
1641 | 1641 | |
@@ -1670,7 +1670,7 @@ discard block |
||
1670 | 1670 | } |
1671 | 1671 | |
1672 | 1672 | return null; |
1673 | - } |
|
1673 | + } |
|
1674 | 1674 | |
1675 | 1675 | /** |
1676 | 1676 | * @see DBManager::massageFieldDef() |
@@ -1692,7 +1692,7 @@ discard block |
||
1692 | 1692 | case 'varchar' : |
1693 | 1693 | case 'nvarchar' : |
1694 | 1694 | $fieldDef['len'] = $this->isTextType($fieldDef['dbType']) ? 'max' : '255'; |
1695 | - break; |
|
1695 | + break; |
|
1696 | 1696 | case 'image' : $fieldDef['len'] = '2147483647'; break; |
1697 | 1697 | case 'ntext' : $fieldDef['len'] = '2147483646'; break; // Note: this is from legacy code, don't know if this is correct |
1698 | 1698 | } |
@@ -1701,7 +1701,7 @@ discard block |
||
1701 | 1701 | && empty($fieldDef['precision']) |
1702 | 1702 | && !strpos($fieldDef['len'], ',')) |
1703 | 1703 | { |
1704 | - $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
|
1704 | + $fieldDef['len'] .= ',0'; // Adding 0 precision if it is not specified |
|
1705 | 1705 | } |
1706 | 1706 | |
1707 | 1707 | if(empty($fieldDef['default']) |
@@ -1709,8 +1709,8 @@ discard block |
||
1709 | 1709 | { |
1710 | 1710 | $fieldDef['default'] = '0'; |
1711 | 1711 | } |
1712 | - if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1713 | - $fieldDef['default'] = ''; |
|
1712 | + if (isset($fieldDef['required']) && $fieldDef['required'] && !isset($fieldDef['default']) ) |
|
1713 | + $fieldDef['default'] = ''; |
|
1714 | 1714 | // if ($fieldDef['type'] == 'bit' && empty($fieldDef['len']) ) |
1715 | 1715 | // $fieldDef['len'] = '1'; |
1716 | 1716 | // if ($fieldDef['type'] == 'bool' && empty($fieldDef['len']) ) |
@@ -1739,30 +1739,30 @@ discard block |
||
1739 | 1739 | */ |
1740 | 1740 | protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
1741 | 1741 | { |
1742 | - //Bug 25814 |
|
1743 | - if(isset($fieldDef['name'])){ |
|
1744 | - $colType = $this->getFieldType($fieldDef); |
|
1745 | - if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1746 | - $fieldDef['len'] = min($fieldDef['len'],38); |
|
1747 | - } |
|
1748 | - //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
|
1749 | - if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1750 | - unset($fieldDef['len']); |
|
1751 | - } |
|
1752 | - } |
|
1753 | - |
|
1754 | - // always return as array for post-processing |
|
1755 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
1756 | - |
|
1757 | - // Bug 24307 - Don't add precision for float fields. |
|
1758 | - if ( stristr($ref['colType'],'float') ) |
|
1759 | - $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1742 | + //Bug 25814 |
|
1743 | + if(isset($fieldDef['name'])){ |
|
1744 | + $colType = $this->getFieldType($fieldDef); |
|
1745 | + if(stristr($this->getFieldType($fieldDef), 'decimal') && isset($fieldDef['len'])){ |
|
1746 | + $fieldDef['len'] = min($fieldDef['len'],38); |
|
1747 | + } |
|
1748 | + //bug: 39690 float(8) is interpreted as real and this generates a diff when doing repair |
|
1749 | + if(stristr($colType, 'float') && isset($fieldDef['len']) && $fieldDef['len'] == 8){ |
|
1750 | + unset($fieldDef['len']); |
|
1751 | + } |
|
1752 | + } |
|
1753 | + |
|
1754 | + // always return as array for post-processing |
|
1755 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
1756 | + |
|
1757 | + // Bug 24307 - Don't add precision for float fields. |
|
1758 | + if ( stristr($ref['colType'],'float') ) |
|
1759 | + $ref['colType'] = preg_replace('/(,\d+)/','',$ref['colType']); |
|
1760 | 1760 | |
1761 | 1761 | if ( $return_as_array ) |
1762 | 1762 | return $ref; |
1763 | 1763 | else |
1764 | 1764 | return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
1765 | - } |
|
1765 | + } |
|
1766 | 1766 | |
1767 | 1767 | /** |
1768 | 1768 | * Saves changes to module's audit table |
@@ -1771,13 +1771,13 @@ discard block |
||
1771 | 1771 | * @param array $changes changes |
1772 | 1772 | */ |
1773 | 1773 | public function save_audit_records(SugarBean $bean, $changes) |
1774 | - { |
|
1775 | - //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
|
1776 | - if($changes['data_type'] == 'date'){ |
|
1777 | - $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1778 | - } |
|
1779 | - parent::save_audit_records($bean,$changes); |
|
1780 | - } |
|
1774 | + { |
|
1775 | + //Bug 25078 fixed by Martin Hu: sqlserver haven't 'date' type, trim extra "00:00:00" |
|
1776 | + if($changes['data_type'] == 'date'){ |
|
1777 | + $changes['before'] = str_replace(' 00:00:00','',$changes['before']); |
|
1778 | + } |
|
1779 | + parent::save_audit_records($bean,$changes); |
|
1780 | + } |
|
1781 | 1781 | |
1782 | 1782 | /** |
1783 | 1783 | * Disconnects from the database |
@@ -1786,7 +1786,7 @@ discard block |
||
1786 | 1786 | */ |
1787 | 1787 | public function disconnect() |
1788 | 1788 | { |
1789 | - $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
1789 | + $GLOBALS['log']->debug('Calling Mssql::disconnect()'); |
|
1790 | 1790 | if(!empty($this->database)){ |
1791 | 1791 | $this->freeResult(); |
1792 | 1792 | mssql_close($this->database); |
@@ -1803,21 +1803,21 @@ discard block |
||
1803 | 1803 | mssql_free_result($dbResult); |
1804 | 1804 | } |
1805 | 1805 | |
1806 | - /** |
|
1807 | - * (non-PHPdoc) |
|
1808 | - * @see DBManager::lastDbError() |
|
1809 | - */ |
|
1806 | + /** |
|
1807 | + * (non-PHPdoc) |
|
1808 | + * @see DBManager::lastDbError() |
|
1809 | + */ |
|
1810 | 1810 | public function lastDbError() |
1811 | 1811 | { |
1812 | 1812 | $sqlmsg = mssql_get_last_message(); |
1813 | 1813 | if(empty($sqlmsg)) return false; |
1814 | 1814 | global $app_strings; |
1815 | 1815 | if (empty($app_strings) |
1816 | - or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
1817 | - or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1816 | + or !isset($app_strings['ERR_MSSQL_DB_CONTEXT']) |
|
1817 | + or !isset($app_strings['ERR_MSSQL_WARNING']) ) { |
|
1818 | 1818 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
1819 | 1819 | //only if connection if made before language is set. |
1820 | - return false; |
|
1820 | + return false; |
|
1821 | 1821 | } |
1822 | 1822 | |
1823 | 1823 | $sqlpos = strpos($sqlmsg, 'Changed database context to'); |
@@ -1826,7 +1826,7 @@ discard block |
||
1826 | 1826 | if ( $sqlpos !== false || $sqlpos2 !== false || $sqlpos3 !== false ) { |
1827 | 1827 | return false; |
1828 | 1828 | } else { |
1829 | - global $app_strings; |
|
1829 | + global $app_strings; |
|
1830 | 1830 | //ERR_MSSQL_DB_CONTEXT: localized version of 'Changed database context to' message |
1831 | 1831 | if (empty($app_strings) or !isset($app_strings['ERR_MSSQL_DB_CONTEXT'])) { |
1832 | 1832 | //ignore the message from sql-server if $app_strings array is empty. This will happen |
@@ -1842,7 +1842,7 @@ discard block |
||
1842 | 1842 | } |
1843 | 1843 | |
1844 | 1844 | if ( strlen($sqlmsg) > 2 ) { |
1845 | - return "SQL Server error: " . $sqlmsg; |
|
1845 | + return "SQL Server error: " . $sqlmsg; |
|
1846 | 1846 | } |
1847 | 1847 | |
1848 | 1848 | return false; |
@@ -2065,7 +2065,7 @@ discard block |
||
2065 | 2065 | public function installConfig() |
2066 | 2066 | { |
2067 | 2067 | return array( |
2068 | - 'LBL_DBCONFIG_MSG3' => array( |
|
2068 | + 'LBL_DBCONFIG_MSG3' => array( |
|
2069 | 2069 | "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
2070 | 2070 | ), |
2071 | 2071 | 'LBL_DBCONFIG_MSG2' => array( |
@@ -2097,8 +2097,8 @@ discard block |
||
2097 | 2097 | * @return string |
2098 | 2098 | */ |
2099 | 2099 | |
2100 | - public function getGuidSQL() |
|
2100 | + public function getGuidSQL() |
|
2101 | 2101 | { |
2102 | - return 'NEWID()'; |
|
2102 | + return 'NEWID()'; |
|
2103 | 2103 | } |
2104 | 2104 | } |
@@ -96,368 +96,368 @@ discard block |
||
96 | 96 | */ |
97 | 97 | class MysqlManager extends DBManager |
98 | 98 | { |
99 | - /** |
|
100 | - * @see DBManager::$dbType |
|
101 | - */ |
|
102 | - public $dbType = 'mysql'; |
|
103 | - public $variant = 'mysql'; |
|
104 | - public $dbName = 'MySQL'; |
|
105 | - public $label = 'LBL_MYSQL'; |
|
106 | - |
|
107 | - protected $maxNameLengths = array( |
|
108 | - 'table' => 64, |
|
109 | - 'column' => 64, |
|
110 | - 'index' => 64, |
|
111 | - 'alias' => 256 |
|
112 | - ); |
|
113 | - |
|
114 | - protected $type_map = array( |
|
115 | - 'int' => 'int', |
|
116 | - 'double' => 'double', |
|
117 | - 'float' => 'float', |
|
118 | - 'uint' => 'int unsigned', |
|
119 | - 'ulong' => 'bigint unsigned', |
|
120 | - 'long' => 'bigint', |
|
121 | - 'short' => 'smallint', |
|
122 | - 'varchar' => 'varchar', |
|
123 | - 'text' => 'text', |
|
124 | - 'longtext' => 'longtext', |
|
125 | - 'date' => 'date', |
|
126 | - 'enum' => 'varchar', |
|
127 | - 'relate' => 'varchar', |
|
128 | - 'multienum'=> 'text', |
|
129 | - 'html' => 'text', |
|
130 | - 'longhtml' => 'longtext', |
|
131 | - 'datetime' => 'datetime', |
|
132 | - 'datetimecombo' => 'datetime', |
|
133 | - 'time' => 'time', |
|
134 | - 'bool' => 'bool', |
|
135 | - 'tinyint' => 'tinyint', |
|
136 | - 'char' => 'char', |
|
137 | - 'blob' => 'blob', |
|
138 | - 'longblob' => 'longblob', |
|
139 | - 'currency' => 'decimal(26,6)', |
|
140 | - 'decimal' => 'decimal', |
|
141 | - 'decimal2' => 'decimal', |
|
142 | - 'id' => 'char(36)', |
|
143 | - 'url' => 'varchar', |
|
144 | - 'encrypt' => 'varchar', |
|
145 | - 'file' => 'varchar', |
|
146 | - 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | - |
|
148 | - ); |
|
149 | - |
|
150 | - protected $capabilities = array( |
|
151 | - "affected_rows" => true, |
|
152 | - "select_rows" => true, |
|
153 | - "inline_keys" => true, |
|
154 | - "create_user" => true, |
|
155 | - "fulltext" => true, |
|
156 | - "collation" => true, |
|
157 | - "create_db" => true, |
|
158 | - "disable_keys" => true, |
|
159 | - ); |
|
160 | - |
|
161 | - /** |
|
162 | - * Parses and runs queries |
|
163 | - * |
|
164 | - * @param string $sql SQL Statement to execute |
|
165 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
166 | - * @param string $msg Message to log if error occurs |
|
167 | - * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
168 | - * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
169 | - * @return resource result set |
|
170 | - */ |
|
171 | - public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
172 | - { |
|
173 | - if(is_array($sql)) { |
|
174 | - return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
175 | - } |
|
176 | - |
|
177 | - parent::countQuery($sql); |
|
178 | - $GLOBALS['log']->info('Query:' . $sql); |
|
179 | - $this->checkConnection(); |
|
180 | - $this->query_time = microtime(true); |
|
181 | - $this->lastsql = $sql; |
|
182 | - $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
183 | - |
|
184 | - $this->query_time = microtime(true) - $this->query_time; |
|
185 | - $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
186 | - |
|
187 | - |
|
188 | - if($keepResult) |
|
189 | - $this->lastResult = $result; |
|
190 | - |
|
191 | - $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
192 | - return $result; |
|
193 | - } |
|
99 | + /** |
|
100 | + * @see DBManager::$dbType |
|
101 | + */ |
|
102 | + public $dbType = 'mysql'; |
|
103 | + public $variant = 'mysql'; |
|
104 | + public $dbName = 'MySQL'; |
|
105 | + public $label = 'LBL_MYSQL'; |
|
106 | + |
|
107 | + protected $maxNameLengths = array( |
|
108 | + 'table' => 64, |
|
109 | + 'column' => 64, |
|
110 | + 'index' => 64, |
|
111 | + 'alias' => 256 |
|
112 | + ); |
|
113 | + |
|
114 | + protected $type_map = array( |
|
115 | + 'int' => 'int', |
|
116 | + 'double' => 'double', |
|
117 | + 'float' => 'float', |
|
118 | + 'uint' => 'int unsigned', |
|
119 | + 'ulong' => 'bigint unsigned', |
|
120 | + 'long' => 'bigint', |
|
121 | + 'short' => 'smallint', |
|
122 | + 'varchar' => 'varchar', |
|
123 | + 'text' => 'text', |
|
124 | + 'longtext' => 'longtext', |
|
125 | + 'date' => 'date', |
|
126 | + 'enum' => 'varchar', |
|
127 | + 'relate' => 'varchar', |
|
128 | + 'multienum'=> 'text', |
|
129 | + 'html' => 'text', |
|
130 | + 'longhtml' => 'longtext', |
|
131 | + 'datetime' => 'datetime', |
|
132 | + 'datetimecombo' => 'datetime', |
|
133 | + 'time' => 'time', |
|
134 | + 'bool' => 'bool', |
|
135 | + 'tinyint' => 'tinyint', |
|
136 | + 'char' => 'char', |
|
137 | + 'blob' => 'blob', |
|
138 | + 'longblob' => 'longblob', |
|
139 | + 'currency' => 'decimal(26,6)', |
|
140 | + 'decimal' => 'decimal', |
|
141 | + 'decimal2' => 'decimal', |
|
142 | + 'id' => 'char(36)', |
|
143 | + 'url' => 'varchar', |
|
144 | + 'encrypt' => 'varchar', |
|
145 | + 'file' => 'varchar', |
|
146 | + 'decimal_tpl' => 'decimal(%d, %d)', |
|
147 | + |
|
148 | + ); |
|
149 | + |
|
150 | + protected $capabilities = array( |
|
151 | + "affected_rows" => true, |
|
152 | + "select_rows" => true, |
|
153 | + "inline_keys" => true, |
|
154 | + "create_user" => true, |
|
155 | + "fulltext" => true, |
|
156 | + "collation" => true, |
|
157 | + "create_db" => true, |
|
158 | + "disable_keys" => true, |
|
159 | + ); |
|
160 | + |
|
161 | + /** |
|
162 | + * Parses and runs queries |
|
163 | + * |
|
164 | + * @param string $sql SQL Statement to execute |
|
165 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
166 | + * @param string $msg Message to log if error occurs |
|
167 | + * @param bool $suppress Flag to suppress all error output unless in debug logging mode. |
|
168 | + * @param bool $keepResult True if we want to push this result into the $lastResult array. |
|
169 | + * @return resource result set |
|
170 | + */ |
|
171 | + public function query($sql, $dieOnError = false, $msg = '', $suppress = false, $keepResult = false) |
|
172 | + { |
|
173 | + if(is_array($sql)) { |
|
174 | + return $this->queryArray($sql, $dieOnError, $msg, $suppress); |
|
175 | + } |
|
176 | + |
|
177 | + parent::countQuery($sql); |
|
178 | + $GLOBALS['log']->info('Query:' . $sql); |
|
179 | + $this->checkConnection(); |
|
180 | + $this->query_time = microtime(true); |
|
181 | + $this->lastsql = $sql; |
|
182 | + $result = $suppress?@mysql_query($sql, $this->database):mysql_query($sql, $this->database); |
|
183 | + |
|
184 | + $this->query_time = microtime(true) - $this->query_time; |
|
185 | + $GLOBALS['log']->info('Query Execution Time:'.$this->query_time); |
|
186 | + |
|
187 | + |
|
188 | + if($keepResult) |
|
189 | + $this->lastResult = $result; |
|
190 | + |
|
191 | + $this->checkError($msg.' Query Failed:' . $sql . '::', $dieOnError); |
|
192 | + return $result; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Returns the number of rows affected by the last query |
197 | 197 | * @param $result |
198 | 198 | * @return int |
199 | 199 | */ |
200 | - public function getAffectedRowCount($result) |
|
201 | - { |
|
202 | - return mysql_affected_rows($this->getDatabase()); |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * Returns the number of rows returned by the result |
|
207 | - * |
|
208 | - * This function can't be reliably implemented on most DB, do not use it. |
|
209 | - * @abstract |
|
210 | - * @deprecated |
|
211 | - * @param resource $result |
|
212 | - * @return int |
|
213 | - */ |
|
214 | - public function getRowCount($result) |
|
215 | - { |
|
216 | - return mysql_num_rows($result); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * Disconnects from the database |
|
221 | - * |
|
222 | - * Also handles any cleanup needed |
|
223 | - */ |
|
224 | - public function disconnect() |
|
225 | - { |
|
226 | - $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
227 | - if(!empty($this->database)){ |
|
228 | - $this->freeResult(); |
|
229 | - mysql_close($this->database); |
|
230 | - $this->database = null; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * @see DBManager::freeDbResult() |
|
236 | - */ |
|
237 | - protected function freeDbResult($dbResult) |
|
238 | - { |
|
239 | - if(!empty($dbResult)) |
|
240 | - mysql_free_result($dbResult); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * @abstract |
|
246 | - * Check if query has LIMIT clause |
|
247 | - * Relevant for now only for Mysql |
|
248 | - * @param string $sql |
|
249 | - * @return bool |
|
250 | - */ |
|
251 | - protected function hasLimit($sql) |
|
252 | - { |
|
253 | - return stripos($sql, " limit ") !== false; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * @see DBManager::limitQuery() |
|
258 | - */ |
|
259 | - public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
260 | - { |
|
200 | + public function getAffectedRowCount($result) |
|
201 | + { |
|
202 | + return mysql_affected_rows($this->getDatabase()); |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * Returns the number of rows returned by the result |
|
207 | + * |
|
208 | + * This function can't be reliably implemented on most DB, do not use it. |
|
209 | + * @abstract |
|
210 | + * @deprecated |
|
211 | + * @param resource $result |
|
212 | + * @return int |
|
213 | + */ |
|
214 | + public function getRowCount($result) |
|
215 | + { |
|
216 | + return mysql_num_rows($result); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * Disconnects from the database |
|
221 | + * |
|
222 | + * Also handles any cleanup needed |
|
223 | + */ |
|
224 | + public function disconnect() |
|
225 | + { |
|
226 | + $GLOBALS['log']->debug('Calling MySQL::disconnect()'); |
|
227 | + if(!empty($this->database)){ |
|
228 | + $this->freeResult(); |
|
229 | + mysql_close($this->database); |
|
230 | + $this->database = null; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * @see DBManager::freeDbResult() |
|
236 | + */ |
|
237 | + protected function freeDbResult($dbResult) |
|
238 | + { |
|
239 | + if(!empty($dbResult)) |
|
240 | + mysql_free_result($dbResult); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * @abstract |
|
246 | + * Check if query has LIMIT clause |
|
247 | + * Relevant for now only for Mysql |
|
248 | + * @param string $sql |
|
249 | + * @return bool |
|
250 | + */ |
|
251 | + protected function hasLimit($sql) |
|
252 | + { |
|
253 | + return stripos($sql, " limit ") !== false; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * @see DBManager::limitQuery() |
|
258 | + */ |
|
259 | + public function limitQuery($sql, $start, $count, $dieOnError = false, $msg = '', $execute = true) |
|
260 | + { |
|
261 | 261 | $start = (int)$start; |
262 | 262 | $count = (int)$count; |
263 | - if ($start < 0) |
|
264 | - $start = 0; |
|
265 | - $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
266 | - |
|
267 | - $sql = "$sql LIMIT $start,$count"; |
|
268 | - $this->lastsql = $sql; |
|
269 | - |
|
270 | - if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
271 | - $this->checkQuery($sql); |
|
272 | - } |
|
273 | - if(!$execute) { |
|
274 | - return $sql; |
|
275 | - } |
|
276 | - |
|
277 | - return $this->query($sql, $dieOnError, $msg); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @see DBManager::checkQuery() |
|
283 | - */ |
|
284 | - protected function checkQuery($sql, $object_name = false) |
|
285 | - { |
|
286 | - $result = $this->query('EXPLAIN ' . $sql); |
|
287 | - $badQuery = array(); |
|
288 | - while ($row = $this->fetchByAssoc($result)) { |
|
289 | - if (empty($row['table'])) |
|
290 | - continue; |
|
291 | - $badQuery[$row['table']] = ''; |
|
292 | - if (strtoupper($row['type']) == 'ALL') |
|
293 | - $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | - if (empty($row['key'])) |
|
295 | - $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
296 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
297 | - $badQuery[$row['table']] .= ' Using FileSort;'; |
|
298 | - if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
299 | - $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
300 | - } |
|
301 | - |
|
302 | - if ( empty($badQuery) ) |
|
303 | - return true; |
|
304 | - |
|
305 | - foreach($badQuery as $table=>$data ){ |
|
306 | - if(!empty($data)){ |
|
307 | - $warning = ' Table:' . $table . ' Data:' . $data; |
|
308 | - if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
309 | - $GLOBALS['log']->fatal($sql); |
|
310 | - $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
311 | - } |
|
312 | - else{ |
|
313 | - $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
314 | - } |
|
315 | - } |
|
316 | - } |
|
317 | - |
|
318 | - return false; |
|
319 | - } |
|
320 | - |
|
321 | - /** |
|
322 | - * @see DBManager::get_columns() |
|
323 | - */ |
|
324 | - public function get_columns($tablename) |
|
325 | - { |
|
326 | - //find all unique indexes and primary keys. |
|
327 | - $result = $this->query("DESCRIBE $tablename"); |
|
328 | - |
|
329 | - $columns = array(); |
|
330 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
331 | - $name = strtolower($row['Field']); |
|
332 | - $columns[$name]['name']=$name; |
|
333 | - $matches = array(); |
|
334 | - preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
335 | - $columns[$name]['type']=strtolower($matches[1][0]); |
|
336 | - if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | - $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | - if ( stristr($row['Extra'],'auto_increment') ) |
|
339 | - $columns[$name]['auto_increment'] = '1'; |
|
340 | - if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
341 | - $columns[$name]['required'] = 'true'; |
|
342 | - if (!empty($row['Default']) ) |
|
343 | - $columns[$name]['default'] = $row['Default']; |
|
344 | - } |
|
345 | - return $columns; |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * @see DBManager::getFieldsArray() |
|
350 | - */ |
|
351 | - public function getFieldsArray($result, $make_lower_case=false) |
|
352 | - { |
|
353 | - $field_array = array(); |
|
354 | - |
|
355 | - if(empty($result)) |
|
356 | - return 0; |
|
357 | - |
|
358 | - $fields = mysql_num_fields($result); |
|
359 | - for ($i=0; $i < $fields; $i++) { |
|
360 | - $meta = mysql_fetch_field($result, $i); |
|
361 | - if (!$meta) |
|
362 | - return array(); |
|
363 | - |
|
364 | - if($make_lower_case == true) |
|
365 | - $meta->name = strtolower($meta->name); |
|
366 | - |
|
367 | - $field_array[] = $meta->name; |
|
368 | - } |
|
369 | - |
|
370 | - return $field_array; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * @see DBManager::fetchRow() |
|
375 | - */ |
|
376 | - public function fetchRow($result) |
|
377 | - { |
|
378 | - if (empty($result)) return false; |
|
379 | - |
|
380 | - return mysql_fetch_assoc($result); |
|
381 | - } |
|
382 | - |
|
383 | - /** |
|
384 | - * @see DBManager::getTablesArray() |
|
385 | - */ |
|
386 | - public function getTablesArray() |
|
387 | - { |
|
388 | - $this->log->debug('Fetching table list'); |
|
389 | - |
|
390 | - if ($this->getDatabase()) { |
|
391 | - $tables = array(); |
|
392 | - $r = $this->query('SHOW TABLES'); |
|
393 | - if (!empty($r)) { |
|
394 | - while ($a = $this->fetchByAssoc($r)) { |
|
395 | - $row = array_values($a); |
|
396 | - $tables[]=$row[0]; |
|
397 | - } |
|
398 | - return $tables; |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - return false; // no database available |
|
403 | - } |
|
404 | - |
|
405 | - /** |
|
406 | - * @see DBManager::version() |
|
407 | - */ |
|
408 | - public function version() |
|
409 | - { |
|
410 | - return $this->getOne("SELECT version() version"); |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * @see DBManager::tableExists() |
|
415 | - */ |
|
416 | - public function tableExists($tableName) |
|
417 | - { |
|
418 | - $this->log->info("tableExists: $tableName"); |
|
419 | - |
|
420 | - if ($this->getDatabase()) { |
|
421 | - $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
422 | - if(empty($result)) return false; |
|
423 | - $row = $this->fetchByAssoc($result); |
|
424 | - return !empty($row); |
|
425 | - } |
|
426 | - |
|
427 | - return false; |
|
428 | - } |
|
429 | - |
|
430 | - /** |
|
431 | - * Get tables like expression |
|
432 | - * @param $like string |
|
433 | - * @return array |
|
434 | - */ |
|
435 | - public function tablesLike($like) |
|
436 | - { |
|
437 | - if ($this->getDatabase()) { |
|
438 | - $tables = array(); |
|
439 | - $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
440 | - if (!empty($r)) { |
|
441 | - while ($a = $this->fetchByAssoc($r)) { |
|
442 | - $row = array_values($a); |
|
443 | - $tables[]=$row[0]; |
|
444 | - } |
|
445 | - return $tables; |
|
446 | - } |
|
447 | - } |
|
448 | - return false; |
|
449 | - } |
|
450 | - |
|
451 | - /** |
|
452 | - * @see DBManager::quote() |
|
453 | - */ |
|
454 | - public function quote($string) |
|
455 | - { |
|
456 | - if(is_array($string)) { |
|
457 | - return $this->arrayQuote($string); |
|
458 | - } |
|
459 | - return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
460 | - } |
|
263 | + if ($start < 0) |
|
264 | + $start = 0; |
|
265 | + $GLOBALS['log']->debug('Limit Query:' . $sql. ' Start: ' .$start . ' count: ' . $count); |
|
266 | + |
|
267 | + $sql = "$sql LIMIT $start,$count"; |
|
268 | + $this->lastsql = $sql; |
|
269 | + |
|
270 | + if(!empty($GLOBALS['sugar_config']['check_query'])){ |
|
271 | + $this->checkQuery($sql); |
|
272 | + } |
|
273 | + if(!$execute) { |
|
274 | + return $sql; |
|
275 | + } |
|
276 | + |
|
277 | + return $this->query($sql, $dieOnError, $msg); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @see DBManager::checkQuery() |
|
283 | + */ |
|
284 | + protected function checkQuery($sql, $object_name = false) |
|
285 | + { |
|
286 | + $result = $this->query('EXPLAIN ' . $sql); |
|
287 | + $badQuery = array(); |
|
288 | + while ($row = $this->fetchByAssoc($result)) { |
|
289 | + if (empty($row['table'])) |
|
290 | + continue; |
|
291 | + $badQuery[$row['table']] = ''; |
|
292 | + if (strtoupper($row['type']) == 'ALL') |
|
293 | + $badQuery[$row['table']] .= ' Full Table Scan;'; |
|
294 | + if (empty($row['key'])) |
|
295 | + $badQuery[$row['table']] .= ' No Index Key Used;'; |
|
296 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using filesort') > 0) |
|
297 | + $badQuery[$row['table']] .= ' Using FileSort;'; |
|
298 | + if (!empty($row['Extra']) && substr_count($row['Extra'], 'Using temporary') > 0) |
|
299 | + $badQuery[$row['table']] .= ' Using Temporary Table;'; |
|
300 | + } |
|
301 | + |
|
302 | + if ( empty($badQuery) ) |
|
303 | + return true; |
|
304 | + |
|
305 | + foreach($badQuery as $table=>$data ){ |
|
306 | + if(!empty($data)){ |
|
307 | + $warning = ' Table:' . $table . ' Data:' . $data; |
|
308 | + if(!empty($GLOBALS['sugar_config']['check_query_log'])){ |
|
309 | + $GLOBALS['log']->fatal($sql); |
|
310 | + $GLOBALS['log']->fatal('CHECK QUERY:' .$warning); |
|
311 | + } |
|
312 | + else{ |
|
313 | + $GLOBALS['log']->warn('CHECK QUERY:' .$warning); |
|
314 | + } |
|
315 | + } |
|
316 | + } |
|
317 | + |
|
318 | + return false; |
|
319 | + } |
|
320 | + |
|
321 | + /** |
|
322 | + * @see DBManager::get_columns() |
|
323 | + */ |
|
324 | + public function get_columns($tablename) |
|
325 | + { |
|
326 | + //find all unique indexes and primary keys. |
|
327 | + $result = $this->query("DESCRIBE $tablename"); |
|
328 | + |
|
329 | + $columns = array(); |
|
330 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
331 | + $name = strtolower($row['Field']); |
|
332 | + $columns[$name]['name']=$name; |
|
333 | + $matches = array(); |
|
334 | + preg_match_all('/(\w+)(?:\(([0-9]+,?[0-9]*)\)|)( unsigned)?/i', $row['Type'], $matches); |
|
335 | + $columns[$name]['type']=strtolower($matches[1][0]); |
|
336 | + if ( isset($matches[2][0]) && in_array(strtolower($matches[1][0]),array('varchar','char','varchar2','int','decimal','float')) ) |
|
337 | + $columns[$name]['len']=strtolower($matches[2][0]); |
|
338 | + if ( stristr($row['Extra'],'auto_increment') ) |
|
339 | + $columns[$name]['auto_increment'] = '1'; |
|
340 | + if ($row['Null'] == 'NO' && !stristr($row['Key'],'PRI')) |
|
341 | + $columns[$name]['required'] = 'true'; |
|
342 | + if (!empty($row['Default']) ) |
|
343 | + $columns[$name]['default'] = $row['Default']; |
|
344 | + } |
|
345 | + return $columns; |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * @see DBManager::getFieldsArray() |
|
350 | + */ |
|
351 | + public function getFieldsArray($result, $make_lower_case=false) |
|
352 | + { |
|
353 | + $field_array = array(); |
|
354 | + |
|
355 | + if(empty($result)) |
|
356 | + return 0; |
|
357 | + |
|
358 | + $fields = mysql_num_fields($result); |
|
359 | + for ($i=0; $i < $fields; $i++) { |
|
360 | + $meta = mysql_fetch_field($result, $i); |
|
361 | + if (!$meta) |
|
362 | + return array(); |
|
363 | + |
|
364 | + if($make_lower_case == true) |
|
365 | + $meta->name = strtolower($meta->name); |
|
366 | + |
|
367 | + $field_array[] = $meta->name; |
|
368 | + } |
|
369 | + |
|
370 | + return $field_array; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * @see DBManager::fetchRow() |
|
375 | + */ |
|
376 | + public function fetchRow($result) |
|
377 | + { |
|
378 | + if (empty($result)) return false; |
|
379 | + |
|
380 | + return mysql_fetch_assoc($result); |
|
381 | + } |
|
382 | + |
|
383 | + /** |
|
384 | + * @see DBManager::getTablesArray() |
|
385 | + */ |
|
386 | + public function getTablesArray() |
|
387 | + { |
|
388 | + $this->log->debug('Fetching table list'); |
|
389 | + |
|
390 | + if ($this->getDatabase()) { |
|
391 | + $tables = array(); |
|
392 | + $r = $this->query('SHOW TABLES'); |
|
393 | + if (!empty($r)) { |
|
394 | + while ($a = $this->fetchByAssoc($r)) { |
|
395 | + $row = array_values($a); |
|
396 | + $tables[]=$row[0]; |
|
397 | + } |
|
398 | + return $tables; |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + return false; // no database available |
|
403 | + } |
|
404 | + |
|
405 | + /** |
|
406 | + * @see DBManager::version() |
|
407 | + */ |
|
408 | + public function version() |
|
409 | + { |
|
410 | + return $this->getOne("SELECT version() version"); |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * @see DBManager::tableExists() |
|
415 | + */ |
|
416 | + public function tableExists($tableName) |
|
417 | + { |
|
418 | + $this->log->info("tableExists: $tableName"); |
|
419 | + |
|
420 | + if ($this->getDatabase()) { |
|
421 | + $result = $this->query("SHOW TABLES LIKE ".$this->quoted($tableName)); |
|
422 | + if(empty($result)) return false; |
|
423 | + $row = $this->fetchByAssoc($result); |
|
424 | + return !empty($row); |
|
425 | + } |
|
426 | + |
|
427 | + return false; |
|
428 | + } |
|
429 | + |
|
430 | + /** |
|
431 | + * Get tables like expression |
|
432 | + * @param $like string |
|
433 | + * @return array |
|
434 | + */ |
|
435 | + public function tablesLike($like) |
|
436 | + { |
|
437 | + if ($this->getDatabase()) { |
|
438 | + $tables = array(); |
|
439 | + $r = $this->query('SHOW TABLES LIKE '.$this->quoted($like)); |
|
440 | + if (!empty($r)) { |
|
441 | + while ($a = $this->fetchByAssoc($r)) { |
|
442 | + $row = array_values($a); |
|
443 | + $tables[]=$row[0]; |
|
444 | + } |
|
445 | + return $tables; |
|
446 | + } |
|
447 | + } |
|
448 | + return false; |
|
449 | + } |
|
450 | + |
|
451 | + /** |
|
452 | + * @see DBManager::quote() |
|
453 | + */ |
|
454 | + public function quote($string) |
|
455 | + { |
|
456 | + if(is_array($string)) { |
|
457 | + return $this->arrayQuote($string); |
|
458 | + } |
|
459 | + return mysql_real_escape_string($this->quoteInternal($string), $this->getDatabase()); |
|
460 | + } |
|
461 | 461 | |
462 | 462 | /** |
463 | 463 | * @see DBManager::quoteIdentifier() |
@@ -467,272 +467,272 @@ discard block |
||
467 | 467 | return '`'.$string.'`'; |
468 | 468 | } |
469 | 469 | |
470 | - /** |
|
471 | - * @see DBManager::connect() |
|
472 | - */ |
|
473 | - public function connect(array $configOptions = null, $dieOnError = false) |
|
474 | - { |
|
475 | - global $sugar_config; |
|
476 | - |
|
477 | - if(is_null($configOptions)) |
|
478 | - $configOptions = $sugar_config['dbconfig']; |
|
479 | - |
|
480 | - if ($this->getOption('persistent')) { |
|
481 | - $this->database = @mysql_pconnect( |
|
482 | - $configOptions['db_host_name'], |
|
483 | - $configOptions['db_user_name'], |
|
484 | - $configOptions['db_password'] |
|
485 | - ); |
|
486 | - } |
|
487 | - |
|
488 | - if (!$this->database) { |
|
489 | - $this->database = mysql_connect( |
|
490 | - $configOptions['db_host_name'], |
|
491 | - $configOptions['db_user_name'], |
|
492 | - $configOptions['db_password'] |
|
493 | - ); |
|
494 | - if(empty($this->database)) { |
|
495 | - $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
496 | - if($dieOnError) { |
|
497 | - if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
498 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
499 | - } else { |
|
500 | - sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
501 | - } |
|
502 | - } else { |
|
503 | - return false; |
|
504 | - } |
|
505 | - } |
|
506 | - // Do not pass connection information because we have not connected yet |
|
507 | - if($this->database && $this->getOption('persistent')){ |
|
508 | - $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
509 | - . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
510 | - . "in your config.php file</b>"; |
|
511 | - } |
|
512 | - } |
|
513 | - if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | - $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
515 | - if($dieOnError) { |
|
516 | - sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
517 | - } else { |
|
518 | - return false; |
|
519 | - } |
|
520 | - } |
|
521 | - |
|
522 | - // cn: using direct calls to prevent this from spamming the Logs |
|
523 | - mysql_query("SET CHARACTER SET utf8", $this->database); |
|
524 | - $names = "SET NAMES 'utf8'"; |
|
525 | - $collation = $this->getOption('collation'); |
|
526 | - if(!empty($collation)) { |
|
527 | - $names .= " COLLATE '$collation'"; |
|
528 | - } |
|
529 | - mysql_query($names, $this->database); |
|
530 | - |
|
531 | - if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | - $GLOBALS['log']->info("connected to db"); |
|
533 | - $this->connectOptions = $configOptions; |
|
534 | - |
|
535 | - $GLOBALS['log']->info("Connect:".$this->database); |
|
536 | - return true; |
|
537 | - } |
|
538 | - |
|
539 | - /** |
|
540 | - * @see DBManager::repairTableParams() |
|
541 | - * |
|
542 | - * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
543 | - * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
544 | - */ |
|
545 | - public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
546 | - { |
|
547 | - $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
548 | - |
|
549 | - if ( $sql == '' ) |
|
550 | - return ''; |
|
551 | - |
|
552 | - if ( stristr($sql,'create table') ) |
|
553 | - { |
|
554 | - if ($execute) { |
|
555 | - $msg = "Error creating table: ".$tablename. ":"; |
|
556 | - $this->query($sql,true,$msg); |
|
557 | - } |
|
558 | - return $sql; |
|
559 | - } |
|
560 | - |
|
561 | - // first, parse out all the comments |
|
562 | - $match = array(); |
|
563 | - preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
564 | - $commentBlocks = $match[0]; |
|
565 | - $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
566 | - |
|
567 | - // now, we should only have alter table statements |
|
568 | - // let's replace the 'alter table name' part with a comma |
|
569 | - $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
570 | - |
|
571 | - // re-add it at the beginning |
|
572 | - $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
573 | - $sql = str_replace(";","",$sql); |
|
574 | - $sql = str_replace("\n","",$sql); |
|
575 | - $sql = "ALTER TABLE $tablename $sql"; |
|
576 | - |
|
577 | - if ( $execute ) |
|
578 | - $this->query($sql,'Error with MySQL repair table'); |
|
579 | - |
|
580 | - // and re-add the comments at the beginning |
|
581 | - $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
582 | - |
|
583 | - return $sql; |
|
584 | - } |
|
585 | - |
|
586 | - /** |
|
587 | - * @see DBManager::convert() |
|
588 | - */ |
|
589 | - public function convert($string, $type, array $additional_parameters = array()) |
|
590 | - { |
|
591 | - $all_parameters = $additional_parameters; |
|
592 | - if(is_array($string)) { |
|
593 | - $all_parameters = array_merge($string, $all_parameters); |
|
594 | - } elseif (!is_null($string)) { |
|
595 | - array_unshift($all_parameters, $string); |
|
596 | - } |
|
597 | - $all_strings = implode(',', $all_parameters); |
|
598 | - |
|
599 | - switch (strtolower($type)) { |
|
600 | - case 'today': |
|
601 | - return "CURDATE()"; |
|
602 | - case 'left': |
|
603 | - return "LEFT($all_strings)"; |
|
604 | - case 'date_format': |
|
605 | - if(empty($additional_parameters)) { |
|
606 | - return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
607 | - } else { |
|
608 | - $format = $additional_parameters[0]; |
|
609 | - if($format[0] != "'") { |
|
610 | - $format = $this->quoted($format); |
|
611 | - } |
|
612 | - return "DATE_FORMAT($string,$format)"; |
|
613 | - } |
|
614 | - case 'ifnull': |
|
615 | - if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
616 | - $all_strings .= ",''"; |
|
617 | - } |
|
618 | - return "IFNULL($all_strings)"; |
|
619 | - case 'concat': |
|
620 | - return "CONCAT($all_strings)"; |
|
621 | - case 'quarter': |
|
622 | - return "QUARTER($string)"; |
|
623 | - case "length": |
|
624 | - return "LENGTH($string)"; |
|
625 | - case 'month': |
|
626 | - return "MONTH($string)"; |
|
627 | - case 'add_date': |
|
628 | - return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
629 | - case 'add_time': |
|
630 | - return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
470 | + /** |
|
471 | + * @see DBManager::connect() |
|
472 | + */ |
|
473 | + public function connect(array $configOptions = null, $dieOnError = false) |
|
474 | + { |
|
475 | + global $sugar_config; |
|
476 | + |
|
477 | + if(is_null($configOptions)) |
|
478 | + $configOptions = $sugar_config['dbconfig']; |
|
479 | + |
|
480 | + if ($this->getOption('persistent')) { |
|
481 | + $this->database = @mysql_pconnect( |
|
482 | + $configOptions['db_host_name'], |
|
483 | + $configOptions['db_user_name'], |
|
484 | + $configOptions['db_password'] |
|
485 | + ); |
|
486 | + } |
|
487 | + |
|
488 | + if (!$this->database) { |
|
489 | + $this->database = mysql_connect( |
|
490 | + $configOptions['db_host_name'], |
|
491 | + $configOptions['db_user_name'], |
|
492 | + $configOptions['db_password'] |
|
493 | + ); |
|
494 | + if(empty($this->database)) { |
|
495 | + $GLOBALS['log']->fatal("Could not connect to server ".$configOptions['db_host_name']." as ".$configOptions['db_user_name'].":".mysql_error()); |
|
496 | + if($dieOnError) { |
|
497 | + if(isset($GLOBALS['app_strings']['ERR_NO_DB'])) { |
|
498 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
499 | + } else { |
|
500 | + sugar_die("Could not connect to the database. Please refer to suitecrm.log for details."); |
|
501 | + } |
|
502 | + } else { |
|
503 | + return false; |
|
504 | + } |
|
505 | + } |
|
506 | + // Do not pass connection information because we have not connected yet |
|
507 | + if($this->database && $this->getOption('persistent')){ |
|
508 | + $_SESSION['administrator_error'] = "<b>Severe Performance Degradation: Persistent Database Connections " |
|
509 | + . "not working. Please set \$sugar_config['dbconfigoption']['persistent'] to false " |
|
510 | + . "in your config.php file</b>"; |
|
511 | + } |
|
512 | + } |
|
513 | + if(!empty($configOptions['db_name']) && !@mysql_select_db($configOptions['db_name'])) { |
|
514 | + $GLOBALS['log']->fatal( "Unable to select database {$configOptions['db_name']}: " . mysql_error($this->database)); |
|
515 | + if($dieOnError) { |
|
516 | + sugar_die($GLOBALS['app_strings']['ERR_NO_DB']); |
|
517 | + } else { |
|
518 | + return false; |
|
519 | + } |
|
520 | + } |
|
521 | + |
|
522 | + // cn: using direct calls to prevent this from spamming the Logs |
|
523 | + mysql_query("SET CHARACTER SET utf8", $this->database); |
|
524 | + $names = "SET NAMES 'utf8'"; |
|
525 | + $collation = $this->getOption('collation'); |
|
526 | + if(!empty($collation)) { |
|
527 | + $names .= " COLLATE '$collation'"; |
|
528 | + } |
|
529 | + mysql_query($names, $this->database); |
|
530 | + |
|
531 | + if(!$this->checkError('Could Not Connect:', $dieOnError)) |
|
532 | + $GLOBALS['log']->info("connected to db"); |
|
533 | + $this->connectOptions = $configOptions; |
|
534 | + |
|
535 | + $GLOBALS['log']->info("Connect:".$this->database); |
|
536 | + return true; |
|
537 | + } |
|
538 | + |
|
539 | + /** |
|
540 | + * @see DBManager::repairTableParams() |
|
541 | + * |
|
542 | + * For MySQL, we can write the ALTER TABLE statement all in one line, which speeds things |
|
543 | + * up quite a bit. So here, we'll parse the returned SQL into a single ALTER TABLE command. |
|
544 | + */ |
|
545 | + public function repairTableParams($tablename, $fielddefs, $indices, $execute = true, $engine = null) |
|
546 | + { |
|
547 | + $sql = parent::repairTableParams($tablename,$fielddefs,$indices,false,$engine); |
|
548 | + |
|
549 | + if ( $sql == '' ) |
|
550 | + return ''; |
|
551 | + |
|
552 | + if ( stristr($sql,'create table') ) |
|
553 | + { |
|
554 | + if ($execute) { |
|
555 | + $msg = "Error creating table: ".$tablename. ":"; |
|
556 | + $this->query($sql,true,$msg); |
|
557 | + } |
|
558 | + return $sql; |
|
559 | + } |
|
560 | + |
|
561 | + // first, parse out all the comments |
|
562 | + $match = array(); |
|
563 | + preg_match_all('!/\*.*?\*/!is', $sql, $match); |
|
564 | + $commentBlocks = $match[0]; |
|
565 | + $sql = preg_replace('!/\*.*?\*/!is','', $sql); |
|
566 | + |
|
567 | + // now, we should only have alter table statements |
|
568 | + // let's replace the 'alter table name' part with a comma |
|
569 | + $sql = preg_replace("!alter table $tablename!is",', ', $sql); |
|
570 | + |
|
571 | + // re-add it at the beginning |
|
572 | + $sql = substr_replace($sql,'',strpos($sql,','),1); |
|
573 | + $sql = str_replace(";","",$sql); |
|
574 | + $sql = str_replace("\n","",$sql); |
|
575 | + $sql = "ALTER TABLE $tablename $sql"; |
|
576 | + |
|
577 | + if ( $execute ) |
|
578 | + $this->query($sql,'Error with MySQL repair table'); |
|
579 | + |
|
580 | + // and re-add the comments at the beginning |
|
581 | + $sql = implode("\n",$commentBlocks) . "\n". $sql . "\n"; |
|
582 | + |
|
583 | + return $sql; |
|
584 | + } |
|
585 | + |
|
586 | + /** |
|
587 | + * @see DBManager::convert() |
|
588 | + */ |
|
589 | + public function convert($string, $type, array $additional_parameters = array()) |
|
590 | + { |
|
591 | + $all_parameters = $additional_parameters; |
|
592 | + if(is_array($string)) { |
|
593 | + $all_parameters = array_merge($string, $all_parameters); |
|
594 | + } elseif (!is_null($string)) { |
|
595 | + array_unshift($all_parameters, $string); |
|
596 | + } |
|
597 | + $all_strings = implode(',', $all_parameters); |
|
598 | + |
|
599 | + switch (strtolower($type)) { |
|
600 | + case 'today': |
|
601 | + return "CURDATE()"; |
|
602 | + case 'left': |
|
603 | + return "LEFT($all_strings)"; |
|
604 | + case 'date_format': |
|
605 | + if(empty($additional_parameters)) { |
|
606 | + return "DATE_FORMAT($string,'%Y-%m-%d')"; |
|
607 | + } else { |
|
608 | + $format = $additional_parameters[0]; |
|
609 | + if($format[0] != "'") { |
|
610 | + $format = $this->quoted($format); |
|
611 | + } |
|
612 | + return "DATE_FORMAT($string,$format)"; |
|
613 | + } |
|
614 | + case 'ifnull': |
|
615 | + if(empty($additional_parameters) && !strstr($all_strings, ",")) { |
|
616 | + $all_strings .= ",''"; |
|
617 | + } |
|
618 | + return "IFNULL($all_strings)"; |
|
619 | + case 'concat': |
|
620 | + return "CONCAT($all_strings)"; |
|
621 | + case 'quarter': |
|
622 | + return "QUARTER($string)"; |
|
623 | + case "length": |
|
624 | + return "LENGTH($string)"; |
|
625 | + case 'month': |
|
626 | + return "MONTH($string)"; |
|
627 | + case 'add_date': |
|
628 | + return "DATE_ADD($string, INTERVAL {$additional_parameters[0]} {$additional_parameters[1]})"; |
|
629 | + case 'add_time': |
|
630 | + return "DATE_ADD($string, INTERVAL + CONCAT({$additional_parameters[0]}, ':', {$additional_parameters[1]}) HOUR_MINUTE)"; |
|
631 | 631 | case 'add_tz_offset' : |
632 | 632 | $getUserUTCOffset = $GLOBALS['timedate']->getUserUTCOffset(); |
633 | 633 | $operation = $getUserUTCOffset < 0 ? '-' : '+'; |
634 | 634 | return $string . ' ' . $operation . ' INTERVAL ' . abs($getUserUTCOffset) . ' MINUTE'; |
635 | 635 | case 'avg': |
636 | 636 | return "avg($string)"; |
637 | - } |
|
638 | - |
|
639 | - return $string; |
|
640 | - } |
|
641 | - |
|
642 | - /** |
|
643 | - * (non-PHPdoc) |
|
644 | - * @see DBManager::fromConvert() |
|
645 | - */ |
|
646 | - public function fromConvert($string, $type) |
|
647 | - { |
|
648 | - return $string; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Returns the name of the engine to use or null if we are to use the default |
|
653 | - * |
|
654 | - * @param object $bean SugarBean instance |
|
655 | - * @return string |
|
656 | - */ |
|
657 | - protected function getEngine($bean) |
|
658 | - { |
|
659 | - global $dictionary; |
|
660 | - $engine = null; |
|
661 | - if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
662 | - $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
663 | - } |
|
664 | - return $engine; |
|
665 | - } |
|
666 | - |
|
667 | - /** |
|
668 | - * Returns true if the engine given is enabled in the backend |
|
669 | - * |
|
670 | - * @param string $engine |
|
671 | - * @return bool |
|
672 | - */ |
|
673 | - protected function isEngineEnabled($engine) |
|
674 | - { |
|
675 | - if(!is_string($engine)) return false; |
|
676 | - |
|
677 | - $engine = strtoupper($engine); |
|
678 | - |
|
679 | - $r = $this->query("SHOW ENGINES"); |
|
680 | - |
|
681 | - while ( $row = $this->fetchByAssoc($r) ) |
|
682 | - if ( strtoupper($row['Engine']) == $engine ) |
|
683 | - return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
684 | - |
|
685 | - return false; |
|
686 | - } |
|
687 | - |
|
688 | - /** |
|
689 | - * @see DBManager::createTableSQL() |
|
690 | - */ |
|
691 | - public function createTableSQL(SugarBean $bean) |
|
692 | - { |
|
693 | - $tablename = $bean->getTableName(); |
|
694 | - $fieldDefs = $bean->getFieldDefinitions(); |
|
695 | - $indices = $bean->getIndices(); |
|
696 | - $engine = $this->getEngine($bean); |
|
697 | - return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
698 | - } |
|
699 | - |
|
700 | - /** |
|
701 | - * Generates sql for create table statement for a bean. |
|
702 | - * |
|
703 | - * @param string $tablename |
|
704 | - * @param array $fieldDefs |
|
705 | - * @param array $indices |
|
706 | - * @param string $engine optional, MySQL engine to use |
|
707 | - * @return string SQL Create Table statement |
|
708 | - */ |
|
709 | - public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
710 | - { |
|
711 | - if ( empty($engine) && isset($fieldDefs['engine'])) |
|
712 | - $engine = $fieldDefs['engine']; |
|
713 | - if ( !$this->isEngineEnabled($engine) ) |
|
714 | - $engine = ''; |
|
715 | - |
|
716 | - $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
717 | - if (empty($columns)) |
|
718 | - return false; |
|
719 | - |
|
720 | - $keys = $this->keysSQL($indices); |
|
721 | - if (!empty($keys)) |
|
722 | - $keys = ",$keys"; |
|
723 | - |
|
724 | - // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
725 | - $collation = $this->getOption('collation'); |
|
726 | - if(empty($collation)) { |
|
727 | - $collation = 'utf8_general_ci'; |
|
728 | - } |
|
729 | - $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
730 | - |
|
731 | - if (!empty($engine)) |
|
732 | - $sql.= " ENGINE=$engine"; |
|
733 | - |
|
734 | - return $sql; |
|
735 | - } |
|
637 | + } |
|
638 | + |
|
639 | + return $string; |
|
640 | + } |
|
641 | + |
|
642 | + /** |
|
643 | + * (non-PHPdoc) |
|
644 | + * @see DBManager::fromConvert() |
|
645 | + */ |
|
646 | + public function fromConvert($string, $type) |
|
647 | + { |
|
648 | + return $string; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Returns the name of the engine to use or null if we are to use the default |
|
653 | + * |
|
654 | + * @param object $bean SugarBean instance |
|
655 | + * @return string |
|
656 | + */ |
|
657 | + protected function getEngine($bean) |
|
658 | + { |
|
659 | + global $dictionary; |
|
660 | + $engine = null; |
|
661 | + if (isset($dictionary[$bean->getObjectName()]['engine'])) { |
|
662 | + $engine = $dictionary[$bean->getObjectName()]['engine']; |
|
663 | + } |
|
664 | + return $engine; |
|
665 | + } |
|
666 | + |
|
667 | + /** |
|
668 | + * Returns true if the engine given is enabled in the backend |
|
669 | + * |
|
670 | + * @param string $engine |
|
671 | + * @return bool |
|
672 | + */ |
|
673 | + protected function isEngineEnabled($engine) |
|
674 | + { |
|
675 | + if(!is_string($engine)) return false; |
|
676 | + |
|
677 | + $engine = strtoupper($engine); |
|
678 | + |
|
679 | + $r = $this->query("SHOW ENGINES"); |
|
680 | + |
|
681 | + while ( $row = $this->fetchByAssoc($r) ) |
|
682 | + if ( strtoupper($row['Engine']) == $engine ) |
|
683 | + return ($row['Support']=='YES' || $row['Support']=='DEFAULT'); |
|
684 | + |
|
685 | + return false; |
|
686 | + } |
|
687 | + |
|
688 | + /** |
|
689 | + * @see DBManager::createTableSQL() |
|
690 | + */ |
|
691 | + public function createTableSQL(SugarBean $bean) |
|
692 | + { |
|
693 | + $tablename = $bean->getTableName(); |
|
694 | + $fieldDefs = $bean->getFieldDefinitions(); |
|
695 | + $indices = $bean->getIndices(); |
|
696 | + $engine = $this->getEngine($bean); |
|
697 | + return $this->createTableSQLParams($tablename, $fieldDefs, $indices, $engine); |
|
698 | + } |
|
699 | + |
|
700 | + /** |
|
701 | + * Generates sql for create table statement for a bean. |
|
702 | + * |
|
703 | + * @param string $tablename |
|
704 | + * @param array $fieldDefs |
|
705 | + * @param array $indices |
|
706 | + * @param string $engine optional, MySQL engine to use |
|
707 | + * @return string SQL Create Table statement |
|
708 | + */ |
|
709 | + public function createTableSQLParams($tablename, $fieldDefs, $indices, $engine = null) |
|
710 | + { |
|
711 | + if ( empty($engine) && isset($fieldDefs['engine'])) |
|
712 | + $engine = $fieldDefs['engine']; |
|
713 | + if ( !$this->isEngineEnabled($engine) ) |
|
714 | + $engine = ''; |
|
715 | + |
|
716 | + $columns = $this->columnSQLRep($fieldDefs, false, $tablename); |
|
717 | + if (empty($columns)) |
|
718 | + return false; |
|
719 | + |
|
720 | + $keys = $this->keysSQL($indices); |
|
721 | + if (!empty($keys)) |
|
722 | + $keys = ",$keys"; |
|
723 | + |
|
724 | + // cn: bug 9873 - module tables do not get created in utf8 with assoc collation |
|
725 | + $collation = $this->getOption('collation'); |
|
726 | + if(empty($collation)) { |
|
727 | + $collation = 'utf8_general_ci'; |
|
728 | + } |
|
729 | + $sql = "CREATE TABLE $tablename ($columns $keys) CHARACTER SET utf8 COLLATE $collation"; |
|
730 | + |
|
731 | + if (!empty($engine)) |
|
732 | + $sql.= " ENGINE=$engine"; |
|
733 | + |
|
734 | + return $sql; |
|
735 | + } |
|
736 | 736 | |
737 | 737 | /** |
738 | 738 | * Does this type represent text (i.e., non-varchar) value? |
@@ -744,745 +744,745 @@ discard block |
||
744 | 744 | return in_array($type, array('blob','text','longblob', 'longtext')); |
745 | 745 | } |
746 | 746 | |
747 | - /** |
|
748 | - * @see DBManager::oneColumnSQLRep() |
|
749 | - */ |
|
750 | - protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
751 | - { |
|
752 | - // always return as array for post-processing |
|
753 | - $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
747 | + /** |
|
748 | + * @see DBManager::oneColumnSQLRep() |
|
749 | + */ |
|
750 | + protected function oneColumnSQLRep($fieldDef, $ignoreRequired = false, $table = '', $return_as_array = false) |
|
751 | + { |
|
752 | + // always return as array for post-processing |
|
753 | + $ref = parent::oneColumnSQLRep($fieldDef, $ignoreRequired, $table, true); |
|
754 | 754 | |
755 | - if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
756 | - $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
757 | - } |
|
755 | + if ( $ref['colType'] == 'int' && !empty($fieldDef['len']) ) { |
|
756 | + $ref['colType'] .= "(".$fieldDef['len'].")"; |
|
757 | + } |
|
758 | 758 | |
759 | - // bug 22338 - don't set a default value on text or blob fields |
|
760 | - if ( isset($ref['default']) && |
|
759 | + // bug 22338 - don't set a default value on text or blob fields |
|
760 | + if ( isset($ref['default']) && |
|
761 | 761 | in_array($ref['colBaseType'], array('text', 'blob', 'longtext', 'longblob'))) |
762 | - $ref['default'] = ''; |
|
763 | - |
|
764 | - if ( $return_as_array ) |
|
765 | - return $ref; |
|
766 | - else |
|
767 | - return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
768 | - } |
|
769 | - |
|
770 | - /** |
|
771 | - * @see DBManager::changeColumnSQL() |
|
772 | - */ |
|
773 | - protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
774 | - { |
|
775 | - $columns = array(); |
|
776 | - if ($this->isFieldArray($fieldDefs)){ |
|
777 | - foreach ($fieldDefs as $def){ |
|
778 | - if ($action == 'drop') |
|
779 | - $columns[] = $def['name']; |
|
780 | - else |
|
781 | - $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
782 | - } |
|
783 | - } else { |
|
784 | - if ($action == 'drop') |
|
785 | - $columns[] = $fieldDefs['name']; |
|
786 | - else |
|
787 | - $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
788 | - } |
|
789 | - |
|
790 | - return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
791 | - } |
|
792 | - |
|
793 | - /** |
|
794 | - * Generates SQL for key specification inside CREATE TABLE statement |
|
795 | - * |
|
796 | - * The passes array is an array of field definitions or a field definition |
|
797 | - * itself. The keys generated will be either primary, foreign, unique, index |
|
798 | - * or none at all depending on the setting of the "key" parameter of a field definition |
|
799 | - * |
|
800 | - * @param array $indices |
|
801 | - * @param bool $alter_table |
|
802 | - * @param string $alter_action |
|
803 | - * @return string SQL Statement |
|
804 | - */ |
|
805 | - protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
806 | - { |
|
807 | - // check if the passed value is an array of fields. |
|
808 | - // if not, convert it into an array |
|
809 | - if (!$this->isFieldArray($indices)) |
|
810 | - $indices[] = $indices; |
|
811 | - |
|
812 | - $columns = array(); |
|
813 | - foreach ($indices as $index) { |
|
814 | - if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | - continue; |
|
816 | - if (isset($index['source']) && $index['source'] != 'db') |
|
817 | - continue; |
|
818 | - |
|
819 | - $type = $index['type']; |
|
820 | - $name = $index['name']; |
|
821 | - |
|
822 | - if (is_array($index['fields'])) |
|
823 | - $fields = implode(", ", $index['fields']); |
|
824 | - else |
|
825 | - $fields = $index['fields']; |
|
826 | - |
|
827 | - switch ($type) { |
|
828 | - case 'unique': |
|
829 | - $columns[] = " UNIQUE $name ($fields)"; |
|
830 | - break; |
|
831 | - case 'primary': |
|
832 | - $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | - break; |
|
834 | - case 'index': |
|
835 | - case 'foreign': |
|
836 | - case 'clustered': |
|
837 | - case 'alternate_key': |
|
838 | - /** |
|
839 | - * @todo here it is assumed that the primary key of the foreign |
|
840 | - * table will always be named 'id'. It must be noted though |
|
841 | - * that this can easily be fixed by referring to db dictionary |
|
842 | - * to find the correct primary field name |
|
843 | - */ |
|
844 | - if ( $alter_table ) |
|
845 | - $columns[] = " INDEX $name ($fields)"; |
|
846 | - else |
|
847 | - $columns[] = " KEY $name ($fields)"; |
|
848 | - break; |
|
849 | - case 'fulltext': |
|
850 | - if ($this->full_text_indexing_installed()) |
|
851 | - $columns[] = " FULLTEXT ($fields)"; |
|
852 | - else |
|
853 | - $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | - break; |
|
855 | - } |
|
856 | - } |
|
857 | - $columns = implode(", $alter_action ", $columns); |
|
858 | - if(!empty($alter_action)){ |
|
859 | - $columns = $alter_action . ' '. $columns; |
|
860 | - } |
|
861 | - return $columns; |
|
862 | - } |
|
863 | - |
|
864 | - /** |
|
865 | - * @see DBManager::setAutoIncrement() |
|
866 | - */ |
|
867 | - protected function setAutoIncrement($table, $field_name) |
|
868 | - { |
|
869 | - return "auto_increment"; |
|
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * Sets the next auto-increment value of a column to a specific value. |
|
874 | - * |
|
875 | - * @param string $table tablename |
|
876 | - * @param string $field_name |
|
877 | - */ |
|
878 | - public function setAutoIncrementStart($table, $field_name, $start_value) |
|
879 | - { |
|
880 | - $start_value = (int)$start_value; |
|
881 | - return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
882 | - } |
|
883 | - |
|
884 | - /** |
|
885 | - * Returns the next value for an auto increment |
|
886 | - * |
|
887 | - * @param string $table tablename |
|
888 | - * @param string $field_name |
|
889 | - * @return string |
|
890 | - */ |
|
891 | - public function getAutoIncrement($table, $field_name) |
|
892 | - { |
|
893 | - $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
894 | - $row = $this->fetchByAssoc($result); |
|
895 | - if (!empty($row['Auto_increment'])) |
|
896 | - return $row['Auto_increment']; |
|
897 | - |
|
898 | - return ""; |
|
899 | - } |
|
900 | - |
|
901 | - /** |
|
902 | - * @see DBManager::get_indices() |
|
903 | - */ |
|
904 | - public function get_indices($tablename) |
|
905 | - { |
|
906 | - //find all unique indexes and primary keys. |
|
907 | - $result = $this->query("SHOW INDEX FROM $tablename"); |
|
908 | - |
|
909 | - $indices = array(); |
|
910 | - while (($row=$this->fetchByAssoc($result)) !=null) { |
|
911 | - $index_type='index'; |
|
912 | - if ($row['Key_name'] =='PRIMARY') { |
|
913 | - $index_type='primary'; |
|
914 | - } |
|
915 | - elseif ( $row['Non_unique'] == '0' ) { |
|
916 | - $index_type='unique'; |
|
917 | - } |
|
918 | - $name = strtolower($row['Key_name']); |
|
919 | - $indices[$name]['name']=$name; |
|
920 | - $indices[$name]['type']=$index_type; |
|
921 | - $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
922 | - } |
|
923 | - return $indices; |
|
924 | - } |
|
925 | - |
|
926 | - /** |
|
927 | - * @see DBManager::add_drop_constraint() |
|
928 | - */ |
|
929 | - public function add_drop_constraint($table, $definition, $drop = false) |
|
930 | - { |
|
931 | - $type = $definition['type']; |
|
932 | - $fields = implode(',',$definition['fields']); |
|
933 | - $name = $definition['name']; |
|
934 | - $sql = ''; |
|
935 | - |
|
936 | - switch ($type){ |
|
937 | - // generic indices |
|
938 | - case 'index': |
|
939 | - case 'alternate_key': |
|
940 | - case 'clustered': |
|
941 | - if ($drop) |
|
942 | - $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | - else |
|
944 | - $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | - break; |
|
946 | - // constraints as indices |
|
947 | - case 'unique': |
|
948 | - if ($drop) |
|
949 | - $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | - else |
|
951 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | - break; |
|
953 | - case 'primary': |
|
954 | - if ($drop) |
|
955 | - $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | - else |
|
957 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | - break; |
|
959 | - case 'foreign': |
|
960 | - if ($drop) |
|
961 | - $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | - else |
|
963 | - $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | - break; |
|
965 | - } |
|
966 | - return $sql; |
|
967 | - } |
|
968 | - |
|
969 | - /** |
|
970 | - * Runs a query and returns a single row |
|
971 | - * |
|
972 | - * @param string $sql SQL Statement to execute |
|
973 | - * @param bool $dieOnError True if we want to call die if the query returns errors |
|
974 | - * @param string $msg Message to log if error occurs |
|
975 | - * @param bool $suppress Message to log if error occurs |
|
976 | - * @return array single row from the query |
|
977 | - */ |
|
978 | - public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
979 | - { |
|
980 | - if(stripos($sql, ' LIMIT ') === false) { |
|
981 | - // little optimization to just fetch one row |
|
982 | - $sql .= " LIMIT 0,1"; |
|
983 | - } |
|
984 | - return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
985 | - } |
|
986 | - |
|
987 | - /** |
|
988 | - * @see DBManager::full_text_indexing_installed() |
|
989 | - */ |
|
990 | - public function full_text_indexing_installed($dbname = null) |
|
991 | - { |
|
992 | - return $this->isEngineEnabled('MyISAM'); |
|
993 | - } |
|
994 | - |
|
995 | - /** |
|
996 | - * @see DBManager::massageFieldDef() |
|
997 | - */ |
|
998 | - public function massageFieldDef(&$fieldDef, $tablename) |
|
999 | - { |
|
1000 | - parent::massageFieldDef($fieldDef,$tablename); |
|
1001 | - |
|
1002 | - if ( isset($fieldDef['default']) && |
|
1003 | - ($fieldDef['dbType'] == 'text' |
|
1004 | - || $fieldDef['dbType'] == 'blob' |
|
1005 | - || $fieldDef['dbType'] == 'longtext' |
|
1006 | - || $fieldDef['dbType'] == 'longblob' )) |
|
1007 | - unset($fieldDef['default']); |
|
1008 | - if ($fieldDef['dbType'] == 'uint') |
|
1009 | - $fieldDef['len'] = '10'; |
|
1010 | - if ($fieldDef['dbType'] == 'ulong') |
|
1011 | - $fieldDef['len'] = '20'; |
|
1012 | - if ($fieldDef['dbType'] == 'bool') |
|
1013 | - $fieldDef['type'] = 'tinyint'; |
|
1014 | - if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1015 | - $fieldDef['default'] = '0'; |
|
1016 | - if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1017 | - $fieldDef['len'] = '255'; |
|
1018 | - if ($fieldDef['dbType'] == 'uint') |
|
1019 | - $fieldDef['len'] = '10'; |
|
1020 | - if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1021 | - $fieldDef['len'] = '11'; |
|
1022 | - |
|
1023 | - if($fieldDef['dbType'] == 'decimal') { |
|
1024 | - if(isset($fieldDef['len'])) { |
|
1025 | - if(strstr($fieldDef['len'], ",") === false) { |
|
1026 | - $fieldDef['len'] .= ",0"; |
|
1027 | - } |
|
1028 | - } else { |
|
1029 | - $fieldDef['len'] = '10,0'; |
|
1030 | - } |
|
1031 | - } |
|
1032 | - } |
|
1033 | - |
|
1034 | - /** |
|
1035 | - * Generates SQL for dropping a table. |
|
1036 | - * |
|
1037 | - * @param string $name table name |
|
1038 | - * @return string SQL statement |
|
1039 | - */ |
|
1040 | - public function dropTableNameSQL($name) |
|
1041 | - { |
|
1042 | - return "DROP TABLE IF EXISTS ".$name; |
|
1043 | - } |
|
1044 | - |
|
1045 | - public function dropIndexes($tablename, $indexes, $execute = true) |
|
1046 | - { |
|
1047 | - $sql = array(); |
|
1048 | - foreach ($indexes as $index) { |
|
1049 | - $name =$index['name']; |
|
1050 | - if($execute) { |
|
1051 | - unset(self::$index_descriptions[$tablename][$name]); |
|
1052 | - } |
|
1053 | - if ($index['type'] == 'primary') { |
|
1054 | - $sql[] = 'DROP PRIMARY KEY'; |
|
1055 | - } else { |
|
1056 | - $sql[] = "DROP INDEX $name"; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - if (!empty($sql)) { |
|
762 | + $ref['default'] = ''; |
|
763 | + |
|
764 | + if ( $return_as_array ) |
|
765 | + return $ref; |
|
766 | + else |
|
767 | + return "{$ref['name']} {$ref['colType']} {$ref['default']} {$ref['required']} {$ref['auto_increment']}"; |
|
768 | + } |
|
769 | + |
|
770 | + /** |
|
771 | + * @see DBManager::changeColumnSQL() |
|
772 | + */ |
|
773 | + protected function changeColumnSQL($tablename, $fieldDefs, $action, $ignoreRequired = false) |
|
774 | + { |
|
775 | + $columns = array(); |
|
776 | + if ($this->isFieldArray($fieldDefs)){ |
|
777 | + foreach ($fieldDefs as $def){ |
|
778 | + if ($action == 'drop') |
|
779 | + $columns[] = $def['name']; |
|
780 | + else |
|
781 | + $columns[] = $this->oneColumnSQLRep($def, $ignoreRequired); |
|
782 | + } |
|
783 | + } else { |
|
784 | + if ($action == 'drop') |
|
785 | + $columns[] = $fieldDefs['name']; |
|
786 | + else |
|
787 | + $columns[] = $this->oneColumnSQLRep($fieldDefs); |
|
788 | + } |
|
789 | + |
|
790 | + return "ALTER TABLE $tablename $action COLUMN ".implode(",$action column ", $columns); |
|
791 | + } |
|
792 | + |
|
793 | + /** |
|
794 | + * Generates SQL for key specification inside CREATE TABLE statement |
|
795 | + * |
|
796 | + * The passes array is an array of field definitions or a field definition |
|
797 | + * itself. The keys generated will be either primary, foreign, unique, index |
|
798 | + * or none at all depending on the setting of the "key" parameter of a field definition |
|
799 | + * |
|
800 | + * @param array $indices |
|
801 | + * @param bool $alter_table |
|
802 | + * @param string $alter_action |
|
803 | + * @return string SQL Statement |
|
804 | + */ |
|
805 | + protected function keysSQL($indices, $alter_table = false, $alter_action = '') |
|
806 | + { |
|
807 | + // check if the passed value is an array of fields. |
|
808 | + // if not, convert it into an array |
|
809 | + if (!$this->isFieldArray($indices)) |
|
810 | + $indices[] = $indices; |
|
811 | + |
|
812 | + $columns = array(); |
|
813 | + foreach ($indices as $index) { |
|
814 | + if(!empty($index['db']) && $index['db'] != $this->dbType) |
|
815 | + continue; |
|
816 | + if (isset($index['source']) && $index['source'] != 'db') |
|
817 | + continue; |
|
818 | + |
|
819 | + $type = $index['type']; |
|
820 | + $name = $index['name']; |
|
821 | + |
|
822 | + if (is_array($index['fields'])) |
|
823 | + $fields = implode(", ", $index['fields']); |
|
824 | + else |
|
825 | + $fields = $index['fields']; |
|
826 | + |
|
827 | + switch ($type) { |
|
828 | + case 'unique': |
|
829 | + $columns[] = " UNIQUE $name ($fields)"; |
|
830 | + break; |
|
831 | + case 'primary': |
|
832 | + $columns[] = " PRIMARY KEY ($fields)"; |
|
833 | + break; |
|
834 | + case 'index': |
|
835 | + case 'foreign': |
|
836 | + case 'clustered': |
|
837 | + case 'alternate_key': |
|
838 | + /** |
|
839 | + * @todo here it is assumed that the primary key of the foreign |
|
840 | + * table will always be named 'id'. It must be noted though |
|
841 | + * that this can easily be fixed by referring to db dictionary |
|
842 | + * to find the correct primary field name |
|
843 | + */ |
|
844 | + if ( $alter_table ) |
|
845 | + $columns[] = " INDEX $name ($fields)"; |
|
846 | + else |
|
847 | + $columns[] = " KEY $name ($fields)"; |
|
848 | + break; |
|
849 | + case 'fulltext': |
|
850 | + if ($this->full_text_indexing_installed()) |
|
851 | + $columns[] = " FULLTEXT ($fields)"; |
|
852 | + else |
|
853 | + $GLOBALS['log']->debug('MYISAM engine is not available/enabled, full-text indexes will be skipped. Skipping:',$name); |
|
854 | + break; |
|
855 | + } |
|
856 | + } |
|
857 | + $columns = implode(", $alter_action ", $columns); |
|
858 | + if(!empty($alter_action)){ |
|
859 | + $columns = $alter_action . ' '. $columns; |
|
860 | + } |
|
861 | + return $columns; |
|
862 | + } |
|
863 | + |
|
864 | + /** |
|
865 | + * @see DBManager::setAutoIncrement() |
|
866 | + */ |
|
867 | + protected function setAutoIncrement($table, $field_name) |
|
868 | + { |
|
869 | + return "auto_increment"; |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * Sets the next auto-increment value of a column to a specific value. |
|
874 | + * |
|
875 | + * @param string $table tablename |
|
876 | + * @param string $field_name |
|
877 | + */ |
|
878 | + public function setAutoIncrementStart($table, $field_name, $start_value) |
|
879 | + { |
|
880 | + $start_value = (int)$start_value; |
|
881 | + return $this->query( "ALTER TABLE $table AUTO_INCREMENT = $start_value;"); |
|
882 | + } |
|
883 | + |
|
884 | + /** |
|
885 | + * Returns the next value for an auto increment |
|
886 | + * |
|
887 | + * @param string $table tablename |
|
888 | + * @param string $field_name |
|
889 | + * @return string |
|
890 | + */ |
|
891 | + public function getAutoIncrement($table, $field_name) |
|
892 | + { |
|
893 | + $result = $this->query("SHOW TABLE STATUS LIKE '$table'"); |
|
894 | + $row = $this->fetchByAssoc($result); |
|
895 | + if (!empty($row['Auto_increment'])) |
|
896 | + return $row['Auto_increment']; |
|
897 | + |
|
898 | + return ""; |
|
899 | + } |
|
900 | + |
|
901 | + /** |
|
902 | + * @see DBManager::get_indices() |
|
903 | + */ |
|
904 | + public function get_indices($tablename) |
|
905 | + { |
|
906 | + //find all unique indexes and primary keys. |
|
907 | + $result = $this->query("SHOW INDEX FROM $tablename"); |
|
908 | + |
|
909 | + $indices = array(); |
|
910 | + while (($row=$this->fetchByAssoc($result)) !=null) { |
|
911 | + $index_type='index'; |
|
912 | + if ($row['Key_name'] =='PRIMARY') { |
|
913 | + $index_type='primary'; |
|
914 | + } |
|
915 | + elseif ( $row['Non_unique'] == '0' ) { |
|
916 | + $index_type='unique'; |
|
917 | + } |
|
918 | + $name = strtolower($row['Key_name']); |
|
919 | + $indices[$name]['name']=$name; |
|
920 | + $indices[$name]['type']=$index_type; |
|
921 | + $indices[$name]['fields'][]=strtolower($row['Column_name']); |
|
922 | + } |
|
923 | + return $indices; |
|
924 | + } |
|
925 | + |
|
926 | + /** |
|
927 | + * @see DBManager::add_drop_constraint() |
|
928 | + */ |
|
929 | + public function add_drop_constraint($table, $definition, $drop = false) |
|
930 | + { |
|
931 | + $type = $definition['type']; |
|
932 | + $fields = implode(',',$definition['fields']); |
|
933 | + $name = $definition['name']; |
|
934 | + $sql = ''; |
|
935 | + |
|
936 | + switch ($type){ |
|
937 | + // generic indices |
|
938 | + case 'index': |
|
939 | + case 'alternate_key': |
|
940 | + case 'clustered': |
|
941 | + if ($drop) |
|
942 | + $sql = "ALTER TABLE {$table} DROP INDEX {$name} "; |
|
943 | + else |
|
944 | + $sql = "ALTER TABLE {$table} ADD INDEX {$name} ({$fields})"; |
|
945 | + break; |
|
946 | + // constraints as indices |
|
947 | + case 'unique': |
|
948 | + if ($drop) |
|
949 | + $sql = "ALTER TABLE {$table} DROP INDEX $name"; |
|
950 | + else |
|
951 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT UNIQUE {$name} ({$fields})"; |
|
952 | + break; |
|
953 | + case 'primary': |
|
954 | + if ($drop) |
|
955 | + $sql = "ALTER TABLE {$table} DROP PRIMARY KEY"; |
|
956 | + else |
|
957 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT PRIMARY KEY ({$fields})"; |
|
958 | + break; |
|
959 | + case 'foreign': |
|
960 | + if ($drop) |
|
961 | + $sql = "ALTER TABLE {$table} DROP FOREIGN KEY ({$fields})"; |
|
962 | + else |
|
963 | + $sql = "ALTER TABLE {$table} ADD CONSTRAINT FOREIGN KEY {$name} ({$fields}) REFERENCES {$definition['foreignTable']}({$definition['foreignField']})"; |
|
964 | + break; |
|
965 | + } |
|
966 | + return $sql; |
|
967 | + } |
|
968 | + |
|
969 | + /** |
|
970 | + * Runs a query and returns a single row |
|
971 | + * |
|
972 | + * @param string $sql SQL Statement to execute |
|
973 | + * @param bool $dieOnError True if we want to call die if the query returns errors |
|
974 | + * @param string $msg Message to log if error occurs |
|
975 | + * @param bool $suppress Message to log if error occurs |
|
976 | + * @return array single row from the query |
|
977 | + */ |
|
978 | + public function fetchOne($sql, $dieOnError = false, $msg = '', $suppress = false) |
|
979 | + { |
|
980 | + if(stripos($sql, ' LIMIT ') === false) { |
|
981 | + // little optimization to just fetch one row |
|
982 | + $sql .= " LIMIT 0,1"; |
|
983 | + } |
|
984 | + return parent::fetchOne($sql, $dieOnError, $msg, $suppress); |
|
985 | + } |
|
986 | + |
|
987 | + /** |
|
988 | + * @see DBManager::full_text_indexing_installed() |
|
989 | + */ |
|
990 | + public function full_text_indexing_installed($dbname = null) |
|
991 | + { |
|
992 | + return $this->isEngineEnabled('MyISAM'); |
|
993 | + } |
|
994 | + |
|
995 | + /** |
|
996 | + * @see DBManager::massageFieldDef() |
|
997 | + */ |
|
998 | + public function massageFieldDef(&$fieldDef, $tablename) |
|
999 | + { |
|
1000 | + parent::massageFieldDef($fieldDef,$tablename); |
|
1001 | + |
|
1002 | + if ( isset($fieldDef['default']) && |
|
1003 | + ($fieldDef['dbType'] == 'text' |
|
1004 | + || $fieldDef['dbType'] == 'blob' |
|
1005 | + || $fieldDef['dbType'] == 'longtext' |
|
1006 | + || $fieldDef['dbType'] == 'longblob' )) |
|
1007 | + unset($fieldDef['default']); |
|
1008 | + if ($fieldDef['dbType'] == 'uint') |
|
1009 | + $fieldDef['len'] = '10'; |
|
1010 | + if ($fieldDef['dbType'] == 'ulong') |
|
1011 | + $fieldDef['len'] = '20'; |
|
1012 | + if ($fieldDef['dbType'] == 'bool') |
|
1013 | + $fieldDef['type'] = 'tinyint'; |
|
1014 | + if ($fieldDef['dbType'] == 'bool' && empty($fieldDef['default']) ) |
|
1015 | + $fieldDef['default'] = '0'; |
|
1016 | + if (($fieldDef['dbType'] == 'varchar' || $fieldDef['dbType'] == 'enum') && empty($fieldDef['len']) ) |
|
1017 | + $fieldDef['len'] = '255'; |
|
1018 | + if ($fieldDef['dbType'] == 'uint') |
|
1019 | + $fieldDef['len'] = '10'; |
|
1020 | + if ($fieldDef['dbType'] == 'int' && empty($fieldDef['len']) ) |
|
1021 | + $fieldDef['len'] = '11'; |
|
1022 | + |
|
1023 | + if($fieldDef['dbType'] == 'decimal') { |
|
1024 | + if(isset($fieldDef['len'])) { |
|
1025 | + if(strstr($fieldDef['len'], ",") === false) { |
|
1026 | + $fieldDef['len'] .= ",0"; |
|
1027 | + } |
|
1028 | + } else { |
|
1029 | + $fieldDef['len'] = '10,0'; |
|
1030 | + } |
|
1031 | + } |
|
1032 | + } |
|
1033 | + |
|
1034 | + /** |
|
1035 | + * Generates SQL for dropping a table. |
|
1036 | + * |
|
1037 | + * @param string $name table name |
|
1038 | + * @return string SQL statement |
|
1039 | + */ |
|
1040 | + public function dropTableNameSQL($name) |
|
1041 | + { |
|
1042 | + return "DROP TABLE IF EXISTS ".$name; |
|
1043 | + } |
|
1044 | + |
|
1045 | + public function dropIndexes($tablename, $indexes, $execute = true) |
|
1046 | + { |
|
1047 | + $sql = array(); |
|
1048 | + foreach ($indexes as $index) { |
|
1049 | + $name =$index['name']; |
|
1050 | + if($execute) { |
|
1051 | + unset(self::$index_descriptions[$tablename][$name]); |
|
1052 | + } |
|
1053 | + if ($index['type'] == 'primary') { |
|
1054 | + $sql[] = 'DROP PRIMARY KEY'; |
|
1055 | + } else { |
|
1056 | + $sql[] = "DROP INDEX $name"; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + if (!empty($sql)) { |
|
1060 | 1060 | $sql = "ALTER TABLE $tablename " . join(",", $sql) . ";"; |
1061 | - if($execute) |
|
1062 | - $this->query($sql); |
|
1063 | - } else { |
|
1064 | - $sql = ''; |
|
1065 | - } |
|
1066 | - return $sql; |
|
1067 | - } |
|
1068 | - |
|
1069 | - /** |
|
1070 | - * List of available collation settings |
|
1071 | - * @return string |
|
1072 | - */ |
|
1073 | - public function getDefaultCollation() |
|
1074 | - { |
|
1075 | - return "utf8_general_ci"; |
|
1076 | - } |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * List of available collation settings |
|
1080 | - * @return array |
|
1081 | - */ |
|
1082 | - public function getCollationList() |
|
1083 | - { |
|
1084 | - $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
1085 | - $r = $this->query($q); |
|
1086 | - $res = array(); |
|
1087 | - while($a = $this->fetchByAssoc($r)) { |
|
1088 | - $res[] = $a['Collation']; |
|
1089 | - } |
|
1090 | - return $res; |
|
1091 | - } |
|
1092 | - |
|
1093 | - /** |
|
1094 | - * (non-PHPdoc) |
|
1095 | - * @see DBManager::renameColumnSQL() |
|
1096 | - */ |
|
1097 | - public function renameColumnSQL($tablename, $column, $newname) |
|
1098 | - { |
|
1099 | - $field = $this->describeField($column, $tablename); |
|
1100 | - $field['name'] = $newname; |
|
1101 | - return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
1102 | - } |
|
1103 | - |
|
1104 | - public function emptyValue($type) |
|
1105 | - { |
|
1106 | - $ctype = $this->getColumnType($type); |
|
1107 | - if($ctype == "datetime") { |
|
1108 | - return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
1109 | - } |
|
1110 | - if($ctype == "date") { |
|
1111 | - return $this->convert($this->quoted("0000-00-00"), "date"); |
|
1112 | - } |
|
1113 | - if($ctype == "time") { |
|
1114 | - return $this->convert($this->quoted("00:00:00"), "time"); |
|
1115 | - } |
|
1116 | - return parent::emptyValue($type); |
|
1117 | - } |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * (non-PHPdoc) |
|
1121 | - * @see DBManager::lastDbError() |
|
1122 | - */ |
|
1123 | - public function lastDbError() |
|
1124 | - { |
|
1125 | - if($this->database) { |
|
1126 | - if(mysql_errno($this->database)) { |
|
1127 | - return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
1128 | - } |
|
1129 | - } else { |
|
1130 | - $err = mysql_error(); |
|
1131 | - if($err) { |
|
1132 | - return $err; |
|
1133 | - } |
|
1134 | - } |
|
1061 | + if($execute) |
|
1062 | + $this->query($sql); |
|
1063 | + } else { |
|
1064 | + $sql = ''; |
|
1065 | + } |
|
1066 | + return $sql; |
|
1067 | + } |
|
1068 | + |
|
1069 | + /** |
|
1070 | + * List of available collation settings |
|
1071 | + * @return string |
|
1072 | + */ |
|
1073 | + public function getDefaultCollation() |
|
1074 | + { |
|
1075 | + return "utf8_general_ci"; |
|
1076 | + } |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * List of available collation settings |
|
1080 | + * @return array |
|
1081 | + */ |
|
1082 | + public function getCollationList() |
|
1083 | + { |
|
1084 | + $q = "SHOW COLLATION LIKE 'utf8%'"; |
|
1085 | + $r = $this->query($q); |
|
1086 | + $res = array(); |
|
1087 | + while($a = $this->fetchByAssoc($r)) { |
|
1088 | + $res[] = $a['Collation']; |
|
1089 | + } |
|
1090 | + return $res; |
|
1091 | + } |
|
1092 | + |
|
1093 | + /** |
|
1094 | + * (non-PHPdoc) |
|
1095 | + * @see DBManager::renameColumnSQL() |
|
1096 | + */ |
|
1097 | + public function renameColumnSQL($tablename, $column, $newname) |
|
1098 | + { |
|
1099 | + $field = $this->describeField($column, $tablename); |
|
1100 | + $field['name'] = $newname; |
|
1101 | + return "ALTER TABLE $tablename CHANGE COLUMN $column ".$this->oneColumnSQLRep($field); |
|
1102 | + } |
|
1103 | + |
|
1104 | + public function emptyValue($type) |
|
1105 | + { |
|
1106 | + $ctype = $this->getColumnType($type); |
|
1107 | + if($ctype == "datetime") { |
|
1108 | + return $this->convert($this->quoted("0000-00-00 00:00:00"), "datetime"); |
|
1109 | + } |
|
1110 | + if($ctype == "date") { |
|
1111 | + return $this->convert($this->quoted("0000-00-00"), "date"); |
|
1112 | + } |
|
1113 | + if($ctype == "time") { |
|
1114 | + return $this->convert($this->quoted("00:00:00"), "time"); |
|
1115 | + } |
|
1116 | + return parent::emptyValue($type); |
|
1117 | + } |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * (non-PHPdoc) |
|
1121 | + * @see DBManager::lastDbError() |
|
1122 | + */ |
|
1123 | + public function lastDbError() |
|
1124 | + { |
|
1125 | + if($this->database) { |
|
1126 | + if(mysql_errno($this->database)) { |
|
1127 | + return "MySQL error ".mysql_errno($this->database).": ".mysql_error($this->database); |
|
1128 | + } |
|
1129 | + } else { |
|
1130 | + $err = mysql_error(); |
|
1131 | + if($err) { |
|
1132 | + return $err; |
|
1133 | + } |
|
1134 | + } |
|
1135 | 1135 | return false; |
1136 | 1136 | } |
1137 | 1137 | |
1138 | - /** |
|
1139 | - * Quote MySQL search term |
|
1140 | - * @param unknown_type $term |
|
1141 | - */ |
|
1142 | - protected function quoteTerm($term) |
|
1143 | - { |
|
1144 | - if(strpos($term, ' ') !== false) { |
|
1145 | - return '"'.$term.'"'; |
|
1146 | - } |
|
1147 | - return $term; |
|
1148 | - } |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Generate fulltext query from set of terms |
|
1152 | - * @param string $fields Field to search against |
|
1153 | - * @param array $terms Search terms that may be or not be in the result |
|
1154 | - * @param array $must_terms Search terms that have to be in the result |
|
1155 | - * @param array $exclude_terms Search terms that have to be not in the result |
|
1156 | - */ |
|
1157 | - public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
1158 | - { |
|
1159 | - $condition = array(); |
|
1160 | - foreach($terms as $term) { |
|
1161 | - $condition[] = $this->quoteTerm($term); |
|
1162 | - } |
|
1163 | - foreach($must_terms as $term) { |
|
1164 | - $condition[] = "+".$this->quoteTerm($term); |
|
1165 | - } |
|
1166 | - foreach($exclude_terms as $term) { |
|
1167 | - $condition[] = "-".$this->quoteTerm($term); |
|
1168 | - } |
|
1169 | - $condition = $this->quoted(join(" ",$condition)); |
|
1170 | - return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
1171 | - } |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * Get list of all defined charsets |
|
1175 | - * @return array |
|
1176 | - */ |
|
1177 | - protected function getCharsetInfo() |
|
1178 | - { |
|
1179 | - $charsets = array(); |
|
1180 | - $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
1181 | - while($row = $this->fetchByAssoc($res)) { |
|
1182 | - $charsets[$row['Variable_name']] = $row['Value']; |
|
1183 | - } |
|
1184 | - return $charsets; |
|
1185 | - } |
|
1186 | - |
|
1187 | - public function getDbInfo() |
|
1188 | - { |
|
1189 | - $charsets = $this->getCharsetInfo(); |
|
1190 | - $charset_str = array(); |
|
1191 | - foreach($charsets as $name => $value) { |
|
1192 | - $charset_str[] = "$name = $value"; |
|
1193 | - } |
|
1194 | - return array( |
|
1195 | - "MySQL Version" => @mysql_get_client_info(), |
|
1196 | - "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
1197 | - "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
1198 | - "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
1199 | - "MySQL Character Set Settings" => join(", ", $charset_str), |
|
1200 | - ); |
|
1201 | - } |
|
1202 | - |
|
1203 | - public function validateQuery($query) |
|
1204 | - { |
|
1205 | - $res = $this->query("EXPLAIN $query"); |
|
1206 | - return !empty($res); |
|
1207 | - } |
|
1208 | - |
|
1209 | - protected function makeTempTableCopy($table) |
|
1210 | - { |
|
1211 | - $this->log->debug("creating temp table for [$table]..."); |
|
1212 | - $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
1213 | - if(empty($result)) { |
|
1214 | - return false; |
|
1215 | - } |
|
1216 | - $row = $this->fetchByAssoc($result); |
|
1217 | - if(empty($row) || empty($row['Create Table'])) { |
|
1218 | - return false; |
|
1219 | - } |
|
1220 | - $create = $row['Create Table']; |
|
1221 | - // rewrite DDL with _temp name |
|
1222 | - $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
1223 | - $r2 = $this->query($tempTableQuery); |
|
1224 | - if(empty($r2)) { |
|
1225 | - return false; |
|
1226 | - } |
|
1227 | - |
|
1228 | - // get sample data into the temp table to test for data/constraint conflicts |
|
1229 | - $this->log->debug('inserting temp dataset...'); |
|
1230 | - $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
1231 | - $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
1232 | - return true; |
|
1233 | - } |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * Tests an ALTER TABLE query |
|
1237 | - * @param string table The table name to get DDL |
|
1238 | - * @param string query The query to test. |
|
1239 | - * @return string Non-empty if error found |
|
1240 | - */ |
|
1241 | - protected function verifyAlterTable($table, $query) |
|
1242 | - { |
|
1243 | - $this->log->debug("verifying ALTER TABLE"); |
|
1244 | - // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
1245 | - // over to the temp tables |
|
1246 | - if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1247 | - $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
1248 | - return ''; |
|
1249 | - } |
|
1250 | - if(!$this->makeTempTableCopy($table)) { |
|
1251 | - return 'Could not create temp table copy'; |
|
1252 | - } |
|
1253 | - |
|
1254 | - // test the query on the test table |
|
1255 | - $this->log->debug('testing query: ['.$query.']'); |
|
1256 | - $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
1257 | - if (strpos($tempTableTestQuery, 'idx') === false) { |
|
1258 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1259 | - return 'Could not use a temp table to test query!'; |
|
1260 | - } |
|
1261 | - |
|
1262 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
1263 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1264 | - } else { |
|
1265 | - // test insertion of an index on a table |
|
1266 | - $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
1267 | - $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
1268 | - $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
1269 | - } |
|
1270 | - $mysqlError = $this->getL(); |
|
1271 | - if(!empty($mysqlError)) { |
|
1272 | - return $mysqlError; |
|
1273 | - } |
|
1274 | - $this->dropTableName("{$table}__uw_temp"); |
|
1275 | - |
|
1276 | - return ''; |
|
1277 | - } |
|
1278 | - |
|
1279 | - protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
1280 | - { |
|
1281 | - $this->log->debug("verifying $querytype statement"); |
|
1282 | - |
|
1283 | - if(!$this->makeTempTableCopy($table)) { |
|
1284 | - return 'Could not create temp table copy'; |
|
1285 | - } |
|
1286 | - // test the query on the test table |
|
1287 | - $this->log->debug('testing query: ['.$query.']'); |
|
1288 | - $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
1289 | - if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1290 | - return 'Could not use a temp table to test query!'; |
|
1291 | - } |
|
1292 | - |
|
1293 | - $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1294 | - $error = $this->lastError(); // empty on no-errors |
|
1295 | - $this->dropTableName("{$table}__uw_temp"); // just in case |
|
1296 | - return $error; |
|
1297 | - } |
|
1298 | - |
|
1299 | - /** |
|
1300 | - * Tests a DROP TABLE query |
|
1301 | - * @param string table The table name to get DDL |
|
1302 | - * @param string query The query to test. |
|
1303 | - * @return string Non-empty if error found |
|
1304 | - */ |
|
1305 | - public function verifyDropTable($table, $query) |
|
1306 | - { |
|
1307 | - return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
1308 | - } |
|
1309 | - |
|
1310 | - /** |
|
1311 | - * Tests an INSERT INTO query |
|
1312 | - * @param string table The table name to get DDL |
|
1313 | - * @param string query The query to test. |
|
1314 | - * @return string Non-empty if error found |
|
1315 | - */ |
|
1316 | - public function verifyInsertInto($table, $query) |
|
1317 | - { |
|
1318 | - return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
1319 | - } |
|
1320 | - |
|
1321 | - /** |
|
1322 | - * Tests an UPDATE query |
|
1323 | - * @param string table The table name to get DDL |
|
1324 | - * @param string query The query to test. |
|
1325 | - * @return string Non-empty if error found |
|
1326 | - */ |
|
1327 | - public function verifyUpdate($table, $query) |
|
1328 | - { |
|
1329 | - return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
1330 | - } |
|
1331 | - |
|
1332 | - /** |
|
1333 | - * Tests an DELETE FROM query |
|
1334 | - * @param string table The table name to get DDL |
|
1335 | - * @param string query The query to test. |
|
1336 | - * @return string Non-empty if error found |
|
1337 | - */ |
|
1338 | - public function verifyDeleteFrom($table, $query) |
|
1339 | - { |
|
1340 | - return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
1341 | - } |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * Check if certain database exists |
|
1345 | - * @param string $dbname |
|
1346 | - */ |
|
1347 | - public function dbExists($dbname) |
|
1348 | - { |
|
1349 | - $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
1350 | - return !empty($db); |
|
1351 | - } |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * Select database |
|
1355 | - * @param string $dbname |
|
1356 | - */ |
|
1357 | - protected function selectDb($dbname) |
|
1358 | - { |
|
1359 | - return mysql_select_db($dbname); |
|
1360 | - } |
|
1361 | - |
|
1362 | - /** |
|
1363 | - * Check if certain DB user exists |
|
1364 | - * @param string $username |
|
1365 | - */ |
|
1366 | - public function userExists($username) |
|
1367 | - { |
|
1368 | - $db = $this->getOne("SELECT DATABASE()"); |
|
1369 | - if(!$this->selectDb("mysql")) { |
|
1370 | - return false; |
|
1371 | - } |
|
1372 | - $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
1373 | - if(!$this->selectDb($db)) { |
|
1374 | - $this->checkError("Cannot select database $db", true); |
|
1375 | - } |
|
1376 | - return !empty($user); |
|
1377 | - } |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * Create DB user |
|
1381 | - * @param string $database_name |
|
1382 | - * @param string $host_name |
|
1383 | - * @param string $user |
|
1384 | - * @param string $password |
|
1385 | - */ |
|
1386 | - public function createDbUser($database_name, $host_name, $user, $password) |
|
1387 | - { |
|
1388 | - $qpassword = $this->quote($password); |
|
1389 | - $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
1138 | + /** |
|
1139 | + * Quote MySQL search term |
|
1140 | + * @param unknown_type $term |
|
1141 | + */ |
|
1142 | + protected function quoteTerm($term) |
|
1143 | + { |
|
1144 | + if(strpos($term, ' ') !== false) { |
|
1145 | + return '"'.$term.'"'; |
|
1146 | + } |
|
1147 | + return $term; |
|
1148 | + } |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Generate fulltext query from set of terms |
|
1152 | + * @param string $fields Field to search against |
|
1153 | + * @param array $terms Search terms that may be or not be in the result |
|
1154 | + * @param array $must_terms Search terms that have to be in the result |
|
1155 | + * @param array $exclude_terms Search terms that have to be not in the result |
|
1156 | + */ |
|
1157 | + public function getFulltextQuery($field, $terms, $must_terms = array(), $exclude_terms = array()) |
|
1158 | + { |
|
1159 | + $condition = array(); |
|
1160 | + foreach($terms as $term) { |
|
1161 | + $condition[] = $this->quoteTerm($term); |
|
1162 | + } |
|
1163 | + foreach($must_terms as $term) { |
|
1164 | + $condition[] = "+".$this->quoteTerm($term); |
|
1165 | + } |
|
1166 | + foreach($exclude_terms as $term) { |
|
1167 | + $condition[] = "-".$this->quoteTerm($term); |
|
1168 | + } |
|
1169 | + $condition = $this->quoted(join(" ",$condition)); |
|
1170 | + return "MATCH($field) AGAINST($condition IN BOOLEAN MODE)"; |
|
1171 | + } |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * Get list of all defined charsets |
|
1175 | + * @return array |
|
1176 | + */ |
|
1177 | + protected function getCharsetInfo() |
|
1178 | + { |
|
1179 | + $charsets = array(); |
|
1180 | + $res = $this->query("show variables like 'character\\_set\\_%'"); |
|
1181 | + while($row = $this->fetchByAssoc($res)) { |
|
1182 | + $charsets[$row['Variable_name']] = $row['Value']; |
|
1183 | + } |
|
1184 | + return $charsets; |
|
1185 | + } |
|
1186 | + |
|
1187 | + public function getDbInfo() |
|
1188 | + { |
|
1189 | + $charsets = $this->getCharsetInfo(); |
|
1190 | + $charset_str = array(); |
|
1191 | + foreach($charsets as $name => $value) { |
|
1192 | + $charset_str[] = "$name = $value"; |
|
1193 | + } |
|
1194 | + return array( |
|
1195 | + "MySQL Version" => @mysql_get_client_info(), |
|
1196 | + "MySQL Host Info" => @mysql_get_host_info($this->database), |
|
1197 | + "MySQL Server Info" => @mysql_get_server_info($this->database), |
|
1198 | + "MySQL Client Encoding" => @mysql_client_encoding($this->database), |
|
1199 | + "MySQL Character Set Settings" => join(", ", $charset_str), |
|
1200 | + ); |
|
1201 | + } |
|
1202 | + |
|
1203 | + public function validateQuery($query) |
|
1204 | + { |
|
1205 | + $res = $this->query("EXPLAIN $query"); |
|
1206 | + return !empty($res); |
|
1207 | + } |
|
1208 | + |
|
1209 | + protected function makeTempTableCopy($table) |
|
1210 | + { |
|
1211 | + $this->log->debug("creating temp table for [$table]..."); |
|
1212 | + $result = $this->query("SHOW CREATE TABLE {$table}"); |
|
1213 | + if(empty($result)) { |
|
1214 | + return false; |
|
1215 | + } |
|
1216 | + $row = $this->fetchByAssoc($result); |
|
1217 | + if(empty($row) || empty($row['Create Table'])) { |
|
1218 | + return false; |
|
1219 | + } |
|
1220 | + $create = $row['Create Table']; |
|
1221 | + // rewrite DDL with _temp name |
|
1222 | + $tempTableQuery = str_replace("CREATE TABLE `{$table}`", "CREATE TABLE `{$table}__uw_temp`", $create); |
|
1223 | + $r2 = $this->query($tempTableQuery); |
|
1224 | + if(empty($r2)) { |
|
1225 | + return false; |
|
1226 | + } |
|
1227 | + |
|
1228 | + // get sample data into the temp table to test for data/constraint conflicts |
|
1229 | + $this->log->debug('inserting temp dataset...'); |
|
1230 | + $q3 = "INSERT INTO `{$table}__uw_temp` SELECT * FROM `{$table}` LIMIT 10"; |
|
1231 | + $this->query($q3, false, "Preflight Failed for: {$q3}"); |
|
1232 | + return true; |
|
1233 | + } |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * Tests an ALTER TABLE query |
|
1237 | + * @param string table The table name to get DDL |
|
1238 | + * @param string query The query to test. |
|
1239 | + * @return string Non-empty if error found |
|
1240 | + */ |
|
1241 | + protected function verifyAlterTable($table, $query) |
|
1242 | + { |
|
1243 | + $this->log->debug("verifying ALTER TABLE"); |
|
1244 | + // Skipping ALTER TABLE [table] DROP PRIMARY KEY because primary keys are not being copied |
|
1245 | + // over to the temp tables |
|
1246 | + if(strpos(strtoupper($query), 'DROP PRIMARY KEY') !== false) { |
|
1247 | + $this->log->debug("Skipping DROP PRIMARY KEY"); |
|
1248 | + return ''; |
|
1249 | + } |
|
1250 | + if(!$this->makeTempTableCopy($table)) { |
|
1251 | + return 'Could not create temp table copy'; |
|
1252 | + } |
|
1253 | + |
|
1254 | + // test the query on the test table |
|
1255 | + $this->log->debug('testing query: ['.$query.']'); |
|
1256 | + $tempTableTestQuery = str_replace("ALTER TABLE `{$table}`", "ALTER TABLE `{$table}__uw_temp`", $query); |
|
1257 | + if (strpos($tempTableTestQuery, 'idx') === false) { |
|
1258 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1259 | + return 'Could not use a temp table to test query!'; |
|
1260 | + } |
|
1261 | + |
|
1262 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery.']'); |
|
1263 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1264 | + } else { |
|
1265 | + // test insertion of an index on a table |
|
1266 | + $tempTableTestQuery_idx = str_replace("ADD INDEX `idx_", "ADD INDEX `temp_idx_", $tempTableTestQuery); |
|
1267 | + $this->log->debug('testing query on temp table: ['.$tempTableTestQuery_idx.']'); |
|
1268 | + $this->query($tempTableTestQuery_idx, false, "Preflight Failed for: {$query}"); |
|
1269 | + } |
|
1270 | + $mysqlError = $this->getL(); |
|
1271 | + if(!empty($mysqlError)) { |
|
1272 | + return $mysqlError; |
|
1273 | + } |
|
1274 | + $this->dropTableName("{$table}__uw_temp"); |
|
1275 | + |
|
1276 | + return ''; |
|
1277 | + } |
|
1278 | + |
|
1279 | + protected function verifyGenericReplaceQuery($querytype, $table, $query) |
|
1280 | + { |
|
1281 | + $this->log->debug("verifying $querytype statement"); |
|
1282 | + |
|
1283 | + if(!$this->makeTempTableCopy($table)) { |
|
1284 | + return 'Could not create temp table copy'; |
|
1285 | + } |
|
1286 | + // test the query on the test table |
|
1287 | + $this->log->debug('testing query: ['.$query.']'); |
|
1288 | + $tempTableTestQuery = str_replace("$querytype `{$table}`", "$querytype `{$table}__uw_temp`", $query); |
|
1289 | + if(strpos($tempTableTestQuery, '__uw_temp') === false) { |
|
1290 | + return 'Could not use a temp table to test query!'; |
|
1291 | + } |
|
1292 | + |
|
1293 | + $this->query($tempTableTestQuery, false, "Preflight Failed for: {$query}"); |
|
1294 | + $error = $this->lastError(); // empty on no-errors |
|
1295 | + $this->dropTableName("{$table}__uw_temp"); // just in case |
|
1296 | + return $error; |
|
1297 | + } |
|
1298 | + |
|
1299 | + /** |
|
1300 | + * Tests a DROP TABLE query |
|
1301 | + * @param string table The table name to get DDL |
|
1302 | + * @param string query The query to test. |
|
1303 | + * @return string Non-empty if error found |
|
1304 | + */ |
|
1305 | + public function verifyDropTable($table, $query) |
|
1306 | + { |
|
1307 | + return $this->verifyGenericReplaceQuery("DROP TABLE", $table, $query); |
|
1308 | + } |
|
1309 | + |
|
1310 | + /** |
|
1311 | + * Tests an INSERT INTO query |
|
1312 | + * @param string table The table name to get DDL |
|
1313 | + * @param string query The query to test. |
|
1314 | + * @return string Non-empty if error found |
|
1315 | + */ |
|
1316 | + public function verifyInsertInto($table, $query) |
|
1317 | + { |
|
1318 | + return $this->verifyGenericReplaceQuery("INSERT INTO", $table, $query); |
|
1319 | + } |
|
1320 | + |
|
1321 | + /** |
|
1322 | + * Tests an UPDATE query |
|
1323 | + * @param string table The table name to get DDL |
|
1324 | + * @param string query The query to test. |
|
1325 | + * @return string Non-empty if error found |
|
1326 | + */ |
|
1327 | + public function verifyUpdate($table, $query) |
|
1328 | + { |
|
1329 | + return $this->verifyGenericReplaceQuery("UPDATE", $table, $query); |
|
1330 | + } |
|
1331 | + |
|
1332 | + /** |
|
1333 | + * Tests an DELETE FROM query |
|
1334 | + * @param string table The table name to get DDL |
|
1335 | + * @param string query The query to test. |
|
1336 | + * @return string Non-empty if error found |
|
1337 | + */ |
|
1338 | + public function verifyDeleteFrom($table, $query) |
|
1339 | + { |
|
1340 | + return $this->verifyGenericReplaceQuery("DELETE FROM", $table, $query); |
|
1341 | + } |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * Check if certain database exists |
|
1345 | + * @param string $dbname |
|
1346 | + */ |
|
1347 | + public function dbExists($dbname) |
|
1348 | + { |
|
1349 | + $db = $this->getOne("SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ".$this->quoted($dbname)); |
|
1350 | + return !empty($db); |
|
1351 | + } |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * Select database |
|
1355 | + * @param string $dbname |
|
1356 | + */ |
|
1357 | + protected function selectDb($dbname) |
|
1358 | + { |
|
1359 | + return mysql_select_db($dbname); |
|
1360 | + } |
|
1361 | + |
|
1362 | + /** |
|
1363 | + * Check if certain DB user exists |
|
1364 | + * @param string $username |
|
1365 | + */ |
|
1366 | + public function userExists($username) |
|
1367 | + { |
|
1368 | + $db = $this->getOne("SELECT DATABASE()"); |
|
1369 | + if(!$this->selectDb("mysql")) { |
|
1370 | + return false; |
|
1371 | + } |
|
1372 | + $user = $this->getOne("select count(*) from user where user = ".$this->quoted($username)); |
|
1373 | + if(!$this->selectDb($db)) { |
|
1374 | + $this->checkError("Cannot select database $db", true); |
|
1375 | + } |
|
1376 | + return !empty($user); |
|
1377 | + } |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * Create DB user |
|
1381 | + * @param string $database_name |
|
1382 | + * @param string $host_name |
|
1383 | + * @param string $user |
|
1384 | + * @param string $password |
|
1385 | + */ |
|
1386 | + public function createDbUser($database_name, $host_name, $user, $password) |
|
1387 | + { |
|
1388 | + $qpassword = $this->quote($password); |
|
1389 | + $this->query("GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, INDEX |
|
1390 | 1390 | ON `$database_name`.* |
1391 | 1391 | TO \"$user\"@\"$host_name\" |
1392 | 1392 | IDENTIFIED BY '{$qpassword}';", true); |
1393 | 1393 | |
1394 | - $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
1395 | - if($host_name != 'localhost') { |
|
1396 | - $this->createDbUser($database_name, "localhost", $user, $password); |
|
1397 | - } |
|
1398 | - } |
|
1399 | - |
|
1400 | - /** |
|
1401 | - * Create a database |
|
1402 | - * @param string $dbname |
|
1403 | - */ |
|
1404 | - public function createDatabase($dbname) |
|
1405 | - { |
|
1406 | - $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
1407 | - } |
|
1408 | - |
|
1409 | - public function preInstall() |
|
1410 | - { |
|
1411 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
1412 | - $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
1413 | - |
|
1414 | - } |
|
1415 | - |
|
1416 | - /** |
|
1417 | - * Drop a database |
|
1418 | - * @param string $dbname |
|
1419 | - */ |
|
1420 | - public function dropDatabase($dbname) |
|
1421 | - { |
|
1422 | - return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
1423 | - } |
|
1424 | - |
|
1425 | - /** |
|
1426 | - * Check if this driver can be used |
|
1427 | - * @return bool |
|
1428 | - */ |
|
1429 | - public function valid() |
|
1430 | - { |
|
1431 | - return function_exists("mysql_connect"); |
|
1432 | - } |
|
1433 | - |
|
1434 | - /** |
|
1435 | - * Check DB version |
|
1436 | - * @see DBManager::canInstall() |
|
1437 | - */ |
|
1438 | - public function canInstall() |
|
1439 | - { |
|
1440 | - $db_version = $this->version(); |
|
1441 | - if(empty($db_version)) { |
|
1442 | - return array('ERR_DB_VERSION_FAILURE'); |
|
1443 | - } |
|
1444 | - if(version_compare($db_version, '4.1.2') < 0) { |
|
1445 | - return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
1446 | - } |
|
1447 | - return true; |
|
1448 | - } |
|
1449 | - |
|
1450 | - public function installConfig() |
|
1451 | - { |
|
1452 | - return array( |
|
1453 | - 'LBL_DBCONFIG_MSG3' => array( |
|
1454 | - "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
1455 | - ), |
|
1456 | - 'LBL_DBCONFIG_MSG2' => array( |
|
1457 | - "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
1458 | - ), |
|
1459 | - 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
1460 | - 'LBL_DBCONFIG_B_MSG1' => array( |
|
1461 | - "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
1462 | - "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
1463 | - ) |
|
1464 | - ); |
|
1465 | - } |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * Disable keys on the table |
|
1469 | - * @abstract |
|
1470 | - * @param string $tableName |
|
1471 | - */ |
|
1472 | - public function disableKeys($tableName) |
|
1473 | - { |
|
1474 | - return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
1475 | - } |
|
1476 | - |
|
1477 | - /** |
|
1478 | - * Re-enable keys on the table |
|
1479 | - * @abstract |
|
1480 | - * @param string $tableName |
|
1481 | - */ |
|
1482 | - public function enableKeys($tableName) |
|
1483 | - { |
|
1484 | - return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
1485 | - } |
|
1394 | + $this->query("SET PASSWORD FOR \"{$user}\"@\"{$host_name}\" = password('{$qpassword}');", true); |
|
1395 | + if($host_name != 'localhost') { |
|
1396 | + $this->createDbUser($database_name, "localhost", $user, $password); |
|
1397 | + } |
|
1398 | + } |
|
1399 | + |
|
1400 | + /** |
|
1401 | + * Create a database |
|
1402 | + * @param string $dbname |
|
1403 | + */ |
|
1404 | + public function createDatabase($dbname) |
|
1405 | + { |
|
1406 | + $this->query("CREATE DATABASE `$dbname` CHARACTER SET utf8 COLLATE utf8_general_ci", true); |
|
1407 | + } |
|
1408 | + |
|
1409 | + public function preInstall() |
|
1410 | + { |
|
1411 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT CHARACTER SET utf8", true); |
|
1412 | + $db->query("ALTER DATABASE `{$setup_db_database_name}` DEFAULT COLLATE utf8_general_ci", true); |
|
1413 | + |
|
1414 | + } |
|
1415 | + |
|
1416 | + /** |
|
1417 | + * Drop a database |
|
1418 | + * @param string $dbname |
|
1419 | + */ |
|
1420 | + public function dropDatabase($dbname) |
|
1421 | + { |
|
1422 | + return $this->query("DROP DATABASE IF EXISTS `$dbname`", true); |
|
1423 | + } |
|
1424 | + |
|
1425 | + /** |
|
1426 | + * Check if this driver can be used |
|
1427 | + * @return bool |
|
1428 | + */ |
|
1429 | + public function valid() |
|
1430 | + { |
|
1431 | + return function_exists("mysql_connect"); |
|
1432 | + } |
|
1433 | + |
|
1434 | + /** |
|
1435 | + * Check DB version |
|
1436 | + * @see DBManager::canInstall() |
|
1437 | + */ |
|
1438 | + public function canInstall() |
|
1439 | + { |
|
1440 | + $db_version = $this->version(); |
|
1441 | + if(empty($db_version)) { |
|
1442 | + return array('ERR_DB_VERSION_FAILURE'); |
|
1443 | + } |
|
1444 | + if(version_compare($db_version, '4.1.2') < 0) { |
|
1445 | + return array('ERR_DB_MYSQL_VERSION', $db_version); |
|
1446 | + } |
|
1447 | + return true; |
|
1448 | + } |
|
1449 | + |
|
1450 | + public function installConfig() |
|
1451 | + { |
|
1452 | + return array( |
|
1453 | + 'LBL_DBCONFIG_MSG3' => array( |
|
1454 | + "setup_db_database_name" => array("label" => 'LBL_DBCONF_DB_NAME', "required" => true), |
|
1455 | + ), |
|
1456 | + 'LBL_DBCONFIG_MSG2' => array( |
|
1457 | + "setup_db_host_name" => array("label" => 'LBL_DBCONF_HOST_NAME', "required" => true), |
|
1458 | + ), |
|
1459 | + 'LBL_DBCONF_TITLE_USER_INFO' => array(), |
|
1460 | + 'LBL_DBCONFIG_B_MSG1' => array( |
|
1461 | + "setup_db_admin_user_name" => array("label" => 'LBL_DBCONF_DB_ADMIN_USER', "required" => true), |
|
1462 | + "setup_db_admin_password" => array("label" => 'LBL_DBCONF_DB_ADMIN_PASSWORD', "type" => "password"), |
|
1463 | + ) |
|
1464 | + ); |
|
1465 | + } |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * Disable keys on the table |
|
1469 | + * @abstract |
|
1470 | + * @param string $tableName |
|
1471 | + */ |
|
1472 | + public function disableKeys($tableName) |
|
1473 | + { |
|
1474 | + return $this->query('ALTER TABLE '.$tableName.' DISABLE KEYS'); |
|
1475 | + } |
|
1476 | + |
|
1477 | + /** |
|
1478 | + * Re-enable keys on the table |
|
1479 | + * @abstract |
|
1480 | + * @param string $tableName |
|
1481 | + */ |
|
1482 | + public function enableKeys($tableName) |
|
1483 | + { |
|
1484 | + return $this->query('ALTER TABLE '.$tableName.' ENABLE KEYS'); |
|
1485 | + } |
|
1486 | 1486 | |
1487 | 1487 | /** |
1488 | 1488 | * Returns a DB specific FROM clause which can be used to select against functions. |
@@ -1501,8 +1501,8 @@ discard block |
||
1501 | 1501 | * @return string |
1502 | 1502 | */ |
1503 | 1503 | |
1504 | - public function getGuidSQL() |
|
1504 | + public function getGuidSQL() |
|
1505 | 1505 | { |
1506 | - return 'UUID()'; |
|
1506 | + return 'UUID()'; |
|
1507 | 1507 | } |
1508 | 1508 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | } |
81 | 81 | break; |
82 | 82 | case "mssql": |
83 | - if ( function_exists('sqlsrv_connect') |
|
83 | + if ( function_exists('sqlsrv_connect') |
|
84 | 84 | && (empty($config['db_mssql_force_driver']) || $config['db_mssql_force_driver'] == 'sqlsrv' )) { |
85 | 85 | $my_db_manager = 'SqlsrvManager'; |
86 | 86 | } elseif (self::isFreeTDS() |
@@ -122,20 +122,20 @@ discard block |
||
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
125 | - * Returns a reference to the DB object for instance $instanceName, or the default |
|
125 | + * Returns a reference to the DB object for instance $instanceName, or the default |
|
126 | 126 | * instance if one is not specified |
127 | 127 | * |
128 | 128 | * @param string $instanceName optional, name of the instance |
129 | 129 | * @return object DBManager instance |
130 | 130 | */ |
131 | - public static function getInstance($instanceName = '') |
|
131 | + public static function getInstance($instanceName = '') |
|
132 | 132 | { |
133 | 133 | global $sugar_config; |
134 | 134 | static $count = 0, $old_count = 0; |
135 | 135 | |
136 | 136 | //fall back to the default instance name |
137 | 137 | if(empty($sugar_config['db'][$instanceName])){ |
138 | - $instanceName = ''; |
|
138 | + $instanceName = ''; |
|
139 | 139 | } |
140 | 140 | if(!isset(self::$instances[$instanceName])){ |
141 | 141 | $config = $sugar_config['dbconfig']; |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | /** |
249 | 249 | * Check if we have freeTDS driver installed |
250 | 250 | * Invoked when connected to mssql. checks if we have freetds version of mssql library. |
251 | - * the response is put into a global variable. |
|
251 | + * the response is put into a global variable. |
|
252 | 252 | * @return bool |
253 | 253 | */ |
254 | 254 | public static function isFreeTDS() |
@@ -256,14 +256,14 @@ discard block |
||
256 | 256 | static $is_freetds = null; |
257 | 257 | |
258 | 258 | if($is_freetds === null) { |
259 | - ob_start(); |
|
260 | - phpinfo(INFO_MODULES); |
|
261 | - $info=ob_get_contents(); |
|
262 | - ob_end_clean(); |
|
259 | + ob_start(); |
|
260 | + phpinfo(INFO_MODULES); |
|
261 | + $info=ob_get_contents(); |
|
262 | + ob_end_clean(); |
|
263 | 263 | |
264 | - $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
264 | + $is_freetds = (strpos($info,'FreeTDS') !== false); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | return $is_freetds; |
268 | - } |
|
268 | + } |
|
269 | 269 | } |
270 | 270 | \ No newline at end of file |