You are here

function biblio_save_node in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 includes/biblio.import.export.inc \biblio_save_node()
  2. 6 biblio.import.export.inc \biblio_save_node()
  3. 7.2 includes/biblio.import.export.inc \biblio_save_node()
9 calls to biblio_save_node()
biblio_import_batch_operations in includes/biblio.import.export.inc
biblio_marc_biblio_import in modules/marcParse/biblio_marc.module
biblio_save_imported_nodes in includes/biblio.import.export.inc
Save node imported from a file.
EndNoteXMLParser::endnote7_endElement in modules/endnote/endnote_xml_parser.inc
EndNoteXMLParser::endnote8_endElement in modules/endnote/endnote_xml_parser.inc

... See full list

File

includes/biblio.import.export.inc, line 598
Functions that are used to import and export biblio data.

Code

function biblio_save_node($node, $terms = array(), $batch = FALSE, $session_id = NULL, $save_node = TRUE) {
  global $user;

  // We are batch processing some import data.
  if ($batch && $session_id) {
    $cache['session_id'] = $session_id;

    // base64_encode to avoid problems unserializing strings with embeded quotes.
    $cache['data'] = base64_encode(serialize($node));
    drupal_write_record('biblio_import_cache', $cache);
    return;
  }
  $node->type = 'biblio';

  // Persist the node revision log since it will be overridden by
  // node_object_prepare().
  $created = !empty($node->created) ? $node->created : NULL;
  $revision_log = !empty($node->log) ? $node->log : NULL;
  node_object_prepare($node);
  $node->created = $created;
  $node->log = $revision_log;
  if (!empty($terms)) {
    foreach ($terms as $key => $value) {
      $node->{$key} = $value;
    }
  }

  // Start by setting the language to undefined and then try to refine it.
  $node->language = 'und';
  if (module_exists('locale')) {
    $node->language = locale_language_url_fallback();
  }
  if (module_exists('i18n') && variable_get('i18n_node_biblio', 0) && variable_get('language_content_type_biblio', 0)) {
    $node->language = module_invoke('i18n', 'default_language');
  }
  if (!isset($node->biblio_type)) {

    // Default to misc if not set.
    $node->biblio_type = 129;
  }

  // $save_node = TRUE, the normal save path.
  if ($save_node) {
    $validation_errors = array();
    $validation_errors = biblio_save_node_validate($node);
    node_save($node);
    if (!empty($validation_errors)) {
      foreach ($validation_errors as $field => $value) {
        $message = $field . ' ' . t('was truncated to fit into the database column');
        $link = l('node/' . $node->nid, 'node/' . $node->nid);
        drupal_set_message($message . '; ' . $link, 'warning');
        watchdog('biblio - import', $message, array(), WATCHDOG_ALERT, $link);
      }
    }

    // (isset($node->nid)) ? $node->nid : 0;.
    return;
  }
  else {
    return (array) $node;
  }
}