Update database.php strlen replace with isset

Used isset instead of empty because empty treats a numeric value of 0 as empty.
This commit is contained in:
FusionPBX
2023-05-13 22:13:40 -06:00
committed by GitHub
parent 714add73fb
commit 64c159931c
+14 -13
View File
@@ -924,7 +924,7 @@
foreach($this->fields as $name => $value) { foreach($this->fields as $name => $value) {
$name = self::sanitize($name); $name = self::sanitize($name);
if ($field_count == $i) { if ($field_count == $i) {
if (strlen($value) > 0) { if (isset($value) && $value != '') {
//$sql .= "'".$value."' "; //$sql .= "'".$value."' ";
$sql .= ":".$name." \n"; $sql .= ":".$name." \n";
$params[$name] = trim($value); $params[$name] = trim($value);
@@ -934,7 +934,7 @@
} }
} }
else { else {
if (strlen($value) > 0) { if (isset($value) && $value != '') {
//$sql .= "'".$value."', "; //$sql .= "'".$value."', ";
$sql .= ":".$name.", \n"; $sql .= ":".$name.", \n";
$params[$name] = trim($value); $params[$name] = trim($value);
@@ -992,7 +992,7 @@
foreach($this->fields as $name => $value) { foreach($this->fields as $name => $value) {
$name = self::sanitize($name); $name = self::sanitize($name);
if (count($this->fields) == $i) { if (count($this->fields) == $i) {
if (strlen($name) > 0 && $value == null) { if (!empty($name) && $value == null) {
$sql .= $name." = null "; $sql .= $name." = null ";
} }
else { else {
@@ -1002,7 +1002,7 @@
} }
} }
else { else {
if (strlen($name) > 0 && $value == null) { if (!empty($name) && $value == null) {
$sql .= $name." = null, "; $sql .= $name." = null, ";
} }
else { else {
@@ -1185,7 +1185,7 @@
} }
} }
} }
if (strlen($field_value) > 0) { if (isset($field_value) && $field_value != '') {
$results = $this->execute($sql, $parameters, 'all'); $results = $this->execute($sql, $parameters, 'all');
unset($parameters); unset($parameters);
if (is_array($results)) { if (is_array($results)) {
@@ -2123,7 +2123,7 @@
$array_key != 'insert_date' && $array_key != 'insert_date' &&
$array_key != 'update_user' && $array_key != 'update_user' &&
$array_key != 'update_date') { $array_key != 'update_date') {
if (strlen($array_value) == 0) { if (!isset($array_value) || $array_value == '') {
$sql .= "null, "; $sql .= "null, ";
} }
elseif ($array_value === "now()") { elseif ($array_value === "now()") {
@@ -2138,6 +2138,7 @@
$params[$array_key] = $_SERVER['REMOTE_ADDR']; $params[$array_key] = $_SERVER['REMOTE_ADDR'];
} }
else { else {
$array_value = $array_value ?? '';
$sql .= ':'.$array_key.", "; $sql .= ':'.$array_key.", ";
$params[$array_key] = trim($array_value); $params[$array_key] = trim($array_value);
} }
@@ -2221,7 +2222,7 @@
foreach ($array as $array_key => $array_value) { foreach ($array as $array_key => $array_value) {
if (!is_array($array_value) && $array_key != $parent_key_name) { if (!is_array($array_value) && $array_key != $parent_key_name) {
$array_key = self::sanitize($array_key); $array_key = self::sanitize($array_key);
if (strlen($array_value) == 0) { if (!isset($array_value) || $array_value == '') {
$sql .= $array_key." = null, "; $sql .= $array_key." = null, ";
} }
elseif ($array_value === "now()") { elseif ($array_value === "now()") {
@@ -2661,8 +2662,8 @@
$this->db->commit(); $this->db->commit();
//set the action if not set //set the action if not set
if (strlen($action ?? '') === 0) { if (empty($action)) {
if (is_array($old_array)) { if (!empty($old_array)) {
$transaction_type = 'update'; $transaction_type = 'update';
} }
else { else {
@@ -2722,13 +2723,13 @@
$sql .= ":remote_address, "; $sql .= ":remote_address, ";
$sql .= "'".$transaction_type."', "; $sql .= "'".$transaction_type."', ";
$sql .= "now(), "; $sql .= "now(), ";
if (is_array($old_array)) { if (!empty($old_array)) {
$sql .= ":transaction_old, "; $sql .= ":transaction_old, ";
} }
else { else {
$sql .= "null, "; $sql .= "null, ";
} }
if (is_array($array)) { if (!empty($array)) {
$sql .= ":transaction_new, "; $sql .= ":transaction_new, ";
} }
else { else {
@@ -2747,11 +2748,11 @@
$statement->bindParam(':app_name', $this->app_name); $statement->bindParam(':app_name', $this->app_name);
} }
$statement->bindParam(':remote_address', $_SERVER['REMOTE_ADDR']); $statement->bindParam(':remote_address', $_SERVER['REMOTE_ADDR']);
if (is_array($old_array)) { if (!empty($old_array)) {
$old_json = json_encode($old_array, JSON_PRETTY_PRINT); $old_json = json_encode($old_array, JSON_PRETTY_PRINT);
$statement->bindParam(':transaction_old', $old_json); $statement->bindParam(':transaction_old', $old_json);
} }
if (isset($new_json)) { if (!empty($new_json)) {
$statement->bindParam(':transaction_new', $new_json); $statement->bindParam(':transaction_new', $new_json);
} }
$message = json_encode($this->message, JSON_PRETTY_PRINT); $message = json_encode($this->message, JSON_PRETTY_PRINT);