1

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%.

Charles
  • 50,943
  • 13
  • 104
  • 142
Ross
  • 46,186
  • 39
  • 120
  • 173

1 Answers1

0

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.

qooplmao
  • 17,622
  • 2
  • 44
  • 69
  • I'm using that config param, but the problem is that I need the paths to be similar, rather than different for each version. It's given me an idea to strip the default_file_path off just before saving though so I'll try that out. – Ross Jun 25 '14 at 14:53
  • With mine each one maps to the same directory in the distribution (`app/Resource/files/uploads`) but it allows me to have it direct to the folder on my local machine but to the shared version in my remote (capifony) distribution. – qooplmao Jun 25 '14 at 14:57