public function MigrateSource::next in Migrate 7.2
Same name and namespace in other branches
- 6.2 includes/source.inc \MigrateSource::next()
Implementation of Iterator::next() - subclasses of MigrateSource should implement getNextRow() to retrieve the next valid source rocord to process.
1 call to MigrateSource::next()
- MigrateSource::rewind in includes/
source.inc - Implementation of Iterator::rewind() - subclasses of MigrateSource should implement performRewind() to do any class-specific setup for iterating source records.
File
- includes/
source.inc, line 281 - Define base for migration sources.
Class
- MigrateSource
- Abstract base class for source handling.
Code
public function next() {
$this->currentKey = NULL;
$this->currentRow = NULL;
migrate_instrument_start(get_class($this) . ' getNextRow');
while ($row = $this
->getNextRow()) {
migrate_instrument_stop(get_class($this) . ' getNextRow');
// Populate the source key for this row
$this->currentKey = $this->activeMigration
->prepareKey($this->activeMap
->getSourceKey(), $row);
// Pick up the existing map row, if any, unless getNextRow() did it.
if (!$this->mapRowAdded) {
$map_row = $this->activeMap
->getRowBySource($this->currentKey);
// Add map info to the row, if present
if ($map_row) {
foreach ($map_row as $field => $value) {
$field = 'migrate_map_' . $field;
$row->{$field} = $value;
}
}
}
// First, determine if this row should be passed to prepareRow(), or
// skipped entirely. The rules are:
// 1. If there's an explicit idlist, that's all we care about (ignore
// highwaters and map rows).
$prepared = FALSE;
if (!empty($this->idList)) {
// Check first source key.
if (!in_array(reset($this->currentKey), $this->idList)) {
// If this is a compound source key, check the full key.
$compoundKey = implode($this->multikeySeparator, $this->currentKey);
if (count($this->currentKey) == 1 || !in_array($compoundKey, $this->idList)) {
// Could not find the key, skip.
continue;
}
}
}
elseif (!isset($row->migrate_map_sourceid1)) {
// Fall through
}
elseif ($row->migrate_map_needs_update == MigrateMap::STATUS_NEEDS_UPDATE) {
// Fall through
}
elseif (empty($this->highwaterField)) {
if ($this->trackChanges) {
if ($this
->prepareRow($row) !== FALSE) {
if ($this
->dataChanged($row)) {
// This is a keeper
$this->currentRow = $row;
break;
}
else {
// No change, skip it.
continue;
}
}
else {
// prepareRow() told us to skip it.
continue;
}
}
else {
// No highwater and not tracking changes, skip.
continue;
}
}
elseif ($this->originalHighwater === '') {
// Fall through
}
else {
// Call prepareRow() here, in case the highwaterField needs preparation
if ($this
->prepareRow($row) !== FALSE) {
if ($row->{$this->highwaterField['name']} > $this->originalHighwater) {
$this->currentRow = $row;
break;
}
else {
// Skip
continue;
}
}
$prepared = TRUE;
}
// Allow the Migration to prepare this row. prepareRow() can return boolean
// FALSE to ignore this row.
if (!$prepared) {
if ($this
->prepareRow($row) !== FALSE) {
// Finally, we've got a keeper.
$this->currentRow = $row;
break;
}
else {
$this->currentRow = NULL;
}
}
}
migrate_instrument_stop(get_class($this) . ' getNextRow');
if (!$this->currentRow) {
$this->currentKey = NULL;
}
}