Hi All,

I'm trying to figure out a way to extract all source item ids list in a unified way for all sourceList classes.

$migration = Migration::getInstance($migration_name);
$source = $migration->getSource();

Source is a iterator so I should be able to loop:

foreach ($source as $row) {
  // Do stuff
}

But I get this exception: Call to a member function getMap() on a non-object in /sites/all/modules/contrib/migrate/includes/source.inc on line 253
(I'm using a MigrateSourceXML class).

Digging into code the reason is that the MigrateSource implementation of rewind uses the current Migration:

public function rewind() {
    $this->activeMigration = Migration::currentMigration();
    $this->activeMap = $this->activeMigration->getMap();
    ... 
}

The current migration variable is set and unset after the method is called in some Migration & MigrationBase methods like:

- beginProcess:

protected function beginProcess($newStatus) {
    // So hook_watchdog() knows what migration (if any) is running
    self::$currentMigration = $this;

- Analyze:

analyze() {
    // The source needs this to find the map table.
    self::$currentMigration = $this;
}

Is there any way to set the currentMigration using current api?

Is there any other approach to loop into source list?

Thanks!

Comments

GeduR created an issue. See original summary.

GeduR’s picture

Title: Retrieve source item list in a common way » Retrieve full source items list in a unified way