View source
<?php
namespace Drupal\node\Plugin\migrate\source\d7;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
class Node extends FieldableEntity {
const JOIN = 'n.vid = nr.vid';
public function query() {
$query = $this
->select('node_revision', 'nr')
->fields('n', array(
'nid',
'type',
'language',
'status',
'created',
'changed',
'comment',
'promote',
'sticky',
'tnid',
'translate',
))
->fields('nr', array(
'vid',
'title',
'log',
'timestamp',
));
$query
->addField('n', 'uid', 'node_uid');
$query
->addField('nr', 'uid', 'revision_uid');
$query
->innerJoin('node', 'n', static::JOIN);
if (isset($this->configuration['node_type'])) {
$query
->condition('type', $this->configuration['node_type']);
}
return $query;
}
public function prepareRow(Row $row) {
foreach (array_keys($this
->getFields('node', $row
->getSourceProperty('type'))) as $field) {
$nid = $row
->getSourceProperty('nid');
$vid = $row
->getSourceProperty('vid');
$row
->setSourceProperty($field, $this
->getFieldValues('node', $field, $nid, $vid));
}
return parent::prepareRow($row);
}
public function fields() {
$fields = array(
'nid' => $this
->t('Node ID'),
'type' => $this
->t('Type'),
'title' => $this
->t('Title'),
'node_uid' => $this
->t('Node authored by (uid)'),
'revision_uid' => $this
->t('Revision authored by (uid)'),
'created' => $this
->t('Created timestamp'),
'changed' => $this
->t('Modified timestamp'),
'status' => $this
->t('Published'),
'promote' => $this
->t('Promoted to front page'),
'sticky' => $this
->t('Sticky at top of lists'),
'revision' => $this
->t('Create new revision'),
'language' => $this
->t('Language (fr, en, ...)'),
'tnid' => $this
->t('The translation set id for this node'),
'timestamp' => $this
->t('The timestamp the latest revision of this node was created.'),
);
return $fields;
}
public function getIds() {
$ids['nid']['type'] = 'integer';
$ids['nid']['alias'] = 'n';
return $ids;
}
}