Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / migrate / source / d6 / TermNode.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Source returning tids from the term_node table for the current revision.
10  *
11  * @MigrateSource(
12  *   id = "d6_term_node",
13  *   source_provider = "taxonomy"
14  * )
15  */
16 class TermNode extends DrupalSqlBase {
17
18   /**
19    * The join options between the node and the term node table.
20    */
21   const JOIN = 'tn.vid = n.vid';
22
23   /**
24    * {@inheritdoc}
25    */
26   public function query() {
27     $query = $this->select('term_node', 'tn')
28       ->distinct()
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);
34     return $query;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function fields() {
41     return [
42       'nid' => $this->t('The node revision ID.'),
43       'vid' => $this->t('The node revision ID.'),
44       'tid' => $this->t('The term ID.'),
45     ];
46   }
47
48   /**
49    * {@inheritdoc}
50    */
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);
60   }
61
62   /**
63    * {@inheritdoc}
64    */
65   public function getIds() {
66     $ids['vid']['type'] = 'integer';
67     $ids['vid']['alias'] = 'tn';
68     return $ids;
69   }
70
71 }