You are here

function biblio_update in Bibliography Module 5

Same name and namespace in other branches
  1. 6.2 biblio.module \biblio_update()
  2. 6 biblio.module \biblio_update()
  3. 7 biblio.module \biblio_update()
  4. 7.2 biblio.module \biblio_update()

Implementation of hook_update().

As an existing node is being updated in the database, we need to do our own database updates.

File

./biblio.module, line 1796

Code

function biblio_update($node) {
  $fields = biblio_get_db_fields();
  $node->biblio_coins = biblio_coins($node);
  if (variable_get('biblio_auto_citekey', 1) && empty($node->biblio_citekey)) {
    $node->biblio_citekey = biblio_citekey_generate($node);
  }
  if (!is_numeric($node->biblio_year)) {
    if (drupal_strtoupper($node->biblio_year) == drupal_strtoupper(t("In Press"))) {
      $node->biblio_year = 9998;
    }
    if (drupal_strtoupper($node->biblio_year) == drupal_strtoupper(t("Submitted"))) {
      $node->biblio_year = 9999;
    }
  }
  foreach ($node as $key => $value) {
    if (in_array($key, $fields) && $key != "0") {

      //$key != "0" to fix a bug related to book module
      $k[] = db_escape_string($key);
      $q[] = end($k) . " = '%s'";
      $v[] = $value;
      $s[] = "'%s'";
    }
  }

  // Update the node in the database:
  if ($node->revision) {
    db_query("INSERT INTO {biblio} (" . implode(", ", $k) . ") VALUES(" . implode(", ", $s) . ")", $v);
  }
  else {
    db_query("UPDATE {biblio} SET " . implode(', ', $q) . " WHERE vid = '{$node->vid}'", $v);
  }
}