class MigrateSourceList in Migrate 7.2
Same name and namespace in other branches
- 6.2 plugins/sources/list.inc \MigrateSourceList
Implementation of MigrateSource, providing the semantics of iterating over IDs provided by a MigrateList and retrieving data from a MigrateItem.
Hierarchy
- class \MigrateSource implements \Iterator
- class \MigrateSourceList
Expanded class hierarchy of MigrateSourceList
File
- plugins/
sources/ list.inc, line 81 - Support for migration from sources with distinct means of listing items to import and obtaining the items themselves.
View source
class MigrateSourceList extends MigrateSource {
/**
* MigrateList object used to obtain ID lists.
*
* @var MigrateList
*/
protected $listClass;
/**
* MigrateItem object used to obtain the source object for a given ID.
*
* @var MigrateItem
*/
protected $itemClass;
/**
* Iterator of IDs from the listing class.
*
* @var Iterator
*/
protected $idIterator;
/**
* List of available source fields.
*
* @var array
*/
protected $fields = array();
/**
* Simple initialization.
*/
public function __construct(MigrateList $list_class, MigrateItem $item_class, $fields = array(), $options = array()) {
parent::__construct($options);
$this->listClass = $list_class;
$this->itemClass = $item_class;
$this->fields = $fields;
}
/**
* Return a string representing the source.
*
* @return string
*/
public function __toString() {
return (string) $this->listClass;
}
/**
* Return MigrateList object used to obtain ID lists.
*
* @return MigrateList
*/
public function listClass() {
return $this->listClass;
}
/**
* 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->listClass, 'computeCount')) {
return $this->listClass
->computeCount();
}
else {
return $this->listClass
->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->listClass
->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()) {
$ids = $this->idIterator
->current();
$this->idIterator
->next();
// Skip empty IDs
if (empty($ids)) {
continue;
}
// Got a good ID, get the data and get out.
$row = $this->itemClass
->getItem($ids);
if ($row) {
// No matter what $ids is, be it a string, integer, object, or array, we
// cast it to an array so that it can be properly mapped to the source
// keys as specified by the map. This is done after getItem is called so
// that the ItemClass doesn't have to care about this requirement.
$ids = (array) $ids;
foreach (array_keys($this->activeMap
->getSourceKey()) as $key_name) {
// Grab the first id and advance the array cursor. Then save the ID
// using the map source key - it will be used for mapping.
$id = current($ids);
next($ids);
$row->{$key_name} = $id;
}
break;
}
}
return $row;
}
/**
* Overrides MigrateSource::hash().
*/
protected function hash($row) {
// Let the item class override the default hash function.
if (method_exists($this->itemClass, 'hash')) {
$hash = $this->itemClass
->hash($row);
}
else {
$hash = parent::hash($row);
}
return $hash;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateSource:: |
protected | property | The MigrateMap class for the current migration. | |
MigrateSource:: |
protected | property | The Migration class currently invoking us, during rewind() and next(). | |
MigrateSource:: |
protected | property | Whether this instance should cache the source count. | |
MigrateSource:: |
protected | property | Key to use for caching counts. | |
MigrateSource:: |
protected | property | The primary key of the current row | |
MigrateSource:: |
protected | property | The current row from the quey | |
MigrateSource:: |
protected | property | Information on the highwater mark for the current migration, if any. | |
MigrateSource:: |
protected | property | List of source IDs to process. | |
MigrateSource:: |
protected | property | By default, next() will directly read the map row and add it to the data row. A source plugin implementation may do this itself (in particular, the SQL source can incorporate the map table into the query) - if so, it should set this TRUE so we… | |
MigrateSource:: |
protected | property | Used in the case of multiple key sources that need to use idlist. | |
MigrateSource:: |
protected | property | Number of rows intentionally ignored (prepareRow() returned FALSE) | |
MigrateSource:: |
protected | property | Number of rows we've at least looked at. | 1 |
MigrateSource:: |
protected | property | The highwater mark at the beginning of the import operation. | |
MigrateSource:: |
protected | property | Whether this instance should not attempt to count the source. | |
MigrateSource:: |
protected | property | If TRUE, we will maintain hashed source rows to determine whether incoming data has changed. | |
MigrateSource:: |
public | function | Return a count of available source records, from the cache if appropriate. Returns -1 if the source is not countable. | |
MigrateSource:: |
public | function | Implementation of Iterator::current() - called when entering a loop iteration, returning the current row | |
MigrateSource:: |
protected | function | Determine whether this row has changed, and therefore whether it should be processed. | |
MigrateSource:: |
public | function | ||
MigrateSource:: |
public | function | ||
MigrateSource:: |
public | function | ||
MigrateSource:: |
public | function | Implementation of Iterator::key - called when entering a loop iteration, returning the key of the current row. It must be a scalar - we will serialize to fulfill the requirement, but using getCurrentKey() is preferable. | |
MigrateSource:: |
public | function | Implementation of Iterator::next() - subclasses of MigrateSource should implement getNextRow() to retrieve the next valid source rocord to process. | |
MigrateSource:: |
protected | function | Give the calling migration a shot at manipulating, and possibly rejecting, the source row. | |
MigrateSource:: |
public | function | Reset numIgnored back to 0. | |
MigrateSource:: |
public | function | Implementation of Iterator::rewind() - subclasses of MigrateSource should implement performRewind() to do any class-specific setup for iterating source records. | |
MigrateSource:: |
public | function | Implementation of Iterator::valid() - called at the top of the loop, returning TRUE to process the loop and FALSE to terminate it | |
MigrateSourceList:: |
protected | property | List of available source fields. | |
MigrateSourceList:: |
protected | property | Iterator of IDs from the listing class. | |
MigrateSourceList:: |
protected | property | MigrateItem object used to obtain the source object for a given ID. | |
MigrateSourceList:: |
protected | property | MigrateList object used to obtain ID lists. | |
MigrateSourceList:: |
public | function | It's the list class that knows how many records are available, so ask it. | |
MigrateSourceList:: |
public | function |
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. Overrides MigrateSource:: |
|
MigrateSourceList:: |
public | function | Implementation of MigrateSource::getNextRow(). | |
MigrateSourceList:: |
protected | function |
Overrides MigrateSource::hash(). Overrides MigrateSource:: |
|
MigrateSourceList:: |
public | function | Return MigrateList object used to obtain ID lists. | |
MigrateSourceList:: |
public | function | Implementation of MigrateSource::performRewind(). | |
MigrateSourceList:: |
public | function |
Simple initialization. Overrides MigrateSource:: |
|
MigrateSourceList:: |
public | function | Return a string representing the source. |