I've been tearing my hair out for the last six hours on this.

I'm migrating a legacy shopping cart system to Drupal Commerce. After upgrading to 2.4 and re-writing all of the code for file migrations, one of my migrations is failing to link during sourceMigration.

The basic setup is: user, a commerce_order entity, and a commerce_billing_profile entity.
- VEUserMigration runs successfully.
- VEOrderBillingProfileMigration runs successfully and populates the map table and the values here are what I expect for sourceid1 and destid1. I don't know if this has any relevance to #1270668: Source Migration destination of multi field mapping is not looked up properly if provided as simple array as I see my migrate_map_veorderbillingprofile has a destid1, destid2 when it should only have destid1?
- VEOrderMigration runs successfully with no notices, but there are no rows created in field_data_commerce_customer_billing, which was mapped with:

    $this->addFieldMapping('commerce_customer_billing', 'user_id')
          ->sourceMigration('VEOrderBillingProfile');

Nothing seems to get set for this value no matter what I try ... defaultValues, etc.

My full migration is here: http://codepad.org/Gek8RAuK

Could you give me a hint as to where I should be looking? Thanks in advance.

CommentFileSizeAuthor
#3 entity_api_schema-1605050-3.patch524 bytesmikeryan

Comments

aidanlis’s picture

Note: I rolled back to the EntityAPI MigrationDestination from commerce_migrate, as the one bundled in migrate_extras doesn't include half the fields that I want to use: #1604916: Missing setter callbacks for commerce_payment_transaction

mikeryan’s picture

Project: Migrate » Migrate Extras
Component: Code » Entity API
Category: support » bug

The original Entity API handler had getKeySchema defined as a regular method rather than a static method, which is how MigrateDestination (the root class) defines it. I made it static without looking closely - it uses a non-existent $this, so yeah, that's going to cause problems. I need to figure out what problems removing the static keyword will cause...

mikeryan’s picture

Status: Active » Needs review
StatusFileSize
new524 bytes

Please give this a try.

aidanlis’s picture

I don't notice any difference, but I'm thinking the problem is not about the key schema ... it's completely failing to write any field values. The native columns on the table are fine, but the fieldable values aren't being written.

E.g. for a commerce_line_item entity, I need to put this in my complete():


    // write to each of the entity's fields directly

    // link the line item to the order
    db_insert('field_data_commerce_line_items')
      ->fields(array(
        'entity_id' => $line_item->order_id,
        'revision_id' => $line_item->order_id,
        'entity_type' => 'commerce_order',
        'bundle' => 'commerce_order',
        'deleted' => 0,
        'language' => LANGUAGE_NONE,
        'delta' => $delta,
        'commerce_line_items_line_item_id' => $line_item->line_item_id,
      ))
      ->execute();

    // commerce_product
    db_insert('field_data_commerce_product')
      ->fields(array(
        'entity_id' => $line_item->line_item_id,
        'revision_id' => $line_item->line_item_id,
        'entity_type' => 'commerce_line_item',
        'bundle' => 'product',
        'deleted' => 0,
        'language' => LANGUAGE_NONE,
        'delta' => $delta,
        'commerce_product_product_id' => $row->product_id,
      ))
      ->execute();

    // commerce_unit_price
    db_insert('field_data_commerce_unit_price')
      ->fields(array(
        'entity_id' => $line_item->line_item_id,
        'revision_id' => $line_item->line_item_id,
        'entity_type' => 'commerce_line_item',
        'bundle' => 'product',
        'deleted' => 0,
        'language' => LANGUAGE_NONE,
        'delta' => $delta,
        'commerce_unit_price_amount' => $row->payment_amount,
        'commerce_unit_price_currency_code' => 'AUD',
      ))
      ->execute();

This wasn't necessary in 2.3 ... any idea what the problematic change could be?

aidanlis’s picture

dupe

jlenni’s picture

probably the same problem. My Media migration doesn't migrate (after upgrade from 2.3->2.4rc1) custom fields on the image entity...

<?php
class NewsMediaMigration extends NewsMigration {
  public function __construct() {
    parent::__construct();
    $this->description = t('News Image(Media) Migration');

    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'n_id' => array(
          'type' => 'varchar',
          'length' => 128,
          'not null' => TRUE,
          )
      ),
    MigrateDestinationMedia::getKeySchema()
    );

    $query = db_select('news', 'n')
    ->fields('p', array('n_id', 'n_img', 'n_img_text', 'n_img_source'))
    ->condition('n_img', '', '!=')
    

    $this->source = new MigrateSourceSQL($query);
    $this->destination = new MigrateDestinationMedia('image');

    $this->addFieldMapping('source_dir')->defaultValue('sites/default/files/newsimages/');

    // Mapped fields
    $this->addFieldMapping('value', 'n_img');

    // @TODO this mapping fails !!!
    $this->addFieldMapping('field_image_caption', 'n_img_text');
    $this->addFieldMapping('field_image_source', 'n_img_source');

  }
}
?>
aidanlis’s picture

Thank goodness it's not just me. I was tearing my hair out.

mikeryan’s picture

jlenni's issue is specific to file/media fields - see #1614318: New file handling loses fields. I have no explanation for the commerce_migrate issue at this time.

mikeryan’s picture

@jlenni - your problem should be fixed in Migrate 2.4.

aidanlis’s picture

Status: Needs review » Active

I re-tried your patch on the latest -dev and I get 100s of array_flip errors suggesting the entities are not being created at all.

mikeryan’s picture

Status: Active » Fixed

Ultimately, removing the static seems the lesser evil.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dave reid’s picture