Skip to content
Snippets Groups Projects
Commit aec115e8 authored by Frode Petterson's avatar Frode Petterson
Browse files

Get CM ID the proper way when adding new content

No relation between Instance and CM until after content is saved.
h5p/h5p-moodle-plugin#112
parent 146aa20e
No related branches found
No related tags found
No related merge requests found
......@@ -65,21 +65,20 @@ class file_storage implements \H5PFileStorage {
*
* @param string $source
* Path on file system to content directory.
* @param int $id
* What makes this content unique.
* @param array $content
* Content properties
*/
public function saveContent($source, $id) {
public function saveContent($source, $content) {
// Remove any old content.
$this->deleteContent($id);
$this->deleteContent($content);
// Contents are stored in a course context.
$cm = \get_coursemodule_from_instance('hvp', $id);
$context = \context_module::instance($cm->id);
$context = \context_module::instance($content['coursemodule']);
$options = array(
'contextid' => $context->id,
'component' => 'mod_hvp',
'filearea' => 'content',
'itemid' => $id,
'itemid' => $content['id'],
'filepath' => '/',
);
......@@ -90,13 +89,12 @@ class file_storage implements \H5PFileStorage {
/**
* Remove content folder.
*
* @param int $id
* Content identifier
* @param array $content
* Content properties
*/
public function deleteContent($id) {
$cm = \get_coursemodule_from_instance('hvp', $id);
$context = \context_module::instance($cm->id);
self::deleteFileTree($context->id, 'content', '/', $id);
public function deleteContent($content) {
$context = \context_module::instance($content['coursemodule']);
self::deleteFileTree($context->id, 'content', '/', $content['id']);
}
/**
......
......@@ -201,9 +201,12 @@ function hvp_delete_instance($id) {
return false;
}
// Load CM
$cm = \get_coursemodule_from_instance('hvp', $id);
// Delete content
$h5pstorage = \mod_hvp\framework::instance('storage');
$h5pstorage->deletePackage(array('id' => $hvp->id, 'slug' => $hvp->slug));
$h5pstorage->deletePackage(array('id' => $hvp->id, 'slug' => $hvp->slug, 'coursemodule' => $cm->id));
// Get library details
$library = $DB->get_record_sql(
......
Subproject commit c88c049438257b30e61801a940167d8805732ff0
Subproject commit fd34af6964857e8a2f9f49423d6bf1a109576ac6
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment