mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2024-09-20 03:36:20 +02: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:
parent
d5c14240a4
commit
04f20d9333
@ -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')
|
||||
* @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);
|
||||
|
||||
$sql = "UPDATE $table_key SET ";
|
||||
|
||||
$pvalues = 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) {
|
||||
if (in_array($key, $timestamp)) {
|
||||
if (db_sqlite()) {
|
||||
@ -1960,10 +1965,12 @@ function db_update($table, $where_col, $where_value, $values, $timestamp = array
|
||||
} else {
|
||||
$set[] = " $key = now() ";
|
||||
}
|
||||
} else {
|
||||
$set[] = " $key = :$key ";
|
||||
$pvalues[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
|
||||
$set[] = " $key = :$key ";
|
||||
$pvalues[$key] = $value;
|
||||
|
||||
}
|
||||
|
||||
$pvalues['where'] = $where_value;
|
||||
|
Loading…
Reference in New Issue
Block a user