diff options
author | Julius Härtl <jus@bitgrid.net> | 2018-03-09 10:37:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-09 10:37:15 +0100 |
commit | e2728aaf387996bbe4d5f35056571ef3b6a6052b (patch) | |
tree | d65baab57a46cc1f4453658a40e68564873b3564 | |
parent | 4fa0cac17c5b359e4351fbeccef6b8692c7dc3db (diff) | |
parent | 85ba5adb337738748000c9367b0bbeb62e08564f (diff) | |
download | nextcloud-server-e2728aaf387996bbe4d5f35056571ef3b6a6052b.tar.gz nextcloud-server-e2728aaf387996bbe4d5f35056571ef3b6a6052b.zip |
Merge pull request #8746 from nextcloud/8705_13
[stable13] Check if the cached js file exists
-rw-r--r-- | lib/private/Template/JSCombiner.php | 9 | ||||
-rw-r--r-- | tests/lib/Template/JSCombinerTest.php | 17 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/private/Template/JSCombiner.php b/lib/private/Template/JSCombiner.php index c5adcee6854..bc548c22fd0 100644 --- a/lib/private/Template/JSCombiner.php +++ b/lib/private/Template/JSCombiner.php @@ -104,13 +104,20 @@ class JSCombiner { * @return bool */ protected function isCached($fileName, ISimpleFolder $folder) { - $fileName = str_replace('.json', '.js', $fileName) . '.deps'; + $fileName = str_replace('.json', '.js', $fileName); + + if (!$folder->fileExists($fileName)) { + return false; + } + + $fileName = $fileName . '.deps'; try { $deps = $this->depsCache->get($folder->getName() . '-' . $fileName); if ($deps === null || $deps === '') { $depFile = $folder->getFile($fileName); $deps = $depFile->getContent(); } + // check again if ($deps === null || $deps === '') { $this->logger->info('JSCombiner: deps file empty: ' . $fileName); diff --git a/tests/lib/Template/JSCombinerTest.php b/tests/lib/Template/JSCombinerTest.php index d5f7000e0a5..bec88801d6b 100644 --- a/tests/lib/Template/JSCombinerTest.php +++ b/tests/lib/Template/JSCombinerTest.php @@ -187,6 +187,10 @@ class JSCombinerTest extends \Test\TestCase { $fileDeps->expects($this->once())->method('getContent')->willReturn('{}'); + $folder->method('fileExists') + ->with('combine.js') + ->willReturn(true); + $folder->method('getFile') ->will($this->returnCallback(function($path) use ($file, $fileDeps) { if ($path === 'combine.js') { @@ -196,6 +200,7 @@ class JSCombinerTest extends \Test\TestCase { if ($path === 'combine.js.deps') { return $fileDeps; } + $this->fail(); })); @@ -221,6 +226,9 @@ class JSCombinerTest extends \Test\TestCase { ->willReturn($folder); $folder->method('getName') ->willReturn('awesomeapp'); + $folder->method('fileExists') + ->with('combine.js') + ->willReturn(true); $file = $this->createMock(ISimpleFile::class); @@ -263,6 +271,9 @@ class JSCombinerTest extends \Test\TestCase { public function testIsCachedWithNotExistingFile() { $fileName = 'combine.json'; $folder = $this->createMock(ISimpleFolder::class); + $folder->method('fileExists') + ->with('combine.js') + ->willReturn(true); $file = $this->createMock(ISimpleFile::class); $folder->method('getFile') ->with('combine.js.deps') @@ -278,6 +289,9 @@ class JSCombinerTest extends \Test\TestCase { public function testIsCachedWithOlderMtime() { $fileName = 'combine.json'; $folder = $this->createMock(ISimpleFolder::class); + $folder->method('fileExists') + ->with('combine.js') + ->willReturn(true); $file = $this->createMock(ISimpleFile::class); $folder->method('getFile') ->with('combine.js.deps') @@ -293,6 +307,9 @@ class JSCombinerTest extends \Test\TestCase { public function testIsCachedWithoutContent() { $fileName = 'combine.json'; $folder = $this->createMock(ISimpleFolder::class); + $folder->method('fileExists') + ->with('combine.js') + ->willReturn(true); $file = $this->createMock(ISimpleFile::class); $folder->method('getFile') ->with('combine.js.deps') |