Skip to content

Commit

Permalink
[TASK] Cleanup h5p default storage
Browse files Browse the repository at this point in the history
  • Loading branch information
liayn committed May 21, 2024
1 parent 331575b commit 4ef3a00
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions h5p-default-storage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @copyright 2016 Joubel AS
* @license MIT
*/
class H5PDefaultStorage implements \H5PFileStorage
class H5PDefaultStorage implements H5PFileStorage
{
private $path, $alteditorpath;

Expand All @@ -44,10 +44,10 @@ public function __construct($path, $alteditorpath = null)
*/
public function saveLibrary($library)
{
$dest = $this->path . '/libraries/' . \H5PCore::libraryToFolderName($library);
$dest = $this->path . '/libraries/' . H5PCore::libraryToFolderName($library);

// Make sure destination dir doesn't exist
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);

// Move library folder
self::copyFileTree($library['uploadDirectory'], $dest);
Expand All @@ -68,10 +68,10 @@ public function deleteLibrary($library)
*/
public function saveContent($source, $content)
{
$dest = "{$this->path}/content/{$content['id']}";
$dest = "$this->path/content/{$content['id']}";

// Remove any old content
\H5PCore::deleteFileTree($dest);
H5PCore::deleteFileTree($dest);

self::copyFileTree($source, $dest);
}
Expand All @@ -84,7 +84,7 @@ public function saveContent($source, $content)
*/
public function deleteContent($content)
{
\H5PCore::deleteFileTree("{$this->path}/content/{$content['id']}");
H5PCore::deleteFileTree("$this->path/content/{$content['id']}");
}

/**
Expand Down Expand Up @@ -148,7 +148,7 @@ public function exportContent($id, $target)
*/
public function exportLibrary($library, $target, $developmentPath = null)
{
$srcFolder = \H5PCore::libraryToFolderName($library);
$srcFolder = H5PCore::libraryToFolderName($library);
$srcPath = ($developmentPath === null ? "/libraries/{$srcFolder}" : $developmentPath);

// Library folders inside the H5P zip file shall not contain patch version in the folder name
Expand Down Expand Up @@ -197,7 +197,7 @@ public function deleteExport($filename)
* Check if the given export file exists
*
* @param string $filename
* @return boolean
* @return bool
*/
public function hasExport($filename)
{
Expand Down Expand Up @@ -399,7 +399,7 @@ public function moveContentDirectory($source, $contentId = null)
}

// TODO: Remove $contentId and never copy temporary files into content folder. JI-366
if ($contentId === null || $contentId == 0) {
if ($contentId == 0) {
$target = $this->getEditorPath();
} else {
// Use content folder
Expand Down Expand Up @@ -437,8 +437,8 @@ public function getContentFile($file, $contentId)
* Used when saving content.
*
* @param string $file path + name
* @param int $contentid
* @return string|int File ID or NULL if not found
* @param $contentId
* @return string|int|null File ID or NULL if not found
*/
public function removeContentFile($file, $contentId)
{
Expand All @@ -453,10 +453,11 @@ public function removeContentFile($file, $contentId)
if (is_dir($dir) && count(scandir($dir)) === 2) { // empty contains '.' and '..'
rmdir($dir); // Remove empty parent
} else {
return; // Not empty
return null; // Not empty
}
}
}
return null;
}

/**
Expand Down Expand Up @@ -530,23 +531,22 @@ public function saveFileFromZip($path, $file, $stream)
* From path
* @param string $destination
* To path
* @return boolean
* Indicates if the directory existed.
* @return void
*
* @throws Exception Unable to copy the file
*/
private static function copyFileTree($source, $destination)
{
if (!self::dirReady($destination)) {
throw new \Exception('unabletocopy');
throw new Exception('unabletocopy');
}

$ignoredFiles = self::getIgnoredFiles("{$source}/.h5pignore");

$dir = opendir($source);
if ($dir === false) {
trigger_error('Unable to open directory ' . $source, E_USER_WARNING);
throw new \Exception('unabletocopy');
throw new Exception('unabletocopy');
}

while (false !== ($file = readdir($dir))) {
Expand Down

0 comments on commit 4ef3a00

Please sign in to comment.