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 * FALSE if the library doesn't exist
*/ */
public function loadLibrary($machineName, $majorVersion, $minorVersion); 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 // Save the libraries we processed during validation
foreach ($this->h5pC->librariesJsonData as $key => &$library) { foreach ($this->h5pC->librariesJsonData as $key => &$library) {
$libraryId = $this->h5pF->getLibraryId($key, $library['majorVersion'], $library['minorVersion']); $libraryId = $this->h5pF->getLibraryId($key, $library['majorVersion'], $library['minorVersion']);
$library['saveDependencies'] = TRUE;
if (!$libraryId) { if (!$libraryId) {
$new = TRUE; $new = TRUE;
} }
@ -768,7 +777,9 @@ class H5PStorage {
$library['libraryId'] = $libraryId; $library['libraryId'] = $libraryId;
} }
else { else {
$library['libraryId'] = $libraryId;
// We already have the same or a newer version of this library // We already have the same or a newer version of this library
$library['saveDependencies'] = FALSE;
continue; continue;
} }
$this->h5pF->saveLibraryData($library, $new); $this->h5pF->saveLibraryData($library, $new);
@ -778,16 +789,19 @@ class H5PStorage {
$this->h5pC->delTree($destination_path); $this->h5pC->delTree($destination_path);
rename($current_path, $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) { foreach ($this->h5pC->librariesJsonData as $key => &$library) {
if (isset($library['preloadedDependencies'])) { if ($library['saveDependencies']) {
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); $this->h5pF->deleteLibraryDependencies($library['libraryId']);
} if (isset($library['preloadedDependencies'])) {
if (isset($library['dynamicDependencies'])) { $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded');
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic'); }
} if (isset($library['dynamicDependencies'])) {
if (isset($library['editorDependencies'])) { $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic');
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); }
if (isset($library['editorDependencies'])) {
$this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor');
}
} }
} }
// Move the content folder // Move the content folder