08977fbc83e2d842a3d8d288317c37f43afef2f0
[yaffs-website] / web / core / modules / book / src / Plugin / migrate / source / Book.php
1 <?php
2
3 namespace Drupal\book\Plugin\migrate\source;
4
5 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
6
7 /**
8  * Drupal 6 and 7 book source.
9  *
10  * @MigrateSource(
11  *   id = "book",
12  *   source_module = "book",
13  * )
14  */
15 class Book extends DrupalSqlBase {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     $query = $this->select('book', 'b')->fields('b', ['nid', 'bid']);
22     $query->join('menu_links', 'ml', 'b.mlid = ml.mlid');
23     $ml_fields = ['mlid', 'plid', 'weight', 'has_children', 'depth'];
24     foreach (range(1, 9) as $i) {
25       $field = "p$i";
26       $ml_fields[] = $field;
27       $query->orderBy('ml.' . $field);
28     }
29     return $query->fields('ml', $ml_fields);
30   }
31
32   /**
33    * {@inheritdoc}
34    */
35   public function getIds() {
36     $ids['mlid']['type'] = 'integer';
37     $ids['mlid']['alias'] = 'ml';
38     return $ids;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function fields() {
45     return [
46       'nid' => $this->t('Node ID'),
47       'bid' => $this->t('Book ID'),
48       'mlid' => $this->t('Menu link ID'),
49       'plid' => $this->t('Parent link ID'),
50       'weight' => $this->t('Weight'),
51       'p1' => $this->t('The first mlid in the materialized path. If N = depth, then pN must equal the mlid. If depth > 1 then p(N-1) must equal the parent link mlid. All pX where X > depth must equal zero. The columns p1 .. p9 are also called the parents.'),
52       'p2' => $this->t('The second mlid in the materialized path. See p1.'),
53       'p3' => $this->t('The third mlid in the materialized path. See p1.'),
54       'p4' => $this->t('The fourth mlid in the materialized path. See p1.'),
55       'p5' => $this->t('The fifth mlid in the materialized path. See p1.'),
56       'p6' => $this->t('The sixth mlid in the materialized path. See p1.'),
57       'p7' => $this->t('The seventh mlid in the materialized path. See p1.'),
58       'p8' => $this->t('The eighth mlid in the materialized path. See p1.'),
59       'p9' => $this->t('The ninth mlid in the materialized path. See p1.'),
60     ];
61   }
62
63 }