From d4ee1d87a53145b5baea84d32bdb386e2106ec13 Mon Sep 17 00:00:00 2001 From: Toby Zerner Date: Fri, 19 Jun 2015 14:44:42 +0930 Subject: [PATCH] Generate a new revision string when files change --- src/Assets/RevisionCompiler.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Assets/RevisionCompiler.php b/src/Assets/RevisionCompiler.php index 171732630..ba76ad2ca 100644 --- a/src/Assets/RevisionCompiler.php +++ b/src/Assets/RevisionCompiler.php @@ -26,10 +26,7 @@ class RevisionCompiler implements CompilerInterface public function getFile() { - if (! ($revision = $this->getRevision())) { - $revision = Str::quickRandom(); - $this->putRevision($revision); - } + $revision = $this->getRevision(); $lastModTime = 0; foreach ($this->files as $file) { @@ -39,8 +36,16 @@ class RevisionCompiler implements CompilerInterface $ext = pathinfo($this->filename, PATHINFO_EXTENSION); $file = $this->path.'/'.substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0); - if (! file_exists($file) + if (! ($exists = file_exists($file)) || filemtime($file) < $lastModTime) { + + if ($exists) { + unlink($file); + } + + $revision = Str::quickRandom(); + $this->putRevision($revision); + $file = $this->path.'/'.substr_replace($this->filename, '-'.$revision, -strlen($ext) - 1, 0); file_put_contents($file, $this->compile()); }