You are here

function node_export_import in Node export 6.2

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

Import Function

Parameters

$node_code: The string of node code.

$method: If set will override the variable table settings

$redirect: Whether to allow redirects

$msg_func: Function used to output status message

$msg_t: Function used to translate

Return value

FALSE is the types check failed Returns the HTML of a node form if required to prepopulate Otherwise returns TRUE, or may redirect.

2 calls to node_export_import()
node_export_drush_callback_import in ./node_export.drush.inc
Drush command callback.
node_export_import_form in ./node_export.module
Import Form

File

./node_export.module, line 519
The Node Export module.

Code

function node_export_import($node_code, $method = NULL, $redirect = TRUE, $msg_func = 'drupal_set_message', $msg_t = 't') {
  $import = node_export_node_decode($node_code);
  $import = node_export_restore_recursion($import);
  $types_exist = node_export_import_types_check($import);
  if ($types_exist) {
    $count = 0;
    if (is_array($import)) {

      // This is a bulk import.
      $total = count($import);

      // Let other modules do special fixing up.
      // The function signature is: hook_node_export_node_bulk_alter(&$nodes, $op).
      // Where $op is 'import'.
      drupal_alter('node_export_node_bulk', $import, 'import');
      $new_nodes = array();
      foreach ($import as $new_node) {
        $new_nid = node_export_node_save($new_node);
        $new_node->nid = $new_nid;
        $new_nodes[] = $new_node;
        $msg_func($msg_t("Imported node !nid: !node", array(
          '!nid' => $new_nid,
          '!node' => l($new_node->title, 'node/' . $new_nid),
        )));
        $count++;
      }
      drupal_alter('node_export_node_bulk', $new_nodes, 'after import');
      $msg_func($msg_t("!count of !total nodes were imported.  Some values may have been reset depending on Node Export's configuration", array(
        '!total' => $total,
        '!count' => $count,
      )));
      if ($redirect) {
        drupal_goto('admin/content/node');
      }
      return TRUE;
    }
    else {

      // We are importing a single node.
      $node =& $import;
      $total = 1;
      $method = !is_null($method) ? $method : variable_get('node_export_method', 'save-edit');
      if ($method == 'save-edit') {
        $new_nid = node_export_node_save($node);
        $msg_func($msg_t("Imported node !nid: !node", array(
          '!nid' => $new_nid,
          '!node' => l($new_node->title, 'node/' . $new_nid),
        )));
        $count++;
        $msg_func($msg_t("!count of !total nodes were imported.  Some values may have been reset depending on Node Export's configuration", array(
          '!total' => $total,
          '!count' => $count,
        )));
        if ($redirect) {
          drupal_goto('node/' . $new_nid . '/edit');
        }
        return TRUE;
      }
      else {
        if ($method == 'prepopulate') {
          include_once drupal_get_path('module', 'node') . '/node.pages.inc';
          return node_export_node_prepopulate($node);
        }
      }
    }
  }
  return FALSE;
}