mirror of
https://github.com/moodle/moodle.git
synced 2025-04-24 09:55:33 +02:00
MDL-42890 backup: Remove usage of log table in backup cron helper
This commit is contained in:
parent
dc06500559
commit
2523979821
@ -226,7 +226,7 @@ class store implements \tool_log\log\store, \core\log\sql_select_reader {
|
||||
$return = '';
|
||||
unset($match[0]); // The first entry is the whole string.
|
||||
foreach ($match as $m) {
|
||||
// We can hard code LIKE here because we are not worried about case sensitivity and we don't want this to be faster.
|
||||
// We hard code LIKE here because we are not worried about case sensitivity and want this to be fast.
|
||||
switch ($m) {
|
||||
case 'crud' :
|
||||
$replace = 'action';
|
||||
|
@ -153,14 +153,9 @@ abstract class backup_cron_automated_helper {
|
||||
// If config backup_auto_skip_modif_days is set to true, skip courses
|
||||
// that have not been modified since the number of days defined.
|
||||
if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_days) {
|
||||
$sqlwhere = "course=:courseid AND time>:time AND ".$DB->sql_like('action', ':action', false, true, true);
|
||||
$timenotmodifsincedays = $now - ($config->backup_auto_skip_modif_days * DAYSECS);
|
||||
// Check log if there were any modifications to the course content.
|
||||
$params = array('courseid' => $course->id,
|
||||
'time' => $timenotmodifsincedays,
|
||||
'action' => '%view%');
|
||||
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
|
||||
|
||||
$logexists = self::is_course_modified($course->id, $timenotmodifsincedays);
|
||||
$skipped = ($course->timemodified <= $timenotmodifsincedays && !$logexists);
|
||||
$skippedmessage = 'Not modified in the past '.$config->backup_auto_skip_modif_days.' days';
|
||||
}
|
||||
@ -169,12 +164,7 @@ abstract class backup_cron_automated_helper {
|
||||
// that have not been modified since previous backup.
|
||||
if ($shouldrunnow && !$skipped && $lastbackupwassuccessful && $config->backup_auto_skip_modif_prev) {
|
||||
// Check log if there were any modifications to the course content.
|
||||
$sqlwhere = "course=:courseid AND time>:time AND ".$DB->sql_like('action', ':action', false, true, true);
|
||||
$params = array('courseid' => $course->id,
|
||||
'time' => $backupcourse->laststarttime,
|
||||
'action' => '%view%');
|
||||
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
|
||||
|
||||
$logexists = self::is_course_modified($course->id, $backupcourse->laststarttime);
|
||||
$skipped = ($course->timemodified <= $backupcourse->laststarttime && !$logexists);
|
||||
$skippedmessage = 'Not modified since previous backup';
|
||||
}
|
||||
@ -668,4 +658,26 @@ abstract class backup_cron_automated_helper {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check logs to find out if a course was modified since the given time.
|
||||
*
|
||||
* @param int $courseid course id to check
|
||||
* @param int $since timestamp, from which to check
|
||||
*
|
||||
* @return bool true if the course was modified, false otherwise. This also returns false if no readers are enabled. This is
|
||||
* intentional, since we cannot reliably determine if any modification was made or not.
|
||||
*/
|
||||
protected static function is_course_modified($courseid, $since) {
|
||||
$logmang = get_log_manager();
|
||||
$readers = $logmang->get_readers('core\log\sql_select_reader');
|
||||
$where = "courseid = :courseid and timecreated > :since and crud <> 'r'";
|
||||
$params = array('courseid' => $courseid, 'since' => $since);
|
||||
foreach ($readers as $reader) {
|
||||
if ($reader->get_events_select_count($where, $params)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user