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

Merge branch 'release' into moodle-mobile

parents 4c897816 29a93315
No related branches found
No related tags found
No related merge requests found
......@@ -12,8 +12,8 @@ php:
env:
global:
- MOODLE_BRANCH=MOODLE_30_STABLE
- IGNORE_PATHS=lang
- MOODLE_BRANCH=MOODLE_36_STABLE
- IGNORE_PATHS=lang,editor,lirbary,reporting
matrix:
- DB=pgsql
- DB=mysqli
......
......@@ -840,28 +840,4 @@ class file_storage implements \H5PFileStorage {
// TODO: Implement.
return false;
}
/**
* Check if upgrades script exist for library.
*
* @param string $machineName
* @param int $majorVersion
* @param int $minorVersion
* @return string Relative path
*/
// @codingStandardsIgnoreLine
public function getUpgradeScript($machinename, $majorversion, $minorversion) {
global $CFG;
$context = \context_system::instance();
$fs = get_file_storage();
$area = 'libraries';
$path = "/{$machinename}-{$majorversion}.{$minorversion}/";
$file = 'upgrades.js';
if ($fs->get_file($context->id, 'mod_hvp', $area, 0, $path, $file)) {
return "/{$area}{$path}{$file}";
} else {
return null;
}
}
}
......@@ -1351,12 +1351,11 @@ class framework implements \H5PFrameworkInterface {
* Implements getNumContent().
*/
// @codingStandardsIgnoreLine
public function getNumContent($libraryid, $skip = NULL) {
public function getNumContent($libraryid) {
global $DB;
$skipquery = empty($skip) ? '' : " AND id NOT IN ($skip)";
return (int) $DB->get_field_sql(
"SELECT COUNT(id) FROM {hvp} WHERE main_library_id = ?{$skipquery}",
"SELECT COUNT(id) FROM {hvp} WHERE main_library_id = ?",
array($libraryid));
}
......@@ -1550,7 +1549,6 @@ class framework implements \H5PFrameworkInterface {
l1.machine_name,
l1.major_version,
l1.minor_version,
l1.patch_version,
l1.add_to,
l1.preloaded_js,
l1.preloaded_css
......@@ -1579,27 +1577,4 @@ class framework implements \H5PFrameworkInterface {
global $CFG;
return (isset($CFG->mod_hvp_library_config) ? $CFG->mod_hvp_library_config : null);
}
/**
* Implements libraryHasUpgrade
*/
// @codingStandardsIgnoreLine
public function libraryHasUpgrade($library) {
global $DB;
return !!$DB->get_field_sql(
"SELECT id
FROM {hvp_libraries}
WHERE machine_name = ?
AND (major_version > ?
OR (major_version = ? AND minor_version > ?))
LIMIT 1",
array(
$library['machineName'],
$library['majorVersion'],
$library['majorVersion'],
$library['minorVersion']
)
);
}
}
......@@ -418,7 +418,7 @@ function hvp_upgrade_2018090300() {
);
}
// Add new libraries fields.
// Add new libraries fields
$table = new xmldb_table('hvp_libraries');
if (!$dbman->field_exists($table, 'add_to')) {
$dbman->add_field($table,
......
......@@ -160,9 +160,6 @@ $string['upgradenothingtodo'] = "There's no content instances to upgrade.";
$string['upgradebuttonlabel'] = 'Upgrade';
$string['upgradeinvalidtoken'] = 'Error: Invalid security token!';
$string['upgradelibrarymissing'] = 'Error: Your library is missing!';
$string['upgradeerrormissinglibrary'] = 'Missing required library %lib.';
$string['errorTooHighVersion'] = 'Parameters contain %used while only %supported or earlier are supported.';
$string['errorNotSupported'] = 'Parameters contain %used which is not supported.';
// Results / report page.
$string['user'] = 'User';
......@@ -201,8 +198,6 @@ $string['nosuchlibrary'] = 'No such library';
$string['noparameters'] = 'No parameters';
$string['invalidparameters'] = 'Invalid Parameters';
$string['missingcontentuserdata'] = 'Error: Could not find content user data';
$string['olduploadoldcontent'] = "You're trying to upload content of an older version of H5P. Please upgrade the content on the server it originated from and try to upload again or turn on the H5P Hub to have this server upgrade it for your automaticall.";
$string['anunexpectedsave'] = 'Something unexpected happened. We were unable to save this content.';
$string['maximumgrade'] = 'Maximum grade';
$string['maximumgradeerror'] = 'Please enter a valid positive integer as the max points available for this activity';
......
......@@ -75,8 +75,6 @@ function hvp_get_core_settings($context) {
'reportingIsEnabled' => true,
'crossorigin' => isset($CFG->mod_hvp_crossorigin) ? $CFG->mod_hvp_crossorigin : null,
'libraryConfig' => $core->h5pF->getLibraryConfig(),
'pluginCacheBuster' => hvp_get_cache_buster(),
'libraryUrl' => $basepath . 'mod/hvp/library/js'
);
return $settings;
......@@ -337,32 +335,16 @@ function hvp_content_upgrade_progress($libraryid) {
}
}
// Determine if any content has been skipped during the process.
$skipped = filter_input(INPUT_POST, 'skipped');
if ($skipped !== null) {
$out->skipped = json_decode($skipped);
// Clean up input, only numbers.
foreach ($out->skipped as $i => $id) {
$out->skipped[$i] = intval($id);
}
$skipped = implode(',', $out->skipped);
} else {
$out->skipped = array();
}
// Get number of contents for this library.
$out->left = $interface->getNumContent($libraryid, $skipped);
$out->left = $interface->getNumContent($libraryid);
if ($out->left) {
$skipquery = empty($skipped) ? '' : " AND id NOT IN ($skipped)";
// Find the 40 first contents using this library version and add to params.
$results = $DB->get_records_sql(
"SELECT id, json_content as params, name as title, authors, source, year_from, year_to,
license, license_version, changes, license_extras, author_comments
FROM {hvp}
WHERE main_library_id = ?
{$skipquery}
ORDER BY name ASC", array($libraryid), 0 , 40
);
......
......@@ -250,15 +250,6 @@ class mod_hvp_mod_form extends moodleform_mod {
$messages = array_merge(\mod_hvp\framework::messages('info'), $errors);
$errors['h5pfile'] = implode('<br/>', $messages);
} else {
foreach ($h5pvalidator->h5pC->mainJsonData['preloadedDependencies'] as $dep) {
if ($dep['machineName'] === $h5pvalidator->h5pC->mainJsonData['mainLibrary']) {
if ($h5pvalidator->h5pF->libraryHasUpgrade($dep)) {
// We do not allow storing old content due to security concerns.
$errors['h5pfile'] = get_string('olduploadoldcontent', 'hvp');
}
}
}
}
}
}
......@@ -288,10 +279,6 @@ class mod_hvp_mod_form extends moodleform_mod {
} else {
$data['h5plibrary'] = $library;
if ($core->h5pF->libraryHasUpgrade($library)) {
// We do not allow storing old content due to security concerns.
$errors['h5peditor'] = get_string('anunexpectedsave', 'hvp');
} else {
// Verify that parameters are valid.
if (empty($data['h5pparams'])) {
$errors['h5peditor'] = get_string('noparameters', 'hvp');
......@@ -306,7 +293,6 @@ class mod_hvp_mod_form extends moodleform_mod {
}
}
}
}
/**
* Validates editor form
......@@ -353,7 +339,7 @@ class mod_hvp_mod_form extends moodleform_mod {
$core = \mod_hvp\framework::instance();
$data->disable = $core->getStorableDisplayOptions($options, 0);
// Remove metadata wrapper from form data.
// Remove metadata wrapper from form data
$params = json_decode($data->h5pparams);
if ($params !== null) {
$data->params = json_encode($params->params);
......@@ -362,18 +348,17 @@ class mod_hvp_mod_form extends moodleform_mod {
}
}
// Cleanup.
// Cleanup
unset($data->h5pparams);
if ($data->h5paction === 'upload') {
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.
// 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->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...
}
}
......
......@@ -81,6 +81,3 @@
.h5p-data-view th[role="button"].h5p-sort:hover:after {
color: #999;
}
.content-upgrade-log {
color: red;
}
......@@ -69,9 +69,6 @@ if (count($versions) < 2) {
'errorScript' => get_string('upgradeerrorscript', 'hvp'),
'errorContent' => get_string('upgradeerrorcontent', 'hvp'),
'errorParamsBroken' => get_string('upgradeerrorparamsbroken', 'hvp'),
'errorLibrary' => get_string('upgradeerrormissinglibrary', 'hvp'),
'errorTooHighVersion' => get_string('upgradeerrortoohighversion', 'hvp'),
'errorNotSupported' => get_string('upgradeerrornotsupported', 'hvp'),
'done' => get_string('upgradedone', 'hvp', $numcontents) .
' <a href="' . (new moodle_url('/mod/hvp/library_list.php'))->out(false) . '">' .
get_string('upgradereturn', 'hvp') . '</a>',
......
......@@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2019022700;
$plugin->version = 2019030600;
$plugin->requires = 2013051403;
$plugin->cron = 0;
$plugin->component = 'mod_hvp';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment