Fixed cached images not being updated when source image is modified

This commit is contained in:
Andy Miller
2019-04-02 12:20:38 -06:00
parent ac2a4e1c06
commit 7efc0f418e
3 changed files with 46 additions and 6 deletions

View File

@@ -13,6 +13,7 @@
* Fixed `Undefined method closure::fields()` when getting avatar for user, thanks @Romarain [#2422](https://github.com/getgrav/grav/issues/2422)
* Grav 1.6: Added `Flex[Class]::getFlexType()` to all flex classes to have the interface for all Flex classes
* FlexObjects: Remove null values during save
* Fix issue with processed images not being updated when existing image is modified
# v1.6.0-rc.4
## 03/20/2019

View File

@@ -33,13 +33,14 @@ class ImageFile extends Image
/**
* This is the same as the Gregwar Image class except this one fires a Grav Event on creation of new cached file
*
* @param string $type the image type
* @param int $quality the quality (for JPEG)
* @param bool $actual
* @param string $type the image type
* @param int $quality the quality (for JPEG)
* @param bool $actual
* @param array $extras
*
* @return string
*/
public function cacheFile($type = 'jpg', $quality = 80, $actual = false)
public function cacheFile($type = 'jpg', $quality = 80, $actual = false, $extras = [])
{
if ($type === 'guess') {
$type = $this->guessType();
@@ -50,7 +51,7 @@ class ImageFile extends Image
}
// Computes the hash
$this->hash = $this->getHash($type, $quality);
$this->hash = $this->getHash($type, $quality, $extras);
// Seo friendly image names
$seofriendly = Grav::instance()['config']->get('system.images.seofriendly', false);
@@ -103,4 +104,42 @@ class ImageFile extends Image
return $this->getFilename($file);
}
/**
* Gets the hash.
* @param string $type
* @param int $quality
* @param [] $extras
* @return null
*/
public function getHash($type = 'guess', $quality = 80, $extras = [])
{
if (null === $this->hash) {
$this->generateHash($type, $quality, $extras);
}
return $this->hash;
}
/**
* Generates the hash.
* @param string $type
* @param int $quality
* @param array $extras
*/
public function generateHash($type = 'guess', $quality = 80, $extras = [])
{
$inputInfos = $this->source->getInfos();
$datas = array(
$inputInfos,
$this->serializeOperations(),
$type,
$quality,
$extras
);
$this->hash = sha1(serialize($datas));
}
}

View File

@@ -619,7 +619,7 @@ class ImageMedium extends Medium
$this->image->merge(ImageFile::open($overlay));
}
return $this->image->cacheFile($this->format, $this->quality);
return $this->image->cacheFile($this->format, $this->quality, false, [$this->get('width'), $this->get('height'), $this->get('modified')]);
}
/**