josegonzalez/upload — Issue #33: Pathing and Naming Callbacks
Author: josegonzalez
Created: 2011-12-17 22:34:53+00:00
State: open

There are currently several places in the plugin that use various naming schemes to get the correct path of an uploaded file or an image thumbnail:

- `thumbnailName` depends upon the value of `thumbnailPrefixStyle` when `thumbnailName` is null.
- If null, `thumbnailPath` defaults to `path`
- The following methods all somehow derive the value of the path/name, depending upon it's particular usage:
* `_setupField()`
* `_resizeImagick()`
* `_resizePhp()`
* `_prepareFilesForDeletion()`
* `afterSave()`

We also have `_path()` method which derives paths for file uploading, but sometimes can't be used because it does too much replacement.

The other issue is that sometimes users would like to override the naming setup such that they can name things in a logical order.

Ideally there would be a single method for each, `retrievePath()`, `retrieveName()`, which would take the following options:

- $model
- $field
- $data (whether from the current save or retrieved from the db)
- $options array
* isThumbnail - a boolean field that is on when we are trying to infer a thumbnail path
* basePath - something like `{ROOT}webroot{DS}files{DS}{size}{DS}{field}{DS}`
* rootDir - root directory to replace `{ROOT}`
* geometry
* size
* thumbnailType
* thumbnailName
* thumbnailMethod
* mediaThumbnailType
* dir field name
* saveType - create, update, delete

With these changes, we could have the user write an override method that would return the data as needed. This would obviate the need for #2 to some extent, as well as create a potential need for #3.

The other thing would be to allow an `afterSave()` callback to rename the original images if necessary - in the case of a created record, we would need to rename the original file if we are to properly handle #2.

Should close both #2 and #3 when this ticket is completed. Will obviously be a fair amount of work, but will ultimately make the plugin a bit more dry as well as give developers the flexibility they need on the filesystem for storing uploaded files.