1
0
mirror of https://github.com/postfixadmin/postfixadmin.git synced 2025-08-09 05:02:44 +03:00

see #469 - try and make sure we do update timestamp fields

They may not be present in our $values array, but update them anyway.
This commit is contained in:
David Goodwin
2021-04-05 21:07:17 +01:00
parent 823f27b29d
commit 60ff94e3c1

View File

@@ -1945,14 +1945,19 @@ function db_insert($table, array $values, $timestamp = array('created', 'modifie
* @param array $timestamp (optional) - array of fields to set to now() - default: array('modified') * @param array $timestamp (optional) - array of fields to set to now() - default: array('modified')
* @return int - number of updated rows * @return int - number of updated rows
*/ */
function db_update($table, $where_col, $where_value, $values, $timestamp = array('modified'), $throw_exceptions = false) { function db_update(string $table, string $where_col, string $where_value, array $values, array $timestamp = array('modified'), bool $throw_exceptions = false):int {
$table_key = table_by_key($table); $table_key = table_by_key($table);
$sql = "UPDATE $table_key SET ";
$pvalues = array(); $pvalues = array();
$set = array(); $set = array();
foreach($timestamp as $k) {
if(!isset($values[$k])) {
$values[$k] = 'x'; // timestamp field not in the values list, add it in so we set it to now() see #469
}
}
foreach ($values as $key => $value) { foreach ($values as $key => $value) {
if (in_array($key, $timestamp)) { if (in_array($key, $timestamp)) {
if (db_sqlite()) { if (db_sqlite()) {
@@ -1960,10 +1965,12 @@ function db_update($table, $where_col, $where_value, $values, $timestamp = array
} else { } else {
$set[] = " $key = now() "; $set[] = " $key = now() ";
} }
} else { continue;
$set[] = " $key = :$key ";
$pvalues[$key] = $value;
} }
$set[] = " $key = :$key ";
$pvalues[$key] = $value;
} }
$pvalues['where'] = $where_value; $pvalues['where'] = $where_value;