3 min read

Updating Drupal registry for themes and modules. Moving Drupal modules.

Sometimes in Drupal, you need to rebuild the registry of themes and modules. This may be necessary when modules or themes are moved, renamed, etc. For example, a module was installed in the folder sites/all/modules, but it must be moved to sites/all/contrib without disabling or uninstalling. When activating the module, its location is recorded in the system tables system, registry, and registry_file. These tables contain a list of available modules, their locations, and the paths of their files. When modules are moved, these tables must be updated accordingly.

To automate this process, use the Registry Rebuild module. In fact, this project is not a typical Drupal module but a script that automatically updates the registry. There are two ways to use this module.

Before performing any actions, make a backup of the database:

drush sql-dump > backup.sql

or

mysqldump -uuser -ppassword db_site_name > backup.sql

Using Registry Rebuild with Drush

  1. Download the module with drush dl registry_rebuild. After running this command, the module is placed in the Drush folder .drush/registry_rebuild. You can also manually download and unpack the archive to your Drush root.
drush dl registry_rebuild
  1. Navigate to your site’s libraries folder (sites/all). For multisite installations, use sites/sitename.
cd sites/all
  1. Run the command drush rr
drush rr

Using Registry Rebuild without Drush

  1. Create a folder sites/all/modules/registry_rebuild. For multisite installations, create sites/sitename/modules/registry_rebuild.

  2. If your modules are located in a specific folder other than sites/all/modules, edit the DRUPAL_ROOT variable in the registry_rebuild.php file.

  3. Copy the file registry_rebuild.php from the module archive into the folder created in step 1.

  4. Execute the file registry_rebuild.php via command line:

cd sites/all/modules/registry_rebuild
php registry_rebuild.php

or visit:

http://yoursite.com/sites/all/modules/registry_rebuild/registry_rebuild.php

You should see a message indicating a successful registry rebuild:

There were 510 files in the registry before and 510 files now. If you don't see any crazy fatal errors, your registry has been rebuilt.

You can verify the results and track changes in the tables: system, registry, and registry_file.