From 1c5b9707e583fff170d9985c2c351d4f442dfc15 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Fri, 23 Sep 2016 10:52:40 +0200 Subject: [PATCH] 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']; }