Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

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

Defines backup_activity_task class

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: 359 lines (15 kb)
Included or required:0 times
Referenced: 1 time
Includes or requires: 0 files

Defines 1 class

backup_activity_task:: (12 methods):
  __construct()
  get_moduleid()
  get_sectionid()
  get_modulename()
  get_activityid()
  get_contextid()
  get_taskbasepath()
  build()
  execute()
  get_setting()
  define_settings()
  encode_content_links()


Class: backup_activity_task  - X-Ref

Provides all the settings and steps to perform one complete backup of the activity

Activities are supposed to provide the subclass of this class in their file
mod/MODULENAME/backup/moodle2/backup_MODULENAME_activity_task.class.php
The expected name of the subclass is backup_MODULENAME_activity_task
__construct($name, $moduleid, $plan = null)   X-Ref
Constructor - instantiates one object of this class

param: string $name the task identifier
param: int $moduleid course module id (id in course_modules table)
param: backup_plan|null $plan the backup plan instance this task is part of

get_moduleid()   X-Ref

return: int the course module id (id in the course_modules table)

get_sectionid()   X-Ref

return: int the course section id (id in the course_sections table)

get_modulename()   X-Ref

return: string the name of the module, eg 'workshop' (from the modules table)

get_activityid()   X-Ref

return: int the id of the activity instance (id in the activity's instances table)

get_contextid()   X-Ref

return: int the id of the associated CONTEXT_MODULE instance

get_taskbasepath()   X-Ref

return: string full path to the directory where this task writes its files

build()   X-Ref
Create all the steps that will be part of this task


execute()   X-Ref
Exceptionally override the execute method, so, based in the activity_included setting, we are able
to skip the execution of one task completely


get_setting($name)   X-Ref
Tries to look for the instance specific setting value, task specific setting value or the
common plan setting value - in that order

param: string $name the name of the setting
return: mixed|null the value of the setting or null if not found

define_settings()   X-Ref
Defines the common setting that any backup activity will have


encode_content_links($content)   X-Ref
Encodes URLs to the activity instance's scripts into a site-independent form

The current instance of the activity may be referenced from other places in
the course by URLs like http://my.moodle.site/mod/workshop/view.php?id=42
Obvisouly, such URLs are not valid any more once the course is restored elsewhere.
For this reason the backup file does not store the original URLs but encodes them
into a transportable form. During the restore, the reverse process is applied and
the encoded URLs are replaced with the new ones valid for the target site.

Every plugin must override this method in its subclass.

param: string $content some HTML text that eventually contains URLs to the activity instance scripts
return: string the content with the URLs encoded