'node_export_import_drush_callback', 'description' => "Import node code from a previous export.", ); return $items; } /** * Implementation of hook_drush_help(). * * This function is called whenever a drush user calls * 'drush help ' * * @param * A string with the help section (prepend with 'drush:') * * @return * A string with the help text for your command. */ function node_export_drush_help($section) { switch ($section) { case 'drush:node_import': return dt("Imports nodes that have been exported by node_export module. Usage: 'drush node_import < datafile'."); } } /** * Drush command callback. * * Import nodes from data. */ function node_export_import_drush_callback() { $commands = func_get_args(); // Switch to the admin user so imported nodes are not anonymous. global $user; $user = user_load(1); $node_code = file_get_contents("php://stdin", "r"); $import = node_export_node_decode($node_code); $types_exist = node_export_import_types_check($import); if ($types_exist) { foreach ($import as $new_node) { $new_nid = node_export_node_save($new_node); drush_print(dt("Imported node $new_nid: '" . $new_node->title . "'.")); } } else { return drush_set_error('DRUSH_NOT_COMPLETED', 'Problem found with the import file. Check the node types exist.'); } }