class MigrateDestinationNodeRevision in Migrate 7.2
Allows you to import revisions.
Adapted from http://www.darrenmothersele.com/blog/2012/07/16/migrating-node-revisions...
Class MigrateDestinationNodeRevision
@author darrenmothersele @author cthos
Hierarchy
- class \MigrateDestination
- class \MigrateDestinationEntity
- class \MigrateDestinationNode
- class \MigrateDestinationEntity
Expanded class hierarchy of MigrateDestinationNodeRevision
File
- plugins/
destinations/ node.inc, line 336 - Support for node destinations.
View source
class MigrateDestinationNodeRevision extends MigrateDestinationNode {
/**
* Basic initialization.
*
* @see parent::__construct
*
* @param string $bundle
* A.k.a. the content type (page, article, etc.) of the node.
* @param array $options
* Options applied to nodes.
*/
public function __construct($bundle, array $options = array()) {
parent::__construct($bundle, $options);
$this->bypassDestIdCheck = TRUE;
}
/**
* Get key schema for the node revision destination.
*
* @see MigrateDestination::getKeySchema
*
* @return array
* Returns the key schema.
*/
public static function getKeySchema() {
return array(
'vid' => array(
'type' => 'int',
'unsigned' => TRUE,
'description' => 'ID of destination node revision',
),
);
}
/**
* Returns additional fields on top of node destinations.
*
* @param string $migration
* Active migration
*
* @return array
* Fields.
*/
public function fields($migration = NULL) {
$fields = parent::fields($migration);
$fields['vid'] = t('Node: <a href="@doc">Revision (vid)</a>', array(
'@doc' => 'http://drupal.org/node/1298724',
));
return $fields;
}
/**
* Rolls back any versions that have been created.
*
* @param array $vids
* Version ids to roll back.
*/
public function bulkRollback(array $vids) {
migrate_instrument_start('revision_delete_multiple');
$this
->prepareRollback($vids);
$nids = array();
foreach ($vids as $vid) {
if ($revision = node_load(NULL, $vid)) {
db_delete('node_revision')
->condition('vid', $revision->vid)
->execute();
module_invoke_all('node_revision_delete', $revision);
field_attach_delete_revision('node', $revision);
$nids[$revision->nid] = $revision->nid;
}
}
$this
->completeRollback($vids);
foreach ($nids as $nid) {
$vid = db_select('node_revision', 'nr')
->fields('nr', array(
'vid',
))
->condition('nid', $nid, '=')
->execute()
->fetchField();
if (!empty($vid)) {
db_update('node')
->fields(array(
'vid' => $vid,
))
->condition('nid', $nid, '=')
->execute();
}
}
migrate_instrument_stop('revision_delete_multiple');
}
/**
* Overridden import method.
*
* This is done because parent::import will return the nid of the newly
* created nodes. This is bad since the migrate_map_* table will have
* nids instead of vids, which could cause a nightmare explosion on
* rollback.
*
* @param stdClass $node
* Populated entity.
*
* @param stdClass $row
* Source information in object format.
*
* @return array|bool
* Array with newly created vid, or FALSE on error.
*
* @throws MigrateException
*/
public function import(stdClass $node, stdClass $row) {
// We're importing revisions, this should be set.
$node->revision = 1;
if (empty($node->nid)) {
throw new MigrateException(t('Missing incoming nid.'));
}
$original_updated = $this->numUpdated;
parent::import($node, $row);
// Reset num updated and increment created since new revision is always an update.
$this->numUpdated = $original_updated;
$this->numCreated++;
if (empty($node->vid)) {
return FALSE;
}
return array(
$node->vid,
);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MigrateDestination:: |
protected | property | Maintain stats on the number of destination objects created or updated. | |
MigrateDestination:: |
protected | property | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | ||
MigrateDestination:: |
public | function | Reset numCreated and numUpdated back to 0. | |
MigrateDestinationEntity:: |
protected | property | The bundle (node type, vocabulary, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | The entity type (node, user, taxonomy_term, etc.) of the destination. | |
MigrateDestinationEntity:: |
protected | property | Default language for text fields in this destination. | |
MigrateDestinationEntity:: |
protected | property | Default input format for text fields in this destination. | |
MigrateDestinationEntity:: |
public static | function | Flattens an array of allowed values. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object (or taking additional action) after saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up after an entity has been rolled back. | |
MigrateDestinationEntity:: |
public static | function | Perform field validation against the field data in an entity. Wraps field_attach_validate to handle exceptions cleanly and provide maximum information for identifying the cause of validation errors. | |
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | ||
MigrateDestinationEntity:: |
public | function | Give handlers a shot at modifying the object before saving it. | |
MigrateDestinationEntity:: |
public | function | Give handlers a shot at cleaning up before an entity has been rolled back. | |
MigrateDestinationEntity:: |
public | function |
Derived classes must implement __toString(). Overrides MigrateDestination:: |
|
MigrateDestinationNode:: |
protected | property | ||
MigrateDestinationNode:: |
public static | function | Return an options array for node destinations. | |
MigrateDestinationNodeRevision:: |
public | function |
Rolls back any versions that have been created. Overrides MigrateDestinationNode:: |
|
MigrateDestinationNodeRevision:: |
public | function |
Returns additional fields on top of node destinations. Overrides MigrateDestinationNode:: |
|
MigrateDestinationNodeRevision:: |
public static | function |
Get key schema for the node revision destination. Overrides MigrateDestinationNode:: |
|
MigrateDestinationNodeRevision:: |
public | function |
Overridden import method. Overrides MigrateDestinationNode:: |
|
MigrateDestinationNodeRevision:: |
public | function |
Basic initialization. Overrides MigrateDestinationNode:: |