5671d4f15665a95fab2b5c4be2341abfe763a6ea
[yaffs-website] / web / core / modules / comment / src / Plugin / migrate / source / d6 / Comment.php
1 <?php
2
3 namespace Drupal\comment\Plugin\migrate\source\d6;
4
5 use Drupal\migrate\Row;
6 use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;
7
8 /**
9  * Drupal 6 comment source from database.
10  *
11  * @MigrateSource(
12  *   id = "d6_comment",
13  *   source_module = "comment"
14  * )
15  */
16 class Comment extends DrupalSqlBase {
17
18   /**
19    * {@inheritdoc}
20    */
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     ]);
27     $query->innerJoin('node', 'n', 'c.nid = n.nid');
28     $query->fields('n', ['type', 'language']);
29     $query->orderBy('c.timestamp');
30     return $query;
31   }
32
33   /**
34    * {@inheritdoc}
35    */
36   public function prepareRow(Row $row) {
37     return parent::prepareRow($this->prepareComment($row));
38   }
39
40   /**
41    * This is a backward compatibility layer for the deprecated migrate source
42    * plugins d6_comment_variable and d6_comment_variable_per_comment_type.
43    *
44    * @param \Drupal\migrate\Row $row
45    *   The row from the source to process.
46    * @return \Drupal\migrate\Row
47    *   The row object.
48    * @deprecated in Drupal 8.4.x, to be removed before Drupal 9.0.x.
49    */
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');
55     }
56     else {
57       $row->setSourceProperty('field_name', 'comment_no_subject');
58       $row->setSourceProperty('comment_type', 'comment_no_subject');
59     }
60
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'));
64
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);
70     }
71     return $row;
72   }
73
74   /**
75    * {@inheritdoc}
76    */
77   public function fields() {
78     return [
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."),
95     ];
96   }
97
98   /**
99    * {@inheritdoc}
100    */
101   public function getIds() {
102     $ids['cid']['type'] = 'integer';
103     return $ids;
104   }
105
106 }