function wwassignment_update_dirty_sets() { // update grades for all instances which have been modified since last cronjob global $CFG, $DB; $timenow = time(); $lastcron = $DB->get_field("modules", "lastcron", array("name" => "wwassignment")); // error_log ("lastcron is $lastcron and time now is $timenow"); //error_log ("sql string = $sql"); // Could we speed this up by getting all of the log records pertaining to webwork in one go? // Or perhaps just the log records which have occured after the lastcron date // Then create a hash with wwassignment->id => timemodified // means just one database lookup $logRecords = get_logs("l.module LIKE \"wwassignment\" AND l.time >{$lastcron} ", null, "l.time ASC"); $wwmodtimes = array(); foreach ($logRecords as $record) { $wwmodtimes[$wwid = $record->info] = $record->time; } // Create an array with the wwid values $idValues = implode(",", array_keys($wwmodtimes)); list($usql, $params) = $DB->get_in_or_equal($idValues); //error_log("values string $idValues"); //error_log("last modification times".print_r($wwmodtimes,true)); $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid, cm.id as wwinstanceid " . "FROM {wwassignment} a, {course_modules} cm, {modules} m WHERE m.name = 'wwassignment' " . "AND m.id=cm.module AND cm.instance=a.id AND a.id {$usql}"; $sql3 = "SELECT a.* FROM {wwassignment} a WHERE a.id {$usql}"; //error_log("last modification times".print_r($wwmodificationtime,true)); if ($rs = $DB->get_recordset_sql($sql, $params)) { foreach ($rs as $wwassignment) { if (!$wwassignment->cmidnumber) { // is this ever needed? $wwassignment->cmidnumber = _wwassignment_cmid(); } $wwassignment->timemodified = $wwmodtimes[$wwassignment->id]; if ($wwassignment->timemodified > $lastcron) { // error_log("instance needs update. timemodified ".$wwassignment->timemodified. // ", lastcron $lastcron, course id ".$wwassignment->course.", wwassignment id ".$wwassignment->id. // ", set name ".$wwassignment->name.", cm.id ".$wwassignment->wwinstanceid); if ($wwassignment->grade != 0) { wwassignment_update_grades($wwassignment); } else { wwassignment_grade_item_update($wwassignment); } // refresh events for this assignment _wwassignment_refresh_event($wwassignment); } else { // error_log("no update needed. timemodified ".$wwassignment->timemodified. // ", lastcron $lastcron, course id ".$wwassignment->course.", wwassignment id ".$wwassignment->id. // ", set name ".$wwassignment->name.", cm.id ".$wwassignment->wwinstanceid); } } $rs->close(); } // error_log("done with updating dirty sets"); return true; }
function wwassignment_update_dirty_sets() { // update grades for all instances which have been modified since last cronjob global $CFG; $timenow = time(); $lastcron = get_field("modules", "lastcron", "name", "wwassignment"); error_log("lastcron is {$lastcron} and time now is {$timenow}"); //error_log ("sql string = $sql"); // Could we speed this up by getting all of the log records pertaining to webwork in one go? // Or perhaps just the log records which have occured after the lastcron date // Then create a hash with wwassignment->id => timemodified // means just one database lookup $logRecords = get_logs("l.module LIKE \"wwassignment\" AND l.time >{$lastcron} ", "l.time ASC"); // possible actions generating a log entry include view, update and 'view all' $wwmodificationtime = array(); foreach ($logRecords as $record) { $wwid = $record->info; if ($wwid > 0) { // the $wwid must not be 0 or blank -- blank id's occur for view all. $wwmodtimes[$wwid] = $record->time; } } // Create an array with the wwid values $idValues = "( " . implode(",", array_keys($wwmodtimes)) . " )"; error_log("values string {$idValues}"); //error_log("last modification times".print_r($wwmodtimes,true)); $sql = "SELECT a.*, cm.idnumber as cmidnumber, a.course as courseid, cm.id as wwinstanceid\n\t\t\t FROM {$CFG->prefix}wwassignment a, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m\n\t\t\t WHERE m.name='wwassignment' AND m.id=cm.module AND cm.instance=a.id AND a.id IN {$idValues}"; error_log("sql {$sql}"); //$sql3 = "SELECT a.* FROM {$CFG->prefix}wwassignment a WHERE a.id IN $idValues"; //error_log("last modification times".print_r($wwmodificationtime,true)); $rs = get_recordset_sql($sql); if ($rs) { while ($wwassignment = rs_fetch_next_record($rs)) { if (!$wwassignment->cmidnumber) { // is this ever needed? $wwassignment->cmidnumber = _wwassignment_cmid(); } $wwassignment->timemodified = $wwmodtimes[$wwassignment->id]; if ($wwassignment->timemodified > $lastcron) { error_log("instance needs update. timemodified " . $wwassignment->timemodified . ", lastcron {$lastcron}, course id " . $wwassignment->course . ", wwassignment id " . $wwassignment->id . ", set name " . $wwassignment->name . ", cm.id " . $wwassignment->wwinstanceid); if ($wwassignment->grade != 0) { wwassignment_update_grades($wwassignment); } else { wwassignment_grade_item_update($wwassignment); } // refresh events for this assignment _wwassignment_refresh_event($wwassignment); } else { error_log("no update needed. timemodified " . $wwassignment->timemodified . ", lastcron {$lastcron}, course id " . $wwassignment->course . ", wwassignment id " . $wwassignment->id . ", set name " . $wwassignment->name . ", cm.id " . $wwassignment->wwinstanceid); } } rs_close($rs); } error_log("done with updating dirty sets"); return true; }