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', 'language']);
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'));
65 // If node did not have a language, use site default language as a fallback.
66 if (!$row->getSourceProperty('language')) {
67 $language_default = $this->variableGet('language_default', NULL);
68 $language = $language_default ? $language_default->language : 'en';
69 $row->setSourceProperty('language', $language);
77 public function fields() {
79 'cid' => $this->t('Comment ID.'),
80 'pid' => $this->t('Parent comment ID. If set to 0, this comment is not a reply to an existing comment.'),
81 'nid' => $this->t('The {node}.nid to which this comment is a reply.'),
82 'uid' => $this->t('The {users}.uid who authored the comment. If set to 0, this comment was created by an anonymous user.'),
83 'subject' => $this->t('The comment title.'),
84 'comment' => $this->t('The comment body.'),
85 'hostname' => $this->t("The author's host name."),
86 'timestamp' => $this->t('The time that the comment was created, or last edited by its author, as a Unix timestamp.'),
87 'status' => $this->t('The published status of a comment. (0 = Published, 1 = Not Published)'),
88 'format' => $this->t('The {filter_formats}.format of the comment body.'),
89 'thread' => $this->t("The vancode representation of the comment's place in a thread."),
90 '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."),
91 '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."),
92 '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."),
93 'type' => $this->t("The {node}.type to which this comment is a reply."),
94 'language' => $this->t("The {node}.language to which this comment is a reply. Site default language is used as a fallback if node does not have a language."),
101 public function getIds() {
102 $ids['cid']['type'] = 'integer';