Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create manually CB file when it is null #25

Merged
merged 1 commit into from
Jan 8, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions classes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ private static function prepare_draft_file_from_hvp(stdClass $hvp, int $copy2cb)
$exportfilename = $hvp->slug . '-' . $hvp->id . '.h5p';
$fs = get_file_storage();
$exportfile = $fs->get_file($coursecontext->id, 'mod_hvp', 'exports', 0, '/', $exportfilename);
mtrace($exportfilename);
if (empty($exportfile)) {
// We need to generate the H5P file.
// There are two scenarios where hvp don't create the package file:
Expand All @@ -421,7 +420,7 @@ private static function prepare_draft_file_from_hvp(stdClass $hvp, int $copy2cb)
$course = $DB->get_record('course', ['id' => $hvp->course], '*', MUST_EXIST);
$COURSE = $course;
// Trigger a fake visualization will create the export file.
$view = new \mod_hvp\view_assets($hvp->cm, $course);
$view = new \mod_hvp\view_assets($hvp->cm, $course);
// Slug value can change on export.
$hvp->slug = $DB->get_field('hvp', 'slug', ['id' => $hvp->id]);
$exportfilename = $hvp->slug . '-' . $hvp->id . '.h5p';
Expand Down Expand Up @@ -455,6 +454,20 @@ private static function prepare_draft_file_from_hvp(stdClass $hvp, int $copy2cb)
$content->set_name($hvp->name);
}
$cbfile = $content->get_file();
if (is_null($cbfile)) {
// Moodle 3.9.1 doesn't create the file in $cb->create_content_from_file so it has to be created manually.
$filerecord = [
'component' => 'contentbank',
'filearea' => 'public',
'itemid' => $content->get_id(),
'author' => fullname($USER),
'filepath' => '/',
'filename' => $exportfile->get_filename(),
'contextid' => $coursecontext->id,
];
$file = $fs->create_file_from_storedfile($filerecord, $exportfile);
$cbfile = $content->get_file();
}

$activityfilerecord = [
'component' => 'user',
Expand Down