0

When running drush migrate-import with --idlist option I got this error:

$ drush mi BeersMigration --update --idlist='1001' -d
...
Importing 'BeersMigration' migration [1.2 sec, 30.83 MB]                                                                                                       [notice]
Migration failed with source plugin exception: Invalid argument supplied for foreach()                                                                     [error]
File .../sites/all/modules/contrib/migrate/plugins/sources/xml.inc, line 718 [8.31 sec, 32.55 MB]

(Drush Version : 6.2.0)

Code and source

Migrate class

class BeersMigration extends XMLMigration {
  public function __construct($arguments) {
    parent::__construct($arguments);

    $fields = array(
      'id' => t('Beer ID'),
      'name' => t('Title'),
      );

    $xml_folder = DRUPAL_ROOT . '/' .
    drupal_get_path('module', 'migrate_beers') . '/xml/';
    $urls= array();
    foreach (glob($xml_folder."/*.xml") as $filename) {
      array_push($urls, $filename);
    }

    $item_xpath = '/catalog/beerList/beer';
    $item_ID_xpath = '@beerID';

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

    $this->destination = new MigrateDestinationNode('node', array('text_format' => 'full_html'));

    $this->map = new MigrateSQLMap($this->machineName,
      array(
        'sourceid' => array(
          'type' => 'varchar',
          'length' => 255,
          ),
        ),
      MigrateDestinationNode::getKeySchema()
      );

    $this->addFieldMapping('field_source_id', 'id')
    ->xpath('@beerID');
    $this->addFieldMapping('title', 'name')
    ->xpath('beerName');
  }
}

Source xml

<?xml version="1.0" encoding="utf-8"?>
<catalog>
  <beerList>
    <beer beerID="1001" lastModified="2013-12-30 11:03:51">
      <beerName>Legado de yuste</beerName>
      <beerDates>
        <beerDate date="10/02/2014" time="10:00" dateEnd="10/02/2014" timeEnd="12:00"/>
      </beerDates>
    </beer>
    <beer beerID="1002" lastModified="2013-12-1 12:03:51">
      <beerName>Estrella Galicia</beerName>
      <beerDates>
        <beerDate date="10/02/2014" time="10:00" dateEnd="10/02/2014" timeEnd="12:00"/>
        <beerDate date="12/02/2014" time="10:00" dateEnd="12/02/2014" timeEnd="13:00"/>
      </beerDates>
    </beer>
  </beerList>
</catalog>

I only got this error when using the drush option --idlist. If I run the migration without --idlist option everything works fine.

I want to migrate an specific item for debugging. Using the source id and the --idlist option always gave me this error. I review the code, however even with the simply code above it shows me the same error.

  • Can you post your migration code? And some sample XML. Also ensure that the xml file is been loaded and contains data. – benjy Feb 10 '14 at 23:17
  • Any thoughts about this? It only happens when using --idlist option. Question is updated. – Miguelos Feb 26 '14 at 16:31
  • Make sure you actually have an XML element under /catalog/beerList/beer called sourceid with the value 1001? Also, what is the -d part? Maybe put that before the --idlist. – benjy Feb 27 '14 at 0:07
  • There is an element with sourceid 1001. The part -d is for showing debug messages. It doesn't affect the behaviour. – Miguelos Mar 17 '14 at 14:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.