X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FCommentEntityTranslation.php;fp=web%2Fcore%2Fmodules%2Fcomment%2Fsrc%2FPlugin%2Fmigrate%2Fsource%2Fd7%2FCommentEntityTranslation.php;h=a749f7107c555808c00ca36f88770d83d8ab14b0;hb=0bf8d09d2542548982e81a441b1f16e75873a04f;hp=0000000000000000000000000000000000000000;hpb=74df008bdbb3a11eeea356744f39b802369bda3c;p=yaffs-website diff --git a/web/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php b/web/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php new file mode 100644 index 000000000..a749f7107 --- /dev/null +++ b/web/core/modules/comment/src/Plugin/migrate/source/d7/CommentEntityTranslation.php @@ -0,0 +1,103 @@ +select('entity_translation', 'et') + ->fields('et') + ->fields('c', [ + 'subject', + ]) + ->condition('et.entity_type', 'comment') + ->condition('et.source', '', '<>'); + + $query->innerJoin('comment', 'c', 'c.cid = et.entity_id'); + $query->innerJoin('node', 'n', 'n.nid = c.nid'); + + $query->addField('n', 'type', 'node_type'); + + $query->orderBy('et.created'); + + return $query; + } + + /** + * {@inheritdoc} + */ + public function prepareRow(Row $row) { + $cid = $row->getSourceProperty('entity_id'); + $language = $row->getSourceProperty('language'); + $node_type = $row->getSourceProperty('node_type'); + $comment_type = 'comment_node_' . $node_type; + + // Get Field API field values. + foreach ($this->getFields('comment', $comment_type) as $field_name => $field) { + // Ensure we're using the right language if the entity is translatable. + $field_language = $field['translatable'] ? $language : NULL; + $row->setSourceProperty($field_name, $this->getFieldValues('comment', $field_name, $cid, NULL, $field_language)); + } + + // If the comment subject was replaced by a real field using the Drupal 7 + // Title module, use the field value instead of the comment subject. + if ($this->moduleExists('title')) { + $subject_field = $row->getSourceProperty('subject_field'); + if (isset($subject_field[0]['value'])) { + $row->setSourceProperty('subject', $subject_field[0]['value']); + } + } + + return parent::prepareRow($row); + } + + /** + * {@inheritdoc} + */ + public function fields() { + return [ + 'entity_type' => $this->t('The entity type this translation relates to'), + 'entity_id' => $this->t('The entity ID this translation relates to'), + 'revision_id' => $this->t('The entity revision ID this translation relates to'), + 'language' => $this->t('The target language for this translation.'), + 'source' => $this->t('The source language from which this translation was created.'), + 'uid' => $this->t('The author of this translation.'), + 'status' => $this->t('Boolean indicating whether the translation is published (visible to non-administrators).'), + 'translate' => $this->t('A boolean indicating whether this translation needs to be updated.'), + 'created' => $this->t('The Unix timestamp when the translation was created.'), + 'changed' => $this->t('The Unix timestamp when the translation was most recently saved.'), + 'subject' => $this->t('The comment title.'), + ]; + } + + /** + * {@inheritdoc} + */ + public function getIds() { + return [ + 'entity_id' => [ + 'type' => 'integer', + 'alias' => 'et', + ], + 'language' => [ + 'type' => 'string', + 'alias' => 'et', + ], + ]; + } + +}