Skip to content

Add now-timestamp parameter to simpleSaveChangeHistory#814

Open
pylipp wants to merge 6 commits intomasterfrom
single-now-for-sequential-db-operations
Open

Add now-timestamp parameter to simpleSaveChangeHistory#814
pylipp wants to merge 6 commits intomasterfrom
single-now-for-sequential-db-operations

Conversation

@pylipp
Copy link
Contributor

@pylipp pylipp commented Feb 4, 2026

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the simpleSaveChangeHistory function to accept a timestamp parameter instead of using SQL's NOW() function directly. This change allows for better control over timestamp generation and ensures consistency when multiple operations need to use the same timestamp.

Changes:

  • Modified simpleSaveChangeHistory function signature to accept a $now parameter before the optional $from and $to parameters
  • Updated all call sites in the changed regions to generate timestamps using PHP's date('Y-m-d H:i:s') and pass them to the function
  • Replaced SQL NOW() calls with parameterized :now placeholders in UPDATE and INSERT queries across multiple files

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
library/lib/tools.php Updated function signature and SQL query to use parameterized timestamp
library/lib/list.php Updated listDeleteAction and listUnDeleteAction to generate and pass timestamps
library/functions.php Updated move_boxes to generate timestamp once per transaction and use it consistently
library/ajax/deleteprofile.php Updated user deletion to use parameterized timestamp
cron/dailyroutine.php Updated daily routine deletions to use parameterized timestamp
Comments suppressed due to low confidence (1)

library/lib/list.php:298

  • When listUnDeleteAction is called recursively for child records (line 298), each recursive call generates a new timestamp. This means parent and child records will have different timestamps in the history table, even though they're part of the same logical operation. Consider passing the $now timestamp as a parameter through the recursive calls to ensure all related records have consistent timestamps.
    if ($recursive) {
        $childs = db_array('SELECT id FROM '.$table.' WHERE parent_id = :id', ['id' => $id]);
        foreach ($childs as $child) {
            $count += listUnDeleteAction($table, $child['id'], $count, true);

@pylipp pylipp force-pushed the single-now-for-sequential-db-operations branch from 18a995c to 8d86bae Compare February 4, 2026 17:31
Copy link
Contributor

Copilot AI commented Feb 4, 2026

@pylipp I've opened a new pull request, #815, to work on those changes. Once the pull request is ready, I'll request review from you.

@pylipp pylipp force-pushed the single-now-for-sequential-db-operations branch from fa3d114 to 89b0c55 Compare February 5, 2026 09:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

library/lib/list.php:276

  • The listUnDeleteAction function generates a new $now timestamp at line 266, but when it recursively calls itself at line 276, it doesn't pass $now as a parameter. This means each recursive call will generate a different timestamp, resulting in inconsistent timestamps between parent and child records. This differs from the pattern used in listDeleteAction (line 230) which correctly passes $now to recursive calls. Consider modifying listUnDeleteAction to accept $now as a parameter and pass it to recursive calls for consistency.
    $now = date('Y-m-d H:i:s');
    $result = db_query('UPDATE '.$table.' SET deleted = '.($null ? 'NULL' : '0').', modified = :now, modified_by = :user_id WHERE id = :id', ['now' => $now, 'id' => $id, 'user_id' => $_SESSION['user']['id']]);
    $count += $result->rowCount();
    if ($result->rowCount()) {
        simpleSaveChangeHistory($table, $id, 'Record recovered', $now);
    }

    if ($recursive) {
        $childs = db_array('SELECT id FROM '.$table.' WHERE parent_id = :id', ['id' => $id]);
        foreach ($childs as $child) {
            $count += listUnDeleteAction($table, $child['id'], $count, true);

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']]);
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When simpleSaveChangeHistory is called without the $from and $to parameters (using the default empty arrays), accessing $from['int'], $from['float'], $to['int'], and $to['float'] at line 298 will trigger "Undefined array key" warnings in PHP 8+. Consider adding null coalescing operators to handle these cases gracefully, such as $from['int'] ?? null instead of $from['int']. This affects all calls to this function that don't provide these parameters, including the new calls added in this PR.

Copilot uses AI. Check for mistakes.
@pylipp pylipp force-pushed the single-now-for-sequential-db-operations branch from 89b0c55 to 0979fa6 Compare February 5, 2026 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants