Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have created my class and when I import it, +I got the same error for all entities. Please tell me how can I import XML entity to drupal 7???
Comments
Comment #1
singhrt CreditAttribution: singhrt commented<?php
class ItemOrderXMLMigration extends XMLMigration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('OrderFeed'));
$this->description = t('XML feed (multi items) of OrderFeed');
//$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'));
}
}
Comment #2
andrewmacpherson CreditAttribution: andrewmacpherson commentedCleaning up tags, moving this text to the main description field.
Comment #3
andrewmacpherson CreditAttribution: andrewmacpherson commented@artisingh
Much of this code looks like it was taken from the documentation.
The crucial line which you need to change is:
$this->destination = new MigrateDestinationEntityAPI('entity_example_basic','first_example_bundle');
This is because you need to say what kind of Drupal Entity you are migrating your data into. Usually this will be a Node type, but could be something else like a Commerce Product or a User. This failed because Drupal doesn't know about the 'entity_example_basic' Entity type.
If you were migrating into Drupal Nodes, you would use the MigrateDestinationNode class, something like this ('article' is the node type):
$this->destination = new MigrateDestinationNode('article');
You would only use MigrateDestinationEntityAPI class if you were migrating into entity types based on the Entity API contrib module.
Comment #4
andrewmacpherson CreditAttribution: andrewmacpherson commentedI also ran into this error. In my case I'm trying to migrate into privatemsg_message entities (from the Private Messages module). I'm using MigrateDestinationEntityAPI.
I don't fully understand it yet, but I think the problem is down to having incomplete entity_info defined for the privatemsg_message entity, either in hook_entity_info() or hook_entity_property_info().
My migration is registering, and I can see my field mappings in migrate UI. I had to add 'setter callback' for a few things (ike timestamp) using hook_entity_property_info_alter() in my custom migration module.
Comment #5
singhrt CreditAttribution: singhrt commented