Skip to content

Commit

Permalink
Fix handling of autoupdate checklist items from logs when there is a …
Browse files Browse the repository at this point in the history
…forum present #122
  • Loading branch information
davosmith committed May 17, 2024
1 parent 9d61320 commit ab38633
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions classes/local/autoupdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,32 @@ protected static function get_logged_userids_legacy($modname, $cmid, $userids) {
protected static function get_logged_userids_new($modname, $cmid, $userids) {
global $DB;

$action = self::get_log_action_new($modname);
if (!$action) {
$actions = self::get_log_action_new($modname);
if (!$actions) {
return [];
}

[$usql, $params] = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);

$params['contextinstanceid'] = $cmid;
$params['contextlevel'] = CONTEXT_MODULE;
$params['target'] = $action[0];
$params['action'] = $action[1];
$select = "contextinstanceid = :contextinstanceid AND contextlevel = :contextlevel
AND target = :target AND action = :action AND userid $usql";

$userids = [];
$entries = self::$reader->get_events_select($select, $params, '', 0, 0);
foreach ($entries as $entry) {
$userids[$entry->userid] = $entry->userid;

if (!is_array($actions[0])) {
// To cope with the few (one!) cases where there are multiple possible actions, wrap the other cases
// in an array (but with only a single item).
$actions = [$actions];
}
foreach ($actions as $action) {
$params['target'] = $action[0];
$params['action'] = $action[1];
$entries = self::$reader->get_events_select($select, $params, '', 0, 0);
foreach ($entries as $entry) {
$userids[$entry->userid] = $entry->userid;
}
}
return array_values($userids);
}
Expand Down

0 comments on commit ab38633

Please sign in to comment.