Skip to content

Fix record deletion condition error in deleteinvalidconfiglog task - #3399

Open
Lai Wei (weilai-irl) wants to merge 3 commits into
MOODLE_405_STABLEfrom
wip-135949-m405
Open

Fix record deletion condition error in deleteinvalidconfiglog task#3399
Lai Wei (weilai-irl) wants to merge 3 commits into
MOODLE_405_STABLEfrom
wip-135949-m405

Conversation

@weilai-irl

Copy link
Copy Markdown
Collaborator

Fix local_o365 adhoc task deleting config_log records only when a matching logstore_standard_log row exists, causing infinite requeueing

The config_log deletion was nested inside the "if (!empty($logidstodelete))"
block, so the records were only removed when a matching record still existed
in logstore_standard_log.

That match is not guaranteed: old log records are removed every night by
\logstore_standard\task\cleanup_task according to the loglifetime setting,
while config_log is never purged by Moodle. When no match is found nothing is
deleted, the task then counts the records again, sees they are still there and
queues another adhoc task, which reads the same records and repeats.

Close the block after the logstore deletion so the config_log records are
always deleted. The execution time check and the pause between chunks move out
of the block as well, so they apply to every chunk.
$totaldeleted only counted logstore_standard_log rows deleted, so the
"Processed X records so far" message logged on hitting the execution
time limit stayed at 0 whenever a chunk had config_log rows with no
matching logstore_standard_log row - the common case this fix targets,
since old log entries are routinely purged by
\logstore_standard\task\cleanup_task while config_log is not. Count
config_log deletions too so the progress message reflects actual work
done.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes the local_o365 ad-hoc cleanup task so it removes config_log rows even when the corresponding logstore_standard_log rows no longer exist (e.g., already purged by Moodle’s standard log cleanup), preventing the task from repeatedly re-queuing without making progress.

Changes:

  • Ensures config_log records are deleted for each processed chunk regardless of whether any matching logstore_standard_log rows are found.
  • Updates the in-code rationale to explain why a logstore match is not guaranteed (standard log retention/cleanup vs. config_log retention).

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Review feedback on the time-limit mtrace message noted that
$totaldeleted combined logstore_standard_log and config_log deletion
counts, making "Processed X records" ambiguous about which table it
refers to. Split it into $totalconfigdeleted and
$totallogstoredeleted, and report both in the message.
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.

deleteinvalidconfiglog never deletes config_log records and keeps queueing new adhoc tasks

3 participants