comment_notify.migrate.inc 1.59 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<?php

/**
 * @file
 * Migration support for the Comment Notify module.
 */

/**
 * Field handler.
 */
class CommentNotifyMigrationHandler extends MigrateDestinationHandler {
12 13 14 15

  /**
   * {@inheritdoc}
   */
16
  public function __construct() {
17
    $this->registerTypes(['comment']);
18 19 20 21 22 23
  }

  /**
   * Make the destination field visible.
   */
  public function fields() {
24
    return [
25 26 27
      'notify' => t('Comment Notify: Whether to send notifications for this comment'),
      'notified' => t('Comment Notify: Whether notifications have been sent for this comment'),
      'notify_hash' => t('Comment Notify: Hash representing this notification'),
28
    ];
29 30 31 32 33 34
  }

  /**
   * Implements MigrateDestinationHandler::prepare().
   *
   * @param $comment
35
   *   The comment object being prepared for saving.
36
   * @param $row
37
   *   Raw source data for the migration - ignored.
38 39
   */
  public function prepare($comment, $row) {
40
    // By default, set notifications off.
41 42 43 44 45 46 47 48 49 50 51 52
    if (!isset($comment->notify)) {
      $comment->notify = 0;
    }
    if (!isset($comment->notify_type)) {
      $comment->notify_type = 1;
    }
  }

  /**
   * Implements MigrateDestinationHandler::complete().
   *
   * @param $comment
53
   *   The comment object taht was just saved.
54
   * @param $row
55
   *   Raw source data for the migration - ignored.
56 57 58 59 60 61
   */
  public function complete($comment, $row) {
    if (!isset($comment->notified) || $comment->notified) {
      comment_notify_mark_comment_as_notified($comment);
    }
  }
62

63 64
}

65 66
/**
 * Implements hook_migrate_api().
67 68
 */
function comment_notify_migrate_api() {
69
  $api = [
70
    'api' => 2,
71
  ];
72 73
  return $api;
}