BeerComment.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace Drupal\migrate_example\Plugin\migrate\source;
  3. use Drupal\migrate\Plugin\migrate\source\SqlBase;
  4. /**
  5. * Source plugin for beer comments.
  6. *
  7. * @MigrateSource(
  8. * id = "beer_comment"
  9. * )
  10. */
  11. class BeerComment extends SqlBase {
  12. /**
  13. * {@inheritdoc}
  14. */
  15. public function query() {
  16. $query = $this->select('migrate_example_beer_comment', 'mec')
  17. ->fields('mec', ['cid', 'cid_parent', 'name', 'mail', 'aid',
  18. 'body', 'bid', 'subject'])
  19. ->orderBy('cid_parent', 'ASC');
  20. return $query;
  21. }
  22. /**
  23. * {@inheritdoc}
  24. */
  25. public function fields() {
  26. $fields = [
  27. 'cid' => $this->t('Comment ID'),
  28. 'cid_parent' => $this->t('Parent comment ID in case of comment replies'),
  29. 'name' => $this->t('Comment name (if anon)'),
  30. 'mail' => $this->t('Comment email (if anon)'),
  31. 'aid' => $this->t('Account ID (if any)'),
  32. 'bid' => $this->t('Beer ID that is being commented upon'),
  33. 'subject' => $this->t('Comment subject'),
  34. ];
  35. return $fields;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function getIds() {
  41. return [
  42. 'cid' => [
  43. 'type' => 'integer',
  44. 'alias' => 'mec',
  45. ],
  46. ];
  47. }
  48. }