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

namespaces
Frode Petterson 2014-08-26 13:24:20 +02:00
commit 68e7c00145
2 changed files with 56 additions and 42 deletions

View File

@ -438,7 +438,7 @@ class H5PValidator {
* @return boolean * @return boolean
* TRUE if the .h5p file is valid * TRUE if the .h5p file is valid
*/ */
public function isValidPackage($skipContent = FALSE) { public function isValidPackage($skipContent = FALSE, $upgradeOnly = FALSE) {
// Create a temporary dir to extract package in. // Create a temporary dir to extract package in.
$tmpDir = $this->h5pF->getUploadedH5pFolderPath(); $tmpDir = $this->h5pF->getUploadedH5pFolderPath();
$tmpPath = $this->h5pF->getUploadedH5pPath(); $tmpPath = $this->h5pF->getUploadedH5pPath();
@ -542,13 +542,22 @@ class H5PValidator {
$libraryH5PData = $this->getLibraryData($file, $filePath, $tmpDir); $libraryH5PData = $this->getLibraryData($file, $filePath, $tmpDir);
if ($libraryH5PData !== FALSE) { if ($libraryH5PData !== FALSE) {
// Library's directory name and machineName in library.json must match // Library's directory name must be:
//if ($libraryH5PData['machineName'] !== $file) { // - <machineName>
// $this->h5pF->setErrorMessage($this->h5pF->t('Library directory name must match machineName in library.json. (Directory: %directoryName , machineName: %machineName)', array('%directoryName' => $file, '%machineName' => $libraryH5PData['machineName']))); // - or -
// $valid = FALSE; // - <machineName>-<majorVersion>.<minorVersion>
// continue; // where mcahineName, majorVersion and minorVersion is read from library.json
//} if ($libraryH5PData['machineName'] !== $file && H5PCore::libraryToString($libraryH5PData, TRUE) !== $file) {
$libraries[$libraryH5PData['machineName']] = $libraryH5PData; $this->h5pF->setErrorMessage($this->h5pF->t('Library directory name must match machineName or machineName-majorVersion.minorVersion (from library.json). (Directory: %directoryName , machineName: %machineName, majorVersion: %majorVersion, minorVersion: %minorVersion)', array(
'%directoryName' => $file,
'%machineName' => $libraryH5PData['machineName'],
'%majorVersion' => $libraryH5PData['majorVersion'],
'%minorVersion' => $libraryH5PData['minorVersion'])));
$valid = FALSE;
continue;
}
$libraryH5PData['uploadDirectory'] = $filePath;
$libraries[H5PCore::libraryToString($libraryH5PData)] = $libraryH5PData;
} }
else { else {
$valid = FALSE; $valid = FALSE;
@ -566,6 +575,29 @@ class H5PValidator {
} }
} }
if ($valid) { if ($valid) {
if ($upgradeOnly) {
// When upgrading, we opnly add allready installed libraries,
// and new dependent libraries
$upgrades = array();
foreach ($libraries as &$library) {
// Is this library already installed?
if ($this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']) !== FALSE) {
$upgrades[H5PCore::libraryToString($library)] = $library;
}
}
while ($missingLibraries = $this->getMissingLibraries($upgrades)) {
foreach ($missingLibraries as $missing) {
$libString = H5PCore::libraryToString($missing);
$library = $libraries[$libString];
if ($library) {
$upgrades[$libString] = $library;
}
}
}
$libraries = $upgrades;
}
$this->h5pC->librariesJsonData = $libraries; $this->h5pC->librariesJsonData = $libraries;
if ($skipContent === FALSE) { if ($skipContent === FALSE) {
@ -713,13 +745,8 @@ class H5PValidator {
private function getMissingDependencies($dependencies, $libraries) { private function getMissingDependencies($dependencies, $libraries) {
$missing = array(); $missing = array();
foreach ($dependencies as $dependency) { foreach ($dependencies as $dependency) {
if (isset($libraries[$dependency['machineName']])) { if (!isset($libraries[H5PCore::libraryToString($dependency)])) {
if (!$this->h5pC->isSameVersion($libraries[$dependency['machineName']], $dependency)) { $missing[H5PCore::libraryToString($dependency)] = $dependency;
$missing[$dependency['machineName']] = $dependency;
}
}
else {
$missing[$dependency['machineName']] = $dependency;
} }
} }
return $missing; return $missing;
@ -1024,17 +1051,10 @@ class H5PStorage {
$library_saved = FALSE; $library_saved = FALSE;
$upgradedLibsCount = 0; $upgradedLibsCount = 0;
$mayUpdateLibraries = $this->h5pF->mayUpdateLibraries(); $mayUpdateLibraries = $this->h5pF->mayUpdateLibraries();
foreach ($this->h5pC->librariesJsonData as $key => &$library) {
$libraryId = $this->h5pF->getLibraryId($key, $library['majorVersion'], $library['minorVersion']); foreach ($this->h5pC->librariesJsonData as &$library) {
$libraryId = $this->h5pF->getLibraryId($library['machineName'], $library['majorVersion'], $library['minorVersion']);
$library['saveDependencies'] = TRUE; $library['saveDependencies'] = TRUE;
$library['skip'] = FALSE;
if ($upgradeOnly) {
// Is this library already installed?
if ($this->h5pF->loadLibrary($library['machineName'], $library['majorVersion'], $library['minorVersion']) === FALSE) {
$library['skip'] = TRUE;
continue;
}
}
if (!$libraryId) { if (!$libraryId) {
$new = TRUE; $new = TRUE;
@ -1057,20 +1077,19 @@ class H5PStorage {
$this->h5pF->saveLibraryData($library, $new); $this->h5pF->saveLibraryData($library, $new);
$current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . $key;
$libraries_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'libraries'; $libraries_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'libraries';
if (!is_dir($libraries_path)) { if (!is_dir($libraries_path)) {
mkdir($libraries_path, 0777, true); mkdir($libraries_path, 0777, true);
} }
$destination_path = $libraries_path . DIRECTORY_SEPARATOR . H5PCore::libraryToString($library, TRUE); $destination_path = $libraries_path . DIRECTORY_SEPARATOR . H5PCore::libraryToString($library, TRUE);
H5PCore::deleteFileTree($destination_path); H5PCore::deleteFileTree($destination_path);
rename($current_path, $destination_path); rename($library['uploadDirectory'], $destination_path);
$library_saved = TRUE; $library_saved = TRUE;
} }
foreach ($this->h5pC->librariesJsonData as $key => &$library) { foreach ($this->h5pC->librariesJsonData as &$library) {
if ($library['saveDependencies'] && !$library['skip']) { if ($library['saveDependencies']) {
$this->h5pF->deleteLibraryDependencies($library['libraryId']); $this->h5pF->deleteLibraryDependencies($library['libraryId']);
if (isset($library['preloadedDependencies'])) { if (isset($library['preloadedDependencies'])) {
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded');
@ -1680,6 +1699,9 @@ class H5PCore {
* FALSE otherwise * FALSE otherwise
*/ */
public function isSameVersion($library, $dependency) { public function isSameVersion($library, $dependency) {
if ($library['machineName'] != $dependency['machineName']) {
return FALSE;
}
if ($library['majorVersion'] != $dependency['majorVersion']) { if ($library['majorVersion'] != $dependency['majorVersion']) {
return FALSE; return FALSE;
} }
@ -1891,8 +1913,7 @@ class H5PCore {
'major' => $library->major_version, 'major' => $library->major_version,
'minor' => $library->minor_version, 'minor' => $library->minor_version,
'patch' => $library->patch_version, 'patch' => $library->patch_version,
), )
'minimumVersions' => $min->versions,
); );
} }
} }
@ -1973,17 +1994,10 @@ class H5PCore {
$downloadUrl = $library['downloadUrl']; $downloadUrl = $library['downloadUrl'];
$libraryName = $library['name']; $libraryName = $library['name'];
$currentVersion = $library['currentVersion']['major'] . '.' . $library['currentVersion']['minor'] .'.' . $library['currentVersion']['patch']; $currentVersion = $library['currentVersion']['major'] . '.' . $library['currentVersion']['minor'] .'.' . $library['currentVersion']['patch'];
$minimumVersions = ''; $html .= "<li><a href=\"$downloadUrl\">$libraryName</a> ($currentVersion)</li>";
$prefix = '';
foreach ($library['minimumVersions'] as $version) {
$minimumVersions .= $prefix . $version['major'] . '.' . $version['minor'] . '.' . $version['patch'];
$prefix = ' or ';
}
$html .= "<li><a href=\"$downloadUrl\">$libraryName</a> (Current version: $currentVersion. Minimum version(s): $minimumVersions)</li>";
} }
$html .= '</ul><span><br>These libraries may cause problems on this site.</div>'; $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; return $html;
} }
} }

View File

@ -97,8 +97,8 @@ var H5PLibraryDetails= H5PLibraryDetails || {};
// Only create pager if needed: // Only create pager if needed:
if(H5PLibraryDetails.currentContent.length > H5PLibraryDetails.PAGER_SIZE) { if(H5PLibraryDetails.currentContent.length > H5PLibraryDetails.PAGER_SIZE) {
H5PLibraryDetails.$previous = $('<button type="button" class="previous h5p-admin">&#xf137;</button>'); H5PLibraryDetails.$previous = $('<button type="button" class="previous h5p-admin"><</button>');
H5PLibraryDetails.$next = $('<button type="button" class="next h5p-admin">&#xf138;</button>'); H5PLibraryDetails.$next = $('<button type="button" class="next h5p-admin">></button>');
H5PLibraryDetails.$previous.on('click', function () { H5PLibraryDetails.$previous.on('click', function () {
if(H5PLibraryDetails.$previous.hasClass('disabled')) { if(H5PLibraryDetails.$previous.hasClass('disabled')) {