4e3f3caa05ab562e537c35b8ac23d9681b53c9a6
[yaffs-website] / web / core / modules / comment / src / Plugin / migrate / source / d7 / Comment.php
1 <?php
2
3 namespace Drupal\comment\Plugin\migrate\source\d7;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
7
8 /**
9  * Drupal 7 comment source from database.
10  *
11  * @MigrateSource(
12  *   id = "d7_comment",
13  *   source_module = "comment"
14  * )
15  */
16 class Comment extends FieldableEntity {
17
18   /**
19    * {@inheritdoc}
20    */
21   public function query() {
22     $query = $this->select('comment', 'c')->fields('c');
23     $query->innerJoin('node', 'n', 'c.nid = n.nid');
24     $query->addField('n', 'type', 'node_type');
25     $query->orderBy('c.created');
26     return $query;
27   }
28
29   /**
30    * {@inheritdoc}
31    */
32   public function prepareRow(Row $row) {
33     $cid = $row->getSourceProperty('cid');
34
35     $node_type = $row->getSourceProperty('node_type');
36     $comment_type = 'comment_node_' . $node_type;
37     $row->setSourceProperty('comment_type', 'comment_node_' . $node_type);
38
39     foreach (array_keys($this->getFields('comment', $comment_type)) as $field) {
40       $row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
41     }
42
43     return parent::prepareRow($row);
44   }
45
46   /**
47    * {@inheritdoc}
48    */
49   public function fields() {
50     return [
51       'cid' => $this->t('Comment ID.'),
52       'pid' => $this->t('Parent comment ID. If set to 0, this comment is not a reply to an existing comment.'),
53       'nid' => $this->t('The {node}.nid to which this comment is a reply.'),
54       'uid' => $this->t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'),
55       'subject' => $this->t('The comment title.'),
56       'comment' => $this->t('The comment body.'),
57       'hostname' => $this->t("The author's host name."),
58       'created' => $this->t('The time that the comment was created, as a Unix timestamp.'),
59       'changed' => $this->t('The time that the comment was edited by its author, as a Unix timestamp.'),
60       'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'),
61       'format' => $this->t('The {filter_formats}.format of the comment body.'),
62       'thread' => $this->t("The vancode representation of the comment's place in a thread."),
63       'name' => $this->t("The comment author's name. Uses {users}.name if the user is logged in, otherwise uses the value typed into the comment form."),
64       'mail' => $this->t("The comment author's email address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
65       'homepage' => $this->t("The comment author's home page address from the comment form, if user is anonymous, and the 'Anonymous users may/must leave their contact information' setting is turned on."),
66       'type' => $this->t("The {node}.type to which this comment is a reply."),
67     ];
68   }
69
70   /**
71    * {@inheritdoc}
72    */
73   public function getIds() {
74     $ids['cid']['type'] = 'integer';
75     return $ids;
76   }
77
78 }