Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.

Differences Between: [Versions 310 and 403] [Versions 311 and 403] [Versions 39 and 403] [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]

Defines various backup steps that will be used by common tasks in backup

Copyright: 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 3100 lines (122 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 54 classes

create_and_clean_temp_stuff:: (1 method):
  define_execution()

drop_and_clean_temp_stuff:: (2 methods):
  define_execution()
  skip_cleaning_temp_dir()

create_taskbasepath_directory:: (1 method):
  define_execution()

backup_activity_structure_step:: (4 methods):
  prepare_activity_structure()
  add_question_usages()
  add_question_references()
  add_question_set_references()

backup_questions_activity_structure_step:: (0 methods):

backup_calculate_question_categories:: (1 method):
  define_execution()

backup_delete_temp_questions:: (1 method):
  define_execution()

backup_block_structure_step:: (1 method):
  prepare_block_structure()

backup_module_structure_step:: (1 method):
  define_structure()

backup_section_structure_step:: (1 method):
  define_structure()

backup_course_structure_step:: (1 method):
  define_structure()

backup_enrolments_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_roles_structure_step:: (1 method):
  define_structure()

backup_final_roles_structure_step:: (1 method):
  define_structure()

backup_final_scales_structure_step:: (1 method):
  define_structure()

backup_final_outcomes_structure_step:: (1 method):
  define_structure()

backup_filters_structure_step:: (1 method):
  define_structure()

backup_comments_structure_step:: (1 method):
  define_structure()

backup_badges_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_calendarevents_structure_step:: (1 method):
  define_structure()

backup_gradebook_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_grade_history_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_userscompletion_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_groups_structure_step:: (3 methods):
  define_structure()
  get_group_custom_fields_for_backup()
  get_grouping_custom_fields_for_backup()

backup_users_structure_step:: (1 method):
  define_structure()

backup_block_instance_structure_step:: (1 method):
  define_structure()

backup_course_logs_structure_step:: (1 method):
  define_structure()

backup_activity_logs_structure_step:: (1 method):
  define_structure()

backup_course_logstores_structure_step:: (1 method):
  define_structure()

backup_course_loglastaccess_structure_step:: (1 method):
  define_structure()

backup_activity_logstores_structure_step:: (0 methods):

backup_course_competencies_structure_step:: (2 methods):
  define_structure()
  execute_condition()

backup_activity_competencies_structure_step:: (2 methods):
  define_structure()
  execute_condition()

backup_inforef_structure_step:: (1 method):
  define_structure()

move_inforef_annotations_to_final:: (1 method):
  define_execution()

backup_final_files_structure_step:: (1 method):
  define_structure()

backup_main_structure_step:: (1 method):
  define_structure()

backup_zip_contents:: (2 methods):
  define_execution()
  progress()

backup_store_backup_file:: (1 method):
  define_execution()

backup_activity_grade_items_to_ids:: (1 method):
  define_execution()

backup_enrolments_execution_step:: (2 methods):
  define_execution()
  annotate_id()

backup_annotate_course_groups_and_groupings:: (1 method):
  define_execution()

backup_annotate_groups_from_groupings:: (1 method):
  define_execution()

backup_annotate_scales_from_outcomes:: (1 method):
  define_execution()

backup_annotate_all_question_files:: (1 method):
  define_execution()

backup_questions_structure_step:: (1 method):
  define_structure()

backup_annotate_all_user_files:: (1 method):
  define_execution()

backup_activity_grading_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_activity_grades_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_activity_grade_history_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_course_completion_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_completion_defaults_structure_step:: (2 methods):
  execute_condition()
  define_structure()

backup_contentbankcontent_structure_step:: (1 method):
  define_structure()

backup_xapistate_structure_step:: (1 method):
  define_structure()


Class: create_and_clean_temp_stuff  - X-Ref

Create the temp dir where backup/restore will happen and create temp ids table.

define_execution()   X-Ref
No description

Class: drop_and_clean_temp_stuff  - X-Ref

Delete the temp dir used by backup/restore (conditionally) and drop temp ids table.
Note we delete the directory but not the corresponding log file that will be
there until cron cleans it up.

define_execution()   X-Ref
No description

skip_cleaning_temp_dir($skip)   X-Ref
No description

Class: create_taskbasepath_directory  - X-Ref

Create the directory where all the task (activity/block...) information will be stored

define_execution()   X-Ref
No description

Class: backup_activity_structure_step  - X-Ref

Abstract structure step, parent of all the activity structure steps. Used to wrap the
activity structure definition within the main <activity ...> tag.

prepare_activity_structure($activitystructure)   X-Ref
Wraps any activity backup structure within the common 'activity' element
that will include common to all activities information like id, context...

param: backup_nested_element $activitystructure the element to wrap
return: backup_nested_element the $activitystructure wrapped by the common 'activity' element

add_question_usages($element, $usageidname, $nameprefix = '')   X-Ref
Attach to $element (usually attempts) the needed backup structures
for question_usages and all the associated data.

param: backup_nested_element $element the element that will contain all the question_usages data.
param: string $usageidname the name of the element that holds the usageid.
param: string $nameprefix this prefix is added to all the element names we create.

add_question_references($element, $component, $questionarea)   X-Ref
Backup the related data from reference table for the instance.

param: backup_nested_element $element
param: string $component
param: string $questionarea

add_question_set_references($element, $component, $questionarea)   X-Ref
Backup the related data from set_reference table for the instance.

param: backup_nested_element $element
param: string $component
param: string $questionarea

Class: backup_questions_activity_structure_step  - X-Ref

Abstract structure step to help activities that store question attempt data, reference data and set reference data.

Class: backup_calculate_question_categories  - X-Ref

backup structure step in charge of calculating the categories to be
included in backup, based in the context being backuped (module/course)
and the already annotated questions present in backup_ids_temp

define_execution()   X-Ref
No description

Class: backup_delete_temp_questions  - X-Ref

backup structure step in charge of deleting all the questions annotated
in the backup_ids_temp table

define_execution()   X-Ref
No description

Class: backup_block_structure_step  - X-Ref

Abstract structure step, parent of all the block structure steps. Used to wrap the
block structure definition within the main <block ...> tag

Class: backup_module_structure_step  - X-Ref

structure step that will generate the module.xml file for the activity,
accumulating various information about the activity, annotating groupings
and completion/avail conf

define_structure()   X-Ref
No description

Class: backup_section_structure_step  - X-Ref

structure step that will generate the section.xml file for the section
annotating files

define_structure()   X-Ref
No description

Class: backup_course_structure_step  - X-Ref

structure step that will generate the course.xml file for the course, including
course category reference, tags, modules restriction information
and some annotations (files & groupings)

define_structure()   X-Ref
No description

Class: backup_enrolments_structure_step  - X-Ref

structure step that will generate the enrolments.xml file for the given course

execute_condition()   X-Ref
Skip enrolments on the front page.

return: bool

define_structure()   X-Ref
No description

Class: backup_roles_structure_step  - X-Ref

structure step that will generate the roles.xml file for the given context, observing
the role_assignments setting to know if that part needs to be included

define_structure()   X-Ref
No description

Class: backup_final_roles_structure_step  - X-Ref

structure step that will generate the roles.xml containing the
list of roles used along the whole backup process. Just raw
list of used roles from role table

define_structure()   X-Ref
No description

Class: backup_final_scales_structure_step  - X-Ref

structure step that will generate the scales.xml containing the
list of scales used along the whole backup process.

define_structure()   X-Ref
No description

Class: backup_final_outcomes_structure_step  - X-Ref

structure step that will generate the outcomes.xml containing the
list of outcomes used along the whole backup process.

define_structure()   X-Ref
No description

Class: backup_filters_structure_step  - X-Ref

structure step in charge of constructing the filters.xml file for all the filters found
in activity

define_structure()   X-Ref
No description

Class: backup_comments_structure_step  - X-Ref

Structure step in charge of constructing the comments.xml file for all the comments found in a given context.

define_structure()   X-Ref
No description

Class: backup_badges_structure_step  - X-Ref

structure step in charge of constructing the badges.xml file for all the badges found
in a given context

execute_condition()   X-Ref
No description

define_structure()   X-Ref
No description

Class: backup_calendarevents_structure_step  - X-Ref

structure step in charge of constructing the calender.xml file for all the events found
in a given context

define_structure()   X-Ref
No description

Class: backup_gradebook_structure_step  - X-Ref

structure step in charge of constructing the gradebook.xml file for all the gradebook config in the course
NOTE: the backup of the grade items themselves is handled by backup_activity_grades_structure_step

execute_condition()   X-Ref
We need to decide conditionally, based on dynamic information
about the execution of this step. Only will be executed if all
the module gradeitems have been already included in backup


define_structure()   X-Ref
No description

Class: backup_grade_history_structure_step  - X-Ref

Step in charge of constructing the grade_history.xml file containing the grade histories.

execute_condition()   X-Ref
Limit the execution.

This applies the same logic than the one applied to {@link backup_gradebook_structure_step},
because we do not want to save the history of items which are not backed up. At least for now.

define_structure()   X-Ref
No description

Class: backup_userscompletion_structure_step  - X-Ref

structure step in charge if constructing the completion.xml file for all the users completion
information in a given activity

execute_condition()   X-Ref
Skip completion on the front page.

return: bool

define_structure()   X-Ref
No description

Class: backup_groups_structure_step  - X-Ref

structure step in charge of constructing the main groups.xml file for all the groups and
groupings information already annotated

define_structure()   X-Ref
No description

get_group_custom_fields_for_backup(int $courseid)   X-Ref
Get custom fields array for group

param: int $courseid
return: array

get_grouping_custom_fields_for_backup(int $courseid)   X-Ref
Get custom fields array for grouping

param: int $courseid
return: array

Class: backup_users_structure_step  - X-Ref

structure step in charge of constructing the main users.xml file for all the users already
annotated (final). Includes custom profile fields, preferences, tags, role assignments and
overrides.

define_structure()   X-Ref
No description

Class: backup_block_instance_structure_step  - X-Ref

structure step in charge of constructing the block.xml file for one
given block (instance and positions). If the block has custom DB structure
that will go to a separate file (different step defined in block class)

define_structure()   X-Ref
No description

Class: backup_activity_logs_structure_step  - X-Ref

structure step in charge of constructing the logs.xml file for all the log records found
in activity

define_structure()   X-Ref
No description

Class: backup_course_logstores_structure_step  - X-Ref

Structure step in charge of constructing the logstores.xml file for the course logs.

This backup step will backup the logs for all the enabled logstore subplugins supporting
it, for logs belonging to the course level.
define_structure()   X-Ref
No description

Class: backup_course_loglastaccess_structure_step  - X-Ref

Structure step in charge of constructing the loglastaccess.xml file for the course logs.

This backup step will backup the logs of the user_lastaccess table.
define_structure()   X-Ref
This function creates the structures for the loglastaccess.xml file.
Expected structure would look like this.
<loglastaccesses>
<loglastaccess id=2>
<userid>5</userid>
<timeaccess>1616887341</timeaccess>
</loglastaccess>
</loglastaccesses>

return: backup_nested_element

Class: backup_activity_logstores_structure_step  - X-Ref

Structure step in charge of constructing the logstores.xml file for the activity logs.

Note: Activity structure is completely equivalent to the course one, so just extend it.

Class: backup_course_competencies_structure_step  - X-Ref

Course competencies backup structure step.

define_structure()   X-Ref
No description

execute_condition()   X-Ref
Execute conditions.

return: bool

Class: backup_activity_competencies_structure_step  - X-Ref

Activity competencies backup structure step.

define_structure()   X-Ref
No description

execute_condition()   X-Ref
Execute conditions.

return: bool

Class: backup_inforef_structure_step  - X-Ref

structure in charge of constructing the inforef.xml file for all the items we want
to have referenced there (users, roles, files...)

define_structure()   X-Ref
No description

Class: move_inforef_annotations_to_final  - X-Ref

This step will get all the annotations already processed to inforef.xml file and
transform them into 'final' annotations.

define_execution()   X-Ref
No description

Class: backup_final_files_structure_step  - X-Ref

structure in charge of constructing the files.xml file with all the
annotated (final) files along the process. At, the same time, and
using one specialised nested_element, will copy them form moodle storage
to backup storage

define_structure()   X-Ref
No description

Class: backup_main_structure_step  - X-Ref

Structure step in charge of creating the main moodle_backup.xml file
where all the information related to the backup, settings, license and

define_structure()   X-Ref
No description

Class: backup_zip_contents  - X-Ref

Execution step that will generate the final zip (.mbz) file with all the contents

define_execution()   X-Ref


progress($progress = file_progress::INDETERMINATE, $max = file_progress::INDETERMINATE)   X-Ref
Implementation for file_progress interface to display unzip progress.

param: int $progress Current progress
param: int $max Max value

Class: backup_store_backup_file  - X-Ref

This step will send the generated backup file to its final destination

define_execution()   X-Ref
No description

Class: backup_activity_grade_items_to_ids  - X-Ref

This step will search for all the activity (not calculations, categories nor aggregations) grade items
and put them to the backup_ids tables, to be used later as base to backup them

define_execution()   X-Ref
No description

Class: backup_enrolments_execution_step  - X-Ref

This step allows enrol plugins to annotate custom fields.

define_execution()   X-Ref
Function that will contain all the code to be executed.


annotate_id($itemname, $itemid)   X-Ref
Annotate a single name/id pair.
This can be called from {@link enrol_plugin::backup_annotate_custom_fields()}.

param: string $itemname
param: int $itemid

Class: backup_annotate_course_groups_and_groupings  - X-Ref

This step will annotate all the groups and groupings belonging to the course

define_execution()   X-Ref
No description

Class: backup_annotate_groups_from_groupings  - X-Ref

This step will annotate all the groups belonging to already annotated groupings

define_execution()   X-Ref
No description

Class: backup_annotate_scales_from_outcomes  - X-Ref

This step will annotate all the scales belonging to already annotated outcomes

define_execution()   X-Ref
No description

Class: backup_annotate_all_question_files  - X-Ref

This step will generate all the file annotations for the already
annotated (final) question_categories. It calculates the different
contexts that are being backup and, annotates all the files
on every context belonging to the "question" component. As far as
we are always including *complete* question banks it is safe and
optimal to do that in this (one pass) way

define_execution()   X-Ref
No description

Class: backup_questions_structure_step  - X-Ref

structure step in charge of constructing the questions.xml file for all the
question categories and questions required by the backup
and letters related to one activity.

define_structure()   X-Ref
No description

Class: backup_annotate_all_user_files  - X-Ref

This step will generate all the file  annotations for the already
annotated (final) users. Need to do this here because each user
has its own context and structure tasks only are able to handle
one context. Also, this step will guarantee that every user has
its context created (req for other steps)

define_execution()   X-Ref
No description

Class: backup_activity_grading_structure_step  - X-Ref

Defines the backup step for advanced grading methods attached to the activity module

execute_condition()   X-Ref
Include the grading.xml only if the module supports advanced grading


define_structure()   X-Ref
Declares the gradable areas structures and data sources


Class: backup_activity_grades_structure_step  - X-Ref

structure step in charge of constructing the grades.xml file for all the grade items
and letters related to one activity

execute_condition()   X-Ref
No grades on the front page.

return: bool

define_structure()   X-Ref
No description

Class: backup_activity_grade_history_structure_step  - X-Ref

Structure step in charge of constructing the grade history of an activity.

This step is added to the task regardless of the setting 'grade_histories'.
The reason is to allow for a more flexible step in case the logic needs to be
split accross different settings to control the history of items and/or grades.
execute_condition()   X-Ref
No grades on the front page.

return: bool

define_structure()   X-Ref
No description

Class: backup_course_completion_structure_step  - X-Ref

Backups up the course completion information for the course.

execute_condition()   X-Ref
No description

define_structure()   X-Ref
The structure of the course completion backup

return: backup_nested_element

Class: backup_completion_defaults_structure_step  - X-Ref

Backup completion defaults for each module type.

execute_condition()   X-Ref
To conditionally decide if one step will be executed or no


define_structure()   X-Ref
The structure of the course completion backup

return: backup_nested_element

Class: backup_contentbankcontent_structure_step  - X-Ref

Structure step in charge of constructing the contentbank.xml file for all the contents found in a given context

define_structure()   X-Ref
Define structure for content bank step


Class: backup_xapistate_structure_step  - X-Ref

Structure step in charge of constructing the xapistate.xml file for all the xAPI states found in a given context.

define_structure()   X-Ref
Define structure for content bank step