Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drupal - moving module folder

Tags:

module

drupal

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?

like image 691
davidosomething Avatar asked Apr 16 '10 16:04

davidosomething


4 Answers

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
like image 194
irakli Avatar answered Nov 01 '22 20:11

irakli


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.

like image 31
McAden Avatar answered Nov 01 '22 19:11

McAden


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.

like image 3
Charlie Schliesser Avatar answered Nov 01 '22 19:11

Charlie Schliesser


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.

like image 2
googletorp Avatar answered Nov 01 '22 21:11

googletorp