Skip to content

Commit 1d0b485

Browse files
author
Bradie Tilley
committed
Fix regeneration of permalink images that previously defaulted to 404 image
1 parent 209bbc9 commit 1d0b485

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

models/ImagePermalink.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,22 @@ public function getPermalinkUrlAttribute(): string
163163
return url('/imageresizestatic/' . $this->identifier . '.' . $this->extension);
164164
}
165165

166+
/**
167+
* If the resized copy of this image exists, delete it.
168+
*
169+
* @return $this
170+
*/
171+
public function deleteResize()
172+
{
173+
if ($this->resizeExists()) {
174+
unlink($this->absolute_path);
175+
}
176+
177+
$this->path = null;
178+
179+
return $this;
180+
}
181+
166182
/**
167183
* Render this image to screen, now.
168184
*
@@ -216,11 +232,14 @@ public static function fromResizer(string $identifier, Resizer $resizer): ImageP
216232
$that->options = $resizer->getCacheableOptions();
217233

218234
$that->save();
219-
} elseif ($that->resizeExists() === false) {
235+
} elseif (($that->resizeExists() === false) || empty($that->image)) {
220236
// In the case where the resize doesn't exist (typically after cache:flush) we want
221237
// to update the image reference as well as options.
222238
$that->image = $resizer->getImagePathRelativePreferred();
223239

240+
// If resize exists, delete the resized copy
241+
$that->deleteResize();
242+
224243
list($mime, $format) = $resizer->detectFormat(true);
225244

226245
$that->mime_type = 'image/' . $mime;

updates/version.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,6 @@
5353
2.2.3:
5454
- Improvements to Permalinks
5555
2.2.4:
56-
- Fix exception when directory doesn't exist during cache clear
56+
- Fix exception when directory doesn't exist during cache clear
57+
2.2.5:
58+
- Fix regeneration of permalink images that previously defaulted to 404 image

0 commit comments

Comments
 (0)