Migrating Drupal 6 CCK Programmatically - New Node Types
CCK allows you to add custom content (node) types to Drupal. However, there is no automated method for migrating these content types to multiple environments, such as local developer machines, integration, quality assurance, staging and production servers.
CCK offers a manually executed export/import process, located at /admin/content/types/export. This works well for migrating from one environment to another. However, this process is time consuming and difficult to track when dealing with multiple target environments running different versions of your node types.
Here is a method for executing these updates programmatically. Updates are stored in a custom module install file and are implemented whenever an environment updates to the latest code base and runs update.php.
Install the Install Profile API module from http://drupal.org/project/install_profile_api.
Perform these steps for each content type to add.
- Use the Drupal admin UI to create the new content type, add the CCK fields and place them in the desired order.
- Export the content type at /admin/content/types/export. Select the type, Export, select all fields, Export. Copy Export data to clipboard.
- Create a new file named {your_content_type}_import.inc in the directory of your custom module.
Example: /sites/all/modules/your_module/article_import.inc - Add "<?php" to the first line of the file and paste the export second line. Save file.
- Add the following lines to a new update function, your_module_update_X(), where X is one number higher than the highest numbered update.
- $file = drupal_get_path('module', 'your_module') . '/new_content_type_import.inc'
- install_content_copy_import_from_file($file, '');
NOTE: For new content types, second parameter must be '' (blank).
- Code any variables for the new content type used by other modules, such as comments or scheduler. Examine the data in your variable table to see what applies in your case.
- variable_set('comment_new_content_type', 0);
- Code any permissions that need to be assigned to roles for this new content type.
Save the custom module to your version control system. Distribute code to your other environments. Run update.php in each environment.
This method is used for new content types only. I will discuss updating content types and adding fields to existing content types in additional posts.
Add new comment