Added file modification timestamps for media images

This commit is contained in:
Matias Griese
2019-01-16 17:59:29 +02:00
parent d27a2171ea
commit 76ff68a594
3 changed files with 46 additions and 1 deletions

View File

@@ -62,6 +62,22 @@ abstract class AbstractMedia extends Getters implements MediaCollectionInterface
return $object;
}
/**
* Set file modification timestamps (query params) for all the media files.
*
* @param string|int|null $timestamp
* @return $this
*/
public function setTimestamps($timestamp = null)
{
/** @var Medium $instance */
foreach ($this->instances as $instance) {
$instance->setTimestamp($timestamp);
}
return $this;
}
/**
* Get a list of all media.
*

View File

@@ -112,6 +112,35 @@ class Medium extends Data implements RenderableInterface, MediaObjectInterface
return false;
}
/**
* Get file modification time for the medium.
*
* @return int|null
*/
public function modified()
{
$path = $this->get('filepath');
if (!file_exists($path)) {
return null;
}
return filemtime($path) ?: null;
}
/**
* Set querystring to file modification timestamp (or value provided as a parameter).
*
* @param string|int|null $timestamp
* @return $this
*/
public function setTimestamp($timestamp = null)
{
$this->set('querystring', (string)($timestamp ?? $this->modified()));
return $this;
}
/**
* Returns an array containing just the metadata
*

View File

@@ -73,7 +73,7 @@ trait FlexMediaTrait
}
}
return $this->media;
return $this->media->setTimestamps();
}
public function checkUploadedMediaFile(UploadedFileInterface $uploadedFile)