Upgraded drupal core with security updates
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / migrate / source / Term.php
1 <?php
2
3 namespace Drupal\taxonomy\Plugin\migrate\source;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Taxonomy term source from database.
10  *
11  * @todo Support term_relation, term_synonym table if possible.
12  *
13  * @MigrateSource(
14  *   id = "taxonomy_term",
15  *   source_provider = "taxonomy"
16  * )
17  *
18  * @deprecated in Drupal 8.3.0, intended to be removed in Drupal 9.0.0.
19  *   Use \Drupal\taxonomy\Plugin\migrate\source\d6\Term or
20  *   \Drupal\taxonomy\Plugin\migrate\source\d7\Term.
21  *
22  * @see https://www.drupal.org/node/2879193
23  */
24 class Term extends DrupalSqlBase {
25
26   /**
27    * Name of the term data table.
28    *
29    * @var string
30    */
31   protected $termDataTable;
32
33   /**
34    * Name of the term hierarchy table.
35    *
36    * @var string
37    */
38   protected $termHierarchyTable;
39
40   /**
41    * {@inheritdoc}
42    */
43   public function query() {
44     if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
45       $this->termDataTable = 'taxonomy_term_data';
46       $this->termHierarchyTable = 'taxonomy_term_hierarchy';
47     }
48     else {
49       $this->termDataTable = 'term_data';
50       $this->termHierarchyTable = 'term_hierarchy';
51     }
52
53     $query = $this->select($this->termDataTable, 'td')
54       ->fields('td')
55       ->distinct()
56       ->orderBy('td.tid');
57
58     if (isset($this->configuration['vocabulary'])) {
59       $query->condition('td.vid', (array) $this->configuration['vocabulary'], 'IN');
60     }
61
62     return $query;
63   }
64
65   /**
66    * {@inheritdoc}
67    */
68   public function fields() {
69     $fields = [
70       'tid' => $this->t('The term ID.'),
71       'vid' => $this->t('Existing term VID'),
72       'name' => $this->t('The name of the term.'),
73       'description' => $this->t('The term description.'),
74       'weight' => $this->t('Weight'),
75       'parent' => $this->t("The Drupal term IDs of the term's parents."),
76     ];
77     if ($this->getModuleSchemaVersion('taxonomy') >= 7000) {
78       $fields['format'] = $this->t('Format of the term description.');
79     }
80     return $fields;
81   }
82
83   /**
84    * {@inheritdoc}
85    */
86   public function prepareRow(Row $row) {
87     // Find parents for this row.
88     $parents = $this->select($this->termHierarchyTable, 'th')
89       ->fields('th', ['parent', 'tid'])
90       ->condition('tid', $row->getSourceProperty('tid'))
91       ->execute()
92       ->fetchCol();
93     $row->setSourceProperty('parent', $parents);
94
95     return parent::prepareRow($row);
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   public function getIds() {
102     $ids['tid']['type'] = 'integer';
103     return $ids;
104   }
105
106 }