Merge branch 'MDL-53660-master' of git://github.com/danpoltawski/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2016-04-20 01:19:58 +02:00
commit 3a97e39825

View File

@ -206,11 +206,17 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
}
protected function after_execute() {
global $DB;
// Add forum related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_forum', 'intro', null);
// Add post related files, matching by itemname = 'forum_post'
$this->add_related_files('mod_forum', 'post', 'forum_post');
$this->add_related_files('mod_forum', 'attachment', 'forum_post');
}
protected function after_restore() {
global $DB;
// If the forum is of type 'single' and no discussion has been ignited
// (non-userinfo backup/restore) create the discussion here, using forum
// information as base for the initial post.
@ -218,7 +224,7 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
$forumrec = $DB->get_record('forum', array('id' => $forumid));
if ($forumrec->type == 'single' && !$DB->record_exists('forum_discussions', array('forum' => $forumid))) {
// Create single discussion/lead post from forum data
$sd = new stdclass();
$sd = new stdClass();
$sd->course = $forumrec->course;
$sd->forum = $forumrec->id;
$sd->name = $forumrec->name;
@ -234,15 +240,11 @@ class restore_forum_activity_structure_step extends restore_activity_structure_s
$fs = get_file_storage();
$files = $fs->get_area_files($this->task->get_contextid(), 'mod_forum', 'intro');
foreach ($files as $file) {
$newfilerecord = new stdclass();
$newfilerecord = new stdClass();
$newfilerecord->filearea = 'post';
$newfilerecord->itemid = $DB->get_field('forum_discussions', 'firstpost', array('id' => $sdid));
$fs->create_file_from_storedfile($newfilerecord, $file);
}
}
// Add post related files, matching by itemname = 'forum_post'
$this->add_related_files('mod_forum', 'post', 'forum_post');
$this->add_related_files('mod_forum', 'attachment', 'forum_post');
}
}