diff --git a/backup/moodle2/backup_hvp_activity_task.class.php b/backup/moodle2/backup_hvp_activity_task.class.php
index ccf035c70df19761ed2650bc61f65d2703d94599..cb961f5b52f5b527066c746f7d36d03c5f9892a0 100644
--- a/backup/moodle2/backup_hvp_activity_task.class.php
+++ b/backup/moodle2/backup_hvp_activity_task.class.php
@@ -25,11 +25,11 @@
defined('MOODLE_INTERNAL') || die();
+require_once($CFG->dirroot . '/backup/moodle2/backup_stepslib.php');
require_once($CFG->dirroot . '/mod/hvp/backup/moodle2/backup_hvp_stepslib.php');
-require_once($CFG->dirroot . '/mod/hvp/backup/moodle2/backup_hvp_settingslib.php');
/**
- * Provides the steps to perform one complete backup of the Choice instance
+ * Provides the steps to perform one complete backup of a H5P instance
*/
class backup_hvp_activity_task extends backup_activity_task {
@@ -40,12 +40,12 @@ class backup_hvp_activity_task extends backup_activity_task {
}
/**
- * Defines a backup step to store the instance data in the choice.xml file
+ * Defines a backup step to store the instance data in the hvp.xml file
*/
protected function define_my_steps() {
- // $this->add_step(new backup_hvp_activity_structure_step('hvp_structure', 'hvp.xml'));
+ $this->add_step(new backup_hvp_activity_structure_step('hvp_structure', 'hvp.xml'));
}
-
+
/**
* Encodes URLs to the index.php and view.php scripts
*
diff --git a/backup/moodle2/backup_hvp_stepslib.php b/backup/moodle2/backup_hvp_stepslib.php
index a02ff4c5ee07102f3189fd038c30d6e5a68724be..30d5ecdbb2b5d18f569a45a65b97a2c38912ca74 100644
--- a/backup/moodle2/backup_hvp_stepslib.php
+++ b/backup/moodle2/backup_hvp_stepslib.php
@@ -15,68 +15,107 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * @package moodlecore
- * @subpackage backup-moodle2
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @package mod_hvp
+ * @copyright 2016 Mediamaisteri Oy {@link http://www.mediamaisteri.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+require_once($CFG->dirroot . '/backup/moodle2/backup_activity_task.class.php');
+
/**
- * Define all the backup steps that will be used by the backup_choice_activity_task
+ * Define all the backup steps that will be used by the backup_hvp_activity_task
*/
/**
- * Define the complete choice structure for backup, with file and id annotations
+ * Define the complete hvp structure for backup, with file and id annotations
*/
class backup_hvp_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
- /*
+
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
- $choice = new backup_nested_element('choice', array('id'), array(
- 'name', 'intro', 'introformat', 'publish',
- 'showresults', 'display', 'allowupdate', 'showunanswered',
- 'limitanswers', 'timeopen', 'timeclose', 'timemodified',
- 'completionsubmit'));
-
- $options = new backup_nested_element('options');
-
- $option = new backup_nested_element('option', array('id'), array(
- 'text', 'maxanswers', 'timemodified'));
-
- $answers = new backup_nested_element('answers');
-
- $answer = new backup_nested_element('answer', array('id'), array(
- 'userid', 'optionid', 'timemodified'));
+ $hvp = new backup_nested_element('hvp', array('id'), array(
+ 'course',
+ 'name',
+ 'json_content',
+ 'embed_type',
+ 'disable',
+ 'main_library_id',
+ 'content_type',
+ 'author',
+ 'license',
+ 'meta_keywords',
+ 'meta_description',
+ 'filtered',
+ 'slug',
+ 'timecreated',
+ 'timemodified',
+ ));
+
+ $hvp_libraries = new backup_nested_element('libraries');
+ $hvp_library = new backup_nested_element('library', null, array(
+ 'machine_name',
+ 'major_version',
+ 'minor_version',
+ 'patch_version',
+ 'dependency_type',
+ 'drop_css',
+ 'weight',
+ ));
+
+ $content_user_data_entries = new backup_nested_element('content_user_data');
+ $content_user_data = new backup_nested_element('entry', array('id'), array(
+ 'user_id',
+ 'hvp_id',
+ 'sub_content_id',
+ 'data_id',
+ 'data',
+ 'preloaded',
+ 'delete_on_content_change',
+ ));
// Build the tree
- $choice->add_child($options);
- $options->add_child($option);
+ $hvp->add_child($content_user_data_entries);
+ $content_user_data_entries->add_child($content_user_data);
- $choice->add_child($answers);
- $answers->add_child($answer);
+ $hvp->add_child($hvp_libraries);
+ $hvp_libraries->add_child($hvp_library);
// Define sources
- $choice->set_source_table('choice', array('id' => backup::VAR_ACTIVITYID));
-
- $option->set_source_table('choice_options', array('choiceid' => backup::VAR_PARENTID), 'id ASC');
+ $hvp->set_source_table('hvp', array('id' => backup::VAR_ACTIVITYID));
+
+ $lib_sql = "SELECT
+ machine_name,
+ major_version,
+ minor_version,
+ patch_version,
+ dependency_type,
+ drop_css,
+ weight
+ FROM {hvp_libraries} hl
+ JOIN {hvp_contents_libraries} hcl
+ ON hl.id = hcl.library_id
+ JOIN {hvp} h
+ ON h.id = hcl.hvp_id
+ WHERE h.id = ?";
+
+ $hvp_library->set_source_sql($lib_sql, array(backup::VAR_ACTIVITYID));
// All the rest of elements only happen if we are including user info
if ($userinfo) {
- $answer->set_source_table('choice_answers', array('choiceid' => '../../id'));
+ $content_user_data->set_source_table('hvp_content_user_data', array('hvp_id' => backup::VAR_PARENTID), 'id ASC');
}
// Define id annotations
- $answer->annotate_ids('user', 'userid');
+ $content_user_data->annotate_ids('user', 'user_id');
// Define file annotations
- $choice->annotate_files('mod_choice', 'intro', null); // This file area hasn't itemid
+ $hvp->annotate_files('mod_hvp', 'content', null);
- // Return the root element (choice), wrapped into standard activity structure
- return $this->prepare_activity_structure($choice);
- */
+ // Return the root element (hvp), wrapped into standard activity structure
+ return $this->prepare_activity_structure($hvp);
}
}
diff --git a/backup/moodle2/restore_hvp_activity_task.class.php b/backup/moodle2/restore_hvp_activity_task.class.php
index 16b7f27343f619004b84fe4f69f10cb4f3c49af5..f99315084a919209fe11a40d2bd82423aa5b0bf6 100644
--- a/backup/moodle2/restore_hvp_activity_task.class.php
+++ b/backup/moodle2/restore_hvp_activity_task.class.php
@@ -15,9 +15,8 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * @package moodlecore
- * @subpackage backup-moodle2
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @package mod_hvp
+ * @copyright 2016 Mediamaisteri Oy {@link http://www.mediamaisteri.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -26,7 +25,7 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/hvp/backup/moodle2/restore_hvp_stepslib.php'); // Because it exists (must).
/**
- * choice restore task that provides all the settings and steps to perform one
+ * hvp restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_hvp_activity_task extends restore_activity_task {
@@ -42,8 +41,7 @@ class restore_hvp_activity_task extends restore_activity_task {
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
- // Choice only has one structure step.
- // $this->add_step(new restore_choice_activity_structure_step('choice_structure', 'choice.xml'));
+ $this->add_step(new restore_hvp_activity_structure_step('hvp_structure', 'hvp.xml'));
}
/**
@@ -53,7 +51,7 @@ class restore_hvp_activity_task extends restore_activity_task {
static public function define_decode_contents() {
$contents = array();
- // $contents[] = new restore_decode_content('choice', array('intro'), 'choice');
+ //$contents[] = new restore_decode_content('hvp', array('intro'), 'hvp');
return $contents;
}
@@ -65,29 +63,30 @@ class restore_hvp_activity_task extends restore_activity_task {
static public function define_decode_rules() {
$rules = array();
- // $rules[] = new restore_decode_rule('CHOICEVIEWBYID', '/mod/choice/view.php?id=$1', 'course_module');
- // $rules[] = new restore_decode_rule('CHOICEINDEX', '/mod/choice/index.php?id=$1', 'course');
+ //$rules[] = new restore_decode_rule('CHOICEVIEWBYID', '/mod/hvp/view.php?id=$1', 'course_module');
+ //$rules[] = new restore_decode_rule('CHOICEINDEX', '/mod/hvp/index.php?id=$1', 'course');
return $rules;
-
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
- * choice logs. It must return one array
+ * hvp logs. It must return one array
* of {@link restore_log_rule} objects
*/
static public function define_restore_log_rules() {
$rules = array();
+
/*
- $rules[] = new restore_log_rule('choice', 'add', 'view.php?id={course_module}', '{choice}');
- $rules[] = new restore_log_rule('choice', 'update', 'view.php?id={course_module}', '{choice}');
- $rules[] = new restore_log_rule('choice', 'view', 'view.php?id={course_module}', '{choice}');
- $rules[] = new restore_log_rule('choice', 'choose', 'view.php?id={course_module}', '{choice}');
- $rules[] = new restore_log_rule('choice', 'choose again', 'view.php?id={course_module}', '{choice}');
- $rules[] = new restore_log_rule('choice', 'report', 'report.php?id={course_module}', '{choice}');
+ $rules[] = new restore_log_rule('hvp', 'add', 'view.php?id={course_module}', '{hvp}');
+ $rules[] = new restore_log_rule('hvp', 'update', 'view.php?id={course_module}', '{hvp}');
+ $rules[] = new restore_log_rule('hvp', 'view', 'view.php?id={course_module}', '{hvp}');
+ $rules[] = new restore_log_rule('hvp', 'choose', 'view.php?id={course_module}', '{hvp}');
+ $rules[] = new restore_log_rule('hvp', 'choose again', 'view.php?id={course_module}', '{hvp}');
+ $rules[] = new restore_log_rule('hvp', 'report', 'report.php?id={course_module}', '{hvp}');
*/
+
return $rules;
}
@@ -105,10 +104,11 @@ class restore_hvp_activity_task extends restore_activity_task {
$rules = array();
/*
// Fix old wrong uses (missing extension)
- $rules[] = new restore_log_rule('choice', 'view all', 'index?id={course}', null,
+ $rules[] = new restore_log_rule('hvp', 'view all', 'index?id={course}', null,
null, null, 'index.php?id={course}');
- $rules[] = new restore_log_rule('choice', 'view all', 'index.php?id={course}', null);
+ $rules[] = new restore_log_rule('hvp', 'view all', 'index.php?id={course}', null);
*/
+
return $rules;
}
}
diff --git a/backup/moodle2/restore_hvp_stepslib.php b/backup/moodle2/restore_hvp_stepslib.php
index 27a324740c640d0bebf2df6c675d2b7cd22e8da9..5bd2f57aaffc9b33f2fa4c859519020c51ebdf6c 100644
--- a/backup/moodle2/restore_hvp_stepslib.php
+++ b/backup/moodle2/restore_hvp_stepslib.php
@@ -15,84 +15,107 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
- * @package moodlecore
- * @subpackage backup-moodle2
- * @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
+ * @package mod_hvp
+ * @copyright 2016 Mediamaisteri Oy {@link http://www.mediamaisteri.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
- * Define all the restore steps that will be used by the restore_choice_activity_task
+ * Define all the restore steps that will be used by the restore_hvp_activity_task
*/
/**
- * Structure step to restore one choice activity
+ * Structure step to restore one H5P activity
*/
class restore_hvp_activity_structure_step extends restore_activity_structure_step {
- /*
+
protected function define_structure() {
$paths = array();
$userinfo = $this->get_setting_value('userinfo');
- $paths[] = new restore_path_element('choice', '/activity/choice');
- $paths[] = new restore_path_element('choice_option', '/activity/choice/options/option');
+ $paths[] = new restore_path_element('hvp', '/activity/hvp');
+ $paths[] = new restore_path_element('library', '/activity/hvp/libraries/library');
+
if ($userinfo) {
- $paths[] = new restore_path_element('choice_answer', '/activity/choice/answers/answer');
+ $paths[] = new restore_path_element('content_user_data', '/activity/hvp/content_user_data/entry');
}
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
- protected function process_choice($data) {
+ protected function process_hvp($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
- $data->timeopen = $this->apply_date_offset($data->timeopen);
- $data->timeclose = $this->apply_date_offset($data->timeclose);
+ $data->timecreated = $this->apply_date_offset($data->timecreated);
$data->timemodified = $this->apply_date_offset($data->timemodified);
- // insert the choice record
- $newitemid = $DB->insert_record('choice', $data);
+ // insert the hvp record
+ $newitemid = $DB->insert_record('hvp', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
- protected function process_choice_option($data) {
+ /**
+ * Connects the restored H5P content to content libraries
+ *
+ * This assumes that the libraries have already been installed
+ * into the system.
+ *
+ * @param array $data Library dependency defitinions of the content
+ */
+ protected function process_library($data) {
global $DB;
$data = (object)$data;
- $oldid = $data->id;
-
- $data->choiceid = $this->get_new_parentid('choice');
- $data->timemodified = $this->apply_date_offset($data->timemodified);
+ //$oldid = $data->id;
+
+ // TODO Cache a list of existing libraries somewhere, so we won't
+ // have to check them multiple times in case restoring more than
+ // one H5P activity.
+ $library = $DB->get_record('hvp_libraries', array(
+ 'machine_name' => $data->machine_name,
+ 'major_version' => $data->major_version,
+ 'minor_version' => $data->minor_version,
+ 'patch_version' => $data->patch_version,
+ ));
+
+ if (empty($library)) {
+ // TODO What to do now? It isn't possible to continue restoring
+ // the activity without the needed libraries.
+
+ print_error("Your system is missing the library {$data->machine_name} version {$data->major_version}.{$data->minor_version}.{$data->patch_version}");
+ }
- $newitemid = $DB->insert_record('choice_options', $data);
- $this->set_mapping('choice_option', $oldid, $newitemid);
+ $content_library = (object) array(
+ 'id' => null,
+ 'hvp_id' => $this->get_new_parentid('hvp'), // From hvp table
+ 'library_id' => $library->id, // From hvp_libraries table
+ 'dependency_type' => $data->dependency_type,
+ 'drop_css' => $data->drop_css,
+ 'weight' => $data->weight,
+ );
+
+ // Note that we're not in fact adding a new library but a connection
+ // between the restored H5P activity and an existing library.
+ $newitemid = $DB->insert_record('hvp_contents_libraries', $content_library);
+
+ // TODO
+ // $this->set_mapping('hvp_todo', $oldid, $newitemid);
}
- protected function process_choice_answer($data) {
- global $DB;
-
- $data = (object)$data;
-
- $data->choiceid = $this->get_new_parentid('choice');
- $data->optionid = $this->get_mappingid('choice_option', $data->optionid);
- $data->userid = $this->get_mappingid('user', $data->userid);
- $data->timemodified = $this->apply_date_offset($data->timemodified);
+ protected function process_content_user_data($data) {
- $newitemid = $DB->insert_record('choice_answers', $data);
- // No need to save this mapping as far as nothing depend on it
- // (child paths, file areas nor links decoder)
}
protected function after_execute() {
- // Add choice related files, no need to match by itemname (just internally handled context)
- $this->add_related_files('mod_choice', 'intro', null);
+ // TODO
+ // Add hvp related files, no need to match by itemname (just internally handled context)
+ $this->add_related_files('mod_hvp', 'content', 'id');
}
- */
}