Ross
Ross

Reputation: 47037

Storing relative paths from the Uploadable Doctrine extension

Is there a way of getting the Doctrine Uploadable extension to store a path relative to a directory in the database?

We use Capistrano to manage releases on our servers, so when a file is uploaded, the stored path looks like: /var/www/sitename/releases/20140625151300/web/uploads/$filename. While the files themselves are safe (uploads is a symlink), when the release is deleted the paths necome broken.

For example, the stored path could just be the filename or relative to %kernel.root_dir%.

Upvotes: 1

Views: 716

Answers (1)

qooplmao
qooplmao

Reputation: 17759

I had the same problem and rather than dig into the listener (which I assume would be the other possibility) I set the path in my parameters file and then referenced that parameter in the stof_doctrine_extensions section. This way it allowed me to have the real path but allow it to be different for each version.

In app/config/parameters.yml

parameters:
    ....
    acme.upload.path: '/The/Absolute/Path/app/Resources/files/uploads'
    ....

In app/config/config.yml

stof_doctrine_extensions:
    ....
    uploadable:
        default_file_path: %acme.upload.path%
    ....

If you're not using the stof bundle then I assume you would just pass the parameter into your listener as one of the calls.

Like I say though, I'm pretty sure you would be able to go into the listener and play with that but I found this the easiest approach.

Upvotes: 0

Related Questions