function node_export_import in Node export 6.3
Same name and namespace in other branches
- 6.2 node_export.module \node_export_import()
- 7.3 node_export.module \node_export_import()
Import Function
Parameters
$code_string: The string of export code.
$msg_t: Function used to translate.
Return value
An array with keys 'success' which is a boolean value representing whether the import was successful and 'output' which contains an array of translated strings to be shown to the user as messages.
3 calls to node_export_import()
- drupal_node_export_callback_import in ./
node_export.drush.inc - Drush command callback.
- node_export_features_features_rebuild in modules/
node_export_features/ node_export_features.module - Implementation of hook_features_rebuild().
- node_export_import_form_submit in ./
node_export.pages.inc - Submit function for import form.
1 string reference to 'node_export_import'
- node_export_dsv_module_implements_alter in modules/
node_export_dsv/ node_export_dsv.module - Implements hook_module_implements_alter().
File
- ./
node_export.module, line 400 - The Node export module.
Code
function node_export_import($code_string, $msg_t = 't') {
// Early check to avoid letting hooligans and the elderly pass data to the
// eval() function call.
if (!node_export_access_import()) {
$error = $msg_t('You do not have permission to import any nodes.');
return array(
'success' => FALSE,
'output' => array(
$error,
),
);
}
// Allow modules to manipulate the $code_string.
drupal_alter('node_export_decode', $code_string);
// Pass the string to each format handler until one returns something useful.
$format_handlers = node_export_format_handlers();
$nodes = array();
$used_format = "";
foreach ($format_handlers as $format_handler => $format) {
$nodes = module_invoke($format_handlers[$format_handler]['#module'], 'node_export_import', $code_string);
if (!empty($nodes)) {
$used_format = $format_handler;
break;
}
}
if (isset($nodes['success']) && !$nodes['success']) {
// Instead of returning nodes, the format handler returned an error array.
// Translate the errors and return them.
foreach ($nodes['output'] as $key => $output) {
$nodes['output'][$key] = $msg_t($output);
}
return array(
'success' => FALSE,
'output' => $nodes['output'],
);
}
if ($used_format == "") {
$error = $msg_t('Node export was unable to recognize the format of the supplied code. No nodes imported.');
return array(
'success' => FALSE,
'output' => array(
$error,
),
);
}
$nodes = node_export_restore_recursion($nodes);
$types_exist = node_export_import_types_check($nodes);
if ($types_exist !== TRUE) {
// There was a problem with the content types check.
$error = $msg_t('Error encountered during import. Node types unknown on this site: %t. No nodes imported.', array(
'%t' => implode(", ", $types_exist),
));
return array(
'success' => FALSE,
'output' => array(
$error,
),
);
}
if (!node_export_access_import_nodes($nodes)) {
// There was a problem with permissions.
$error = $msg_t('You do not have permission to perform a Node export: import on one or more of these nodes. No nodes imported.');
return array(
'success' => FALSE,
'output' => array(
$error,
),
);
}
$count = 0;
$total = count($nodes);
// Let other modules do special fixing up.
drupal_alter('node_export', $nodes, 'import', $used_format);
$new_nodes = array();
$new_nid = 0;
$messages = array();
foreach ($nodes as $original_node) {
$skip = FALSE;
$node = node_export_node_clone($original_node);
// Handle existing nodes.
$uuid_nid = node_export_node_get_by_uuid($node->uuid, TRUE);
if (!empty($uuid_nid)) {
$existing = variable_get('node_export_existing', 'new');
switch ($existing) {
case 'new':
$node->is_new = TRUE;
unset($node->nid);
unset($node->uuid);
break;
case 'revision':
$node->nid = $uuid_nid;
$node->is_new = FALSE;
$node->revision = 1;
break;
case 'skip':
$skip = TRUE;
break;
}
}
// Let other modules do special fixing up.
drupal_alter('node_export_node', $node, $original_node, 'import');
if (!$skip) {
node_export_save($node);
$new_nodes[] = $node;
$messages[] = $msg_t("Imported node !nid: !node", array(
'!nid' => $node->nid,
'!node' => l($node->title, 'node/' . $node->nid),
));
$count++;
}
}
drupal_alter('node_export', $new_nodes, 'after import', $used_format);
$messages[] = $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,
));
// Clear the page and block caches.
cache_clear_all();
return array(
'success' => TRUE,
'output' => $messages,
);
}