Skip to content
Snippets Groups Projects
Commit 1645ec88 authored by thomasmars's avatar thomasmars
Browse files

Fix content slug available check and legacy upload title check

- isContentSlugAvailable() could have identical slugs, which would cause the get_field_sql to return an error, since it should only return a single field.
- title is a property of the metadata object, not an index
parent 76a776c9
No related branches found
No related tags found
No related merge requests found
......@@ -1366,7 +1366,7 @@ class framework implements \H5PFrameworkInterface {
public function isContentSlugAvailable($slug) {
global $DB;
return !$DB->get_field_sql("SELECT slug FROM {hvp} WHERE slug = ?", array($slug));
return !$DB->get_records_sql("SELECT id, slug FROM {hvp} WHERE slug = ?", array($slug));
}
/**
......
......@@ -352,13 +352,13 @@ class mod_hvp_mod_form extends moodleform_mod {
unset($data->h5pparams);
if ($data->h5paction === 'upload') {
if (empty($data->metadata) || empty($data->metadata['title'])) {
if (empty($data->metadata) || empty($data->metadata->title)) {
// Fix for legacy content upload to work.
// Fetch title from h5p.json or use a default string if not available
$h5pvalidator = \mod_hvp\framework::instance('validator');
$data->metadata['title'] = empty($h5pvalidator->h5pC->mainJsonData['title']) ? 'Uploaded Content' : $h5pvalidator->h5pC->mainJsonData['title'];
$data->metadata->title = empty($h5pvalidator->h5pC->mainJsonData['title']) ? 'Uploaded Content' : $h5pvalidator->h5pC->mainJsonData['title'];
}
$data->name = $data->metadata['title']; // Sort of a hack, but there is no JavaScript that sets the value when there is no editor...
$data->name = $data->metadata->title; // Sort of a hack, but there is no JavaScript that sets the value when there is no editor...
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment