From 18b24759183589b09e02a4df8317115f7187c04b Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Sat, 13 Apr 2013 14:11:25 +0200 Subject: [PATCH] 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 --- h5p.classes.php | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 8f58986..d6a1c16 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -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,16 +789,19 @@ 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 (isset($library['preloadedDependencies'])) { - $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); - } - if (isset($library['dynamicDependencies'])) { - $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic'); - } - if (isset($library['editorDependencies'])) { - $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); + if ($library['saveDependencies']) { + $this->h5pF->deleteLibraryDependencies($library['libraryId']); + if (isset($library['preloadedDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['preloadedDependencies'], 'preloaded'); + } + if (isset($library['dynamicDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['dynamicDependencies'], 'dynamic'); + } + if (isset($library['editorDependencies'])) { + $this->h5pF->saveLibraryDependencies($library['libraryId'], $library['editorDependencies'], 'editor'); + } } } // Move the content folder