From a20150b0ca076c8cf15644d39f3a15f136cfa6b6 Mon Sep 17 00:00:00 2001 From: Massimiliano Arione Date: Mon, 6 May 2019 10:57:08 +0200 Subject: [PATCH] deprecate non-property use of CurrentDateTimeDirectoryNamer see #992 --- Naming/CurrentDateTimeDirectoryNamer.php | 6 +++--- Resources/doc/namers.md | 22 ++++++++++------------ 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Naming/CurrentDateTimeDirectoryNamer.php b/Naming/CurrentDateTimeDirectoryNamer.php index 48507bf3..379e436b 100644 --- a/Naming/CurrentDateTimeDirectoryNamer.php +++ b/Naming/CurrentDateTimeDirectoryNamer.php @@ -56,9 +56,6 @@ public function configure(array $options): void } } - /** - * {@inheritdoc} - */ public function directoryName($object, PropertyMapping $mapping): string { if (empty($this->dateTimeFormat)) { @@ -67,6 +64,9 @@ public function directoryName($object, PropertyMapping $mapping): string if (null !== $this->dateTimeProperty) { $dateTime = $this->propertyAccessor->getValue($object, $this->dateTimeProperty)->format('U'); } else { + // see https://github.com/dustin10/VichUploaderBundle/issues/992 + $msg = 'Not passing "date_time_property" option is deprecated and will be removed in version 2.'; + @trigger_error($msg, E_USER_DEPRECATED); $dateTime = $this->dateTimeHelper->getTimestamp(); } diff --git a/Resources/doc/namers.md b/Resources/doc/namers.md index e2c90279..e9b4efc8 100644 --- a/Resources/doc/namers.md +++ b/Resources/doc/namers.md @@ -148,17 +148,6 @@ For example, if your object has a `getUploadTimestamp(): \DateTimeInterface` met To use it, you just have to specify the service for the `directory_namer` configuration option of your mapping: -``` yaml -vich_uploader: - # ... - mappings: - product_image: - upload_destination: product_image - directory_namer: Vich\UploaderBundle\Naming\CurrentDateTimeDirectoryNamer -``` - -Or provide configuration: - ``` yaml vich_uploader: # ... @@ -167,9 +156,18 @@ vich_uploader: upload_destination: product_image directory_namer: service: Vich\UploaderBundle\Naming\CurrentDateTimeDirectoryNamer - options: {date_time_format: 'Y/d/m'} # will create directory "2018/23/09" for curent date "2018-09-23" + options: + date_time_format: 'Y/d/m' # will create directory "2018/23/09" for curent date "2018-09-23" + date_time_property: uploadTimestamp # see above example ``` +**Note**: + +> Not passing `date_time_property` to CurrentDateTimeDirectoryNamer is deprecated since version 1.9 and +> will be removed in version 2. +> You should always use an object property, otherwise the namer will fallback to current timestamp, +> losing name predictability. + If no directory namer is configured for a mapping, the bundle will simply use the `upload_destination` configuration option.