3 namespace Drupal\taxonomy\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Source returning tids from the term_node table for the current revision.
12 * id = "d6_term_node",
13 * source_provider = "taxonomy"
16 class TermNode extends DrupalSqlBase {
19 * The join options between the node and the term node table.
21 const JOIN = 'tn.vid = n.vid';
26 public function query() {
27 $query = $this->select('term_node', 'tn')
29 ->fields('tn', ['nid', 'vid'])
30 ->fields('n', ['type']);
31 // Because this is an inner join it enforces the current revision.
32 $query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]);
33 $query->innerJoin('node', 'n', static::JOIN);
40 public function fields() {
42 'nid' => $this->t('The node revision ID.'),
43 'vid' => $this->t('The node revision ID.'),
44 'tid' => $this->t('The term ID.'),
51 public function prepareRow(Row $row) {
52 // Select the terms belonging to the revision selected.
53 $query = $this->select('term_node', 'tn')
54 ->fields('tn', ['tid'])
55 ->condition('n.nid', $row->getSourceProperty('nid'));
56 $query->join('node', 'n', static::JOIN);
57 $query->innerJoin('term_data', 'td', 'td.tid = tn.tid AND td.vid = :vid', [':vid' => $this->configuration['vid']]);
58 $row->setSourceProperty('tid', $query->execute()->fetchCol());
59 return parent::prepareRow($row);
65 public function getIds() {
66 $ids['vid']['type'] = 'integer';
67 $ids['vid']['alias'] = 'tn';