You are here

function node_export_node_clone in Node export 7.3

Same name and namespace in other branches
  1. 6.3 node_export.module \node_export_node_clone()
  2. 6.2 node_export.module \node_export_node_clone()

Prepare a clone of the node during import.

2 calls to node_export_node_clone()
node_export_features_node_export_alter in modules/node_export_features/node_export_features.module
Implements hook_node_export_alter().
node_export_import in ./node_export.module
Import Function

File

./node_export.module, line 801
The Node export module.

Code

function node_export_node_clone($original_node) {
  global $user;
  $node = clone $original_node;
  $node->nid = NULL;
  $node->vid = NULL;
  if (variable_get('node_export_reset_author_' . $node->type, TRUE)) {
    $node->name = !empty($user->name) ? $user->name : (!empty($user->uid) ? NULL : variable_get('anonymous', t('Anonymous')));
    $node->uid = $user->uid;
    $node->revision_uid = $user->uid;
  }

  // note: a uid of 0 is erroneous in any case, reset it to 1 (admin user)
  if ($node->revision_uid == 0) {
    $node->revision_uid = 1;
  }
  if (variable_get('node_export_reset_created_' . $node->type, TRUE)) {
    $node->created = NULL;
  }
  if (variable_get('node_export_reset_changed_' . $node->type, TRUE)) {
    $node->changed = NULL;
  }
  if (variable_get('node_export_reset_revision_timestamp_' . $node->type, TRUE)) {
    $node->revision_timestamp = NULL;
  }
  if (variable_get('node_export_reset_last_comment_timestamp_' . $node->type, TRUE)) {
    $node->last_comment_timestamp = NULL;
  }
  if (variable_get('node_export_reset_menu_' . $node->type, TRUE)) {
    $node->menu = NULL;
  }
  if (variable_get('node_export_reset_path_' . $node->type, TRUE)) {
    $node->path = NULL;
  }
  else {
    if (is_array($node->path) && isset($node->path['pid'])) {
      unset($node->path['pid']);
    }
    if (module_exists('pathauto')) {

      // Prevent pathauto from creating a new path alias.
      $node->path['pathauto'] = FALSE;
    }
  }
  if (variable_get('node_export_reset_book_mlid_' . $node->type, TRUE) && isset($node->book['mlid'])) {
    $node->book['mlid'] = NULL;
  }

  // @todo - is this still needed?
  $node->files = array();
  if (variable_get('node_export_reset_status_' . $node->type, FALSE)) {
    $node->status = FALSE;
  }
  if (variable_get('node_export_reset_promote_' . $node->type, FALSE)) {
    $node->promote = FALSE;
  }
  if (variable_get('node_export_reset_sticky_' . $node->type, FALSE)) {
    $node->sticky = FALSE;
  }

  // check for a data casting error
  if ($node->data == 'b:0;') {

    // data has been serialized as a FALSE instead of NULL
    $node->data = NULL;
  }

  // sort the node keys, so that there is a consistent representation for
  // (drupal_)var_export
  $array_node = (array) $node;
  ksort($array_node);
  $node = (object) $array_node;
  return $node;
}