mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-28 17:02:04 +03:00
Fixed issue where more images than expected could be deleted
When deleting images, images within the same directory, that have a suffix of the delete image name, would also be deleted. Added test to cover.
This commit is contained in:
@ -223,6 +223,7 @@ class ImageService extends UploadService
|
||||
$storage->setVisibility($thumbFilePath, 'public');
|
||||
$this->cache->put('images-' . $image->id . '-' . $thumbFilePath, $thumbFilePath, 60 * 60 * 72);
|
||||
|
||||
|
||||
return $this->getPublicUrl($thumbFilePath);
|
||||
}
|
||||
|
||||
@ -292,11 +293,9 @@ class ImageService extends UploadService
|
||||
|
||||
/**
|
||||
* Destroys an image at the given path.
|
||||
* Searches for image thumbnails in addition to main provided path..
|
||||
* @param string $path
|
||||
* @return bool
|
||||
* Searches for image thumbnails in addition to main provided path.
|
||||
*/
|
||||
protected function destroyImagesFromPath(string $path)
|
||||
protected function destroyImagesFromPath(string $path): bool
|
||||
{
|
||||
$storage = $this->getStorage();
|
||||
|
||||
@ -306,8 +305,7 @@ class ImageService extends UploadService
|
||||
|
||||
// Delete image files
|
||||
$imagesToDelete = $allImages->filter(function ($imagePath) use ($imageFileName) {
|
||||
$expectedIndex = strlen($imagePath) - strlen($imageFileName);
|
||||
return strpos($imagePath, $imageFileName) === $expectedIndex;
|
||||
return basename($imagePath) === $imageFileName;
|
||||
});
|
||||
$storage->delete($imagesToDelete->all());
|
||||
|
||||
|
Reference in New Issue
Block a user