Skip to content

Commit 7b66a85

Browse files
Merge pull request #985 from nextcloud/fix/new-image-failure
Fix bug that thumbnail file needs to be created if not yet existing
2 parents 6f787d4 + ab69e3a commit 7b66a85

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
[#965](https://github.com/nextcloud/cookbook/pull/965) @christianlupus
2020
- Mark cookbook app as compatible with NC24
2121
[#977](https://github.com/nextcloud/cookbook/pull/977) @christianlupus
22+
- Fix bug that prevent generation of thumbnails when no previous thumbnails are present
23+
[#985](https://github.com/nextcloud/cookbook/pull/985) @christianlupus
2224

2325
### Documentation
2426
- Corrected some spelling issues

lib/Helper/ImageService/ThumbnailFileHelper.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ private function recreateSingleThumbnail(Folder $recipeFolder, int $type): void
8989

9090
if ($this->fileHelper->hasImage($recipeFolder)) {
9191
$full = $this->fileHelper->getImage($recipeFolder);
92-
$file = $recipeFolder->get($filename);
92+
if ($recipeFolder->nodeExists($filename)) {
93+
$file = $recipeFolder->get($filename);
94+
} else {
95+
$file = $recipeFolder->newFile($filename);
96+
}
9397

9498
$this->generationHelper->generateThumbnail($full, $type, $file);
9599
} else {

tests/Unit/Helper/ImageService/ThumbnailFileHelperTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,18 @@ public function testRecreateThumbnails($thumbExists, $miniExists) {
198198
];
199199
$f->method('get')->willReturnMap($fileMap);
200200

201+
$cnt = 0;
202+
if (! $thumbExists) {
203+
$cnt ++;
204+
}
205+
if (! $miniExists) {
206+
$cnt ++;
207+
}
201208
$newFileMap = [
202209
['thumb.jpg', null, $thumb],
203210
['thumb16.jpg', null, $mini],
204211
];
205-
$f->method('newFile')->willReturnMap($newFileMap);
212+
$f->expects($this->exactly($cnt))->method('newFile')->willReturnMap($newFileMap);
206213

207214
$full = $this->createStub(File::class);
208215
$this->fileHelper->method('hasImage')->willReturn(true);

0 commit comments

Comments
 (0)