abstract class DrupalVersion in Drupal-to-Drupal data migration 7.2
There should be an implementation of this abstract class, named DrupalVersion{version #}, for each Drupal version supported as a source. It will implement any functions needed by multiple version-specific classes (e.g., nodes as well as users).
Hierarchy
- class \DrupalVersion
Expanded class hierarchy of DrupalVersion
1 string reference to 'DrupalVersion'
- DrupalMigration::__construct in ./
migrate_d2d.migrate.inc - Required arguments:
File
- ./
migrate_d2d.migrate.inc, line 243 - Base classes for all Drupal-to-Drupal migration classes.
View source
abstract class DrupalVersion {
/**
* Arguments for the containing migration. Primarily of interest for
* the source_connection.
*
* @var array
*/
protected $arguments;
/**
* An array of information on CCK/core fields.
*
* @var array
* key - field -name
* value - array of information:
* label: User-visible description of the field
* type: type of the field
* columns: array of database columns for the field
*/
protected $sourceFieldInfo = array();
public function getSourceFieldInfo() {
return $this->sourceFieldInfo;
}
/**
* The entity type (node, user, etc.)
*
* @var string
*/
protected $entityType;
/**
* The bundle (node type pre-D7) - article, blog, etc.
*
* @var string
*/
protected $bundle;
/**
* Pass the migration class arguments through to the version class.
*
* @param $arguments
*/
public function __construct($arguments) {
$this->arguments = $arguments;
}
/**
* @abstract
* Returns an array keyed by the source system's format identifier (integer ID
* or machine name), with the destination Drupal 7 machine name as the value.
*/
public abstract function getDefaultFormatMappings();
/**
* @abstract
* Given a source path (e.g., node/1234 or user/35), return the alias from
* the source database.
*
* @param $pattern
* @param $id
*/
public abstract function getPath($source);
/**
* @abstract
* Return the names and labels of all custom fields (CCK pre-D7, core fields
* D7 and later) attached to the given entity type and bundle.
*
* @param $entity_type
* Type of entity ('node', 'user', etc.) for which to retrieve field info.
* @param $bundle
* Bundle within the entity type (e.g., 'article', 'blog', etc.).
* @param $include_body
* Treat a node body as if it were a custom field (for supporting
* content_profile).
*
* @return array
* An array keyed by field name, with field labels as the values.
*/
public function getSourceFields($entity_type, $bundle, $include_body = FALSE) {
$this
->populateSourceFieldInfo($entity_type, $bundle);
$fields = array();
foreach ($this->sourceFieldInfo as $field_name => $info) {
$fields[$field_name] = $info['label'];
$i = 0;
if (isset($info['columns'])) {
foreach ($info['columns'] as $display_name => $column_name) {
// We skip the first column, which we've covered with the field name
// itself.
if ($i > 0) {
$fields[$display_name] = t('!label subfield', array(
'!label' => $info['label'],
));
}
$i++;
}
}
}
return $fields;
}
/**
* Get any core profile values associated with this user.
*
* @param $row
* @param $entity_id
*/
public function getProfileValues($row, $entity_id) {
$query = Database::getConnection('default', $this->arguments['source_connection'])
->select('profile_values', 'v')
->fields('v', array(
'value',
))
->condition('uid', $entity_id)
->condition('value', '', '<>');
$query
->innerJoin('profile_fields', 'f', 'v.fid=f.fid');
$query
->fields('f', array(
'name',
'type',
));
$result = $query
->execute();
foreach ($result as $data_row) {
switch ($data_row->type) {
case 'checkbox':
switch (trim(strtolower($data_row->value))) {
case 'n':
$data_row->value = 0;
break;
case 'y':
$data_row->value = 1;
break;
default:
break;
}
break;
case 'date':
// Dates may be serialized arrays or NULLs.
if (strpos($data_row->value, 'a:') === 0) {
$date_array = unserialize($data_row->value);
$data_row->value = $date_array['year'] . '-' . $date_array['month'] . '-' . $date_array['day'];
}
elseif (strpos($data_row->value, 'N;') === 0) {
$data_row->value = NULL;
}
break;
}
$row->{$data_row->name} = $data_row->value;
}
return $row;
}
/**
* @abstract
* Add CCK/core field values to the source row.
*
* @param $row
* @param $entity_id
*
* @return array
*/
public abstract function getSourceValues($row, $entity_id);
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DrupalVersion:: |
protected | property | Arguments for the containing migration. Primarily of interest for the source_connection. | |
DrupalVersion:: |
protected | property | The bundle (node type pre-D7) - article, blog, etc. | |
DrupalVersion:: |
protected | property | The entity type (node, user, etc.) | |
DrupalVersion:: |
protected | property | An array of information on CCK/core fields. | |
DrupalVersion:: |
abstract public | function | @abstract Returns an array keyed by the source system's format identifier (integer ID or machine name), with the destination Drupal 7 machine name as the value. | 3 |
DrupalVersion:: |
abstract public | function | @abstract Given a source path (e.g., node/1234 or user/35), return the alias from the source database. | 3 |
DrupalVersion:: |
public | function | Get any core profile values associated with this user. | 3 |
DrupalVersion:: |
public | function | ||
DrupalVersion:: |
public | function | @abstract Return the names and labels of all custom fields (CCK pre-D7, core fields D7 and later) attached to the given entity type and bundle. | |
DrupalVersion:: |
abstract public | function | @abstract Add CCK/core field values to the source row. | 3 |
DrupalVersion:: |
public | function | Pass the migration class arguments through to the version class. |