Backup 2 dependent activities?

Backup 2 dependent activities?

by Russell England -
Number of replies: 1
Picture of Plugin developers

So I've developed 2 modules that depend on each other called decisionpoint and decisionitem.

Decisionitem is basically a label resource, it is related to a single decisionpoint and is hidden from students.

Decisionpoint is an activity that lists the decisionitems so a user can make a choice. When a user makes a choice, the decisionitem and the decisionpoint are marked as complete.

The reason for the development is for access restrictions. So when a user reaches a decisionpoint, they choose a decisionitem. What is displayed next in the course depends on the decision they made.

The problem I have is keeping the relationship between the 2 when backing up. In the decisionitem table I record the decisionpointid which will change when it is restored. Any ideas?

Average of ratings: -
In reply to Russell England

Re: Backup 2 dependent activities?

by Russell England -
Picture of Plugin developers
Woohoo! figured it out:


https://docs.moodle.org/dev/Restore_2.0_for_developers#Code_that_runs_after_restore


Added this to /mod/decisionitem/backup/moodle2/restore_decisionitem_activity_task.class.php

    /**
     * Re-map the decisionpointid
     */
    public function after_restore() {
        global $DB;

        $decisionitem = $DB->get_record('decisionitem', array('id' => $this->get_activityid()));

        if (empty($decisionitem->decisionpointid)) {
            // Nothing to do.
            return;
        }

        // Look for the new decision point id.
        if ($newitem = restore_dbops::get_backup_ids_record($this->get_restoreid(), 'decisionpoint', $decisionitem->decisionpointid)) {
            $decisionitem->decisionpointid = $newitem->newitemid;
        }

        if (!$DB->record_exists('decisionpoint', array('id' => $decisionitem->decisionpointid, 'course' => $decisionitem->course))) {
            // Doesn't exist anymore.
            $decisionitem->decisionpointid = 0;
        }

        // Update it.
        $DB->update_record('decisionitem', $decisionitem);
    }