mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-32148 Backup: Adding config settings for skipping courses in automated backups
This commit is contained in:
parent
ccd90e765e
commit
914442ae29
@ -169,6 +169,25 @@ if ($hassiteconfig
|
||||
500 => '500');
|
||||
$temp->add(new admin_setting_configselect('backup/backup_auto_keep', new lang_string('keep'), new lang_string('backupkeephelp'), 1, $keepoptoins));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_shortname', new lang_string('backup_shortname', 'admin'), new lang_string('backup_shortnamehelp', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_hidden', new lang_string('skiphidden', 'backup'), new lang_string('skiphiddenhelp', 'backup'), 1));
|
||||
$temp->add(new admin_setting_configselect('backup/backup_auto_skip_modif_days', new lang_string('skipmodifdays', 'backup'), new lang_string('skipmodifdayshelp', 'backup'), 30, array(
|
||||
0 => new lang_string('never'),
|
||||
1 => new lang_string('numdays', '', 1),
|
||||
2 => new lang_string('numdays', '', 2),
|
||||
3 => new lang_string('numdays', '', 3),
|
||||
5 => new lang_string('numdays', '', 5),
|
||||
7 => new lang_string('numdays', '', 7),
|
||||
10 => new lang_string('numdays', '', 10),
|
||||
14 => new lang_string('numdays', '', 14),
|
||||
20 => new lang_string('numdays', '', 20),
|
||||
30 => new lang_string('numdays', '', 30),
|
||||
60 => new lang_string('numdays', '', 60),
|
||||
90 => new lang_string('numdays', '', 90),
|
||||
120 => new lang_string('numdays', '', 120),
|
||||
180 => new lang_string('numdays', '', 180),
|
||||
365 => new lang_string('numdays', '', 365)
|
||||
)));
|
||||
$temp->add(new admin_setting_configcheckbox('backup/backup_auto_skip_modif_prev', new lang_string('skipmodifprev', 'backup'), new lang_string('skipmodifprevhelp', 'backup'), 0));
|
||||
|
||||
// Automated defaults section.
|
||||
$temp->add(new admin_setting_heading('automatedsettings', new lang_string('automatedsettings','backup'), ''));
|
||||
|
@ -69,6 +69,7 @@ abstract class backup_cron_automated_helper {
|
||||
$status = true;
|
||||
$emailpending = false;
|
||||
$now = time();
|
||||
$config = get_config('backup');
|
||||
|
||||
mtrace("Checking automated backup status",'...');
|
||||
$state = backup_cron_automated_helper::get_automated_backup_state($rundirective);
|
||||
@ -127,37 +128,72 @@ abstract class backup_cron_automated_helper {
|
||||
|
||||
// Skip courses that do not yet need backup
|
||||
$skipped = !(($backupcourse->nextstarttime > 0 && $backupcourse->nextstarttime < $now) || $rundirective == self::RUN_IMMEDIATELY);
|
||||
$skippedmessage = 'Do not yet need backup';
|
||||
if ($skipped && $backupcourse->nextstarttime != $nextstarttime) {
|
||||
$backupcourse->nextstarttime = $nextstarttime;
|
||||
$backupcourse->laststatus = backup_cron_automated_helper::BACKUP_STATUS_SKIPPED;
|
||||
$backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
|
||||
$DB->update_record('backup_courses', $backupcourse);
|
||||
mtrace('Backup of \'' . $course->fullname . '\' is scheduled on ' . $showtime);
|
||||
}
|
||||
|
||||
// Skip backup of unavailable courses that have remained unmodified in a month
|
||||
if (!$skipped && empty($course->visible) && ($now - $course->timemodified) > 31*24*60*60) { //Hidden + settings were unmodified last month
|
||||
//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' => $now-31*24*60*60, 'action' => '%view%');
|
||||
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
|
||||
if (!$logexists) {
|
||||
$backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
|
||||
$backupcourse->nextstarttime = $nextstarttime;
|
||||
$DB->update_record('backup_courses', $backupcourse);
|
||||
mtrace('Skipping unchanged course '.$course->fullname);
|
||||
$skipped = true;
|
||||
// Check courses that must be skipped from settings.
|
||||
if (!$skipped) {
|
||||
// If config backup_auto_skip_hidden is set to true, skip courses that are not visible.
|
||||
$skipped = ($config->backup_auto_skip_hidden && !$course->visible);
|
||||
$skippedmessage = 'Not visible';
|
||||
|
||||
if (!$skipped) {
|
||||
$sqlwhere = "course=:courseid AND time>:time AND ".$DB->sql_like('action', ':action', false, true, true);
|
||||
// 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 ($config->backup_auto_skip_modif_days) {
|
||||
$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);
|
||||
|
||||
$skipped = ($course->timemodified <= $timenotmodifsincedays && !$logexists);
|
||||
$skippedmessage = 'Not modified since '.$config->backup_auto_skip_modif_days.' days';
|
||||
}
|
||||
|
||||
// If config backup_auto_skip_modif_prev is set to true, skip courses
|
||||
// that have not been modified since previous backup.
|
||||
if (!$skipped && $config->backup_auto_skip_modif_prev) {
|
||||
// Make sure that backup last status is OK or SKIPPED.
|
||||
$hasrightstatus = $backupcourse->laststatus == self::BACKUP_STATUS_SKIPPED ||
|
||||
$backupcourse->laststatus == self::BACKUP_STATUS_OK;
|
||||
if ($hasrightstatus) {
|
||||
//Check log if there were any modifications to the course content.
|
||||
$params = array('courseid' => $course->id,
|
||||
'time' => $backupcourse->laststarttime,
|
||||
'action' => '%view%');
|
||||
$logexists = $DB->record_exists_select('log', $sqlwhere, $params);
|
||||
|
||||
$skipped = ($course->timemodified <= $backupcourse->laststarttime && !$logexists);
|
||||
$skippedmessage = 'Not modified since previous backup';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Now we backup every non-skipped course
|
||||
if (!$skipped) {
|
||||
// Skip courses not needed for backup.
|
||||
if ($skipped) {
|
||||
$backupcourse->laststatus = self::BACKUP_STATUS_SKIPPED;
|
||||
$backupcourse->nextstarttime = $nextstarttime;
|
||||
$DB->update_record('backup_courses', $backupcourse);
|
||||
mtrace('Skipping '.$course->fullname.' ('.$skippedmessage.')');
|
||||
}
|
||||
// Backup every non-skipped courses.
|
||||
else {
|
||||
mtrace('Backing up '.$course->fullname.'...');
|
||||
|
||||
//We have to send a email because we have included at least one backup
|
||||
$emailpending = true;
|
||||
|
||||
//Only make the backup if laststatus isn't 2-UNFINISHED (uncontrolled error)
|
||||
if ($backupcourse->laststatus != 2) {
|
||||
if ($backupcourse->laststatus != self::BACKUP_STATUS_UNFINISHED) {
|
||||
//Set laststarttime
|
||||
$starttime = time();
|
||||
|
||||
|
@ -239,5 +239,11 @@ $string['setting_course_shortname'] = 'Course short name';
|
||||
$string['setting_course_startdate'] = 'Course startdate';
|
||||
$string['setting_keep_roles_and_enrolments'] = 'Keep current roles and enrolments';
|
||||
$string['setting_keep_groups_and_groupings'] = 'Keep current groups and groupings';
|
||||
$string['skiphidden'] = 'Skip hidden courses';
|
||||
$string['skiphiddenhelp'] = 'Choose whether or not to skip hidden courses';
|
||||
$string['skipmodifdays'] = 'Skip courses not modified since';
|
||||
$string['skipmodifdayshelp'] = 'Choose to skip courses that have not been modified since a number of days';
|
||||
$string['skipmodifprev'] = 'Skip courses not modified since previous backup';
|
||||
$string['skipmodifprevhelp'] = 'Choose whether or not to skip courses that have not been modified since previous backup';
|
||||
$string['totalcategorysearchresults'] = 'Total categories: {$a}';
|
||||
$string['totalcoursesearchresults'] = 'Total courses: {$a}';
|
||||
|
Loading…
x
Reference in New Issue
Block a user