Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
CONTRIB-5842 - Fixed: Dataform preset without user data is not applie…
…d in a new activity.
  • Loading branch information
itamart committed Jul 26, 2015
1 parent 3b889d4 commit 974bf7c
Showing 1 changed file with 23 additions and 27 deletions.
50 changes: 23 additions & 27 deletions classes/preset_manager.php
Expand Up @@ -285,37 +285,33 @@ public function create_preset_from_backup($userdata) {
$bc->set_status(backup::STATUS_AWAITING);

$bc->execute_plan();

$results = $bc->get_results();
$bc->destroy();
unset($bc);

if ($file = $results['backup_destination']) {
$fs = get_file_storage();

$fs = get_file_storage();
if ($users and !$anon) {
$contextid = $df->context->id;
$files = $fs->get_area_files($contextid, 'backup', 'activity', 0, 'timemodified', false);
} else {
$usercontext = context_user::instance($USER->id);
$contextid = $usercontext->id;
$files = $fs->get_area_files($contextid, 'user', 'backup', 0, 'timemodified', false);
}
if (!empty($files)) {
$coursecontext = context_course::instance($df->course->id);
foreach ($files as $file) {
if ($file->get_contextid() != $contextid) {
continue;
}
$preset = new object;
$preset->contextid = $coursecontext->id;
$preset->component = 'mod_dataform';
$preset->filearea = self::PRESET_COURSEAREA;
$preset->filepath = '/';
$preset->filename = clean_filename(str_replace(' ', '_', $df->name).
'-dataform-preset-'.
gmdate("Ymd_Hi"). '-'.
str_replace(' ', '-', get_string("preset$userdata", 'dataform')). '.mbz');
$presetname = clean_filename(
str_replace(' ', '_', $df->name).
'-dataform-preset-'.
gmdate("Ymd_Hi"). '-'.
str_replace(' ', '-', get_string("preset$userdata", 'dataform')). '.mbz'
);

$fs->create_file_from_storedfile($preset, $file);
$file->delete();
return true;
}

$preset = new \stdClass;
$preset->contextid = $coursecontext->id;
$preset->component = 'mod_dataform';
$preset->filearea = self::PRESET_COURSEAREA;
$preset->filepath = '/';
$preset->filename = $presetname;

$fs->create_file_from_storedfile($preset, $file);
$file->delete();
return true;
}
return false;
}
Expand Down

0 comments on commit 974bf7c

Please sign in to comment.