Merge branch 'master' of github.com:h5p/h5p-php-library

Conflicts:
	h5p.classes.php
namespaces
Pål Jørgensen 2014-08-26 12:08:35 +02:00
commit f65af6b758
1 changed files with 63 additions and 40 deletions

View File

@ -1886,33 +1886,29 @@ class H5PCore {
return; return;
} }
// Read and parse library-support.json $minVersions = getMinimumVersionsSupported(realpath(dirname(__FILE__)) . '/library-support.json');
$jsonString = file_get_contents(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: // Get all libraries installed, check if any of them is not supported:
$libraries = $this->h5pF->loadLibraries(); $libraries = $this->h5pF->loadLibraries();
$unsupportedLibraries = array(); $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'];
}
// Iterate over all installed libraries // Iterate over all installed libraries
foreach ($libraries as $machine_name => $libraryList) { foreach ($libraries as $library_name => $versions) {
// Check if there are any minimum version requirements for this library if (!isset($minVersions[$library_name])) {
if (isset($minimumLibraryVersions[$machine_name])) { continue;
$minimumVersions = $minimumLibraryVersions[$machine_name]['versions']; }
$min = $minVersions[$library_name];
// For each version of this library, check if it is supported // For each version of this library, check if it is supported
foreach ($libraryList as $library) { foreach ($versions as $library) {
if (!self::isLibraryVersionSupported($library, $minimumVersions)) { if (!$this->isLibraryVersionSupported($library, $min->versions)) {
// Current version of this library is not supported // Current version of this library is not supported
$unsupportedLibraries[] = array ( $unsupportedLibraries[] = array (
'name' => $library->title, 'name' => $library_name,
'downloadUrl' => $minimumLibraryVersions[$machine_name]['downloadUrl'], 'downloadUrl' => $min->downloadUrl,
'currentVersion' => array ( 'currentVersion' => array (
'major' => $library->major_version, 'major' => $library->major_version,
'minor' => $library->minor_version, 'minor' => $library->minor_version,
@ -1921,13 +1917,40 @@ class H5PCore {
); );
} }
} }
}
}
$this->h5pF->setUnsupportedLibraries(empty($unsupportedLibraries) ? NULL : $unsupportedLibraries); $this->h5pF->setUnsupportedLibraries(empty($unsupportedLibraries) ? NULL : $unsupportedLibraries);
} }
} }
/**
* 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 * Check if a specific version of a library is supported
* *
@ -1935,22 +1958,22 @@ class H5PCore {
* @param array An array containing versions * @param array An array containing versions
* @return boolean TRUE if supported, otherwise FALSE * @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; $major_supported = $minor_supported = $patch_supported = false;
foreach ($minimumVersions as $minimumVersion) { foreach ($minimumVersions as $minimumVersion) {
// A library is supported if: // A library is supported if:
// --- major is higher than any minimumversion // --- major is higher than any minimumversion
// --- minor is higher than any minimumversion for a given major // --- minor is higher than any minimumversion for a given major
// --- major and minor equals and patch is >= supported // --- 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']) { if ($library->major_version == $minimumVersion->major) {
$minor_supported |= ($library->minor_version > $minimumVersion['minor']); $minor_supported |= ($library->minor_version > $minimumVersion->minor);
} }
if ($library->major_version == $minimumVersion['major'] && if ($library->major_version == $minimumVersion->major &&
$library->minor_version == $minimumVersion['minor']) { $library->minor_version == $minimumVersion->minor) {
$patch_supported |= ($library->patch_version >= $minimumVersion['patch']); $patch_supported |= ($library->patch_version >= $minimumVersion->patch);
} }
} }