From 615bac7c08e4fe23726fc45edbe8615ee9b7139b Mon Sep 17 00:00:00 2001 From: Thomas Horn Sivertsen Date: Thu, 1 Feb 2018 12:18:31 +0100 Subject: [PATCH] HFP-1806 Add presave for development and public libraries --- h5p-default-storage.class.php | 10 +++------- h5p-file-storage.interface.php | 4 ++-- h5p.classes.php | 16 ++++++++++++++-- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/h5p-default-storage.class.php b/h5p-default-storage.class.php index a06c47c..9766e47 100644 --- a/h5p-default-storage.class.php +++ b/h5p-default-storage.class.php @@ -457,13 +457,9 @@ class H5PDefaultStorage implements \H5PFileStorage { * @param string $name * @return bool */ - public function hasPresave($name) { - $filePath = implode(DIRECTORY_SEPARATOR, [ - $this->path, - 'libraries', - $name, - 'presave.js', - ]); + public function hasPresave($libraryFolder, $developmentPath = null) { + $path = is_null($developmentPath) ? 'libraries' . DIRECTORY_SEPARATOR . $libraryFolder : $developmentPath; + $filePath = realpath($this->path . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . 'presave.js'); return file_exists($filePath); } diff --git a/h5p-file-storage.interface.php b/h5p-file-storage.interface.php index 953365c..976605e 100644 --- a/h5p-file-storage.interface.php +++ b/h5p-file-storage.interface.php @@ -194,7 +194,7 @@ interface H5PFileStorage { /** * Check if the library has a presave.js in the root folder * - * @return string|null Path to script or null if missing + * @return string|null Path if presave.js found */ - public function hasPresave($name); + public function hasPresave($libraryName, $developmentPath = null); } diff --git a/h5p.classes.php b/h5p.classes.php index 80399d9..efac783 100644 --- a/h5p.classes.php +++ b/h5p.classes.php @@ -2118,7 +2118,7 @@ class H5PCore { $dependency['version'] = "?ver={$dependency['majorVersion']}.{$dependency['minorVersion']}.{$dependency['patchVersion']}"; $this->getDependencyAssets($dependency, 'preloadedJs', $files['scripts'], $prefix); $this->getDependencyAssets($dependency, 'preloadedCss', $files['styles'], $prefix); - if( $this->fs->hasPresave($libraryName) ){ + if( $this->hasPresave($libraryName) ){ $this->addPresaveFile($files, $dependency, $prefix); } } @@ -2134,9 +2134,21 @@ class H5PCore { return $files; } + public function hasPresave($libraryName) + { + if( isset($this->h5pD) ){ + extract(H5PCore::libraryFromString($libraryName)); + $library = $this->h5pD->getLibrary($machineName, $majorVersion, $minorVersion); + if( !is_null($library)){ + return $this->fs->hasPresave($libraryName, $library['path']); + } + } + return $this->fs->hasPresave($libraryName); + } + public function addPresaveFile(&$assets, $library, $prefix = ''){ $this->getDependencyAssets([ - 'path' => 'libraries' . DIRECTORY_SEPARATOR . self::libraryToString($library, true), + 'path' => array_key_exists('path', $library) ? $library['path'] : 'libraries' . DIRECTORY_SEPARATOR . self::libraryToString($library, true), 'version' => array_key_exists('version', $library) ? $library['version'] : "?ver={$library['majorVersion']}.{$library['minorVersion']}.{$library['patchVersion']}", 'presaveJs' => ['presave.js'] ], 'presaveJs', $assets['scripts'], $prefix);