From 09785c67bd9875902c59a30afb65f9ba156d7f97 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Tue, 27 May 2014 19:30:29 +0200 Subject: [PATCH] Ensure symlink is always created --- lib/Alchemy/Phrasea/Http/StaticFile/AbstractStaticMode.php | 7 +++++++ lib/Alchemy/Phrasea/Http/StaticFile/Apache.php | 2 ++ lib/Alchemy/Phrasea/Http/StaticFile/Nginx.php | 2 ++ lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php | 5 +++++ 4 files changed, 16 insertions(+) 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)); + } }