You are here

function faq_update in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 5.2 faq.module \faq_update()
  2. 6 faq.module \faq_update()
  3. 7.2 faq.module \faq_update()

Implements hook_update().

Updates the faq node question text in the 'faq_questions' table.

Parameters

object $node: The node object.

File

./faq.module, line 261
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function faq_update($node) {
  if (isset($node->revision) && $node->revision) {
    faq_insert($node);
  }
  else {

    // Empty detailed question as default.
    $detailed_question = array(
      'value' => '',
    );
    if ($items = field_get_items('node', $node, 'field_detailed_question')) {
      $detailed_question = reset($items);
    }

    // Just to be safe, we do a merge query instead of an update query.
    db_merge('faq_questions')
      ->fields(array(
      'question' => $node->title,
      'detailed_question' => $detailed_question['value'],
    ))
      ->key(array(
      'nid' => $node->nid,
      'vid' => $node->vid,
    ))
      ->execute();
  }
}