Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Static Public Member Functions | Public Attributes | Static Protected Member Functions | List of all members
backup_cron_automated_helper Class Reference

This class is an abstract class with methods that can be called to aid the running of automated backups over cron. More...

Static Public Member Functions

static calculate_next_automated_backup ($ignoredtimezone, $now)
 Works out the next time the automated backup should be run. More...
 
static get_automated_backup_lock ($rundirective=self::RUN_ON_SCHEDULE)
 Try to get lock for automated backup. More...
 
static get_backup_status_array ()
 Gets the results from the last automated backup that was run based upon the statuses of the courses that were looked at. More...
 
static launch_automated_backup ($course, $starttime, $userid)
 Launches a automated backup routine for the given course. More...
 
static outcome_from_results ($results)
 Returns the backup outcome by analysing its results. More...
 
static remove_deleted_courses_from_schedule ()
 Removes deleted courses fromn the backup_courses table so that we don't waste time backing them up. More...
 
static remove_excess_backups ($course, $now=null)
 Removes excess backups from a specified course. More...
 
static run_automated_backup ($rundirective=self::RUN_ON_SCHEDULE)
 Runs the automated backups if required. More...
 

Public Attributes

const AUTO_BACKUP_DISABLED = 0
 
const AUTO_BACKUP_ENABLED = 1
 
const AUTO_BACKUP_MANUAL = 2
 
const BACKUP_STATUS_ERROR = 0
 Course automated backup errored.
 
const BACKUP_STATUS_NOTYETRUN = 5
 Course automated backup has yet to be run.
 
const BACKUP_STATUS_OK = 1
 Course automated backup completed successfully.
 
const BACKUP_STATUS_QUEUED = 6
 Course automated backup has been added to adhoc task queue.
 
const BACKUP_STATUS_SKIPPED = 3
 Course automated backup was skipped.
 
const BACKUP_STATUS_UNFINISHED = 2
 Course automated backup never finished.
 
const BACKUP_STATUS_WARNING = 4
 Course automated backup had warnings.
 
const RUN_IMMEDIATELY = 1
 Run immediately.
 
const RUN_ON_SCHEDULE = 0
 Run if required by the schedule set in config. More...
 
const STATE_DISABLED = 1
 Automated backups are disabled and will not be run.
 
const STATE_OK = 0
 Automated backups are active and ready to run.
 
const STATE_RUNNING = 2
 Automated backups are all ready running!
 
const STORAGE_COURSE = 0
 Automated backup storage in course backup filearea.
 
const STORAGE_COURSE_AND_DIRECTORY = 2
 Automated backup storage in course backup filearea and specified directory.
 
const STORAGE_DIRECTORY = 1
 Automated backup storage in specified directory.
 

Static Protected Member Functions

static get_backups_to_delete ($backupfiles, $now)
 Get the list of backup files to delete depending on the automated backup settings. More...
 
static get_courses ($now=null)
 Get the courses to backup. More...
 
static is_course_modified ($courseid, $since)
 Check logs to find out if a course was modified since the given time. More...
 
static remove_excess_backups_from_course ($course, $now)
 Removes excess backups in the course backup filearea from a specified course. More...
 
static remove_excess_backups_from_directory ($course, $now)
 Removes excess backups in the specified external directory from a specified course. More...
 

Detailed Description

This class is an abstract class with methods that can be called to aid the running of automated backups over cron.

Member Function Documentation

◆ calculate_next_automated_backup()

static backup_cron_automated_helper::calculate_next_automated_backup (   $ignoredtimezone,
  $now 
)
static

Works out the next time the automated backup should be run.

Parameters
mixed$ignoredtimezoneall settings are in server timezone!
int$nowtimestamp, should not be in the past, most likely time()
Return values
inttimestamp of the next execution at server time

◆ get_automated_backup_lock()

static backup_cron_automated_helper::get_automated_backup_lock (   $rundirective = self::RUN_ON_SCHEDULE)
static

Try to get lock for automated backup.

Parameters
int$rundirective
Return values
core::lock::lock|boolean- An instance of core\lock\lock if the lock was obtained, or false.

◆ get_backup_status_array()

static backup_cron_automated_helper::get_backup_status_array ( )
static

Gets the results from the last automated backup that was run based upon the statuses of the courses that were looked at.

Return values
array

◆ get_backups_to_delete()

static backup_cron_automated_helper::get_backups_to_delete (   $backupfiles,
  $now 
)
staticprotected

Get the list of backup files to delete depending on the automated backup settings.

Parameters
array$backupfilesExisting backup files
int$nowStarting time of the process
Return values
arrayBackup files to delete

◆ get_courses()

static backup_cron_automated_helper::get_courses (   $now = null)
staticprotected

Get the courses to backup.

When there are multiple courses to backup enforce some order to the record set. The following is the preference order. First backup courses that do not have an entry in backup_courses first, as they are likely new and never been backed up. Do the oldest modified courses first. Then backup courses that have previously been backed up starting with the oldest next start time.

Parameters
null | int$nowtimestamp to use in course selection.
Return values
moodle_recordsetThe recordset of matching courses.

◆ is_course_modified()

static backup_cron_automated_helper::is_course_modified (   $courseid,
  $since 
)
staticprotected

Check logs to find out if a course was modified since the given time.

Parameters
int$courseidcourse id to check
int$sincetimestamp, from which to check
Return values
booltrue 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.

◆ launch_automated_backup()

static backup_cron_automated_helper::launch_automated_backup (   $course,
  $starttime,
  $userid 
)
static

Launches a automated backup routine for the given course.

Parameters
stdClass$course
int$starttime
int$userid
Return values
bool

◆ outcome_from_results()

static backup_cron_automated_helper::outcome_from_results (   $results)
static

Returns the backup outcome by analysing its results.

Parameters
array$resultsreturned by a backup
Return values
intself::BACKUP_STATUS_OK and other constants

◆ remove_deleted_courses_from_schedule()

static backup_cron_automated_helper::remove_deleted_courses_from_schedule ( )
static

Removes deleted courses fromn the backup_courses table so that we don't waste time backing them up.

Return values
int

◆ remove_excess_backups()

static backup_cron_automated_helper::remove_excess_backups (   $course,
  $now = null 
)
static

Removes excess backups from a specified course.

Parameters
stdClass$courseCourse object
int$nowStarting time of the process
Return values
boolWhether or not backups is being removed

◆ remove_excess_backups_from_course()

static backup_cron_automated_helper::remove_excess_backups_from_course (   $course,
  $now 
)
staticprotected

Removes excess backups in the course backup filearea from a specified course.

Parameters
stdClass$courseCourse object
int$nowStarting time of the process
Return values
boolWhether or not backups are being removed

◆ remove_excess_backups_from_directory()

static backup_cron_automated_helper::remove_excess_backups_from_directory (   $course,
  $now 
)
staticprotected

Removes excess backups in the specified external directory from a specified course.

Parameters
stdClass$courseCourse object
int$nowStarting time of the process
Return values
boolWhether or not backups are being removed

◆ run_automated_backup()

static backup_cron_automated_helper::run_automated_backup (   $rundirective = self::RUN_ON_SCHEDULE)
static

Runs the automated backups if required.

Parameters
bool$rundirective

Member Data Documentation

◆ RUN_ON_SCHEDULE

const backup_cron_automated_helper::RUN_ON_SCHEDULE = 0

Run if required by the schedule set in config.

Default.


The documentation for this class was generated from the following file: