protected function update()
{
// only do this if the file exists and contains data
if ($this->getDataChanged() || !$this->getCustomSetting("imageDimensionsCalculated")) {
try {
// save the current data into a tmp file to calculate the dimensions, otherwise updates wouldn't be updated
// because the file is written in parent::update();
$tmpFile = $this->getTemporaryFile();
$dimensions = $this->getDimensions($tmpFile, true);
unlink($tmpFile);
if ($dimensions && $dimensions["width"]) {
$this->setCustomSetting("imageWidth", $dimensions["width"]);
$this->setCustomSetting("imageHeight", $dimensions["height"]);
}
} catch (\Exception $e) {
Logger::error("Problem getting the dimensions of the image with ID " . $this->getId());
}
// this is to be downward compatible so that the controller can check if the dimensions are already calculated
// and also to just do the calculation once, because the calculation can fail, an then the controller tries to
// calculate the dimensions on every request an also will create a version, ...
$this->setCustomSetting("imageDimensionsCalculated", true);
}
parent::update();
$this->clearThumbnails();
// now directly create "system" thumbnails (eg. for the tree, ...)
if ($this->getDataChanged()) {
try {
$path = $this->getThumbnail(Image\Thumbnail\Config::getPreviewConfig())->getFileSystemPath();
// set the modification time of the thumbnail to the same time from the asset
// so that the thumbnail check doesn't fail in Asset\Image\Thumbnail\Processor::process();
// we need the @ in front of touch because of some stream wrapper (eg. s3) which don't support touch()
@touch($path, $this->getModificationDate());
} catch (\Exception $e) {
Logger::error("Problem while creating system-thumbnails for image " . $this->getRealFullPath());
Logger::error($e);
}
}
}