Skip to content

Activity Archiving Drivers

This document defines the interface that activity archiving driver implementations must adhere to.

Overview

The abstract driver base class for activity archiving drivers is \local_archiving\local\driver\archivingmod.

Overview reduced for bravery

For bravery, the following overview diagram is reduced to the most important classes and members. Therefore, some details like methods, parameters, or members are omitted. Please refer to the plugin source code for a complete reference.

classDiagram
    direction TB

    class archivingmod {
        <<abstract>>
        #context: context_module
        #cmid: int
        #courseid: int

        +get_supported_activities()$ string[]
        +can_be_archived() bool
        +execute_task(task: activity_archiving_task) void
        +get_task_content_metadata(task: activity_archiving_task) task_content_metadata[]
        +get_task_content_metadata_labels(metadata: task_content_metadata[]) stdClass[]
        +fingerprint() cm_state_fingerprint
        +get_job_create_form(handler: string, cminfo: cm_info) job_create_form
        +get_archiving_eventlist()$ string[]
        +get_refids_for_event(event: core_event_base) int[]|null
    }

    class base {
        <<abstract>>
        +ALLOWED_PLUGIN_TYPES: const string[]

        +get_frankenstyle_name() stdClass
        +get_plugin_type() string
        +get_plugin_name() string
        +is_ready()$ bool
        +is_enabled() bool
    }

    class archivingmod_quiz {
    }

    class archivingmod_assign {
    }

    class archivingmod_other {
    }

    class activity_archiving_task {
        #taskid: int
        #archivejob: archive_job
        #archivingmod: archivingmod
        #context: context_module
        #userid: int
        #status: activity_archiving_task_status
        #settings: stdClass
        #metadata: task_content_metadata[]

        +create() activity_archiving_task
        +get(id: int) activity_archiving_task
        +get_progesss() int
        +link_artifact(artifactfile: stored_file) void
        +generate_artifactfile_info(filename: string) stdClass
    }

    class task_content_metadata {
        +taskid: int
        +userid: int
        +reftable: string|null
        +refid: int|null
        +summary: string|null
    }

    class archive_job {
        #id: int
        #context: context_module
        #courseid: int
        #cmid: int
        #userid: int
        #status: archive_job_status
        #settings: stdClass
        #refids: int[]|null
        #fingerprint: archive_job_fingerprint

        +create() archive_job
        +get(id: int) archive_job
        +get_settings() stdClass
        +get_refids() int[]|null
        +delete() void
        +enqueue() void
        +execute() void
    }

    class activity_archiving_task_status {
        <<enumeration>>
        UNINITIALIZED
        CREATED
        AWAITING_PROCESSING
        RUNNING
        FINALIZING
        FINISHED
        CANCELED
        FAILED
        TIMEOUT
        UNKNOWN
    }

    %% Relationships
    base  <|--  archivingmod
    archivingmod <|-- archivingmod_quiz
    archivingmod <|-- archivingmod_assign
    archivingmod <|-- archivingmod_other
    activity_archiving_task -- archivingmod
    task_content_metadata -- archivingmod
    archive_job -- activity_archiving_task
    activity_archiving_task_status -- activity_archiving_task

    %% style
    style archive_job fill:#dedede,stroke:#666666
    style activity_archiving_task fill:#dedede,stroke:#666666
    style task_content_metadata fill:#dedede,stroke:#666666
    style activity_archiving_task_status fill:#dedede,stroke:#666666
Hold "Shift" to enable pan & zoom

Implementation

Each activity archiving driver must implement the \local_archiving\local\driver\archivingmod interface with a class, placed at the following location: /local/archiving/mod/<pluginname>/classes/archivingmod.php, where <pluginname> is the name of the activity archiving driver (e.g., quiz, assign, ...).

Each activity archiving driver specifies the mod types that it supports via the get_supported_activities() method. During creation, each activity archiving driver instance is bound to a specific activity instance by its respective module context (\context_module). The method can_be_archived() is then used to determine whether the targeted activity is ready to be archived or not.

When creating a new archive job, the method get_job_create_form() returns the Moodle form that is presented to the user upon archive job creation, containing all necessary options for the activity archiving task of the targeted activity. All form data will be stored inside the created archive job and can be accessed via the job settings API.

After creation and once scheduled for execution, the archiving manager will call the execute_task() method of the activity archiving driver with the activity archiving task that should be processed. If an task executor yields before the job is finished, it will be re-executed periodically until it is either finished or canceled. Lastly, at any point in time, the get_task_content_metadata() method can be used to retrieve metadata about the data that is being targeted by a specific activity archiving task. This metadata will be processed by the archiving manager and stored inside the archive jobs metadata record.

To display archived objects to the user (e.g., on the archive job details page), the get_task_content_metadata_labels() method resolves a list of stored task content metadata entries to human-readable information. For each entry, it returns an object with the following properties, indexed by the metadata entry ID:

  • label: Plain text label that identifies the archived object (e.g., "Attempt ID 1234").
  • url: A \moodle_url pointing to the referenced object, or null if it does not exist (anymore).
  • details: Sanitized HTML with additional information about the archived object (e.g., attempt number, date, or attachments), or null if none is available. Drivers are responsible for escaping all user data within the details.

The fingerprint() method creates a hash that represents the current state of the referenced activity. Such fingerprints are used to determine if the course module has changed since the last archive job. They are based on a minimalistic set of data that guarantees to change whenever the activity is changed in any way (e.g., new quiz attempt, regrading, changed questions, ...). The given data must be serializable and is used to calculate the final fingerprint hash.

Partial archiving

Archive jobs can be scoped to a specific set of objects (e.g., quiz attempts or assignment submissions) by passing a list of reference IDs (refids) during job creation. The meaning of these IDs is defined by the respective activity archiving driver (e.g., quiz attempt IDs for archivingmod_quiz or submission IDs for archivingmod_assign). The reference IDs of a job can be retrieved via $task->get_job()->get_refids() and must be interpreted as follows:

  • null: No restriction. All objects of the targeted activity should be archived.
  • Non-empty list of IDs: Only the listed objects should be archived.

Activity archiving drivers must respect the reference IDs within both execute_task() and get_task_content_metadata(). Like the job settings, reference IDs are cleared once an archive job reaches a final state.

Event-based archiving

Activity archiving drivers can expose Moodle events that are suitable to trigger the creation of new archive jobs via the static get_archiving_eventlist() method. It returns a list of fully qualified event class names (e.g., \mod_quiz\event\attempt_submitted). The activity archiving driver itself must not observe or handle these events. Instead, archiving triggers (e.g., the event-based trigger) use this list to allow administrators to select events and to create archive jobs once they occur.

For each exposed event, the get_refids_for_event() method must resolve a given event instance to the IDs of the objects that should be archived (see partial archiving). The return value must be interpreted as follows:

  • null: All objects of the targeted activity should be archived.
  • Non-empty list of IDs: Only the listed objects should be archived.
  • Empty list: The event does not reference any archivable object (e.g., a quiz preview attempt) and no archive job should be created.

The default implementations of both methods expose no events and return null respectively, so that implementing event-based archiving is optional for activity archiving drivers.