From a5e80e5219c311a4b58d7620948c21fbb5986eb3 Mon Sep 17 00:00:00 2001 From: Micheal Date: Fri, 4 Sep 2020 16:16:48 +0200 Subject: [PATCH] 07 Fix delete image on edit and avoid double slash --- Core/H5POptions.php | 14 +++++++++++--- Core/H5PSymfony.php | 2 +- DependencyInjection/StuditH5PExtension.php | 5 ++++- Editor/LibraryStorage.php | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/Core/H5POptions.php b/Core/H5POptions.php index 5c77c52..42a2c0f 100644 --- a/Core/H5POptions.php +++ b/Core/H5POptions.php @@ -99,15 +99,23 @@ public function getUploadedH5pPath($set = null) public function getRelativeH5PPath() { - return "/". $this->getOption('storage_dir'); + $dir = $this->getOption('storage_dir'); + + return $dir[0] === '/' ? $dir : '/' . $dir; } public function getAbsoluteH5PPathWithSlash(){ - return $this->getAbsoluteWebPath() . '/' . $this->getOption('storage_dir') .'/'; + $dir = $this->getOption('storage_dir'); + $dir = $dir[0] === '/' ? $dir : '/' . $dir; + + return $this->getAbsoluteWebPath() . $dir .'/'; } public function getAbsoluteH5PPath() { - return $this->getAbsoluteWebPath() . '/' . $this->getOption('storage_dir'); + $dir = $this->getOption('storage_dir'); + $dir = $dir[0] === '/' ? $dir : '/' . $dir; + + return $this->getAbsoluteWebPath() . $dir; } public function getAbsoluteWebPath() diff --git a/Core/H5PSymfony.php b/Core/H5PSymfony.php index 235d836..83dea3f 100644 --- a/Core/H5PSymfony.php +++ b/Core/H5PSymfony.php @@ -523,7 +523,7 @@ private function storeContent($contentData, Content $content) { $library = $this->manager->getRepository('StuditH5PBundle:Library')->find($contentData['library']['libraryId']); $content->setLibrary($library); - $content->setParameters($contentData['params']); + $content->setParameters(str_replace('#tmp','', $contentData['params'])); $content->setDisabledFeatures($contentData['disable']); $content->setFilteredParameters(null); $this->manager->persist($content); diff --git a/DependencyInjection/StuditH5PExtension.php b/DependencyInjection/StuditH5PExtension.php index b77f7cf..5d5b5cb 100644 --- a/DependencyInjection/StuditH5PExtension.php +++ b/DependencyInjection/StuditH5PExtension.php @@ -25,7 +25,10 @@ public function load(array $configs, ContainerBuilder $container) $loader->load('services.yml'); /** @var $definition Definition **/ $definition = $container->getDefinition("studit_h5p.core"); - $definition->setArgument(1, $container->getParameter('kernel.project_dir') . '/' . $config['web_dir'] . '/' . $config["storage_dir"]); + $dir = $config["storage_dir"]; + $dir[0] === '/' ? $dir : '/' . $dir; + + $definition->setArgument(1, $container->getParameter('kernel.project_dir') . '/' . $config['web_dir'] . $dir); $definition->setArgument(2, '/'); $definition->setArgument(3, 'en'); $definition->setArgument(4, true); diff --git a/Editor/LibraryStorage.php b/Editor/LibraryStorage.php index 1547a3e..7f5b9e2 100644 --- a/Editor/LibraryStorage.php +++ b/Editor/LibraryStorage.php @@ -65,7 +65,7 @@ public function storeLibraryData($library, $parameters, Content $content = null) if (!$content){ $contentData['id'] = $contentId; } - $this->updateLibraryFiles($contentId, $contentData, $oldLibrary, $oldParameters); + $this->updateLibraryFiles($contentId, $contentData, $oldLibrary, $oldParameters->params ?? null); return $contentId; } private function updateLibraryFiles($contentId, $contentData, $oldLibrary, $oldParameters)