Skip to content

Commit

Permalink
Fix regeneration of permalink images that previously defaulted to 404…
Browse files Browse the repository at this point in the history
… image
  • Loading branch information
Bradie Tilley committed Jan 13, 2021
1 parent 209bbc9 commit 1d0b485
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 20 additions & 1 deletion models/ImagePermalink.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,22 @@ public function getPermalinkUrlAttribute(): string
return url('/imageresizestatic/' . $this->identifier . '.' . $this->extension);
}

/**
* If the resized copy of this image exists, delete it.
*
* @return $this
*/
public function deleteResize()
{
if ($this->resizeExists()) {
unlink($this->absolute_path);
}

$this->path = null;

return $this;
}

/**
* Render this image to screen, now.
*
Expand Down Expand Up @@ -216,11 +232,14 @@ public static function fromResizer(string $identifier, Resizer $resizer): ImageP
$that->options = $resizer->getCacheableOptions();

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

// If resize exists, delete the resized copy
$that->deleteResize();

list($mime, $format) = $resizer->detectFormat(true);

$that->mime_type = 'image/' . $mime;
Expand Down
4 changes: 3 additions & 1 deletion updates/version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@
2.2.3:
- Improvements to Permalinks
2.2.4:
- Fix exception when directory doesn't exist during cache clear
- Fix exception when directory doesn't exist during cache clear
2.2.5:
- Fix regeneration of permalink images that previously defaulted to 404 image

0 comments on commit 1d0b485

Please sign in to comment.