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?
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:
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')
Move folders
drush cc allirakli'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.
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
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."
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.