From 263a987eeb515195460a20a2560862a42fa8fea5 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 23 Sep 2016 10:31:55 +0200 Subject: [PATCH 1/4] Added document root when creating zip Thanks to paravibe on Drupal.org for contributing. --- h5p.classes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 0b2d7f8..660351c 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1574,11 +1574,15 @@ Class H5PExport { $zip = new ZipArchive(); $zip->open($tmpFile, ZipArchive::CREATE | ZipArchive::OVERWRITE); + // Some system needs the root prefix for ZipArchive's addFile() + $rootPrefix = (empty($_SERVER['DOCUMENT_ROOT']) ? '' : $_SERVER['DOCUMENT_ROOT'] . '/'); + // Add all the files from the tmp dir. foreach ($files as $file) { // Please note that the zip format has no concept of folders, we must // use forward slashes to separate our directories. $zip->addFile($file->absolutePath, $file->relativePath); + $zip->addFile($rootPrefix . $file->absolutePath, $file->relativePath); } // Close zip and remove tmp dir From 1c5b9707e583fff170d9985c2c351d4f442dfc15 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 23 Sep 2016 10:52:40 +0200 Subject: [PATCH 2/4] Regenerate export if missing on view Thanks to paravibe on Drupal.org for contributing. --- h5p-default-storage.class.php | 11 +++++++++++ h5p-file-storage.interface.php | 8 ++++++++ h5p.classes.php | 5 ++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index 5b8ffeb..a1cd27f 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -151,6 +151,17 @@ class H5PDefaultStorage implements \H5PFileStorage { } } + /** + * Check if the given export file exists + * + * @param string $filename + * @return boolean + */ + public function hasExport($filename) { + $target = "{$this->path}/exports/{$filename}"; + return file_exists($target); + } + /** * Will concatenate all JavaScrips and Stylesheets into two files in order * to improve page performance. diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index dfaa67a..3e4de89 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -90,6 +90,14 @@ interface H5PFileStorage { */ public function deleteExport($filename); + /** + * Check if the given export file exists + * + * @param string $filename + * @return boolean + */ + public function hasExport($filename); + /** * Will concatenate all JavaScrips and Stylesheets into two files in order * to improve page performance. diff --git a/h5p.classes.php b/h5p.classes.php index 660351c..c1892cd 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1812,7 +1812,10 @@ class H5PCore { * @return Object NULL on failure. */ public function filterParameters(&$content) { - if (isset($content['filtered']) && $content['filtered'] !== '') { + if (!empty($content['filtered']) && + (!$this->exportEnabled || + ($content['slug'] && + $this->fs->hasExport($content['slug'] . '-' . $content['id'] . '.h5p')))) { return $content['filtered']; } From ce796cf0cf011084320b7bea0c724dd212351f6e Mon Sep 17 00:00:00 2001 From: Mikael Lindqvist Date: Mon, 26 Sep 2016 12:05:02 +0200 Subject: [PATCH 3/4] don't fail silently in createExportFile --- h5p-default-storage.class.php | 11 +++++++++-- h5p.classes.php | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index a1cd27f..4d0385f 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -132,11 +132,18 @@ class H5PDefaultStorage implements \H5PFileStorage { * Path on file system to temporary export file. * @param string $filename * Name of export file. + * @throws Exception Unable to save the file */ public function saveExport($source, $filename) { $this->deleteExport($filename); - self::dirReady("{$this->path}/exports"); - copy($source, "{$this->path}/exports/{$filename}"); + + if (!self::dirReady("{$this->path}/exports")) { + throw new Exception("Unable to create directory for H5P export file."); + } + + if (!copy($source, "{$this->path}/exports/{$filename}")) { + throw new Exception("Unable to save H5P export file."); + } } /** diff --git a/h5p.classes.php b/h5p.classes.php index c1892cd..4d903af 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1595,6 +1595,7 @@ Class H5PExport { } catch (Exception $e) { $this->h5pF->setErrorMessage($this->h5pF->t($e->getMessage())); + return false; } unlink($tmpFile); From e4266efb222d870acce46ff5a036728aa5a3e865 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 30 Sep 2016 13:41:50 +0200 Subject: [PATCH 4/4] Added framework method to clear dirsize cache HFP-23 --- h5p.classes.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/h5p.classes.php b/h5p.classes.php index 4d903af..4a3203a 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -553,6 +553,11 @@ interface H5PFrameworkInterface { * return int */ public function getLibraryContentCount(); + + /** + * Will trigger after the export file is created. + */ + public function afterExportCreated(); } /** @@ -1599,6 +1604,7 @@ Class H5PExport { } unlink($tmpFile); + $this->h5pF->afterExportCreated(); return true; }