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_module = "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',
27 $query->innerJoin('node', 'n', 'c.nid = n.nid');
28 $query->fields('n', ['type']);
29 $query->orderBy('c.timestamp');
36 public function prepareRow(Row $row) {
37 return parent::prepareRow($this->prepareComment($row));
41 * This is a backward compatibility layer for the deprecated migrate source
42 * plugins d6_comment_variable and d6_comment_variable_per_comment_type.
44 * @param \Drupal\migrate\Row $row
45 * The row from the source to process.
46 * @return \Drupal\migrate\Row
48 * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x.
50 protected function prepareComment(Row $row) {
51 if ($this->variableGet('comment_subject_field_' . $row->getSourceProperty('type'), 1)) {
52 // Comment subject visible.
53 $row->setSourceProperty('field_name', 'comment');
54 $row->setSourceProperty('comment_type', 'comment');
57 $row->setSourceProperty('field_name', 'comment_no_subject');
58 $row->setSourceProperty('comment_type', 'comment_no_subject');
61 // In D6, status=0 means published, while in D8 means the opposite.
62 // See https://www.drupal.org/node/237636.
63 $row->setSourceProperty('status', !$row->getSourceProperty('status'));
70 public function fields() {
72 'cid' => $this->t('Comment ID.'),
73 'pid' => $this->t('Parent comment ID. If set to 0, this comment is not a reply to an existing comment.'),
74 'nid' => $this->t('The {node}.nid to which this comment is a reply.'),
75 'uid' => $this->t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'),
76 'subject' => $this->t('The comment title.'),
77 'comment' => $this->t('The comment body.'),
78 'hostname' => $this->t("The author's host name."),
79 'timestamp' => $this->t('The time that the comment was created, or last edited by its author, as a Unix timestamp.'),
80 'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'),
81 'format' => $this->t('The {filter_formats}.format of the comment body.'),
82 'thread' => $this->t("The vancode representation of the comment's place in a thread."),
83 '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."),
84 '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."),
85 '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."),
86 'type' => $this->t("The {node}.type to which this comment is a reply."),
93 public function getIds() {
94 $ids['cid']['type'] = 'integer';