Skip to content

Commit

Permalink
deprecate non-property use of CurrentDateTimeDirectoryNamer
Browse files Browse the repository at this point in the history
  • Loading branch information
garak committed May 6, 2019
1 parent 43adde0 commit a20150b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Naming/CurrentDateTimeDirectoryNamer.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ public function configure(array $options): void
}
}

/**
* {@inheritdoc}
*/
public function directoryName($object, PropertyMapping $mapping): string
{
if (empty($this->dateTimeFormat)) {
Expand All @@ -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();
}

Expand Down
22 changes: 10 additions & 12 deletions Resources/doc/namers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
# ...
Expand All @@ -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.

Expand Down

0 comments on commit a20150b

Please sign in to comment.