Do not attempt to save library dependencies for libraries that have already been saved, and also remove previous dependencies for libraries that are beeing patched

namespaces
Svein-Tore Griff With 2013-04-13 14:11:25 +02:00
parent d51e6e8d01
commit 18b2475918
1 changed files with 23 additions and 9 deletions

View File

@ -170,6 +170,14 @@ interface H5PFrameworkInterface {
* FALSE if the library doesn't exist
*/
public function loadLibrary($machineName, $majorVersion, $minorVersion);
/**
* Delete all dependencies belonging to given library
*
* @param int $libraryId
* Library Id
*/
public function deleteLibraryDependencies($libraryId);
}
/**
@ -760,6 +768,7 @@ class H5PStorage {
// Save the libraries we processed during validation
foreach ($this->h5pC->librariesJsonData as $key => &$library) {
$libraryId = $this->h5pF->getLibraryId($key, $library['majorVersion'], $library['minorVersion']);
$library['saveDependencies'] = TRUE;
if (!$libraryId) {
$new = TRUE;
}
@ -768,7 +777,9 @@ class H5PStorage {
$library['libraryId'] = $libraryId;
}
else {
$library['libraryId'] = $libraryId;
// We already have the same or a newer version of this library
$library['saveDependencies'] = FALSE;
continue;
}
$this->h5pF->saveLibraryData($library, $new);
@ -778,8 +789,10 @@ class H5PStorage {
$this->h5pC->delTree($destination_path);
rename($current_path, $destination_path);
}
// All libraries have been saved, we now save all the dependencies
foreach ($this->h5pC->librariesJsonData as $key => &$library) {
if ($library['saveDependencies']) {
$this->h5pF->deleteLibraryDependencies($library['libraryId']);
if (isset($library['preloadedDependencies'])) {
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded');
}
@ -790,6 +803,7 @@ class H5PStorage {
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor');
}
}
}
// Move the content folder
$current_path = $this->h5pF->getUploadedH5pFolderPath() . DIRECTORY_SEPARATOR . 'content';
$destination_path = $this->h5pF->getH5pPath() . DIRECTORY_SEPARATOR . 'content' . DIRECTORY_SEPARATOR . $contentId;