Hello all!

I open this issue after using WebFm extensively and facing the issue I'm about to describe several times. This is not a BUG per se, but I couldn't think of a better Category for it.

The issue

WebFM keeps a DB field named "path" where the path to each file is kept. Each record is stored in this way:
/fulll/path/to/file.ext
which would be something like this:
/path/to/drupal/sites/yoursite/files/webfm/path/to/file.ext

This presents a big problem, a Website is not movable. What do I mean?

Lets say I keep a live site and a devel site. the Path to the files folder for each site is:

Live:  /http/drupal/sites/live/files/webfm/folder/myfile.ext
Devel: /http/drupal/sites/devel/files/webfm/folder/myfile.ext

When I then move my DB from Live to Devel (if I want to setup a testing enviroment) or Devel to Live (if I want to publish whatever I've been developing) the paths to each WebFM file will be pointing to the wrong site.

My thoughts

This is easily fixable because within the WebFM settings we are asked to set a WebFM folder that resides in the Drupal's file directory for the site that we are using. This means that the paths kept in WebFM table can be:
relative/path/to/file.ext
And they would be relative to Drupal's file directory for that site. And we then add the rest of the path when processing the files.

My solution

There are two possible options to address this issue.

  • Change all the code to work with relative paths and add the rest of the path where needed using drupal's file API: file_directory_path()
  • Only change the DB queries so that when reading we convert the relative path to absolute and then return full paths for the module to work with, and when writing we convert then from absolute to relative (basically we remove the /full/path/to/drupal/sites/example.com/files/webfm/ part)

I'm working on the second solution for now because it is just faster (and I need this functionality now), but I think the first one is the proper way to do it.

I'll publish my possible solution (patch) once I have it ready.

Cheers

Federico

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jm.federico’s picture

Well, see, it's really late here so I did made a mistake. Paths are stored relative to Drupal's installation path, but concept is the same. This is what is being stored
sites/example.com/files/webfm/my/folders/myfile.ext

and this is what I think we should store
my/folders/myfile.ext

Cheers (and sweet dreams for me)

Federico

cgmonroe’s picture

Sounds like a good thing. Your approach of dealing with it at retrieval/storage is probably the best way to do this. If I remember the code correctly, the file info is pretty much retrieved and stored in a small part of the code. Doing the conversions there makes the more sense than trying the change ALL the code to deal with the change.

IMHO, the patch should include upgrade code to modify existing table info to match the new format. A possible alternative to this might be to have this is an admin option that can be turned on for new installs. This option should check if there are files in the old format and warn/disallow it's use.

nhck’s picture

Category: bug » feature
Priority: Normal » Major
Status: Active » Needs work
pillarsdotnet’s picture

Status: Needs work » Needs review
FileSize
8.57 KB

Patch.

Setting to "needs review", but there should be some kind of warning in admin/settings/webfm that once you set the WebFM Root, changing it requires either moving files or manually updating the database.

Hmm... moving the WebFM repository from SRC to DST:

  • Unpatched:
    1. Set the WebFM Root to an ancestor of both SRC and DST.
    2. Use WebFM to move all files from SRC to DST.
    3. Set the WebFM Root to DST
  • Patched (option 1):
    1. Turn off Drupal CRON processing.
    2. Use another file manager (FTP, SFTP, shell) to move all files from SRC to DST.
    3. Set the WebFM Root to DST.
    4. Turn on Drupal CRON processing.
  • Patched (option 2):
    1. Use another file manager (FTP, SFTP, shell) to copy all files from SRC to DST.
    2. Set the WebFM Root to DST.
    3. Delete the original files in SRC.
pillarsdotnet’s picture