diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/AbstractStaticMode.php b/lib/Alchemy/Phrasea/Http/StaticFile/AbstractStaticMode.php index 50e87bee7b..eb09db5de5 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/AbstractStaticMode.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/AbstractStaticMode.php @@ -24,4 +24,11 @@ abstract class AbstractStaticMode extends AbstractServerMode parent::__construct($mapping); } + + protected function ensureSymlink($pathFile) + { + if (false === $this->symlinker->hasSymlink($pathFile)) { + $this->symlinker->symlink($pathFile); + } + } } diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/Apache.php b/lib/Alchemy/Phrasea/Http/StaticFile/Apache.php index f614c8b0a1..76b77df46b 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/Apache.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/Apache.php @@ -40,6 +40,8 @@ class Apache extends AbstractStaticMode implements StaticFileModeInterface */ public function getUrl($pathFile) { + $this->ensureSymlink($pathFile); + return Url::factory(sprintf('%s/%s', $this->mapping['mount-point'], $this->symlinker->getSymlinkBasePath($pathFile))); } diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/Nginx.php b/lib/Alchemy/Phrasea/Http/StaticFile/Nginx.php index 5b23398d6d..8019f61ae5 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/Nginx.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/Nginx.php @@ -40,6 +40,8 @@ class Nginx extends AbstractStaticMode implements StaticFileModeInterface */ public function getUrl($pathFile) { + $this->ensureSymlink($pathFile); + return Url::factory(sprintf('%s/%s', $this->mapping['mount-point'], $this->symlinker->getSymlinkBasePath($pathFile))); } diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php b/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php index 320e158c59..87b53f3d7f 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php @@ -86,4 +86,9 @@ class SymLinker $this->getSymlinkBasePath($pathFile) ); } + + public function hasSymlink($pathFile) + { + return file_exists($this->getSymlinkPath($pathFile)); + } }