 FeedsCommentProcessor.inc       |  383 +++++++++-----------------------------
 feeds_comment_processor.info    |    4 +-
 feeds_comment_processor.install |   40 ++---
 feeds_comment_processor.module  |   44 +++--
 4 files changed, 129 insertions(+), 342 deletions(-)

diff --git a/FeedsCommentProcessor.inc b/FeedsCommentProcessor.inc
index 1b2d178..4d21b04 100644
--- a/FeedsCommentProcessor.inc
+++ b/FeedsCommentProcessor.inc
@@ -18,98 +18,76 @@ define('FEEDS_COMMENT_UPDATE_EXISTING', 2);
  * Creates comments from feed items.
  */
 class FeedsCommentProcessor extends FeedsProcessor {
-
   /**
-   * Implementation of FeedsProcessor::process().
+   * Define entity type.
    */
-  public function process(FeedsImportBatch $batch, FeedsSource $source) {
-
-    // Keep track of processed items in this pass.
-    $processed = 0;
-    if (!$batch->getTotal(FEEDS_PROCESSING)) {
-      $batch->setTotal(FEEDS_PROCESSING, $batch->getItemCount());
-    }
-
-    while ($item = $batch->shiftItem()) {
-
-      // Create/update if item does not exist or update existing is enabled.
-      if (!($cid = $this->existingItemId($batch, $source)) || ($this->config['update_existing'] != FEEDS_SKIP_EXISTING)) {
-        // Only proceed if item has actually changed.
-        $hash = $this->hash($item);
-        if (!empty($cid) && $hash == $this->getHash($cid)) {
-          continue;
-        }
+  public function entityType() {
+    return 'comment';
+  }
 
-        $comment = $this->buildComment($cid, $source->feed_nid);
-        $comment->feeds_comment_item->hash = $hash;
+  /**
+   * Implements parent::entityInfo().
+   */
+  protected function entityInfo() {
+    $info = parent::entityInfo();
+    $info['label plural'] = t('Comments');
+    return $info;
+  }
 
-        // Map and save comment. If errors occur don't stop but report them.
-        try {
-          $this->map($batch, $comment);
-          if (empty($comment->nid)) {
-            throw new Exception("Unable create comment with empty NID");
-          }
-          _feeds_comment_save((array)$comment);
-          if (!empty($cid)) {
-            $batch->updated++;
-          }
-          else {
-            $batch->created++;
-          }
-        }
-        catch (Exception $e) {
-          drupal_set_message($e->getMessage(), 'warning');
-          watchdog('feeds', $e->getMessage(), array(), WATCHDOG_WARNING);
-        }
-      }
+  /**
+   * Creates a new comment in memory and returns it.
+   */
+  protected function newEntity(FeedsSource $source) {
+    $comment = new stdClass();
+    $comment->cid = 0;
+    $comment->pid = 0;
+    $comment->uid = $this->config['author'];
+    $account = user_load($comment->uid);
+    $comment->mail = $account->mail;
+    $comment->name = $account->name;
+    $comment->hostname = '127.0.0.1';
+    $comment->created = FEEDS_REQUEST_TIME;
+    $comment->is_anonymous = 0;
+    $comment->status = 0;
+    $comment->language = LANGUAGE_NONE;
+    $comment->comment_body[$comment->language][0]['format'] = $this->config['input_format'];
+    $comment->feeds_comment_item = new stdClass();
+    $comment->feeds_comment_item->id = $this->id;
+    $comment->feeds_comment_item->imported = FEEDS_REQUEST_TIME;
+    $comment->feeds_comment_item->feed_nid = $source->feed_nid;
+    $comment->feeds_comment_item->guid = '';
+    return $comment;
+  }
 
-      $processed++;
-      if ($processed >= variable_get('feeds_comment_batch_size', FEEDS_COMMENT_BATCH_SIZE)) {
-        $batch->setProgress(FEEDS_PROCESSING, $batch->created + $batch->updated);
-        return;
-      }
-    }
+  /**
+   * Loads an existing comment.
+   */
+  protected function entityLoad(FeedsSource $source, $cid) {
+    return comment_load($cid);
+  }
 
-    // Set messages.
-    if ($batch->created) {
-      drupal_set_message(format_plural($batch->created, 'Created @number comment', 'Created @number comments.', array('@number' => $batch->created,)));
-    }
-    elseif ($batch->updated) {
-      drupal_set_message(format_plural($batch->updated, 'Updated @number comment.', 'Updated @number comments.', array('@number' => $batch->updated,)));
-    }
-    else {
-      drupal_set_message(t('There are no new comments.'));
+  /**
+   * Validates a comment.
+   */
+  protected function entityValidate($comment) {
+    if (empty($comment->nid)) {
+      throw new FeedsValidationException(t('Unable to create comment with empty NID.'));
     }
-    $batch->setProgress(FEEDS_PROCESSING, FEEDS_BATCH_COMPLETE);
   }
 
   /**
-   * Implementation of FeedsProcessor::clear().
+   * Save a comment.
    */
-  public function clear(FeedsBatch $batch, FeedsSource $source) {
-    if (!$batch->getTotal(FEEDS_CLEARING)) {
-      $total = db_result(db_query("SELECT COUNT(cid) FROM {feeds_comment_item} WHERE id = '%s' AND feed_nid = %d", $source->id, $source->feed_nid));
-      $batch->setTotal(FEEDS_CLEARING, $total);
-    }
-    $result = db_query_range("SELECT cid FROM {feeds_comment_item} WHERE id = '%s' AND feed_nid = %d", $source->id, $source->feed_nid, 0, variable_get('feeds_comment_batch_size', FEEDS_COMMENT_BATCH_SIZE));
-    while ($comment = db_fetch_object($result)) {
-      _feeds_comment_delete($comment->cid);
-      $batch->deleted++;
-    }
-    if (db_result(db_query_range("SELECT cid FROM {feeds_comment_item} WHERE id = '%s' AND feed_nid = %d", $source->id, $source->feed_nid, 0, 1))) {
-      $batch->setProgress(FEEDS_CLEARING, $batch->deleted);
-      return;
-    }
+  public function entitySave($comment) {
+    comment_submit($comment);
+    comment_save($comment);
+  }
 
-    // Set message.
-    drupal_get_messages('status');
-    if ($batch->deleted) {
-      drupal_set_message(format_plural($batch->deleted, 'Deleted @number comment.', 'Deleted @number comments.', array('@number' => $batch->deleted)));
-    }
-    else {
-      drupal_set_message(t('There is no content to be deleted.'));
-    }
-    $batch->setProgress(FEEDS_CLEARING, FEEDS_BATCH_COMPLETE);
+  /**
+   * Delete multiple comments.
+   */
+  protected function entityDeleteMultiple($cids) {
+    comment_delete_multiple($cids);
   }
 
   /**
@@ -122,11 +100,11 @@ class FeedsCommentProcessor extends FeedsProcessor {
     if ($time == FEEDS_EXPIRE_NEVER) {
       return;
     }
-    $result = db_query_range("SELECT c.cid FROM {comments} c INNER JOIN {feeds_comment_item} fci ON c.cid = fni.nid WHERE fci.id = '%s' AND c.timestamp < %d", $this->id, FEEDS_REQUEST_TIME - $time, 0, variable_get('feeds_comment_batch_size', FEEDS_COMMENT_BATCH_SIZE));
+    $result = db_query_range("SELECT c.cid FROM {comment} c INNER JOIN {feeds_comment_item} fci ON c.cid = fci.cid WHERE fci.id = :id AND c.created < :timestamp", 0, variable_get('feeds_comment_batch_size', FEEDS_COMMENT_BATCH_SIZE), array(':id' => $this->id, ':timestamp' => FEEDS_REQUEST_TIME - $time));
     while ($comment = db_fetch_object($result)) {
-      _feeds_comment_delete($comment->nid);
+      comment_delete($comment->cid);
     }
-    if (db_result(db_query_range("SELECT c.cid FROM {comment} c INNER JOIN {feeds_comment_item} fci ON c.cid = fci.nid WHERE fci.id = '%s' AND c.timestamp < %d", $this->id, FEEDS_REQUEST_TIME - $time, 0, 1))) {
+    if (db_result(db_query_range("SELECT c.cid FROM {comment} c INNER JOIN {feeds_comment_item} fci ON c.cid = fci.cid WHERE fci.id = :id AND c.created < :timestamp", 0, 1, array(':id' => $this->id, ':timestamp' => FEEDS_REQUEST_TIME - $time)))) {
       return FEEDS_BATCH_ACTIVE;
     }
     return FEEDS_BATCH_COMPLETE;
@@ -144,7 +122,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
    */
   public function configDefaults() {
     return array(
-      'input_format' => FILTER_FORMAT_DEFAULT,
+      'input_format' => filter_default_format(),
       'update_existing' => FEEDS_SKIP_EXISTING,
       'expire' => FEEDS_EXPIRE_NEVER,
       'mappings' => array(),
@@ -157,11 +135,11 @@ class FeedsCommentProcessor extends FeedsProcessor {
    */
   public function configForm(&$form_state) {
     $form = array();
-    $format_options = array(FILTER_FORMAT_DEFAULT => t('Default format'));
+    $format_options = array(filter_default_format() => t('Default format'));
     $formats = filter_formats();
-      foreach ($formats as $format) {
-        $format_options[$format->format] = $format->name;
-      }
+    foreach ($formats as $format) {
+      $format_options[$format->format] = $format->name;
+    }
     $form['input_format'] = array(
       '#type' => 'select',
       '#title' => t('Input format'),
@@ -169,7 +147,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
       '#options' => $format_options,
       '#default_value' => $this->config['input_format'],
     );
-    $author = user_load(array('uid' => $this->config['author']));
+    $author = user_load($this->config['author']);
     $form['author'] = array(
       '#type' => 'textfield',
       '#title' => t('Author'),
@@ -203,7 +181,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
    * Override parent::configFormValidate().
    */
   public function configFormValidate(&$values) {
-    if ($author = user_load(array('name' => $values['author']))) {
+    if ($author = user_load_by_name($values['author'])) {
       $values['author'] = $author->uid;
     }
     else {
@@ -214,12 +192,17 @@ class FeedsCommentProcessor extends FeedsProcessor {
   /**
    * Override setTargetElement to operate on a target item that is a comment.
    */
-  public function setTargetElement($target_comment, $target_element, $value) {
-    if (in_array($target_element, array('guid'))) {
-      $target_comment->feeds_comment_item->$target_element = $value;
-    }
-    elseif (array_key_exists($target_element, $this->getMappingTargets())) {
-      $target_comment->$target_element = $value;
+  public function setTargetElement(FeedsSource $source, $target_comment, $target_element, $value) {
+    switch ($target_element) {
+      case 'comment':
+        $target_comment->comment_body[$target_comment->language][0]['value'] = $value;
+        break;
+      case 'guid':
+        $target_comment->feeds_comment_item->guid = $value;
+        break;
+      default:
+        parent::setTargetElement($source, $target_comment, $target_element, $value);
+        break;
     }
   }
 
@@ -231,7 +214,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
       'pid' => array(
         'name' => t('Parent ID'),
         'description' => t('The cid to which this comment is a reply.'),
-       ),
+      ),
       'nid' => array(
         'name' => t('Node ID'),
         'description' => t('The nid to which this comment is a reply.'),
@@ -243,7 +226,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
       'subject' => array(
         'name' => t('Title'),
         'description' => t('The title of the comment.'),
-       ),
+      ),
       'comment' => array(
         'name' => t('Comment'),
         'description' => t('The comment body.'),
@@ -251,8 +234,8 @@ class FeedsCommentProcessor extends FeedsProcessor {
       'hostname' => array(
         'name' => t('Hostname'),
         'description' => t('The author\'s host name.'),
-       ),
-      'timestamp' => array(
+      ),
+      'created' => array(
         'name' => t('Published date'),
         'description' => t('The UNIX time when a comment has been saved.'),
       ),
@@ -281,7 +264,7 @@ class FeedsCommentProcessor extends FeedsProcessor {
 
     // Let other modules expose mapping targets.
     self::loadMappers();
-    drupal_alter('feeds_comment_processor_targets', $targets);
+    feeds_alter('feeds_comment_processor_targets', $targets);
 
     return $targets;
   }
@@ -289,208 +272,24 @@ class FeedsCommentProcessor extends FeedsProcessor {
   /**
    * Get cid of an existing feed item comment if available.
    */
-  protected function existingItemId($source_item, FeedsSource $source) {
+  protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
+    if ($cid = parent::existingEntityId($source, $result)) {
+      return $cid;
+    }
 
     // Iterate through all unique targets and test whether they do already
     // exist in the database.
-    foreach ($this->uniqueTargets($source_item) as $target => $value) {
+    foreach ($this->uniqueTargets($source, $result) as $target => $value) {
       switch ($target) {
         case 'guid':
-          $cid = db_result(db_query("SELECT cid FROM {feeds_comment_item} WHERE feed_nid = %d AND id = '%s' AND guid = '%s'", $source->feed_nid, $source->id, $value));
+          $cid = db_query("SELECT cid FROM {feeds_comment_item} WHERE feed_nid = :feed_nid AND id = :id AND guid = :guid", array(':feed_nid' => $source->feed_nid, ':id' => $source->id, ':guid' => $value))->fetchField();
           break;
       }
       if ($cid) {
-        // Return with the first nid found.
+        // Return with the first cid found.
         return $cid;
       }
     }
     return 0;
   }
-
-  /**
-   * Creates a new comment object in memory and returns it.
-   */
-  protected function buildComment($cid, $feed_nid) {
-    $comment = new stdClass();
-    if (empty($cid)) {
-      $comment->created = FEEDS_REQUEST_TIME;
-      $populate = TRUE;
-    }
-    else {
-      if ($this->config['update_existing'] == FEEDS_UPDATE_EXISTING) {
-        $comment = _comment_load($cid);
-      }
-      else {
-        $comment->cid = $cid;
-        $populate = TRUE;
-      }
-    }
-    if ($populate) {
-      $comment->timestamp = FEEDS_REQUEST_TIME;
-      $comment->format = $this->config['input_format'];
-      $comment->feeds_comment_item = new stdClass();
-      $comment->feeds_comment_item->id = $this->id;
-      $comment->feeds_comment_item->imported = FEEDS_REQUEST_TIME;
-      $comment->feeds_comment_item->feed_nid = $feed_nid;
-      $comment->feeds_comment_item->guid = '';
-      $comment->uid = $this->config['author'];
-      $account = user_load(array('uid' => $comment->uid));
-      $comment->name = $account->name;
-      $comment->mail = $account->mail;
-      $comment->status = 0;
-      $comment->pid = 0;
-      $comment->hostname = '127.0.0.1';
-
-    }
-
-    return $comment;
-  }
-
-  /**
-   * Create MD5 hash of item and mappings array.
-   *
-   * Include mappings as a change in mappings may have an affect on the item
-   * produced.
-   *
-   * @return Always returns a hash, even with empty, NULL, FALSE:
-   *  Empty arrays return 40cd750bba9870f18aada2478b24840a
-   *  Empty/NULL/FALSE strings return d41d8cd98f00b204e9800998ecf8427e
-   */
-  protected function hash($item) {
-    static $serialized_mappings;
-    if (!$serialized_mappings) {
-      $serialized_mappings = serialize($this->config['mappings']);
-    }
-    return hash('md5', serialize($item) . $serialized_mappings);
-  }
-
-  /**
-   * Retrieve MD5 hash of $cid from DB.
-   * @return Empty string if no item is found, hash otherwise.
-   */
-  protected function getHash($cid) {
-    $hash = db_result(db_query("SELECT hash FROM {feeds_comment_item} WHERE cid = %d", $cid));
-    if ($hash) {
-      // Return with the hash.
-      return $hash;
-    }
-    return '';
-  }
-}
-
-function _feeds_comment_delete($cid) {
-  module_load_include('inc', 'comment', 'comment.admin');
-  $to_delete = _comment_load($cid);
-  // Delete comment and its replies.
-  _comment_delete_thread($to_delete);
-  _comment_update_node_statistics($to_delete->nid);
-}
-
-/**
- * This function is copied and pasted from comment_save in Drupal core and then
- * modified to get rid of access restrictions and to prevent extraneous dsms.
- *
- * @param $edit
- *   A comment array.
- *
- * @return
- *   If the comment is successfully saved the comment ID is returned. If the comment
- *   is not saved, FALSE is returned.
- */
-function _feeds_comment_save($edit) {
-  global $user;
-
-  $edit += array(
-    'mail' => '',
-    'homepage' => '',
-    'name' => '',
-    'status' => user_access('post comments without approval') ? COMMENT_PUBLISHED : COMMENT_NOT_PUBLISHED,
-  );
-  if ($edit['cid']) {
-    // Update the comment in the database.
-    db_query("UPDATE {comments} SET status = %d, timestamp = %d, subject = '%s', comment = '%s', format = %d, uid = %d, name = '%s', mail = '%s', homepage = '%s' WHERE cid = %d", $edit['status'], $edit['timestamp'], $edit['subject'], $edit['comment'], $edit['format'], $edit['uid'], $edit['name'], $edit['mail'], $edit['homepage'], $edit['cid']);
-
-    // Allow modules to respond to the updating of a comment.
-    comment_invoke_comment($edit, 'update');
-
-    // Add an entry to the watchdog log.
-    watchdog('content', 'Comment: updated %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid'])));
-  }
-  else {
-    // Add the comment to database.
-    // Here we are building the thread field. See the documentation for
-    // comment_render().
-    if ($edit['pid'] == 0) {
-      // This is a comment with no parent comment (depth 0): we start
-      // by retrieving the maximum thread level.
-      $max = db_result(db_query('SELECT MAX(thread) FROM {comments} WHERE nid = %d', $edit['nid']));
-
-      // Strip the "/" from the end of the thread.
-      $max = rtrim($max, '/');
-
-      // Finally, build the thread field for this new comment.
-      $thread = int2vancode(vancode2int($max) + 1) .'/';
-    }
-    else {
-      // This is comment with a parent comment: we increase
-      // the part of the thread value at the proper depth.
-
-      // Get the parent comment:
-      $parent = _comment_load($edit['pid']);
-
-      // Strip the "/" from the end of the parent thread.
-      $parent->thread = (string) rtrim((string) $parent->thread, '/');
-
-      // Get the max value in _this_ thread.
-      $max = db_result(db_query("SELECT MAX(thread) FROM {comments} WHERE thread LIKE '%s.%%' AND nid = %d", $parent->thread, $edit['nid']));
-
-      if ($max == '') {
-        // First child of this parent.
-        $thread = $parent->thread .'.'. int2vancode(0) .'/';
-      }
-      else {
-        // Strip the "/" at the end of the thread.
-        $max = rtrim($max, '/');
-
-        // We need to get the value at the correct depth.
-        $parts = explode('.', $max);
-        $parent_depth = count(explode('.', $parent->thread));
-        $last = $parts[$parent_depth];
-
-        // Finally, build the thread field for this new comment.
-        $thread = $parent->thread .'.'. int2vancode(vancode2int($last) + 1) .'/';
-      }
-    }
-
-    if (empty($edit['timestamp'])) {
-      $edit['timestamp'] = time();
-    }
-
-    if ($edit['uid'] === $user->uid && isset($user->name)) { // '===' Need to modify anonymous users as well.
-      $edit['name'] = $user->name;
-    }
-
-    db_query("INSERT INTO {comments} (nid, pid, uid, subject, comment, format, hostname, timestamp, status, thread, name, mail, homepage) VALUES (%d, %d, %d, '%s', '%s', %d, '%s', %d, %d, '%s', '%s', '%s', '%s')", $edit['nid'], $edit['pid'], $edit['uid'], $edit['subject'], $edit['comment'], $edit['format'], empty($edit['hostname']) ? ip_address() : $edit['hostname'], $edit['timestamp'], $edit['status'], $thread, $edit['name'], $edit['mail'], $edit['homepage']);
-    $edit['cid'] = db_last_insert_id('comments', 'cid');
-
-    // Tell the other modules a new comment has been submitted.
-    comment_invoke_comment($edit, 'insert');
-
-    // Add an entry to the watchdog log.
-    watchdog('content', 'Comment: added %subject.', array('%subject' => $edit['subject']), WATCHDOG_NOTICE, l(t('view'), 'node/'. $edit['nid'], array('fragment' => 'comment-'. $edit['cid'])));
-  }
-  _comment_update_node_statistics($edit['nid']);
-
-  // Clear the cache so an anonymous user can see his comment being added.
-  cache_clear_all();
-
-  // Explain the approval queue if necessary, and then
-  // redirect the user to the node he's commenting on.
-  if ($edit['status'] == COMMENT_NOT_PUBLISHED) {
-    drupal_set_message(t('Your comment has been queued for moderation by site administrators and will be published after approval.'));
-  }
-  else {
-    comment_invoke_comment($edit, 'publish');
-  }
-  return $edit['cid'];
 }
diff --git a/feeds_comment_processor.info b/feeds_comment_processor.info
index d492d9c..b035c77 100644
--- a/feeds_comment_processor.info
+++ b/feeds_comment_processor.info
@@ -3,5 +3,7 @@ description = Create and update comments from parsed content.
 package = Feeds
 dependencies[] = feeds
 dependencies[] = comment
-core = 6.x
+core = 7.x
 php = 5.2
+
+files[] = FeedsCommentProcessor.inc
diff --git a/feeds_comment_processor.install b/feeds_comment_processor.install
index 193e349..2f655aa 100644
--- a/feeds_comment_processor.install
+++ b/feeds_comment_processor.install
@@ -1,18 +1,24 @@
 <?php
+/**
+ * @file
+ * Install, update and uninstall functions for the feeds_comment_processor module.
+ *
+ */
+
 
 /**
- * Implementation of hook_schema().
+ * Implements hook_schema().
  */
 function feeds_comment_processor_schema() {
   $schema = array();
   $schema['feeds_comment_item'] = array(
-    'description' => t('Stores additional information about feed item comments. Used by FeedsCommentProcessor.'),
+    'description' => 'Stores additional information about feed item comments. Used by FeedsCommentProcessor.',
     'fields' => array(
       'cid' => array(
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'description' => t("Primary Key: The feed item comment's cid."),
+        'description' => "Primary Key: The feed item comment's cid.",
       ),
       'id' => array(
         'type' => 'varchar',
@@ -25,25 +31,18 @@ function feeds_comment_processor_schema() {
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'description' => t("Node id of the owner feed, if available."),
+        'description' => "Node id of the owner feed, if available.",
       ),
       'imported' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'description' => t('Import date of the feed item, as a Unix timestamp.'),
+        'description' => 'Import date of the feed item, as a Unix timestamp.',
       ),
       'guid' => array(
         'type' => 'text',
         'not null' => TRUE,
-        'description' => t('Unique identifier for the feed item.'),
-      ),
-      'hash' => array(
-        'type' => 'varchar',
-        'length' => 32, // The length of an MD5 hash.
-        'not null' => TRUE,
-        'default' => '',
-        'description' => t('The hash of the item.'),
+        'description' => 'Unique identifier for the feed item.',
       ),
     ),
     'primary key' => array('cid'),
@@ -57,18 +56,3 @@ function feeds_comment_processor_schema() {
   return $schema;
 }
 
-/**
- * Implementation of hook_install().
- */
-function feeds_comment_processor_install() {
-  // Create tables.
-  drupal_install_schema('feeds_comment_processor');
-}
-
-/**
- * Implementation of hook_uninstall().
- */
-function feeds_comment_processor_uninstall() {
-  // Remove tables.
-  drupal_uninstall_schema('feeds_comment_processor');
-}
diff --git a/feeds_comment_processor.module b/feeds_comment_processor.module
index ae61f97..f1c9d44 100644
--- a/feeds_comment_processor.module
+++ b/feeds_comment_processor.module
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Implementation of hook_feeds_plugins().
+ * Implements hook_feeds_plugins().
  */
 function feeds_comment_processor_feeds_plugins() {
   $path = drupal_get_path('module', 'feeds_comment_processor');
@@ -22,28 +22,30 @@ function feeds_comment_processor_feeds_plugins() {
 }
 
 /**
- * Handles FeedsCommentProcessor specific hook_comment operations.
+ * Implements hook_comment_insert().
  */
-function _feeds_comment_processor_comment(&$comment, $op) {
-  switch ($op) {
-    case 'insert':
-      if (isset($comment['feeds_comment_item'])) {
-        $comment['feeds_comment_item']->cid = $comment['cid'];
-        drupal_write_record('feeds_comment_item', $comment['feeds_comment_item']);
-      }
-      break;
-    case 'update':
-      if (isset($comment['feeds_comment_item'])) {
-        $comment['feeds_comment_item']->cid = $comment['cid'];
-        drupal_write_record('feeds_comment_item', $comment['feeds_comment_item'], 'cid');
-      }
-      break;
-    case 'delete':
-      db_query("DELETE FROM {feeds_comment_item} WHERE cid = %d", $comment->cid);
-      break;
+function feeds_comment_processor_comment_insert($comment) {
+  if (isset($comment->feeds_comment_item)) {
+    $comment->feeds_comment_item->cid = $comment->cid;
+    drupal_write_record('feeds_comment_item', $comment->feeds_comment_item);
   }
 }
 
-function feeds_comment_processor_comment(&$a1, $op) {
-  _feeds_comment_processor_comment($a1, $op);
+/**
+ * Implements hook_comment_update().
+ */
+function feeds_comment_processor_comment_update($comment) {
+  if (isset($comment->feeds_comment_item)) {
+    $comment->feeds_comment_item->cid = $comment->cid;
+    drupal_write_record('feeds_comment_item', $comment->feeds_comment_item, 'cid');
+  }
+}
+
+/**
+ * Implements hook_comment_delete().
+ */
+function feeds_comment_processor_comment_delete($comment) {
+  db_delete('feeds_comment_item')
+  ->condition('cid', $comment->cid)
+  ->execute();
 }
