Would be nice if this was possible.
sites/default/files => sites/example.com/files

Comments

yktdan’s picture

Or from those of us who upgraded from D5 where the files were in /files and not in sites/default/files.

malc0mn’s picture

I had thought about making this possible...

Could you describe the use case you have in mind? In wich situation will you have such directories in one single files table?

File maintenance solely sticks to the files table now, so if these

  • sites/default/files/jules.png
  • sites/example.com/files/haley.jpg

files are in a single table, then moving from one to the other should theoretically be possible (totally untested though, and doubting while I'm writing this...).

mikeytown2’s picture

Moving from the default site dir to a more specific dir would be the use case. Helpful for multisite migrations.

Lets say you have 2 drupal sites that are very similar and you wish to use a single multisite setup instead of 2 code bases. Being able to migrate the default dir would make this process a lot simpler.

malc0mn’s picture

Correct me if I'm wrong, but this would involve migrating files from one files table to another. Depending how you have set up your multisite environment, this would require the module to switch databases:

  • Multisite setup with separate database per site (and possibly different DB users)
  • Multisite setup with one database but table prefixing enabled per site

Right?

I already had migration of files that are not in the files table in mind with content search and replace of the new destinations in the DB tables.

mikeytown2’s picture

No need to switch databases; in a multisite setup, each settings.php gets its own database (unless your using db_prefixing; and in that case you prefix the db with a different prefix before importing); so you do all the operations on the same database.

How I would frame it; have the user change the file_directory_path setting (admin/settings/file-system/settings) and then press the "migrate file directory path" button. This launches a bulk api operation that then copies/moves (make it configurable) each file over to the new directory and changes the database entries. If you do a copy operation (not move) you can use replace in the DB to make the SQL run a lot quicker.

malc0mn’s picture

So, just to make sure I understand your request correctly:

  1. You have setup a Drupal site the usual way with sites/default/files as the files directory. Content has been added, in fact it's been running smoothly for quite some time
  2. Now you're building a new site, very similar to the one already there, so you'll be adding it to the same codebase as a multisite setup:
    • Existing site is siteone.com using sites/default/files
    • New site is sitenew.com using sites/sitenew.com/files
  3. In order to keep things clean / consistant, you will now want to migrate the sites/default/files directory to sites/siteone.com/files. In order to do this, you simply adjust the default file folder in the file system settings clicking a new button named 'Migrate all files to new dir' which will simply trigger a File maintenance move action, starting up the batch process and moving (= copying and deleting the original afterwards) the files to the new dir, wile updating the paths in the content tables just as it does now.

    If that's it (is that it?), that would be damn nice and is easily implementable (I built it to be easily extendable with 'new' actions).

    EDIT: mental note: can the server write to the /sites folder to create / rename dirs? Undoubtedly the answer is "no". Need to test this and look into using chmod which is still no use if the server has no rights to modify anything in /sites :s

mikeytown2’s picture

Thats the idea :)

mikeytown2’s picture

You don't need to have php chmod. If you want to do this migration live it can be done; if I'm thinking correctly. Lets say we want to migrate default to siteone.com. Create the siteone.com dir and copy over the settings.php file. Now that drupal install is running out of siteone.com but all it's files still point to the old default dir. Switching the default dir setting will make all new files and css/js aggregates come from siteone.com and not default; we now need to migrate over the files. The server user needs to create the siteone.com dir in the sites folder and set the correct permissions of the new files folder.

malc0mn’s picture

Should that not be:

The server user needs to create the files dir in the sites/sitesone.com folder and set the correct permissions of the new files folder.

if I'm still following correctly?

EDIT: Just did a quick test in a clean 6.20 local sandbox. When changing your default files directory, the directory must exist and be writeble by the server as per Drupal core specs. This would mean that the correct procedure is:

  1. Create the new sites/siteone.com folder
  2. Move the settings.php there
  3. Create the new sites/siteone.com/files folder
  4. Chmod the sites/siteone.com/files folder so as to allow writing by the server
  5. Change your file system settings and hit 'Migrate files'

There is no way that the server can do 1-4 itself on a proper setup... Correct me if I'm wrong, but that would be a security risk ;-)

EDIT: at least the error message for hitting the Migrate files on an improper setup is ready, lol.

mikeytown2’s picture

yep. The sitesone.com folder and settings.php should be read only, where the files dir has fairly loose permissions. I would check the sitesone.com folder and settings.php to make sure they are read only. Follow what core does in this case.
http://drupalcode.org/project/drupal.git/blob?f=INSTALL.txt#l112
http://api.drupal.org/api/drupal/install.php/function/install_tasks/6
http://api.drupal.org/api/drupal/includes--install.inc/function/drupal_v...
http://api.drupal.org/api/drupal/includes--install.inc/function/drupal_i...

malc0mn’s picture

Well, my idea was to let the settings form behave as it always does when you hit the sumbit button. I'll only add an EXTRA submit handler ($form['#submit'][] = '_file_maintenance_migrate';) that will check the $form_state['values']['op'] to be t('Migrate files'). If this submit handler is called, it means that the default submit handler did all the work it usually does and it's safe for File maintenance to do it's migration job on all of the files.
Seems the best, cleanest and least invasive way to do it.

malc0mn’s picture

Assigned: Unassigned » malc0mn

Check out the 6.x-1.x branch to test the 1st phase. Initial testing shows that this works like a charm.

TODO: keep the existing subdirs while migrating. Might seem a big todo, but it isn't. Quite minor, but running out of time for this evening ;-)

malc0mn’s picture

Version: 6.x-1.0-beta1 » 6.x-1.0-beta3

New beta release here:

http://drupal.org/node/1199854

Is there a use of adding the new Migration functionality to the bulk actions, so you can 'migrate' files outside of the folder defined in admin/settings/file-system?

An absolute prerequisite for this, IMHO, is that the user must assure the existence of this folder and set the proper permissions, just like with the default files folder...

TallDavid’s picture

Subscribe. Just like yktdan in #1, we have several sites that were upgraded from Drupal 5 where the files are in /files and not in /sites/default/files. Seems like it may be a 'best practice' to move the files to the standard location prior to an upgrade of these sites to Drupal 7.

TallDavid’s picture

malc0mn’s picture

@14 TallDavid: in D5, are all of those files in the files table as well, or are they really 'stand alone' files in the docroot/files dir?