Skip to content

Commit

Permalink
JI-3485 Add support for deleting previous minor version library
Browse files Browse the repository at this point in the history
  • Loading branch information
fnoks committed May 10, 2022
1 parent b24aa58 commit b25b66c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
4 changes: 4 additions & 0 deletions h5p-default-storage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ public function saveLibrary($library) {
self::copyFileTree($library['uploadDirectory'], $dest);
}

public function deleteLibrary($library) {
// TODO
}

/**
* Store the content folder.
*
Expand Down
7 changes: 7 additions & 0 deletions h5p-file-storage.interface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ interface H5PFileStorage {
*/
public function saveLibrary($library);

/**
* Delete library folder
*
* @param array $library
*/
public function deleteLibrary($library);

/**
* Store the content folder.
*
Expand Down
26 changes: 16 additions & 10 deletions h5p.classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -1620,20 +1620,20 @@ private function saveLibraries() {

// Go through libraries that came with this package
foreach ($this->h5pC->librariesJsonData as $libString => &$library) {
// Find local library identifier
$libraryId = $this->h5pC->getLibraryId($library, $libString);
// Find local library with same major + minor
$existingLibrary = $this->h5pC->loadLibrary($library['machineName'], $library['majorVersion'], $library['minorVersion']);

// Assume new library
$new = TRUE;
if ($libraryId) {
// Found old library
$library['libraryId'] = $libraryId;
if ($existingLibrary) {
// We have the library installed already (with the same major + minor)

if ($this->h5pF->isPatchedLibrary($library)) {
// This is a newer version than ours. Upgrade!
$new = FALSE;
}
else {
$library['libraryId'] = $existingLibrary['libraryId'];

// Is this a newer patchVersion?
$new = $existingLibrary['patchVersion'] < $library['patchVersion'];

if (!$new) {
$library['saveDependencies'] = FALSE;
// This is an older version, no need to save.
continue;
Expand Down Expand Up @@ -1663,6 +1663,10 @@ private function saveLibraries() {
// Remove tmp folder
H5PCore::deleteFileTree($library['uploadDirectory']);

if ($existingLibrary) {
$this->h5pC->fs->deleteLibrary($existingLibrary);
}

if ($new) {
$newOnes++;
}
Expand Down Expand Up @@ -3159,6 +3163,8 @@ private function getDisplayOptionsAsArray($disable) {
* @return int Identifier, or FALSE if non-existent
*/
public function getLibraryId($library, $libString = NULL) {
static $libraryIdMap = [];

if (!$libString) {
$libString = self::libraryToString($library);
}
Expand Down

0 comments on commit b25b66c

Please sign in to comment.