You are here

function document_update in Document 7

Same name and namespace in other branches
  1. 6 document.module \document_update()
  2. 8.x document.module \document_update()

Implementation of hook_update().

File

./document.module, line 390

Code

function document_update($node) {

  //$revisions = node_revision_list($node);

  // if this is a new node or we're adding a new revision,
  if (property_exists($node, 'revision') && $node->revision) {
    document_insert($node);
  }
  else {
    if (!isset($node->document_publishing)) {

      //While publishing a document in the callback, other fields cannot change. But taxonomy is not available,

      //and hence we should not make any updations during async document publishing by the node.
      $author = $node->document_author;
      $year = $node->document_year;
      $type = _document_get_node_terms($node);
      $keywords = $node->document_keywords;
      $abstract = $node->document_abstract;

      //The Url/External status of a document cannot change without creating a revision.

      //A revision would lead to insertion code above. So, no need to update Url/External status.
      db_update('document')
        ->fields(array(
        'type' => $type,
        'author' => $author,
        'publish_year' => $year,
        'abstract' => $abstract,
        'keywords' => $keywords,
      ))
        ->condition('nid', $node->nid)
        ->condition('vid', $node->vid)
        ->execute();
    }
  }
}