Posted by artatac on October 11, 2009 at 12:47pm
| Project: | Node export |
| Version: | 7.x-3.x-dev |
| Component: | Node export |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Issue Summary
I created a new book called 'All Fruit@ and then created a child page called 'Apple green'. When I then exported it to another drupal site it worked apart from reversing the book structure. which is wrongly now
Apple green is good
--All Fruit
See export file below
array(
array(
'nid' => '35',
'type' => 'book',
'language' => '',
'uid' => '1',
'status' => '1',
'created' => '1255262677',
'changed' => '1255262677',
'comment' => '2',
'promote' => '0',
'moderate' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
'vid' => '35',
'revision_uid' => '1',
'title' => 'Apple green is good ',
'body' => 'Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good
Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good ',
'teaser' => 'Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good Apple green is good
',
'log' => '',
'revision_timestamp' => '1255262677',
'format' => '1',
'name' => 'webmaster',
'picture' => '',
'data' => 'a:1:{s:13:\"form_build_id\";s:37:\"form-78fa815e174ba0184b2cfe5ee19028de\";}',
'field_image_cache' => array(
'0' => array(
'fid' => NULL,
'list' => '1',
'data' => array(
'description' => '',
'alt' => '',
'title' => '',
),
'alt' => '',
'title' => '',
'uid' => '1',
'filename' => 'applegreen.jpg',
'filepath' => '#FILES_DIRECTORY_PATH#/applegreen.jpg',
'filemime' => 'image/jpeg',
'filesize' => '15385',
'status' => 1,
'timestamp' => '1255262642',
'filefield_upload' => 'Upload',
'filefield_remove' => 'Remove',
'upload' => '',
'node_export_file_path' => 'sites/default/files/applegreen.jpg',
),
),
'path' => 'apple-green-good',
'book' => array(
'mlid' => '826',
'nid' => '35',
'bid' => '34',
'menu_name' => 'book-toc-34',
'plid' => '825',
'link_path' => 'node/35',
'router_path' => 'node/%',
'link_title' => 'Apple green is good ',
'options' => array(),
'module' => 'book',
'hidden' => '0',
'external' => '0',
'has_children' => '0',
'expanded' => '0',
'weight' => '0',
'depth' => '2',
'customized' => '0',
'p1' => '825',
'p2' => '826',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
'href' => 'node/35',
'title' => 'Apple green is good ',
),
'last_comment_timestamp' => '1255262677',
'last_comment_name' => NULL,
'comment_count' => '0',
'taxonomy' => array(
'tags' => array(
'2' => 'Apple',
),
),
'menu' => array(
'link_title' => '',
'mlid' => 0,
'plid' => 0,
'menu_name' => 'primary-links',
'weight' => 0,
'options' => array(),
'module' => 'menu',
'expanded' => 0,
'hidden' => 0,
'has_children' => 0,
'customized' => 0,
'parent_depth_limit' => 8,
),
'#_export_node_encode_object' => '1',
),
array(
'nid' => '34',
'type' => 'story',
'language' => '',
'uid' => '1',
'status' => '1',
'created' => '1255262556',
'changed' => '1255262605',
'comment' => '0',
'promote' => '0',
'moderate' => '0',
'sticky' => '0',
'tnid' => '0',
'translate' => '0',
'vid' => '34',
'revision_uid' => '1',
'title' => 'All Fruit ',
'body' => 'All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here
All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here ',
'teaser' => 'All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here All Fruit text here ',
'log' => '',
'revision_timestamp' => '1255262605',
'format' => '1',
'name' => 'webmaster',
'picture' => '',
'data' => 'a:1:{s:13:\"form_build_id\";s:37:\"form-78fa815e174ba0184b2cfe5ee19028de\";}',
'field_video' => array(
'0' => array(
'embed' => NULL,
'value' => NULL,
'provider' => NULL,
'data' => array(),
),
),
'field_image_cache' => array(
'0' => array(
'fid' => NULL,
'list' => '1',
'data' => array(
'description' => '',
'alt' => '',
'title' => '',
),
'uid' => '1',
'filename' => 'all_fruit.jpg',
'filepath' => '#FILES_DIRECTORY_PATH#/all_fruit.jpg',
'filemime' => 'image/jpeg',
'filesize' => '15888',
'status' => '1',
'timestamp' => '1255262578',
'node_export_file_path' => 'sites/default/files/all_fruit.jpg',
),
),
'path' => 'all-fruit',
'book' => array(
'mlid' => '825',
'nid' => '34',
'bid' => '34',
'menu_name' => 'book-toc-34',
'plid' => '0',
'link_path' => 'node/34',
'router_path' => 'node/%',
'link_title' => 'All Fruit ',
'options' => array(),
'module' => 'book',
'hidden' => '0',
'external' => '0',
'has_children' => '1',
'expanded' => '0',
'weight' => '0',
'depth' => '1',
'customized' => '0',
'p1' => '825',
'p2' => '0',
'p3' => '0',
'p4' => '0',
'p5' => '0',
'p6' => '0',
'p7' => '0',
'p8' => '0',
'p9' => '0',
'updated' => '0',
'href' => 'node/34',
'title' => 'All Fruit ',
),
'last_comment_timestamp' => '1255262556',
'last_comment_name' => NULL,
'comment_count' => '0',
'taxonomy' => array(
'tags' => array(
'2' => 'Fruit',
),
),
'menu' => array(
'link_title' => '',
'mlid' => 0,
'plid' => 0,
'menu_name' => 'primary-links',
'weight' => 0,
'options' => array(),
'module' => 'menu',
'expanded' => 0,
'hidden' => 0,
'has_children' => 0,
'customized' => 0,
'parent_depth_limit' => 8,
),
'#_export_node_encode_object' => '1',
),
)
Comments
#1
Books are not preserved. This module is designed to export nodes, not books.
#2
Thanks Daniel - I did read that, and could understand it not exporting book info, but why in that case does it export it wrongly. Better to loose all the book structure info and recreate it that have to undo the wrong info. Also if it does invert the structure perhaps the code could be tweaked to either ignore this info or make it export the correct way round - just a thought
#3
I'm not sure why it's reversing the book structure - could be a fluke that the nids are swapped around. Either way there is nothing handling the book information during import. The more I think of it, I guess it wouldn't be that hard to write a bit of logic to check for this first, and since book.module is in core this is a legit feature request.
PS. In the latest versions of this module you can there is a config option to remove some of the book structure info from the export codes.
#4
Thanks Daniel
I will try and reproduce this and give you access to it so we can understand if this is always doing the same thing
#5
Hi Daniel
I have worked out what is happening. I created a fresh drupal install > added node_export > and enabled book module. I then duplicated the empty site. In site B I created 3 book nodes with a book structure of:
Fruit intro page
--Red apple page
----Toffee apples are great
I then exported them and pasted them into (empty) site A > and the book pages got messed up. I checked to import text and it seemed fine so I then reexported these pages and compared the 2 text files (see attached pdf). The bottom line is that node export text file gathers the nodes from the newest to the oldest. In my simple case this is
toffee apple (node id 3)
Red apple (node id 2)
Fruit intro page (node id 1)
But when you import this into the empty file it ignores the original node id and processes the file from the top ie toffee apple becomes node id 1 etc.
To prove this I manually altered the import file just pasting the text blocks so they became
Fruit intro page (node id 1)
Red apple (node id 2)
toffee apple (node id 3)
Fruit into (the original node id 1) gets processed first and retains its node id 1 etc AND retains its correct book structure
For those who are not looking to try and preserve the node ids having the export file ordered oldest to newest would make no difference but for those who would value it matching it would be a great help
If you need more info let me know - regards
Joe
#6
Hi Daniel
could I request the reversing node order as described above as a feature request please. If you need any extra info let me know - thanks Joe
#7
The only way to solve this is to handle book structures completely. Reversing the nids just happens to fix your test case import - but it will not work in all cases.
#8
good point - all I can do then is request that book handling be considered as a future feature please
Thanks
Joe
#9
#10
Hi danielb, this might help the situation. I recently had to deal with many exported book and wrote this helper function to manage them. It needs cleaning up, and still needs the rest of the integration with node_export.
Here's a rough, rather brute force, plan that may work:
The helper function to create book outlines is:
<?php
/**
* Sets outline information for a book page.
*
* Examples:
* // Create this page a new book
* $a_book = node_load(123); // assuming $a_book->type == 'book'
* $a_book->book = array(); // Reset the book information
* install_book_set_outline($a_book, NULL, TRUE);
*
* // Add a child page
* $child = node_load(124); // assuming $child->type == 'book'
* $child->book = array(); // Reset the book information
* install_book_set_outline($child, $a_book->book['mlid']);
*
* @params $node
* The book page node.
* @params $plid
* Menu MLID of the item to be this page's parent.
* @params $weight
* Sets the menu weight of this book.
* @params $reset
* Make this node into a new book / page. Clearing any old book outline
* information.
*/
function install_book_set_outline(&$node, $plid = NULL, $weight = 0, $reset = FALSE) {
// The object needs to at least be something that looks like a book page
if (!$reset && !is_array($node->book)) {
return FALSE;
}
// Resets the book
if ($reset) {
// Delete any existing information for this book
if ($node->book['mlid']) {
db_query("DELETE FROM {book} WHERE mlid = %d", $node->book['mlid']);
menu_link_delete($node->book['mlid']);
}
$node->book = array();
$node->book['bid'] = 'new';
$node->book['mlid'] = NULL;
}
// Makes this a child book page of a parent MLID
if (is_numeric($plid)) {
$parent = book_link_load($plid);
if ($parent && $parent['access']) {
$node->book['bid'] = $parent['bid'];
$node->book['plid'] = $parent['mlid'];
$node->book['menu_name'] = $parent['menu_name'];
}
// Set defaults.
$node->book += _book_link_defaults(!empty($node->nid) ? $node->nid : 'new');
}
// Set the weight
$node->book['weight'] = (int) $weight;
// Allow other modules to deal with the bid changing
if (isset($node->book['bid']) && !isset($node->book['original_bid'])) {
$node->book['original_bid'] = $node->book['bid'];
}
// Find the depth limit for the parent select
if (isset($node->book['bid']) && !isset($node->book['parent_depth_limit'])) {
$node->book['parent_depth_limit'] = _book_parent_depth_limit($node->book);
}
if (!empty($node->book['bid'])) {
if ($node->book['bid'] == 'new') {
// New nodes that are their own book.
$node->book['bid'] = $node->nid;
}
$node->book['nid'] = $node->nid;
$node->book['menu_name'] = book_menu_name($node->book['bid']);
return _book_update_outline($node);
// The following should now exist
// * $node->book['bid']
// * $node->book['mlid']
// * $node->book['plid']
}
return NULL;
}
?>
#11
I also need to be able to export content in books, so I created a module,
node_export_book, to do that. Attached is the result of my work.I chose to patch the
node_exportmodule rather than just create a new module because I don't have CVS access yet, I don't have time to maintain a module right now and I figure that, sincebookis part of core, the ability to export books might as well go withnode_exportitself.I was developing on the HEAD of
node_export-6.x-2.x; but AFAIK it should work on any 6.x-2.x version ofnode_export. I did not develop for 6.x-3.x because the HEAD of that branch did not actually work at the time.@James Andres, your
install_book_set_outline()function was super-useful and saved me a lot of work! Thanks!Disclaimer: CVS apparently doesn't like it when you add files (refuses to generate patches), and I couldn't find any best-practices to get around this (or at least, ones that worked for me), so I ended up using Git to generate the patch instead. Git signifies creating a file by patching nothing (/dev/null) into a file... patching worked fine on my systems (OS/X and Linux), but I can imagine the patch not applying as nicely on non-UNIX systems, which may or may not have a /dev/null.
#12
I won't use that patch, because it's against the 2.x, and I don't know if I'll be able to get a git patch to apply. But thanks for your efforts, I will use your patch and James' post as reference when I get around to this.
#13
I just tried running my patch against 6.x-3.x HEAD. It applies cleanly, but I don't think that one of the hooks is being called: some of the fields that I expect to be in the node code are set to
FALSEinstead of having a UUID (like I expect). I suspect this is because the hook has changed names slightly, but I haven't done enough investigation to be able to say that for certain.I will investigate further and try to generate a patch for 6.x-3.x HEAD.
#14
Don't worry about making a new patch, I have another idea on what might work here, and I can always reference your previous patch for clues.
#15
@danielb: Okay.
Returning issue to previous state.
#16
I just used my patched module again and discovered that I forgot to mention something important earlier: it only parents the book pages properly if the exported book pages do not contain the `Menu link` information (i.e.: it only works if the node array is missing the
'menu' => ...sub-array).This is because the Book module uses menu items to build the book structures.
#17
is this planned to be in the 3.x version? I'd love to account for this module in the outline designer and allow for a context menu option for 'export node structure'
#18
@danielb, have you made any progress implementing this in version 3.x?
@btopro approached me through e-mail for some support, and we ended up discussing whether or not it would be good to make a separate
node_export_bookmodule so that people can take advantage of it right away. It would also save the maintainers ofnode_exportfrom the trouble of maintainingnode_export_book. I'm interested in feedback from anyone in the thread — does anyone have any comments about this? Is this a good idea? Would anyone use the module?#19
If not, we can post the poc here for reference. This is a screenshot of the GUI modification provided by the node_export_book module that's been thrown together
#20
Development of features on this module will now be focused on 7.x-3.x-dev, with backports possible after fixing.