3 namespace Drupal\comment\Plugin\migrate\source\d7;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
9 * Drupal 7 comment source from database.
13 * source_module = "comment"
16 class Comment extends FieldableEntity {
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');
32 public function prepareRow(Row $row) {
33 $cid = $row->getSourceProperty('cid');
35 $node_type = $row->getSourceProperty('node_type');
36 $comment_type = 'comment_node_' . $node_type;
37 $row->setSourceProperty('comment_type', 'comment_node_' . $node_type);
39 foreach (array_keys($this->getFields('comment', $comment_type)) as $field) {
40 $row->setSourceProperty($field, $this->getFieldValues('comment', $field, $cid));
43 return parent::prepareRow($row);
49 public function fields() {
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."),
73 public function getIds() {
74 $ids['cid']['type'] = 'integer';