From 72d38fd977e058ec07ae9ad7847378a80227187b Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 25 Aug 2014 11:35:14 +0200 Subject: [PATCH 1/3] Fixed bug where it appears like you can upgrade libraries without content. --- js/h5p-library-list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index aeba889..ba6d0ab 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -50,7 +50,7 @@ var H5PLibraryList= H5PLibraryList || {}; if (library.upgradeUrl === null) { $('.h5p-admin-upgrade-library', $libraryRow).remove(); } - else if (library.upgradeUrl === false || library.numContent === 0) { + else if (library.upgradeUrl === false || library.numContent === '0') { $('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true); } else { From 96b75f7d73347009a41470175af0ca7636f129fb Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Mon, 25 Aug 2014 15:18:29 +0200 Subject: [PATCH 2/3] Revert "Fixed bug where it appears like you can upgrade libraries without content." Source was elsewhere. This reverts commit 72d38fd977e058ec07ae9ad7847378a80227187b. --- js/h5p-library-list.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/js/h5p-library-list.js b/js/h5p-library-list.js index ba6d0ab..aeba889 100644 --- a/js/h5p-library-list.js +++ b/js/h5p-library-list.js @@ -50,7 +50,7 @@ var H5PLibraryList= H5PLibraryList || {}; if (library.upgradeUrl === null) { $('.h5p-admin-upgrade-library', $libraryRow).remove(); } - else if (library.upgradeUrl === false || library.numContent === '0') { + else if (library.upgradeUrl === false || library.numContent === 0) { $('.h5p-admin-upgrade-library', $libraryRow).attr('disabled', true); } else { From 4955e9da59db0bab7c1fad18d73bcb21e8675de9 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 26 Aug 2014 11:26:41 +0200 Subject: [PATCH 3/3] Did some minor refactoring of "minimum version support" to ease implementation of this in other systems. --- h5p.classes.php | 105 +++++++++++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 41 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 14529fc..22cf185 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -585,7 +585,7 @@ class H5PValidator { $this->h5pF->setErrorMessage($this->h5pF->t('Missing required library @library', array('@library' => H5PCore::libraryToString($library)))); } if (!$this->h5pF->mayUpdateLibraries()) { - $this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this.")); + $this->h5pF->setInfoMessage($this->h5pF->t("Note that the libraries may exist in the file you uploaded, but you're not allowed to upload new libraries. Contact the site administrator about this.")); } } $valid = empty($missingLibraries) && $valid; @@ -1864,42 +1864,36 @@ class H5PCore { return; } - // Read and parse library-support.json - $jsonString = file_get_contents(realpath(dirname(__FILE__)).'/library-support.json'); + $minVersions = getMinimumVersionsSupported(realpath(dirname(__FILE__)) . '/library-support.json'); + if ($minVersions === NULL) { + return; + } - if($jsonString !== FALSE) { - // Get all libraries installed, check if any of them is not supported: - $libraries = $this->h5pF->loadLibraries(); - $unsupportedLibraries = array(); - $minimumLibraryVersions = array(); - - $librariesSupported = json_decode($jsonString, true); - foreach ($librariesSupported as $library) { - $minimumLibraryVersions[$library['machineName']]['versions'] = $library['minimumVersions']; - $minimumLibraryVersions[$library['machineName']]['downloadUrl'] = $library['downloadUrl']; + // Get all libraries installed, check if any of them is not supported: + $libraries = $this->h5pF->loadLibraries(); + $unsupportedLibraries = array(); + + // Iterate over all installed libraries + foreach ($libraries as $library_name => $versions) { + if (!isset($minVersions[$library_name])) { + continue; } + $min = $minVersions[$library_name]; - // Iterate over all installed libraries - foreach ($libraries as $machine_name => $libraryList) { - // Check if there are any minimum version requirements for this library - if (isset($minimumLibraryVersions[$machine_name])) { - $minimumVersions = $minimumLibraryVersions[$machine_name]['versions']; - // For each version of this library, check if it is supported - foreach ($libraryList as $library) { - if (!self::isLibraryVersionSupported($library, $minimumVersions)) { - // Current version of this library is not supported - $unsupportedLibraries[] = array ( - 'name' => $machine_name, - 'downloadUrl' => $minimumLibraryVersions[$machine_name]['downloadUrl'], - 'currentVersion' => array ( - 'major' => $library->major_version, - 'minor' => $library->minor_version, - 'patch' => $library->patch_version, - ), - 'minimumVersions' => $minimumVersions, - ); - } - } + // For each version of this library, check if it is supported + foreach ($versions as $library) { + if (!$this->isLibraryVersionSupported($library, $min->versions)) { + // Current version of this library is not supported + $unsupportedLibraries[] = array ( + 'name' => $library_name, + 'downloadUrl' => $min->downloadUrl, + 'currentVersion' => array ( + 'major' => $library->major_version, + 'minor' => $library->minor_version, + 'patch' => $library->patch_version, + ), + 'minimumVersions' => $min->versions, + ); } } @@ -1907,6 +1901,35 @@ class H5PCore { } } + /** + * Returns a list of the minimum version of libraries that are supported. + * This is needed because some old libraries are no longer supported by core. + * + * TODO: Make it possible for the systems to cache this list between requests. + * + * @param string $path to json file + * @return array indexed using library names + */ + public function getMinimumVersionsSupported($path) { + $minSupported = array(); + + // Get list of minimum version for libraries. Some old libraries are no longer supported. + $libraries = file_get_contents($path); + if ($libraries !== FALSE) { + $libraries = json_decode($libraries); + if ($libraries !== NULL) { + foreach ($libraries as $library) { + $minSupported[$library->machineName] = (object) array( + 'versions' => $library->minimumVersions, + 'downloadUrl' => $library->downloadUrl + ); + } + } + } + + return empty($minSupported) ? NULL : $minSupported; + } + /** * Check if a specific version of a library is supported * @@ -1914,22 +1937,22 @@ class H5PCore { * @param array An array containing versions * @return boolean TRUE if supported, otherwise FALSE */ - private static function isLibraryVersionSupported ($library, $minimumVersions) { + public function isLibraryVersionSupported ($library, $minimumVersions) { $major_supported = $minor_supported = $patch_supported = false; foreach ($minimumVersions as $minimumVersion) { // A library is supported if: // --- major is higher than any minimumversion // --- minor is higher than any minimumversion for a given major // --- major and minor equals and patch is >= supported - $major_supported |= ($library->major_version > $minimumVersion['major']); + $major_supported |= ($library->major_version > $minimumVersion->major); - if ($library->major_version == $minimumVersion['major']) { - $minor_supported |= ($library->minor_version > $minimumVersion['minor']); + if ($library->major_version == $minimumVersion->major) { + $minor_supported |= ($library->minor_version > $minimumVersion->minor); } - if ($library->major_version == $minimumVersion['major'] && - $library->minor_version == $minimumVersion['minor']) { - $patch_supported |= ($library->patch_version >= $minimumVersion['patch']); + if ($library->major_version == $minimumVersion->major && + $library->minor_version == $minimumVersion->minor) { + $patch_supported |= ($library->patch_version >= $minimumVersion->patch); } }