itemsClass = $items_class; $this->fields = $fields; } /** * Return a string representing the source. * * @return string */ public function __toString() { return (string) $this->itemsClass; } /** * Returns a list of fields available to be mapped from the source query. * Since we can't reliably figure out what "fields" are in the source, * it's up to the implementing Migration constructor to fill them in. * * @return array * Keys: machine names of the fields (to be passed to addFieldMapping) * Values: Human-friendly descriptions of the fields. */ public function fields() { return $this->fields; } /** * It's the list class that knows how many records are available, so ask it. * * @return int */ public function computeCount() { // @API: Support old count method for now. if (method_exists($this->itemsClass, 'computeCount')) { return $this->itemsClass->computeCount(); } else { return $this->itemsClass->count(); } } /** * Implementation of MigrateSource::performRewind(). * * @return void */ public function performRewind() { // If there isn't a specific ID list passed in, get it from the list class. if ($this->idList) { $this->idsToProcess = $this->idList; } else { $this->idsToProcess = $this->itemsClass->getIdList(); } $this->idIterator = ($this->idsToProcess instanceof Iterator) ? $this->idsToProcess : new ArrayIterator($this->idsToProcess); $this->idIterator->rewind(); } /** * Implementation of MigrateSource::getNextRow(). * * @return null|stdClass */ public function getNextRow() { $row = NULL; while ($this->idIterator->valid()) { $id = $this->idIterator->current(); $this->idIterator->next(); // Skip empty IDs if (empty($id)) { continue; } // Got a good ID, get the data and get out. $row = $this->itemsClass->getItem($id); if ($row) { // Save the ID using the map source key - it will be used for mapping $sourceKey = $this->activeMap->getSourceKey(); $key_name = key($sourceKey); $row->$key_name = $id; } break; } return $row; } }