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

pull/25/head
Frode Petterson 2016-07-29 13:47:17 +02:00
commit 1ef52dfafe
2 changed files with 0 additions and 306 deletions

View File

@ -92,36 +92,6 @@ interface H5PFrameworkInterface {
*/ */
public function loadLibraries(); public function loadLibraries();
/**
* Saving the unsupported library list
*
* @param array
* A list of unsupported libraries. Each list entry contains:
* - name: MachineName for the library
* - downloadUrl: URL to a location a new version of the library may be downloaded from
* - currentVersion: The unsupported version of the library installed on the system.
* This is an associative array containing:
* - major: The major version of the library
* - minor: The minor version of the library
* - patch: The patch version of the library
*/
public function setUnsupportedLibraries($libraries);
/**
* Returns unsupported libraries
*
* @return array
* A list of unsupported libraries. Each entry contains an associative array with:
* - name: MachineName for the library
* - downloadUrl: URL to a location a new version of the library may be downloaded from
* - currentVersion: The unsupported version of the library installed on the system.
* This is an associative array containing:
* - major: The major version of the library
* - minor: The minor version of the library
* - patch: The patch version of the library
*/
public function getUnsupportedLibraries();
/** /**
* Returns the URL to the library admin page * Returns the URL to the library admin page
* *
@ -1355,9 +1325,6 @@ class H5PStorage {
// Remove temp content folder // Remove temp content folder
H5PCore::deleteFileTree($basePath); H5PCore::deleteFileTree($basePath);
} }
// Update supported library list if necessary:
$this->h5pC->validateLibrarySupport(TRUE);
} }
/** /**
@ -2122,9 +2089,6 @@ class H5PCore {
*/ */
public function deleteLibrary($libraryId) { public function deleteLibrary($libraryId) {
$this->h5pF->deleteLibrary($libraryId); $this->h5pF->deleteLibrary($libraryId);
// Force update of unsupported libraries list:
$this->validateLibrarySupport(TRUE);
} }
/** /**
@ -2335,133 +2299,6 @@ class H5PCore {
return $obj ? (object) $newArr : $newArr; return $obj ? (object) $newArr : $newArr;
} }
/**
* Check if currently installed H5P libraries are supported by
* the current version of core. Which versions of which libraries are supported is
* defined in the library-support.json file.
*
* @param boolean $force If TRUE, unsupported libraries list are rebuilt. If FALSE, list is
* rebuilt only if non-existing
*/
public function validateLibrarySupport($force = false) {
if (!$force && $this->h5pF->getUnsupportedLibraries() !== NULL) {
return;
}
$minVersions = $this->getMinimumVersionsSupported(realpath(dirname(__FILE__)) . '/library-support.json');
if ($minVersions === NULL) {
return;
}
// 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];
// 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,
)
);
}
}
}
$this->h5pF->setUnsupportedLibraries($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
*
* @param array $library An array containing versions
* @param array $minimumVersions
* @return bool TRUE if supported, otherwise FALSE
*/
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 minimum version
// --- minor is higher than any minimum version for a given major
// --- major and minor equals and patch is >= supported
/** @var object $library */
$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 &&
$library->minor_version == $minimumVersion->minor) {
$patch_supported |= ($library->patch_version >= $minimumVersion->patch);
}
}
return ($patch_supported || $minor_supported || $major_supported);
}
/**
* Helper function for creating markup for the unsupported libraries list
*
* @param $libraries
* @return string Html
*/
public function createMarkupForUnsupportedLibraryList($libraries) {
$html = '<div><span>The following versions of H5P libraries are not supported anymore:<span><ul>';
foreach ($libraries as $library) {
$downloadUrl = $library['downloadUrl'];
$libraryName = $library['name'];
$currentVersion = $library['currentVersion']['major'] . '.' . $library['currentVersion']['minor'] .'.' . $library['currentVersion']['patch'];
$html .= "<li><a href=\"$downloadUrl\">$libraryName</a> ($currentVersion)</li>";
}
$html .= '</ul><span><br>These libraries may cause problems on this site. See <a href="http://h5p.org/releases/h5p-core-1.3">here</a> for more info</div>';
return $html;
}
/** /**
* Detects if the site was accessed from localhost, * Detects if the site was accessed from localhost,
* through a local network or from the internet. * through a local network or from the internet.

View File

@ -1,143 +0,0 @@
[
{
"machineName": "H5P.CoursePresentation",
"downloadUrl": "http://h5p.org/presentation",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 64
},
{
"major": 1,
"minor": 1,
"patch": 10
}
]
},
{
"machineName": "H5P.Blanks",
"downloadUrl": "http://h5p.org/fill-in-the-blanks",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 65
}
]
},
{
"machineName": "H5P.Dialogcards",
"downloadUrl": "http://h5p.org/dialog-cards",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 28
}
]
},
{
"machineName": "H5P.DragQuestion",
"downloadUrl": "http://h5p.org/drag-and-drop",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 61
}
]
},
{
"machineName": "H5P.InteractiveVideo",
"downloadUrl": "http://h5p.org/interactive-video",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 31
},
{
"major": 1,
"minor": 1,
"patch": 10
},
{
"major": 1,
"minor": 2,
"patch": 10
}
]
},
{
"machineName": "H5P.Flashcards",
"downloadUrl": "http://h5p.org/flashcards",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 37
}
]
},
{
"machineName": "H5P.ImageHotspots",
"downloadUrl": "http://h5p.org/image-hotspots",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 5
}
]
},
{
"machineName": "H5P.JoubelUI",
"downloadUrl": "http://h5p.org/fill-in-the-blanks",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 6
}
]
},
{
"machineName": "H5P.MultiChoice",
"downloadUrl": "http://h5p.org/multichoice",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 51
}
]
},
{
"machineName": "H5P.QuestionSet",
"downloadUrl": "http://h5p.org/question-set",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 53
}
]
},
{
"machineName": "H5P.Summary",
"downloadUrl": "http://h5p.org/summary",
"minimumVersions": [
{
"major": 1,
"minor": 0,
"patch": 38
},
{
"major": 1,
"minor": 1,
"patch": 4
}
]
}
]