From 284c722e042b936574c07df29251fee930cfdadd Mon Sep 17 00:00:00 2001 From: Bastian Heist Date: Fri, 20 Jul 2018 12:52:36 +0200 Subject: [PATCH] BUGFIX: Fixes #51 by moving export filename building for contents to a single place. --- h5p.classes.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/h5p.classes.php b/h5p.classes.php index 22ea069..b3e67c2 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -1688,7 +1688,7 @@ Class H5PExport { $zip->close(); H5PCore::deleteFileTree($tmpPath); - $filename = $content['slug'] . '-' . $content['id'] . '.h5p'; + $filename = self::buildExportFileName($content); try { // Save export $this->h5pC->fs->saveExport($tmpFile, $filename); @@ -1733,13 +1733,21 @@ Class H5PExport { } } + /** + * @param array $content object + * @return string the export filename + */ + public static function buildExportFileName($content) { + return ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p'; + } + /** * Delete .h5p file * * @param array $content object */ public function deleteExport($content) { - $this->h5pC->fs->deleteExport(($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p'); + $this->h5pC->fs->deleteExport(self::buildExportFileName($content)); } /** @@ -1947,7 +1955,7 @@ class H5PCore { if (!empty($content['filtered']) && (!$this->exportEnabled || ($content['slug'] && - $this->fs->hasExport($content['slug'] . '-' . $content['id'] . '.h5p')))) { + $this->fs->hasExport(H5PExport::buildExportFileName($content))))) { return $content['filtered']; } @@ -1976,7 +1984,7 @@ class H5PCore { $content['slug'] = $this->generateContentSlug($content); // Remove old export file - $this->fs->deleteExport($content['id'] . '.h5p'); + $this->fs->deleteExport(H5PExport::buildExportFileName($content)); } if ($this->exportEnabled) {