From f4ba0af1efd4c73e2dd41f6e463bcffc2244138d Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Tue, 12 Jan 2016 12:55:03 +0100 Subject: [PATCH] Fixed default file storage implementation --- h5p-default-storage.class.php | 46 +++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 08d3810..517caf9 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -1,25 +1,34 @@ path = $path; - - // TODO: Check if Dirs are ready? Perhaps in each function? } /** @@ -47,7 +56,12 @@ class DefaultStorage implements \H5P\FileStorage { * What makes this content unique. */ public function saveContent($source, $id) { - self::copyFileTree($source, $this->path . '/content/' . $id); + $dest = "{$this->path}/content/{$id}"; + + // Remove any old content + \H5PCore::deleteFileTree($dest); + + self::copyFileTree($source, $dest); } /** @@ -57,7 +71,7 @@ class DefaultStorage implements \H5P\FileStorage { * Content identifier */ public function deleteContent($id) { - // TODO + \H5PCore::deleteFileTree("{$this->path}/content/{$id}"); } /** @@ -80,7 +94,7 @@ class DefaultStorage implements \H5P\FileStorage { * Path */ public function getTmpPath() { - // TODO + return $this->path . '/temp/' . uniqid('h5p-'); } /** @@ -92,7 +106,7 @@ class DefaultStorage implements \H5P\FileStorage { * Where the content folder will be saved */ public function exportContent($id, $target) { - self::copyFileTree($this->path . '/content/' . $id, $target); + self::copyFileTree("{$this->path}/content/{$id}", $target); } /** @@ -104,7 +118,8 @@ class DefaultStorage implements \H5P\FileStorage { * Where the library folder will be saved */ public function exportLibrary($library, $target) { - // TODO + $folder = \H5PCore::libraryToString($library, TRUE); + self::copyFileTree("{$this->path}/libraries/{$folder}", $target); } /** @@ -116,7 +131,9 @@ class DefaultStorage implements \H5P\FileStorage { * Name of export file. */ public function saveExport($source, $filename) { - // TODO + $this->deleteExport($filename); + self::dirReady("{$this->path}/exports"); + copy($source, "{$this->path}/exports/{$filename}"); } /** @@ -125,7 +142,10 @@ class DefaultStorage implements \H5P\FileStorage { * @param string $filename */ public function deleteExport($filename) { - // TODO + $target = "{$this->path}/exports/{$filename}"; + if (file_exists($target)) { + unlink($target); + } } /** @@ -151,11 +171,11 @@ class DefaultStorage implements \H5P\FileStorage { while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..') && $file != '.git' && $file != '.gitignore') { - if (is_dir($source . DIRECTORY_SEPARATOR . $file)) { - self::copyFileTree($source . DIRECTORY_SEPARATOR . $file, $destination . DIRECTORY_SEPARATOR . $file); + if (is_dir("{$source}/{$file}")) { + self::copyFileTree("{$source}/{$file}", "{$destination}/{$file}"); } else { - copy($source . DIRECTORY_SEPARATOR . $file,$destination . DIRECTORY_SEPARATOR . $file); + copy("{$source}/{$file}", "{$destination}/{$file}"); } } }