3 namespace Drupal\comment\Plugin\migrate\source\d6;
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
9 * Drupal 6 comment source from database.
13 * source_provider = "comment"
16 class Comment extends DrupalSqlBase {
21 public function query() {
22 $query = $this->select('comments', 'c')
23 ->fields('c', ['cid', 'pid', 'nid', 'uid', 'subject',
24 'comment', 'hostname', 'timestamp', 'status', 'thread', 'name',
25 'mail', 'homepage', 'format']);
26 $query->innerJoin('node', 'n', 'c.nid = n.nid');
27 $query->fields('n', ['type']);
28 $query->orderBy('c.timestamp');
35 public function prepareRow(Row $row) {
36 if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) {
37 // Comment subject visible.
38 $row->setSourceProperty('field_name', 'comment');
39 $row->setSourceProperty('comment_type', 'comment');
42 $row->setSourceProperty('field_name', 'comment_no_subject');
43 $row->setSourceProperty('comment_type', 'comment_no_subject');
45 // In D6, status=0 means published, while in D8 means the opposite.
46 // See https://www.drupal.org/node/237636.
47 $row->setSourceProperty('status', !$row->getSourceProperty('status'));
48 return parent::prepareRow($row);
54 public function fields() {
56 'cid' => $this->t('Comment ID.'),
57 'pid' => $this->t('Parent comment ID. If set to 0, this comment is not a reply to an existing comment.'),
58 'nid' => $this->t('The {node}.nid to which this comment is a reply.'),
59 'uid' => $this->t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'),
60 'subject' => $this->t('The comment title.'),
61 'comment' => $this->t('The comment body.'),
62 'hostname' => $this->t("The author's host name."),
63 'timestamp' => $this->t('The time that the comment was created, or last edited by its author, as a Unix timestamp.'),
64 'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'),
65 'format' => $this->t('The {filter_formats}.format of the comment body.'),
66 'thread' => $this->t("The vancode representation of the comment's place in a thread."),
67 '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."),
68 '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."),
69 '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."),
70 'type' => $this->t("The {node}.type to which this comment is a reply."),
77 public function getIds() {
78 $ids['cid']['type'] = 'integer';