abstract class MigrateSourceReference in Relation 7
Same name and namespace in other branches
- 8.2 relation_migrate/relation_migrate.source.inc \MigrateSourceReference
- 8 relation_migrate/relation_migrate.source.inc \MigrateSourceReference
Migration source for *ference field. This source is primary used in relation_migrate to convert *reference entries into relation entities.
Hierarchy
- class \MigrateSource implements \Iterator
- class \MigrateSourceReference
Expanded class hierarchy of MigrateSourceReference
File
- relation_migrate/
relation_migrate.source.inc, line 12 - Source plugin for *reference fields.
View source
abstract class MigrateSourceReference extends MigrateSource {
/**
* Place where data is stored during import.
*/
protected $result = array();
/**
* ID of a row, that will be imported during next iteration.
*/
protected $next_row = 0;
/**
* Machine names of fields that will be imported.
*/
protected $fields = array();
/**
* Field type.
*/
protected $field_type;
/**
* Constructor.
*
* @param string $field Field type machine name.
* @param array $fields List of fields to be migrated.
*/
public function __construct($field_type, array $fields, array $options = array()) {
parent::__construct($options);
$this->fields = $fields;
$this->field_type = $field_type;
}
/**
* Return a string representing the source, for display in the UI.
*/
public function __toString() {
return t('Migrate %type fields: %fields', array(
'%type' => $this->field_type,
'%fields' => implode(',', $this->fields),
));
}
/**
* Returns a list of fields available to be mapped from the source,
* keyed by field name.
*/
public function fields() {
return array(
'source_type' => t('Source entity type'),
'source_id' => t('Source entity ID'),
'destination_type' => t('Destination entity type'),
'destination_id' => t('Destination entity ID'),
'field_name' => t('Field name'),
);
}
/**
* Return the number of available source records.
*/
public function computeCount() {
$rows_count = 0;
foreach ($this->fields as $field_name) {
$rows_count += db_query('SELECT count(*) FROM {field_data_' . $field_name . '} WHERE deleted = 0')
->fetchField();
}
return $rows_count;
}
/**
* Do whatever needs to be done to start a fresh traversal of the source data.
*/
public function performRewind() {
$this->result = array();
$this->next_row = 0;
// Load data for each field and merge all records in result array.
foreach ($this->fields as $field_name) {
$field_info = field_info_field($field_name);
$columns = array_keys($field_info['columns']);
if (!empty($field_info) && $field_info['type'] == $this->field_type) {
$field_data = db_select('field_data_' . $field_name, 'f')
->fields('f', array(
'entity_type',
'entity_id',
'delta',
$field_name . '_' . $columns[0],
))
->condition('deleted', 0);
$field_data
->addExpression(":name", 'field_name', array(
':name' => $field_name,
));
$field_data = $field_data
->execute()
->fetchAll();
$this->result = array_merge($this->result, $field_data);
}
}
}
/**
* Constructs row object, that should be returned from $this->getNextRow().
*
* @param stdClass $item Row item as returned from DB.
* @param string $destination_type Destiantion entity type.
* @param string $field_name Field's machine name.
*/
protected function _constructRow(stdClass $item, $destination_type, $field_name) {
$field_info = field_info_field($field_name);
$columns = array_keys($field_info['columns']);
$id_key = $field_name . '_' . $columns[0];
$ret = array(
'source_type' => $item->entity_type,
'source_id' => $item->entity_id,
'destination_type' => $destination_type,
'destination_id' => $item->{$id_key},
'field_name' => $field_name,
'delta' => $item->delta,
);
return (object) $ret;
}
}
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:: |
protected | function | Generate a hash of the source row. | 3 |
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 | |
MigrateSourceReference:: |
protected | property | Machine names of fields that will be imported. | |
MigrateSourceReference:: |
protected | property | Field type. | |
MigrateSourceReference:: |
protected | property | ID of a row, that will be imported during next iteration. | |
MigrateSourceReference:: |
protected | property | Place where data is stored during import. | |
MigrateSourceReference:: |
public | function | Return the number of available source records. | |
MigrateSourceReference:: |
public | function |
Returns a list of fields available to be mapped from the source,
keyed by field name. Overrides MigrateSource:: |
|
MigrateSourceReference:: |
public | function | Do whatever needs to be done to start a fresh traversal of the source data. | |
MigrateSourceReference:: |
protected | function | Constructs row object, that should be returned from $this->getNextRow(). | |
MigrateSourceReference:: |
public | function |
Constructor. Overrides MigrateSource:: |
4 |
MigrateSourceReference:: |
public | function | Return a string representing the source, for display in the UI. |