You are here

function node_import_set_object in Node import 6

Store an object-id in the node_import cache.

As some string->object-id lookups can be expensive (in db queries) and most of the time the same strings are looked up (eg users), we have a cache of object-ids we already have looked up.

This function is used to store an object-id in the cache.

Parameters

$type: String. The type of object (eg 'user').

$value: String or array. The value we haved looked up.

$oid: Integer. The looked-up object-id. If NULL, the currently stored object-id is returned without setting the $type/$value to NULL. If you want to reset (eg make it NULL) a value, use

node_import_set_object($type, $value, NULL, TRUE);

$reset: Boolean. Whether to reset the cache. If $type is NULL, the whole cache is reset. If $value is not NULL only the cache for that specific $type/$value is reset.

Return value

Integer. The looked-up object-id. NULL if not found.

See also

node_import_get_object().

Related topics

7 calls to node_import_set_object()
book_node_import_values_alter in supported/book.inc
Implementation of hook_node_import_values_alter().
menu_node_import_values_alter in supported/menu.inc
Implementation of hook_node_import_values_alter().
node_import_check_book_reference in supported/book.inc
Check whether the value is a book (by NID or Title).
node_import_check_node_reference in ./node_import.inc
Check if the value is a valid node reference (by nid or title).
node_import_check_user_reference in ./node_import.inc
Check if the value is a valid user (by uid, name or email).

... See full list

File

./node_import.inc, line 1413
Public API of the Node import module.

Code

function node_import_set_object($type, $value, $oid = NULL, $reset = FALSE) {
  static $cache;
  if (!isset($cache)) {
    $cache = array();
  }
  if (isset($type) && !isset($cache[$type])) {
    $cache[$type] = array();
  }
  $stored_value = NULL;
  if (isset($value)) {
    $stored_value = is_array($value) ? implode("\n", array_map('drupal_strtolower', $value)) : drupal_strtolower($value);
  }
  if ($reset) {
    if (isset($type)) {
      if (isset($value)) {
        unset($cache[$type][$stored_value]);
      }
      else {
        $cache[$type] = array();
      }
    }
    else {
      $cache = array();
    }
    return;
  }
  if (isset($oid)) {
    $cache[$type][$stored_value] = $oid;
  }
  return isset($cache[$type][$stored_value]) ? $cache[$type][$stored_value] : NULL;
}