From 70de9852e752f5efe2f8230a551d7ea6a743468b Mon Sep 17 00:00:00 2001 From: Karen Stevenson Date: Fri, 11 Feb 2011 13:54:38 +0000 Subject: [PATCH] #1058186 by Owen Barton, Start drush support for Content Migrate. --- modules/content_migrate/content_migrate.info | 2 + .../includes/content_migrate.admin.inc | 28 ++++++-- .../includes/content_migrate.drush.inc | 72 ++++++++++++++++++++ 3 files changed, 94 insertions(+), 8 deletions(-) create mode 100644 modules/content_migrate/includes/content_migrate.drush.inc diff --git a/modules/content_migrate/content_migrate.info b/modules/content_migrate/content_migrate.info index fe19746..39d0072 100644 --- a/modules/content_migrate/content_migrate.info +++ b/modules/content_migrate/content_migrate.info @@ -4,8 +4,10 @@ description = Migrate fields and field data from CCK D6 format to the D7 field f core = 7.x package = CCK files[] = content_migrate.module +files[] = content_migrate.api.php files[] = includes/content_migrate.admin.inc files[] = includes/content_migrate.values.inc +files[] = includes/content_migrate.drush.inc files[] = modules/content_migrate.text.inc files[] = modules/content_migrate.number.inc files[] = modules/content_migrate.optionwidgets.inc diff --git a/modules/content_migrate/includes/content_migrate.admin.inc b/modules/content_migrate/includes/content_migrate.admin.inc index a172ec5..11c08e0 100644 --- a/modules/content_migrate/includes/content_migrate.admin.inc +++ b/modules/content_migrate/includes/content_migrate.admin.inc @@ -6,20 +6,16 @@ */ /** - * Form generator for the migration selection form. - * - * @todo Make this into a nice table where you have - * an option to check all available fields to migrate - * them all at once. + * Determine which fields can be migrated, have already been migrated, and are + * unable to be migrated due to missing modules. */ -function content_migrate_select($form, &$form_state) { - $form = array(); +function content_migrate_get_options() { $options = array('available' => array(), 'converted' => array(), 'missing' => array()); $field_values = content_migrate_get_field_values(); if (empty($field_values)) { drupal_set_message(t('There is no D6 field information in this database.')); - return $form; + return FALSE; } $type_names = node_type_get_names(); @@ -63,6 +59,22 @@ function content_migrate_select($form, &$form_state) { $options['available'][$field_name] = $data; } } + return $options; +} + +/** + * Form generator for the migration selection form. + * + * @todo Make this into a nice table where you have + * an option to check all available fields to migrate + * them all at once. + */ +function content_migrate_select($form, &$form_state) { + $form = array(); + $options = content_migrate_get_options(); + if (!$options) { + return $form; + } $header = array(t('Field'), t('Field type'), t('Content type(s)'), t('Other information')); $form['#tree'] = TRUE; diff --git a/modules/content_migrate/includes/content_migrate.drush.inc b/modules/content_migrate/includes/content_migrate.drush.inc new file mode 100644 index 0000000..56a4aa2 --- /dev/null +++ b/modules/content_migrate/includes/content_migrate.drush.inc @@ -0,0 +1,72 @@ + 'Migrate fields.', + ); + $items['content-migrate-field-structure'] = array( + 'description' => 'Migrate a single field structure.', + 'arguments' => array( + 'name' => 'A field system name.', + ), + ); + $items['content-migrate-field-data'] = array( + 'description' => 'Migrate a single field data.', + ); + + return $items; +} + +/** + * Command callback. + */ +function drush_content_migrate() { + module_load_include('inc', 'content_migrate', 'includes/content_migrate.admin'); + $fields = content_migrate_get_options(); + $field_names = array_keys($fields['available']); + + foreach ($field_names as $field_name) { + drush_invoke_process_args('content-migrate-field-structure', array($field_name)); + } + foreach ($field_names as $field_name) { + drush_invoke_process_args('content-migrate-field-data', array($field_name)); + } +} + +function drush_content_migrate_field_structure($field_name) { + drush_log('Migrating structure: ' . $field_name); + module_load_include('inc', 'content_migrate', 'includes/content_migrate.admin'); + _content_migrate_batch_process_create_fields(array($field_name)); +} + +function drush_content_migrate_field_data($field_name) { + drush_log('Migrating data: ' . $field_name); + module_load_include('inc', 'content_migrate', 'includes/content_migrate.admin'); + $context = array( + 'sandbox' => array(), + ); + _content_migrate_batch_process_migrate_data($field_name, $context); +} -- 1.7.4.1