You are here

function nodejs_subscribe_node_update in Node.js integration 7

Same name and namespace in other branches
  1. 6 nodejs_subscribe/nodejs_subscribe.module \nodejs_subscribe_node_update()

Implements hook_node_update().

TODO: When disabling subscriptions for users on a node, delete all active subscriptions

File

nodejs_subscribe/nodejs_subscribe.module, line 170

Code

function nodejs_subscribe_node_update($node) {
  global $user;
  if (isset($node->nodejs_subscribe)) {
    if ($node->nodejs_subscribe['nodejs_subscriptions_allowed']) {
      $transaction = db_transaction();
      try {
        db_query('DELETE FROM {nodejs_subscribe_node} WHERE nid = :nid', array(
          ':nid' => $node->nid,
        ));
        db_query('INSERT INTO {nodejs_subscribe_node} (nid, subscribe) VALUES (:nid, :subscribe)', array(
          ':nid' => $node->nid,
          ':subscribe' => $node->nodejs_subscribe['nodejs_subscriptions_allowed'],
        ));
      } catch (Exception $e) {
        $transaction
          ->rollback();
        watchdog('nodejs_subscribe', 'Error processing node subscription for nid %nid', array(
          ':nid' => $node->nid,
        ));
      }
    }
    else {
      db_query('DELETE FROM {nodejs_subscribe_node} WHERE nid = :nid', array(
        ':nid' => $node->nid,
      ));
    }
  }
  if (nodejs_subscribe_is_node_subscribed_to($node->nid)) {
    nodejs_subscribe_send_notification($node, 'update');
  }
}