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..e614ac7 100644 --- a/commerce_migrate_ubercart.info +++ b/commerce_migrate_ubercart.info @@ -16,5 +16,5 @@ 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 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.module b/commerce_migrate_ubercart.module index b30b55c..74f6bdf 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. @@ -45,6 +36,7 @@ function commerce_migrate_ubercart_admin_form($form, &$form_state) { '#title' => t('Source database key in settings.php'), '#description' => t('The source database key in settings.php that describes an external database from which the import should be done. If left as "default" the default database will be used (and it must have all the Ubercart tables in it.)'), '#default_value' => variable_get('commerce_migrate_ubercart_source_database', 'default'), + '#required' => true, ); $form['commerce_migrate_ubercart_source_database_api_version'] = array( '#type' => 'select', @@ -55,25 +47,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; @@ -101,7 +74,18 @@ function commerce_migrate_ubercart_admin_form($form, &$form_state) { 'visible' => array( ':input[name=commerce_migrate_ubercart_user_map_ok]' => array('checked' => TRUE) )), + ); + foreach (commerce_customer_profile_types() as $type => $profile_type) { + $cust_options[$profile_type['type']] = $profile_type['name']; + } + $form['commerce_migrate_ubercart_customer_profile_type'] = array( + '#type' => 'select', + '#title' => t('Commerce customer profile type'), + '#description' => t('It is possible to have more than one customer profile type in Drupal Commerce. Select the one you want to use for the incoming data.'), + '#options' => $cust_options, + '#default_value' => variable_get('commerce_migrate_ubercart_customer_profile_type', ''), + '#required' => true, ); return system_settings_form($form); @@ -119,19 +103,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..f70c64e 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, @@ -32,10 +31,10 @@ class CommerceMigrateUbercartCustomerBillingProfileMigration extends Migration { $query->leftJoin('uc_countries', 'uc', 'uo.billing_country = uc.country_id'); $query->leftJoin('uc_zones', 'uz', 'uo.billing_zone = uz.zone_id'); $query->fields('uo', array('order_id', 'billing_first_name', 'billing_last_name', - 'billing_company', 'billing_street1', + 'billing_company', 'billing_street1', 'billing_street2', 'billing_city', 'billing_postal_code', 'delivery_first_name', 'delivery_last_name', - 'delivery_company', 'delivery_street1', + 'delivery_company', 'delivery_street1', 'delivery_street2', 'delivery_city', 'delivery_postal_code', 'created')); $query->fields('uc', array('country_iso_code_2')); @@ -63,7 +62,7 @@ class CommerceMigrateUbercartCustomerBillingProfileMigration extends Migration { } public function prepare($profile, stdClass $row) { - $profile->type = 'billing'; + $profile->type = variable_get('commerce_migrate_ubercart_customer_profile_type', 'billing'); $profile->status = TRUE; // We'll use the billing name and address from ubercart if there is a @@ -80,6 +79,8 @@ class CommerceMigrateUbercartCustomerBillingProfileMigration extends Migration { $profile->commerce_customer_address[LANGUAGE_NONE][0] = array( 'xnl' => '' . $name . '', 'name_line' => $name, + 'first_name' => $row->first_name, + 'last_name' => $row->last_name, 'administrative_area' => $row->zone_code, 'country' => !empty($row->country_iso_code_2) ? $row->country_iso_code_2 : 'US', 'thoroughfare' => $row->street1, 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..c577542 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, @@ -64,8 +62,13 @@ class CommerceMigrateUbercartOrderMigration extends Migration { // Most order statuses (pending, cancelled, completed) are the same // between the two systems. However, some are not. if ($order->status == 'payment_received') { - // @todo Revisit this, these two statuses are not really the same. - $order->status = 'checkout_payment'; + $order->status = 'processing'; + } + if ($order->status == 'in_checkout') { + $order->status = 'checkout_checkout'; + } + if ($order->status == 'paypal_pending') { + $order->status = 'pending'; } } diff --git a/product.inc b/product.inc index 1a49371..e694124 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,11 +25,12 @@ 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'); $query->innerJoin('uc_products', 'ucp', 'n.nid = ucp.nid AND n.vid = ucp.vid'); - $query->fields('n', array('nid', 'vid', 'type', 'title', 'created', 'changed')) + $query->fields('n', array('nid', 'vid', 'type', 'title', 'created', 'changed', 'status')) ->fields('ucp', array('model', 'sell_price')) ->condition('n.type', $arguments['type']) ->distinct(); @@ -50,6 +38,12 @@ class CommerceMigrateUbercartProductMigration extends DynamicMigration { $query->addField('n', 'uid', 'uid'); } + // Only deals with one currency, but at least trys to detect what one. + $currency_code_setting = $connection->select('variable', 'v') + ->fields('v', array('value')) + ->condition('v.name', 'uc_currency_code') + ->execute()->fetchField(); + $this->source = new MigrateSourceSQL($query, array(), NULL, array('map_joinable' => FALSE)); $this->destination = new MigrateDestinationEntityAPI('commerce_product', $arguments['type']); @@ -57,7 +51,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'); @@ -68,124 +62,23 @@ class CommerceMigrateUbercartProductMigration extends DynamicMigration { else { $this->addFieldMapping('uid', 'uid')->defaultValue(0); } - $this->addFieldMapping('status') - ->defaultValue(1); - $this->addFieldMapping('product_id')->issueGroup(t('DNM')); - $this->addFieldMapping('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) { + // Probably unnecessary but we should respect the status of the old products. + $this->addFieldMapping('status', 'status') + ->defaultValue(1); - // Prepare the imagefields, from http://drupal.org/node/1159234 - $connection = commerce_migrate_ubercart_get_source_connection(); + $this->addFieldMapping('language', NULL)->defaultValue(LANGUAGE_NONE); - foreach ($this->image_fields as $fieldname) { + $this->addFieldMapping(NULL, 'vid')->issueGroup(t('DNM')); + $this->addFieldMapping('path')->issueGroup(t('DNM')); - 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; - } + $this->addFieldMapping('commerce_price', 'sell_price'); - $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); - } + if ($currency_code_setting == NULL) { + $this->addFieldMapping('commerce_price:currency_code', NULL)->defaultValue('USD'); } - } - - /** - * 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); + else { + $this->addFieldMapping('commerce_price:currency_code', NULL)->defaultValue($currency_code_setting); } - 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..deaa695 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,30 +60,31 @@ 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'); $this->addFieldMapping('changed', 'changed'); + + // This gets mapped later on in prepareRow as $row->path. $this->addFieldMapping('path', 'path')->defaultValue(NULL); // Fields // 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 +131,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); - } -}