I am currently working on an evolution of a website powered by Drupal (version 5). This evolution requires to install a new theme which will then be enabled for specific pages. Activating a new theme triggers the creation of a new set of configuration options for the blocks. In Drupal, blocks are boxes of content that may be rendered into certain regions of web pages, for example, into sidebars. Blocks can be positioned by specifying which area of the page they should appear in (e.g., a sidebar).

Unfortunately, the settings for the blocks for the new theme are reset to the default values. It is a bit problematic because these settings are usually identical across similar themes. For example, my project has already 85 activated blocks including 27 visible blocks. The visibility of these blocks are often controlled by PHP code.

A bit of SQL can however resolve the issue by copying the block settings from one theme to another. In the following code, the current theme is old-theme and the newly activated theme is new-theme.

UPDATE blocks AS export_blocks
INNER JOIN blocks AS import_blocks ON import_blocks.module = export_blocks.module AND
					import_blocks.delta = export_blocks.delta 
SET 
export_blocks.weight = import_blocks.weight,
export_blocks.region = import_blocks.region,
export_blocks.visibility = import_blocks.visibility,
export_blocks.pages = import_blocks.pages,
export_blocks.title = import_blocks.title,
export_blocks.status = import_blocks.status

WHERE export_blocks.theme = 'new-theme' AND import_blocks.theme = 'old-theme'