14
votes

Is it safe to move my modules

  • From sites/all/modules/
  • To sites/all/modules/contrib and sites/all/modules/custom

on a production site?

That is, does Drupal automatically detect that the module is still there, but in a new path?

10

10 Answers

21
votes

Drupal versions up to D6 kept module location in the system table, but starting from D7 there're multiple places where path is recorded (e.g. registry and registry_file tables) so just moving the folder and clearing cache will not do it, most probably will lead to significant problems.

A sequence of steps you can try:

  1. Backup your database
  2. Check-in your code into version control
  3. Run following queries:

    UPDATE system
    SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
    
    UPDATE registry
    SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
    
    UPDATE registry_file
    SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib')
    
  4. Move folders

  5. Run: drush cc all
3
votes

If you move a module Drupal will see that the old one is broken, and a new one exists. It will not assume the two are the same thing - simply moved.

3
votes

irakli's answer worked well for me, but I wanted to add some additional complexity to the queries in case others find them useful.

Step 1 – Update all 'custom' modules if you're lucky enough to have them sharing a namespace:

UPDATE system SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/custom') WHERE name LIKE 'custom_namespace_%';
UPDATE registry SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/custom') WHERE name LIKE 'custom_namespace_%';
UPDATE registry_file SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/custom') WHERE filename LIKE '%custom_namespace_%';

Step 2 - Update all 'dev' modules:

UPDATE system SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/dev') WHERE name LIKE 'devel%';
UPDATE registry SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/dev') WHERE name LIKE 'devel%';
UPDATE registry_file SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/dev') WHERE filename LIKE '%devel%';

Step 3 - Update all 'contrib' modules:

UPDATE system SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib');
UPDATE registry_file SET filename = REPLACE(filename, 'sites/all/modules', 'sites/all/modules/contrib')

Then throw all of your modules into the appropriate sites/all/modules/contrib|custom|dev folders, clear your cache, and you're good to go.

2
votes

Drupal stores the file location in the system table, the info will be rebuilt when you clear the module cache, so if you move the stuff and clear the cache afterwards you should be fine.

2
votes

If you are on D7, then this drupal documentation page is the best way to go ahead with moving modules around - How to move modules and themes

1
votes

It's good to have /contrib and /custom subfolder for the modules. For D7, specially if you use entity, you should disable the modules, move them and then re-enable. It works.

The alternative, move the modules to the subfolders and clear cache, sometimes doesn't work and may generate WSOD.

1
votes

use http://drupal.org/project/registry_rebuild "Registry Rebuild will also rebuild the system table to get the modules in the right place so you can bootstrap."

  • backup the db
  • uploaded the 'module'
  • moved all the modules
  • run the script sites/all/modules/registry_rebuild/registry_rebuild.php
  • reload the site
  • if you get an error clear the browser cache and all is working again
1
votes

dont forget to use this module after changing the modules folder :

https://drupal.org/project/registry_rebuild

1
votes

Actually you only need to do the update on the system table and then do the following:

drush rr 

and maybe..

drush cc all

drush rr
0
votes

You can move most of the modules safely, if you clear the cache afterwards (drush cc all).

However, some modules, especially ctools, store file path information in places other than the system table or caches. You may have to leave those modules in their original location, but you can still move everything else.