From 29a9331542281123ef05da83508ded68b63ef4a3 Mon Sep 17 00:00:00 2001 From: Thomas Marstrander <marstranderthomas@gmail.com> Date: Wed, 20 Feb 2019 16:08:32 +0100 Subject: [PATCH] Revert automatic upgrade changes --- classes/file_storage.php | 22 ---------------------- classes/framework.php | 29 ++--------------------------- db/upgrade.php | 2 +- lang/en/hvp.php | 5 ----- locallib.php | 20 +------------------- mod_form.php | 37 +++++++++++-------------------------- styles.css | 3 --- upgrade_content_page.php | 3 --- 8 files changed, 15 insertions(+), 106 deletions(-) diff --git a/classes/file_storage.php b/classes/file_storage.php index 324b135..4e7603b 100644 --- a/classes/file_storage.php +++ b/classes/file_storage.php @@ -840,26 +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) { - $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; - } - } } diff --git a/classes/framework.php b/classes/framework.php index edc5b6a..c7ed7b1 100644 --- a/classes/framework.php +++ b/classes/framework.php @@ -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'] - ) - ); - } } diff --git a/db/upgrade.php b/db/upgrade.php index c783364..a9d391e 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -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, diff --git a/lang/en/hvp.php b/lang/en/hvp.php index 68a7a84..e094873 100644 --- a/lang/en/hvp.php +++ b/lang/en/hvp.php @@ -159,9 +159,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'; @@ -200,8 +197,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'; diff --git a/locallib.php b/locallib.php index d0172f6..40ad8b7 100644 --- a/locallib.php +++ b/locallib.php @@ -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 ); diff --git a/mod_form.php b/mod_form.php index d39fdae..4df7784 100644 --- a/mod_form.php +++ b/mod_form.php @@ -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,20 +279,15 @@ 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'); + // Verify that parameters are valid. + if (empty($data['h5pparams'])) { + $errors['h5peditor'] = get_string('noparameters', 'hvp'); } else { - // Verify that parameters are valid. - if (empty($data['h5pparams'])) { - $errors['h5peditor'] = get_string('noparameters', 'hvp'); + $params = json_decode($data['h5pparams']); + if ($params === null) { + $errors['h5peditor'] = get_string('invalidparameters', 'hvp'); } else { - $params = json_decode($data['h5pparams']); - if ($params === null) { - $errors['h5peditor'] = get_string('invalidparameters', 'hvp'); - } else { - $data['h5pparams'] = $params; - } + $data['h5pparams'] = $params; } } } @@ -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... } } diff --git a/styles.css b/styles.css index 36544d9..7d3c0b7 100644 --- a/styles.css +++ b/styles.css @@ -81,6 +81,3 @@ .h5p-data-view th[role="button"].h5p-sort:hover:after { color: #999; } -.content-upgrade-log { - color: red; -} diff --git a/upgrade_content_page.php b/upgrade_content_page.php index f9c9ba7..7ac1fee 100644 --- a/upgrade_content_page.php +++ b/upgrade_content_page.php @@ -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>', -- GitLab