b2511c59a53e9da92e4a2f9e2b58d87e4e61a5fa
[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']);
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     return $row;
65   }
66
67   /**
68    * {@inheritdoc}
69    */
70   public function fields() {
71     return [
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."),
87     ];
88   }
89
90   /**
91    * {@inheritdoc}
92    */
93   public function getIds() {
94     $ids['cid']['type'] = 'integer';
95     return $ids;
96   }
97
98 }