You are here

function nodejs_subscribe_node_update in Node.js integration 6

Same name and namespace in other branches
  1. 7 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 259

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 = %d', $node->nid);
        db_query('INSERT INTO {nodejs_subscribe_node} (nid, subscribe) VALUES (%d, %d)', $node->nid, $node->nodejs_subscribe['nodejs_subscriptions_allowed']);
      } catch (Exception $e) {
        $transaction
          ->rollback();
        watchdog('nodejs_subscribe', t('Error processing node subscription for nid %nid', array(
          ':nid' => $node->nid,
        )));
      }
    }
    else {
      db_query('DELETE FROM {nodejs_subscribe_node} WHERE nid = %d', $node->nid);
    }
  }
  if (nodejs_subscribe_is_node_subscribed_to($node->nid)) {
    nodejs_subscribe_send_notification($node, 'update');
  }
}