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 { ...@@ -65,21 +65,20 @@ class file_storage implements \H5PFileStorage {
* *
* @param string $source * @param string $source
* Path on file system to content directory. * Path on file system to content directory.
* @param int $id * @param array $content
* What makes this content unique. * Content properties
*/ */
public function saveContent($source, $id) { public function saveContent($source, $content) {
// Remove any old content. // Remove any old content.
$this->deleteContent($id); $this->deleteContent($content);
// Contents are stored in a course context. // Contents are stored in a course context.
$cm = \get_coursemodule_from_instance('hvp', $id); $context = \context_module::instance($content['coursemodule']);
$context = \context_module::instance($cm->id);
$options = array( $options = array(
'contextid' => $context->id, 'contextid' => $context->id,
'component' => 'mod_hvp', 'component' => 'mod_hvp',
'filearea' => 'content', 'filearea' => 'content',
'itemid' => $id, 'itemid' => $content['id'],
'filepath' => '/', 'filepath' => '/',
); );
...@@ -90,13 +89,12 @@ class file_storage implements \H5PFileStorage { ...@@ -90,13 +89,12 @@ class file_storage implements \H5PFileStorage {
/** /**
* Remove content folder. * Remove content folder.
* *
* @param int $id * @param array $content
* Content identifier * Content properties
*/ */
public function deleteContent($id) { public function deleteContent($content) {
$cm = \get_coursemodule_from_instance('hvp', $id); $context = \context_module::instance($content['coursemodule']);
$context = \context_module::instance($cm->id); self::deleteFileTree($context->id, 'content', '/', $content['id']);
self::deleteFileTree($context->id, 'content', '/', $id);
} }
/** /**
......
...@@ -201,9 +201,12 @@ function hvp_delete_instance($id) { ...@@ -201,9 +201,12 @@ function hvp_delete_instance($id) {
return false; return false;
} }
// Load CM
$cm = \get_coursemodule_from_instance('hvp', $id);
// Delete content // Delete content
$h5pstorage = \mod_hvp\framework::instance('storage'); $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 // Get library details
$library = $DB->get_record_sql( $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