-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add now-timestamp parameter to simpleSaveChangeHistory #814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
4161bf2
0a1a05b
6e2357c
8819561
4de464e
0979fa6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -286,33 +286,38 @@ function utf8_decode_array($array) | |
| return $array; | ||
| } | ||
|
|
||
| function simpleSaveChangeHistory($table, $record, $changes, $from = [], $to = []) | ||
| function simpleSaveChangeHistory($table, $record, $changes, $now = null, $from = [], $to = []) | ||
| { | ||
| // from and to variable must be arrays with entry 'int' or 'float' | ||
| if (!db_tableexists('history')) { | ||
| return; | ||
| } | ||
| db_query('INSERT INTO history (tablename, record_id, changes, user_id, ip, changedate, from_int, from_float, to_int, to_float) VALUES (:table,:id,:change,:user_id,:ip,NOW(), :from_int, :from_float, :to_int, :to_float)', ['table' => $table, 'id' => $record, 'change' => $changes, 'user_id' => $_SESSION['user']['id'], 'ip' => $_SERVER['REMOTE_ADDR'], 'from_int' => $from['int'], 'from_float' => $from['float'], 'to_int' => $to['int'], 'to_float' => $to['float']]); | ||
| if (null === $now) { | ||
| $now = date('Y-m-d H:i:s'); | ||
| } | ||
| db_query('INSERT INTO history (tablename, record_id, changes, user_id, ip, changedate, from_int, from_float, to_int, to_float) VALUES (:table,:id,:change,:user_id,:ip,:now, :from_int, :from_float, :to_int, :to_float)', ['table' => $table, 'id' => $record, 'change' => $changes, 'user_id' => $_SESSION['user']['id'], 'ip' => $_SERVER['REMOTE_ADDR'], 'now' => $now, 'from_int' => $from['int'], 'from_float' => $from['float'], 'to_int' => $to['int'], 'to_float' => $to['float']]); | ||
|
||
| } | ||
|
|
||
| function simpleBulkSaveChangeHistory($table, $records, $changes, $from = [], $to = []) | ||
| function simpleBulkSaveChangeHistory($table, $records, $changes, $now = null) | ||
| { | ||
| // from and to variable must be arrays with entry 'int' or 'float' | ||
| if (!db_tableexists('history')) { | ||
| return; | ||
| } | ||
| if (null === $now) { | ||
| $now = date('Y-m-d H:i:s'); | ||
| } | ||
| $query = ''; | ||
| $params = []; | ||
| $params = ['now' => $now]; | ||
| if (is_iterable($records)) { | ||
| for ($i = 0; $i < sizeof($records); ++$i) { | ||
| $query .= "(:table{$i},:id{$i},:change{$i},:user_id{$i},:ip{$i},NOW(), :from_int{$i}, :from_float{$i}, :to_int{$i}, :to_float{$i})"; | ||
| $params = array_merge($params, ['table'.$i => $table, 'id'.$i => $records[$i], 'change'.$i => $changes, 'user_id'.$i => $_SESSION['user']['id'], 'ip'.$i => $_SERVER['REMOTE_ADDR'], 'from_int'.$i => $from['int'], 'from_float'.$i => $from['float'], 'to_int'.$i => $to['int'], 'to_float'.$i => $to['float']]); | ||
| $query .= "(:table{$i},:id{$i},:change{$i},:user_id{$i},:ip{$i},:now)"; | ||
| $params = array_merge($params, ['table'.$i => $table, 'id'.$i => $records[$i], 'change'.$i => $changes, 'user_id'.$i => $_SESSION['user']['id'], 'ip'.$i => $_SERVER['REMOTE_ADDR']]); | ||
| if ($i !== sizeof($records) - 1) { | ||
| $query .= ','; | ||
| } | ||
| } | ||
| } | ||
| if (strlen($query) > 0) { | ||
| db_query("INSERT INTO history (tablename, record_id, changes, user_id, ip, changedate, from_int, from_float, to_int, to_float) VALUES {$query}", $params); | ||
| db_query("INSERT INTO history (tablename, record_id, changes, user_id, ip, changedate) VALUES {$query}", $params); | ||
pylipp marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.