diff --git a/README.txt b/README.txt index 694d9d7..c88affa 100644 --- a/README.txt +++ b/README.txt @@ -29,10 +29,7 @@ Assumptions and Limitations: do not want to bring paths over, then disable path module. * The product image field(s) are configurable; the destination fields will be named the same as the source fields. -* Product types are created *by the migration* from the base "Product" type - and the uc_product_classes table. -* Delete all existing product types, products, line items, and orders in your - commerce install. -* Consider deleting any existing product display nodes. +* You must have a product_type for each type that was defined in the old site, + the module will prompt you to do so if it has not been done. * You must have an existing Product Display content type named product_display. * See http://drupal.org/node/1206776#comment-4685032 for one import recipe. diff --git a/commerce_migrate_ubercart.info b/commerce_migrate_ubercart.info index ee6312f..bfab2ab 100644 --- a/commerce_migrate_ubercart.info +++ b/commerce_migrate_ubercart.info @@ -16,5 +16,6 @@ files[] = customer_billing_profile.inc files[] = line_item.inc files[] = order.inc files[] = product.inc -files[] = product_type.inc files[] = product_node.inc +files[] = commerce_migrate_ubercart.migrate.inc +files[] = commerce_migrate_ubercart.module diff --git a/commerce_migrate_ubercart.install b/commerce_migrate_ubercart.install index 6dfe4f0..74303af 100644 --- a/commerce_migrate_ubercart.install +++ b/commerce_migrate_ubercart.install @@ -8,30 +8,6 @@ * Implements hook_uninstall() to deregister migrations. */ function commerce_migrate_ubercart_uninstall() { - $migrations = array( - 'CommerceMigrateUbercartCustomerBillingProfile', - 'CommerceMigrateUbercartLineItem', - 'CommerceMigrateUbercartOrder', - 'CommerceMigrateUbercartLineItem', - 'CommerceMigrateUbercartNode', - 'CommerceMigrateUbercartProductType', - ); - module_load_include('module', 'commerce_migrate_ubercart'); - module_load_include('inc', 'commerce_migrate_ubercart', 'product'); - module_load_include('inc', 'commerce_migrate_ubercart', 'customer_billing_profile'); - module_load_include('inc', 'commerce_migrate_ubercart', 'line_item'); - module_load_include('inc', 'commerce_migrate_ubercart', 'order'); - module_load_include('inc', 'commerce_migrate_ubercart', 'product_node'); - module_load_include('inc', 'commerce_migrate_ubercart', 'product_type'); - $migrations = array_merge( - $migrations, - CommerceMigrateUbercartProductMigration::getProductMigrations(), - CommerceMigrateUbercartNodeMigration::getProductNodeMigrations() - ); - foreach ($migrations as $migration) { - Migration::deregisterMigration($migration); - } - // Get rid of old variables. $variables = array( 'commerce_migrate_ubercart_source_database_api_version', diff --git a/commerce_migrate_ubercart.migrate.inc b/commerce_migrate_ubercart.migrate.inc new file mode 100644 index 0000000..0babea5 --- /dev/null +++ b/commerce_migrate_ubercart.migrate.inc @@ -0,0 +1,133 @@ + 'commerce_ubercart', + ); + + /** + * Customer Billing Profile + */ + $customer_billing_arguments = $common_arguments + array( + 'machine_name' => 'CommerceMigrateUbercartCustomerBillingProfile', + 'class_name' => 'CommerceMigrateUbercartCustomerBillingProfileMigration', + 'description' => t('Import customer billing profiles from Ubercart.'), + ); + + /** + * Products + */ + $types = array(); + if ($configured != FALSE) { + db_set_active(variable_get('commerce_migrate_ubercart_source_database', 'default')); + $result = db_query("SELECT DISTINCT n.type AS type, ucp.pcid AS pcid, ucp.name AS name, ucp.description AS description FROM node n LEFT OUTER JOIN uc_product_classes ucp ON n.type = ucp.pcid WHERE ( (type IN ('product')) OR (pcid IS NOT NULL ) )"); + db_set_active(); + } + if (isset($result)) { + foreach($result as $row) { + $types[$row->type] = $row->type; + } + } + $target_types = commerce_product_types(); + foreach($types as $type) { + if (isset($target_types[$type])) { + $product_arguments[] = array( + 'machine_name' => 'CommerceMigrateUbercartProduct' . ucfirst($type), + 'class_name' => 'CommerceMigrateUbercartProductMigration', + 'description' => t('Import products from Ubercart.'), + 'type' => $type, + ); + $products[] = 'CommerceMigrateUbercartProduct' . ucfirst($type); + } + else { + drupal_set_message(t("Product type :type does not exist. Create it to enable migrations of this type, then go to the configuration page and click 're-register statically-defined classes.'", array(':type' => $row->type)), 'warning'); + } + } + + /** + * Product Nodes + */ + if (isset($products)) { + foreach($types as $type) { + $dependency_name = 'CommerceMigrateUbercartProduct' . ucfirst($type); + $node_arguments[] = array( + 'machine_name' => 'CommerceMigrateUbercartNode' . ucfirst($type), + 'class_name' => 'CommerceMigrateUbercartNodeMigration', + 'description' => t('Import nodes from Ubercart.'), + 'dependencies' => array($dependency_name), + 'type' => $type, + 'products' => $products, + ); + } + } + + /** + * Orders + */ + $order_arguments = $common_arguments + array( + 'class_name' => 'CommerceMigrateUbercartOrderMigration', + 'description' => t('Import orders from Ubercart.'), + 'dependencies' => array('CommerceMigrateUbercartCustomerBillingProfile'), + ); + + /** + * Line Items + */ + if ($configured != FALSE) { + if (isset($products)) { + $line_item_arguments = $common_arguments + array( + 'class_name' => 'CommerceMigrateUbercartLineItem', + 'description' => t('Import order line items from Ubercart.'), + 'dependencies' => array('CommerceMigrateUbercartOrder'), + 'products' => $products, + ); + } + } + + /** + * Register all the classes + */ + $api = array( + 'api' => 2, + 'groups' => array( + 'commerce_ubercart' => array( + 'title' => t('Commerce Migrate Ubercart'), + ), + ), + ); + + if ($configured != FALSE) { + $api['migrations'] = array( + 'CommerceMigrateUbercartCustomerBillingProfile' => $customer_billing_arguments, + 'CommerceMigrateUbercartOrder' => $order_arguments, + ); + + if (isset($products)) { + + $api['migrations']['CommerceMigrateUbercartLineItem'] = $line_item_arguments; + + // Register all the product migrations + foreach ($product_arguments as $arguments) { + $arguments = array_merge_recursive($arguments, $common_arguments); + $api['migrations'][$arguments['machine_name']] = $arguments; + } + + // Register all the node migrations + foreach ($node_arguments as $arguments) { + $arguments = array_merge_recursive($arguments, $common_arguments); + $api['migrations'][$arguments['machine_name']] = $arguments; + } + } + } + + return $api; +} diff --git a/commerce_migrate_ubercart.module b/commerce_migrate_ubercart.module index b30b55c..11ea1a9 100644 --- a/commerce_migrate_ubercart.module +++ b/commerce_migrate_ubercart.module @@ -7,7 +7,7 @@ define('SOURCE_DATABASE_DRUPAL_VERSION', variable_get('commerce_migrate_ubercart function commerce_migrate_ubercart_menu() { $items['admin/content/migrate/ubercart_migration_options'] = array( 'title' => 'Configure Ubercart Migration', - 'description' => 'Database and filesystem configuration for Commerce Migrate Ubercart', + 'description' => 'Database configuration for Commerce Migrate Ubercart', 'type' => MENU_LOCAL_TASK, 'page callback' => 'drupal_get_form', 'page arguments' => array('commerce_migrate_ubercart_admin_form'), @@ -26,15 +26,6 @@ function commerce_migrate_ubercart_menu() { function commerce_migrate_ubercart_entity_info_alter(&$entity_info) { unset($entity_info['commerce_order']['locking mode']); } -/* - * Implements hook_migrate_api(). - */ -function commerce_migrate_ubercart_migrate_api() { - $api = array( - 'api' => 2, - ); - return $api; -} /** * Administrative form to set migration options. @@ -55,25 +46,6 @@ function commerce_migrate_ubercart_admin_form($form, &$form_state) { ), '#default_value' => variable_get('commerce_migrate_ubercart_source_database_api_version', 'd7'), ); - $form['commerce_migrate_ubercart_image_fields'] = array( - '#type' => 'textfield', - '#title' => t('Source Imagefield types to be migrated'), - '#description' => t('Comma-delimited list of machine names of image-type fields to be migrated. For many Ubercart versions this may be field_image_cache (D6 direct import or D7 migrated from D6) or uc_product_image (D7 installed fresh)'), - '#default_value' => variable_get('commerce_migrate_ubercart_image_fields', 'field_image_cache'), - ); - $form['commerce_migrate_ubercart_public_files_directory'] = array( - '#type' => 'textfield', - '#title' => t('Relative or absolute path to the public files directory used for Ubercart images'), - '#description' => t('Enter a path like /path/to/files which indicates where the source Ubercart files directory can be found. This is used for images in a Drupal 7 source.'), - '#default_value' => variable_get('commerce_migrate_ubercart_public_files_directory', variable_get('file_public_path', 'sites/default/files')), - ); - $form['commerce_migrate_ubercart_source_drupal_root'] = array( - '#type' => 'textfield', - '#title' => t('Relative or absolute path to the root of the source Drupal installation'), - '#description' => t('Enter a path like /path/to/files which indicates DRUPAL_ROOT of the source files. This is used to obtain image locations in a Drupal 6 source.'), - '#default_value' => variable_get('commerce_migrate_ubercart_source_drupal_root', DRUPAL_ROOT), - ); - $filters = filter_formats(); foreach ($filters as $machine_name => $info) { $options[$machine_name] = $info->name; @@ -119,19 +91,18 @@ function commerce_migrate_ubercart_admin_form_validate($form, &$form_state) { else { try { $connection = Database::getConnection('default', $migration_source_db); + $query = $connection->select('uc_product_classes', 'upc') + ->fields('upc', array('pcid')) + ->countQuery()->execute()->fetchField(); } catch (Exception $e) { form_set_error('commerce_migrate_ubercart_source_database', t('The database key $databases["%key"] is not functional (Exception message %msg', array('%key' => $migration_source_db, '%msg' => $e->getMessage()))); } $x = 1; } - - $ubercart_public_filepath = $form_state['values']['commerce_migrate_ubercart_public_files_directory']; - - if (!file_exists($ubercart_public_filepath)) { - form_set_error('commerce_migrate_ubercart_public_files_directory', t('The directory %dir does not exist.', array('%dir' => $ubercart_public_filepath))); - } + migrate_static_registration(); } + /** * Decide whether we have an external database and return the correct connection. * diff --git a/customer_billing_profile.inc b/customer_billing_profile.inc index 65a229e..3bb32aa 100644 --- a/customer_billing_profile.inc +++ b/customer_billing_profile.inc @@ -8,9 +8,8 @@ */ class CommerceMigrateUbercartCustomerBillingProfileMigration extends Migration { - public function __construct() { - parent::__construct(); - $this->description = t('Import customer billing profiles from Ubercart.'); + public function __construct(array $arguments) { + parent::__construct($arguments); // Create a map object for tracking the relationships between source rows $this->map = new MigrateSQLMap($this->machineName, diff --git a/line_item.inc b/line_item.inc index 068a3b5..01cd42f 100644 --- a/line_item.inc +++ b/line_item.inc @@ -10,10 +10,8 @@ */ class CommerceMigrateUbercartLineItem extends Migration { - public function __construct() { - parent::__construct(); - $this->description = t('Import order line items from Ubercart.'); - $this->dependencies = array('CommerceMigrateUbercartOrder'); + public function __construct(array $arguments) { + parent::__construct($arguments); // Create a map object for tracking the relationships between source rows $this->map = new MigrateSQLMap($this->machineName, @@ -48,9 +46,7 @@ class CommerceMigrateUbercartLineItem extends Migration { $this->addFieldMapping('commerce_total', 'price'); $this->addFieldMapping('commerce_product', 'nid') ->defaultValue(0) - ->sourceMigration(CommerceMigrateUbercartProductMigration::getProductMigrations()); - // @todo - //$this->addFieldMapping('commerce_display_path', ''); + ->sourceMigration($arguments['products']); } function prepare($line_item, stdClass $row) { @@ -97,5 +93,4 @@ class CommerceMigrateUbercartLineItem extends Migration { ->condition('commerce_line_items_line_item_id', $line_item_id) ->execute(); } - } diff --git a/order.inc b/order.inc index 087bba9..8b23b9f 100644 --- a/order.inc +++ b/order.inc @@ -6,10 +6,8 @@ */ class CommerceMigrateUbercartOrderMigration extends Migration { - public function __construct() { - parent::__construct(); - $this->description = t('Import orders from Ubercart.'); - $this->dependencies = array('CommerceMigrateUbercartCustomerBillingProfile'); + public function __construct(array $arguments) { + parent::__construct($arguments); // Create a map object for tracking the relationships between source rows $this->map = new MigrateSQLMap($this->machineName, diff --git a/product.inc b/product.inc index 1a49371..28c84bb 100644 --- a/product.inc +++ b/product.inc @@ -7,23 +7,10 @@ * (so that products of each type can be imported separately) */ -class CommerceMigrateUbercartProductMigration extends DynamicMigration { - - protected $file_public_path = ""; - protected $file_private_path = ""; - protected $file_temporary_path = ""; - protected $source_drupal_root = ""; - protected $image_fields = ""; +class CommerceMigrateUbercartProductMigration extends Migration { public function __construct(array $arguments) { - $this->arguments = $arguments; - parent::__construct(); - $this->description = t('Import products from Ubercart.'); - $this->dependencies = array('CommerceMigrateUbercartProductType'); - $this->image_fields = preg_split('/ *[, ]+ */', variable_get('commerce_migrate_ubercart_image_fields', 'field_image_cache')); - - $this->file_public_path = variable_get('commerce_migrate_ubercart_public_files_directory', variable_get('file_public_path', 'sites/default/files')); - $this->source_drupal_root = variable_get('commerce_migrate_ubercart_source_drupal_root', DRUPAL_ROOT); + parent::__construct($arguments); // Create a map object for tracking the relationships between source rows $this->map = new MigrateSQLMap($this->machineName, @@ -38,6 +25,7 @@ class CommerceMigrateUbercartProductMigration extends DynamicMigration { ), MigrateDestinationEntityAPI::getKeySchema('commerce_product', $arguments['type']) ); + // Create a MigrateSource object, which manages retrieving the input data. $connection = commerce_migrate_ubercart_get_source_connection(); $query = $connection->select('node', 'n'); @@ -57,7 +45,7 @@ class CommerceMigrateUbercartProductMigration extends DynamicMigration { // Properties $this->addFieldMapping('sku', 'model'); $this->addFieldMapping('type', 'type') - ->sourceMigration('CommerceMigrateUbercartProductType'); + ->defaultValue($arguments['type']); $this->addFieldMapping('title', 'title'); $this->addFieldMapping('created', 'created'); $this->addFieldMapping('changed', 'changed'); @@ -69,123 +57,10 @@ class CommerceMigrateUbercartProductMigration extends DynamicMigration { $this->addFieldMapping('uid', 'uid')->defaultValue(0); } $this->addFieldMapping('status') - ->defaultValue(1); - $this->addFieldMapping('product_id')->issueGroup(t('DNM')); - $this->addFieldMapping('path')->issueGroup(t('DNM')); + ->defaultValue(1); + $this->addFieldMapping(NULL, 'product_id')->issueGroup(t('DNM')); + $this->addFieldMapping(NULL, 'path')->issueGroup(t('DNM')); // Fields $this->addFieldMapping('commerce_price', 'sell_price'); - $this->addFieldMapping('field_commerce_file_s3', 'commerce_file_s3') - ->arguments(array( - 'skip_source_file_check' => TRUE, - 'preserve_files' => TRUE, - 'file_function' => 'file_link', - )); - foreach($this->image_fields as $field) { - $this->addFieldMapping($field, $field) - ->arguments(array( - 'file_function' => 'file_copy', - 'file_replace' => FILE_EXISTS_REPLACE, - )); - } - // @todo: This entire section should be overridden in a subclass - if (module_exists('commerce_migrate_uc_file_s3')) { - $this->addFieldMapping('field_commerce_file_s3', 'commerce_file_s3') - ->arguments(array( - 'skip_source_file_check' => TRUE, - 'preserve_files' => TRUE, - 'file_function' => 'file_link', - )); - } - } - - public function prepareRow($row) { - - // Prepare the imagefields, from http://drupal.org/node/1159234 - $connection = commerce_migrate_ubercart_get_source_connection(); - - foreach ($this->image_fields as $fieldname) { - - switch (SOURCE_DATABASE_DRUPAL_VERSION) { - case 'd7': - $query = $connection->select("field_data_$fieldname", 'img'); - $query->innerJoin('file_managed', 'f', "img.{$fieldname}_fid = f.fid"); - $query->fields('f', array('fid', 'uri')); - $query->fields('img', array("{$fieldname}_alt", "{$fieldname}_title")); - $query->condition('img.entity_id', $row->nid) - ->condition('img.revision_id', $row->vid); - break; - case 'd6': - $query = $connection->select("content_{$fieldname}", 'img'); - $query->innerJoin('files', 'f', "{$fieldname}_fid = f.fid"); - $query->addField('f', 'filepath', 'uri'); // Pretend it's D7 uri. - $query->addField('f', 'fid', 'fid'); - $query->addField('img', "{$fieldname}_data"); - $query->condition('img.nid', $row->nid) - ->condition('img.vid', $row->vid); - break; - } - - $result = $query->execute(); - foreach ($result as $image_row) { - $path = $image_row->uri; - // We have to munge the path because migrate's 'source_path' doesn't - // really work right with streamwrapper paths. - switch (SOURCE_DATABASE_DRUPAL_VERSION) { - case 'd7': - $path = str_replace('public://', $this->file_public_path . '/', $path); - break; - case 'd6': - $path = $this->source_drupal_root . '/' . $path; - break; - } - $row->{$fieldname}[] = $path; - } - } - // @todo: MUST be moved into a subclass! - // module existence. But for now, this will have to do it. - if (module_exists('commerce_migrate_uc_file_s3')) { - // Prepare the commerce_file fields - $query = $connection->select('uc_product_features', 'upf') - ->condition('upf.fid', 'file_s3'); - $query->innerJoin('node', 'n', 'upf.nid = n.nid'); - $query->leftJoin('uc_file_s3_products', 'ufsp', 'upf.pfid = ufsp.pfid'); - $query->innerJoin('uc_files_s3', 'ufs', 'ufs.fid = ufsp.fid'); - $query->fields('n', array('nid', 'vid', 'type', 'title', 'created', 'changed')) - ->fields('ufsp', array('model', 'description', 'download_limit', 'address_limit', 'time_quantity')) - ->fields('ufs', array('filename')) - ->distinct(); - $query->condition('n.nid', $row->nid) - ->condition('n.vid', $row->vid); - $result = $query->execute(); - foreach ($result as $file_row) { - $path = 's3://' . $file_row->filename; - $value = array( - 'path' => $path, - 'download_limit' => $file_row->download_limit, - 'address_limit' => $file_row->address_limit, - 'duration' => $file_row->time_quantity, - ); - $row->commerce_file_s3[] = drupal_json_encode($value); - } - } - } - - /** - * Return a list of all product migrations. - */ - public static function getProductMigrations() { - $migrations = array(); - foreach (commerce_product_types() as $type => $product_type) { - $migrations[] = 'CommerceMigrateUbercartProduct' . ucfirst($type); - } - return $migrations; - } - - - /** - * Construct the machine name (identifying the migration in "drush ms" and other places). - */ - protected function generateMachineName($class_name = NULL) { - return 'CommerceMigrateUbercartProduct' . ucfirst($this->arguments['type']); } } diff --git a/product_node.inc b/product_node.inc index ad2ee30..8034e26 100644 --- a/product_node.inc +++ b/product_node.inc @@ -5,21 +5,14 @@ * Commerce Product Display Node migration. * This is a dynamic migration, reused for every product type * (so that products of each type can be imported separately) - * @todo Migrate the product image. - * @todo Do we want a node type per ubercart product class? */ -class CommerceMigrateUbercartNodeMigration extends DynamicMigration { +class CommerceMigrateUbercartNodeMigration extends Migration { // An array mapping D6 format names to this D7 databases formats. public $filter_format_mapping = array(); public function __construct(array $arguments) { - $this->arguments = $arguments; - parent::__construct(); - $this->description = t('Import product nodes from Ubercart.'); - $dependency_name = 'CommerceMigrateUbercartProduct' . ucfirst($this->arguments['type']); - $this->dependencies = array($dependency_name); - + parent::__construct($arguments); // Create a map object for tracking the relationships between source rows $this->map = new MigrateSQLMap($this->machineName, array( @@ -67,12 +60,12 @@ class CommerceMigrateUbercartNodeMigration extends DynamicMigration { $this->destination = new MigrateDestinationNode('product_display'); // Properties - // Default uid to 0 if we're not mapping it. + // Default uid to 1 if we're not mapping it. if (variable_get('commerce_migrate_ubercart_user_map_ok', FALSE)) { - $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('commerce_migrate_ubercart_user_migration_class', ""))->defaultValue(0); + $this->addFieldMapping('uid', 'uid')->sourceMigration(variable_get('commerce_migrate_ubercart_user_migration_class', ""))->defaultValue(1); } else { - $this->addFieldMapping('uid', 'uid')->defaultValue(0); + $this->addFieldMapping('uid', 'uid')->defaultValue(1); } $this->addFieldMapping('title', 'title'); $this->addFieldMapping('created', 'created'); @@ -83,14 +76,13 @@ class CommerceMigrateUbercartNodeMigration extends DynamicMigration { // We have no idea of which type the referenced product is, so // we specify all (for the sourceMigration). $this->addFieldMapping('field_product', 'nid') - ->sourceMigration(CommerceMigrateUbercartProductMigration::getProductMigrations()); + ->sourceMigration($arguments['products']); - $arguments = MigrateTextFieldHandler::arguments(array('source_field' => 'body_summary'), - array('source_field' => 'body_format'), - array('source_field' => 'language')); $this->addFieldMapping('body', 'body_value') - ->arguments($arguments) ->defaultValue(''); + $this->addFieldMapping('body:summary'); + $this->addFieldMapping('body:format', 'body_format'); + $this->addFieldMapping('body:language')->defaultValue('UND'); } public function prepareRow($row) { @@ -137,22 +129,4 @@ class CommerceMigrateUbercartNodeMigration extends DynamicMigration { } return variable_get('commerce_migrate_ubercart_default_filter_format', 'plain_text'); } - - /** - * Return a list of all product migrations. - */ - public static function getProductNodeMigrations() { - $migrations = array(); - foreach (commerce_product_types() as $type => $product_type) { - $migrations[] = 'CommerceMigrateUbercartNode' . ucfirst($type); - } - return $migrations; - } - - /** - * Construct the machine name (identifying the migration in "drush ms" and other places). - */ - protected function generateMachineName($class_name = NULL) { - return 'CommerceMigrateUbercartNode' . ucfirst($this->arguments['type']); - } } diff --git a/product_type.inc b/product_type.inc deleted file mode 100644 index 5945019..0000000 --- a/product_type.inc +++ /dev/null @@ -1,89 +0,0 @@ -description = t('Import product types from Ubercart.'); - - // Create a map object for tracking the relationships between source rows - $this->map = new MigrateSQLMap($this->machineName, - array( - 'type' => array('type' => 'varchar', - 'length' => 32, - 'not null' => TRUE, - 'description' => 'The node type identifier.', - ), - ), - MigrateDestinationCommerceProductType::getKeySchema() - ); - - // This nastiness grabs all the 'product' types named in the - // uc_product_classes table and adds to it the 'product' type, if it - // exists in the node table. It evaluates to - // SELECT DISTINCT n.type AS type, ucp.pcid AS pcid, ucp.name AS name, ucp.description AS description - // FROM - // {node} n - // LEFT OUTER JOIN {uc_product_classes} ucp ON n.type = ucp.pcid - // WHERE ( (type IN ('product')) OR (pcid IS NOT NULL ) ) - - $connection = commerce_migrate_ubercart_get_source_connection(); - $query = $connection->select('node', 'n') - ->fields('n', array('type')) - ->distinct(); - - $query->leftJoin('uc_product_classes', 'ucp', 'n.type = ucp.pcid'); - $query->addField('ucp', 'pcid'); - $query->addField('ucp', 'name'); - $query->addField('ucp', 'description'); - $query->condition( - db_or() - ->condition('type', array('product'), 'IN') - ->isNotNull('pcid')); - $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); - $this->destination = new MigrateDestinationCommerceProductType(); - - $this->addFieldMapping('type', 'type'); - $this->addFieldMapping('name', 'name')->defaultValue(t('Product')); - $this->addFieldMapping('description', 'description')->defaultValue(t('A basic Product')); - } - - function prepare($type, stdClass $row) { - // Based on this, the save function selects between an INSERT and an UPDATE. - // Done here instead of in the plugin so that an UPDATE could be done by changing - // the line bellow. - $type->is_new = TRUE; - } - - /** - * A new type has been created, create necessary imagefields and register the - * appropriate migrations. - */ - public function complete($entity, stdClass $row) { - $type = $entity->type; - - $image_fields = preg_split('/ *, */', variable_get('commerce_migrate_ubercart_image_fields', 'image_field')); - foreach ($image_fields as $fieldname) { - MigrateDestinationCommerceProductType::createFieldImageInstance($type, $fieldname); - } - - $product_migration = 'CommerceMigrateUbercartProduct' . ucfirst($type); - $node_migration = 'CommerceMigrateUbercartNode' . ucfirst($type); - Migration::registerMigration('CommerceMigrateUbercartProductMigration', $product_migration, array('type' => $type)); - Migration::registerMigration('CommerceMigrateUbercartNodeMigration', $node_migration, array('type' => $type)); - } - - /** - * The type has been deleted, deregister the migration. - */ - public function completeRollback($type) { - $product_migration = 'CommerceMigrateUbercartProduct' . ucfirst($type); - $node_migration = 'CommerceMigrateUbercartNode' . ucfirst($type); - Migration::deregisterMigration($product_migration); - Migration::deregisterMigration($node_migration); - } -}