如何使用迁移模块将实体从XML迁移到Drupal 7

时间:2014-12-09 07:02:48

标签: php drupal-7 migration

我使用迁移模块创建了一个类,但我无法迁移实体。我的班级代码在下面请检查并告诉我它的问题是什么?

<?php
class ItemOrderXMLMigration extends XMLMigration {
  public function __construct() {
    parent::__construct(MigrateGroup::getInstance('OrderFeed'));
    $this->description = t('Migrate entity from XML file');

    //$this->softDependencies = array('WineFileCopy');

    $fields = array(
      'Number' => t('Number'),
      'Date' => t('Date'),
      'SubTotal' => t('Sub Total'),
      'Discount' => t('Discount'),
      'ShippingCharges' => t('Shipping Charges'),
      'ShippingChargesDiscount' => t('Shipping Charges Discount'),
      'NumItems' => t('NumItems'),
      'VATPercentage' => t('VAT Percentage'),
      'CurrencyCode' => t('Currency Code'),
      'PaymentTypeDesc' => t('Payment Type Desc'),
      'OrderState' => t('Order State'),
    );

    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'Number' => array(
          'type' => 'varchar',
          'length' => 225,
          'not null' => TRUE,
        )
      ),
      MigrateDestinationEntityAPI::getKeySchema('entity_example_basic','first_example_bundle')
    );

    $xml_folder = DRUPAL_ROOT . '/' . drupal_get_path('module', 'products_import') . '/xml/';
    $items_url = $xml_folder . 'OrderFeed.xml';
    $item_xpath = '/Orders/Item';  // relative to document
    $item_ID_xpath = 'Number';         // relative to item_xpath and gets assembled
                                         // into full path /producers/producer/sourceid

    $items_class = new MigrateItemsXML($items_url, $item_xpath, $item_ID_xpath);
    $this->source = new MigrateSourceMultiItems($items_class, $fields);

    $this->destination = new MigrateDestinationEntityAPI('entity_example_basic','first_example_bundle');

    $this->addFieldMapping('field_number', 'Number')
         ->xpath('Number');
    $this->addFieldMapping('field_subtotal', 'SubTotal')
         ->xpath('SubTotal');
    $this->addFieldMapping('field_discount', 'Discount')
         ->xpath('Discount');
    //$this->addUnmigratedDestinations(array('weight'));
  }
}
?>

当我导入它时,我收到了所有实体的保存错误消息:从空值创建默认对象文件/var/www/mig/migration/sites/all/modules/migrate_extras/entity_api.inc,第227行

2 个答案:

答案 0 :(得分:1)

尝试使用最新或更新的迁移模块https://www.drupal.org/project/migrate。我认为你使用的旧版本有一些问题需要迁移实体。

答案 1 :(得分:0)

为什么不使用Feeds module模块尝试使用Feed导入程序(XPath parser)?它非常简单,您可以使用上传的文件或源URL。