b8a603d0fed2b9632e4f13927e3b584dfa2330e4
[yaffs-website] / web / core / modules / taxonomy / src / Plugin / migrate / source / d6 / Term.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  * Taxonomy term source from database.
10  *
11  * @todo Support term_relation, term_synonym table if possible.
12  *
13  * @MigrateSource(
14  *   id = "d6_taxonomy_term",
15  *   source_provider = "taxonomy"
16  * )
17  */
18 class Term extends DrupalSqlBase {
19
20   /**
21    * {@inheritdoc}
22    */
23   public function query() {
24     $query = $this->select('term_data', 'td')
25       ->fields('td')
26       ->distinct()
27       ->orderBy('td.tid');
28
29     if (isset($this->configuration['bundle'])) {
30       $query->condition('td.vid', (array) $this->configuration['bundle'], 'IN');
31     }
32
33     return $query;
34   }
35
36   /**
37    * {@inheritdoc}
38    */
39   public function fields() {
40     $fields = [
41       'tid' => $this->t('The term ID.'),
42       'vid' => $this->t('Existing term VID'),
43       'name' => $this->t('The name of the term.'),
44       'description' => $this->t('The term description.'),
45       'weight' => $this->t('Weight'),
46       'parent' => $this->t("The Drupal term IDs of the term's parents."),
47     ];
48     return $fields;
49   }
50
51   /**
52    * {@inheritdoc}
53    */
54   public function prepareRow(Row $row) {
55     // Find parents for this row.
56     $parents = $this->select('term_hierarchy', 'th')
57       ->fields('th', ['parent', 'tid'])
58       ->condition('tid', $row->getSourceProperty('tid'))
59       ->execute()
60       ->fetchCol();
61     $row->setSourceProperty('parent', $parents);
62
63     return parent::prepareRow($row);
64   }
65
66   /**
67    * {@inheritdoc}
68    */
69   public function getIds() {
70     $ids['tid']['type'] = 'integer';
71     return $ids;
72   }
73
74 }