db_utils.php ➔ db_convert()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1
Metric Value
cc 1
eloc 2
nc 1
nop 4
dl 0
loc 4
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
6
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
7
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
8
 *
9
 * This program is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU Affero General Public License version 3 as published by the
11
 * Free Software Foundation with the addition of the following permission added
12
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License along with
22
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
23
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
 * 02110-1301 USA.
25
 *
26
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
28
 *
29
 * The interactive user interfaces in modified source and object code versions
30
 * of this program must display Appropriate Legal Notices, as required under
31
 * Section 5 of the GNU Affero General Public License version 3.
32
 *
33
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34
 * these Appropriate Legal Notices must retain the display of the "Powered by
35
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
36
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
37
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
38
 ********************************************************************************/
39
40
41
42
43
/**
44
 * @deprecated use DBManager::convert() instead.
45
 */
46
function db_convert($string, $type, $additional_parameters=array(),$additional_parameters_oracle_only=array())
47
	{
48 49
    return $GLOBALS['db']->convert($string, $type, $additional_parameters, $additional_parameters_oracle_only);
49
            }
50
51
/**
52
 * @deprecated use DBManager::concat() instead.
53
 */
54
function db_concat($table, $fields)
55
	{
56 2
    return $GLOBALS['db']->concat($table, $fields);
57
}
58
59
/**
60
 * @deprecated use DBManager::fromConvert() instead.
61
 */
62
function from_db_convert($string, $type)
63
	{
64 1
    return $GLOBALS['db']->fromConvert($string, $type);
65
	}
66
67
$toHTML = array(
68
	'"' => '&quot;',
69
	'<' => '&lt;',
70
	'>' => '&gt;',
71
	"'" => '&#039;',
72
);
73
$GLOBALS['toHTML_keys'] = array_keys($toHTML);
74
$GLOBALS['toHTML_values'] = array_values($toHTML);
75
$GLOBALS['toHTML_keys_set'] = implode("", $GLOBALS['toHTML_keys']);
76
/**
77
 * Replaces specific characters with their HTML entity values
78
 * @param string $string String to check/replace
79
 * @param bool $encode Default true
80
 * @return string
81
 *
82
 * @todo Make this utilize the external caching mechanism after re-testing (see
83
 *       log on r25320).
84
 *
85
 * Bug 49489 - removed caching of to_html strings as it was consuming memory and
86
 * never releasing it
87
 */
88
function to_html($string, $encode=true){
89 229
	if (empty($string)) {
90 181
		return $string;
91
	}
92
93 214
	global $toHTML;
94
95 214
	if($encode && is_string($string)){
96
		/*
97
		 * cn: bug 13376 - handle ampersands separately
98
		 * credit: ashimamura via bug portal
99
		 */
100
		//$string = str_replace("&", "&amp;", $string);
101
102 214
        if(is_array($toHTML))
103
        { // cn: causing errors in i18n test suite ($toHTML is non-array)
104 214
            $string = str_ireplace($GLOBALS['toHTML_keys'],$GLOBALS['toHTML_values'],$string);
105
		}
106
	}
107
108 214
    return $string;
109
}
110
111
112
/**
113
 * Replaces specific HTML entity values with the true characters
114
 * @param string $string String to check/replace
115
 * @param bool $encode Default true
116
 * @return string
117
 */
118
function from_html($string, $encode=true) {
119 232
    if (!is_string($string) || !$encode) {
120 154
        return $string;
121
    }
122
123 209
	global $toHTML;
124 209
    static $toHTML_values = null;
125 209
    static $toHTML_keys = null;
126 209
    static $cache = array();
127 209
    if (!empty($toHTML) && is_array($toHTML) && (!isset($toHTML_values) || !empty($GLOBALS['from_html_cache_clear']))) {
128 1
        $toHTML_values = array_values($toHTML);
129 1
        $toHTML_keys = array_keys($toHTML);
130
    }
131
132
    // Bug 36261 - Decode &amp; so we can handle double encoded entities
133 209
	$string = str_ireplace("&amp;", "&", $string);
134
135 209
    if (!isset($cache[$string])) {
136 99
        $cache[$string] = str_ireplace($toHTML_values, $toHTML_keys, $string);
137
    }
138 209
    return $cache[$string];
139
}
140
141
/*
142
 * Return a version of $proposed that can be used as a column name in any of our supported databases
143
 * Practically this means no longer than 25 characters as the smallest identifier length for our supported DBs is 30 chars for Oracle plus we add on at least four characters in some places (for indices for example)
144
 * @param string $name Proposed name for the column
145
 * @param string $ensureUnique
146
 * @param int $maxlen Deprecated and ignored
0 ignored issues
show
Documentation introduced by
There is no parameter named $maxlen. Did you maybe mean $maxLen?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
147
 * @return string Valid column name trimmed to right length and with invalid characters removed
148
 */
149
function getValidDBName ($name, $ensureUnique = false, $maxLen = 30)
150
{
151 1
    return DBManagerFactory::getInstance()->getValidDBName($name, $ensureUnique);
152
}
153
154
155
/**
156
 * isValidDBName
157
 *
158
 * Utility to perform the check during install to ensure a database name entered by the user
159
 * is valid based on the type of database server
160
 * @param string $name Proposed name for the DB
161
 * @param string $dbType Type of database server
162
 * @return bool true or false based on the validity of the DB name
163
 */
164
function isValidDBName($name, $dbType)
165
{
166 1
    $db = DBManagerFactory::getTypeInstance($dbType);
167 1
    return $db->isDatabaseNameValid($name);
168
}
169