You are here

function discussthis_node_update in Discuss This! 7

Implements hook_node_update().

File

./discussthis.node.inc, line 217
File with node discussion display methods.

Code

function discussthis_node_update($node) {
  if ($node) {
    if ($node->type != 'forum') {
      if (user_access('override discuss this forums')) {

        // The forum field is only available for nodes that are
        // not yet attached to a topic, so it may not be defined
        if (isset($node->discussthis['discussthis_forum'])) {
          $discussthis_forum['nid'] = $node->nid;
          $discussthis_forum['forum_tid'] = $node->discussthis['discussthis_forum'];
          _discussthis_set_forum($discussthis_forum);
        }

        // topics are defined by nid
        $transaction = db_transaction();
        try {
          $sql = "DELETE FROM {discussthis} WHERE nid = %d";

          // TODO Please review the conversion of this statement to the D7 database API syntax.

          /* db_query($sql, $node->nid) */
          db_delete('discussthis')
            ->condition('nid', $node->nid)
            ->execute();
          if (!empty($node->discussthis['discussthis_topic'])) {
            $sql = "INSERT INTO {discussthis} (nid, topic_nid) VALUES (%d, %d)";

            // TODO Please review the conversion of this statement to the D7 database API syntax.

            /* db_query($sql, $node->nid, $node->discussthis['discussthis_topic']) */
            $id = db_insert('discussthis')
              ->fields(array(
              'nid' => $node->nid,
              'topic_nid' => $node->discussthis['discussthis_topic'],
            ))
              ->execute();
          }
        } catch (Exception $e) {
          $transaction
            ->rollback();
          watchdog_exception('my_type', $e);
        }
      }
    }
  }
}