This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit

eZ Community » Forums » Developer » Content sections are lost when...

Content sections are lost when copying a tree

Content sections are lost when copying a tree

Wednesday 14 December 2011 6:04:58 pm - 5 replies


I'm using a custom batch to copy trees with bin/php/ezsubtreecopy.php.

When I use ezsubtreecopy.php or the GUI, the content sections are set to their new parent's.

How can I force the script to keep the original sections ?

Many thanks.

Modified on Wednesday 14 December 2011 6:05:43 pm by Vincent Robic

Wednesday 14 December 2011 6:39:41 pm

Hi Vincent

The script does not have such functionallity, but you can add it yourself and it shouldn't be that much trouble.

The script already has options to keep creator and publish time from the original objects, so you might wanna take a look at those options as an example and add "keep section" option based on those two existing options.

Wednesday 14 December 2011 6:45:36 pm

Hello Vincent,


Sections are assigned to content objects -not- nodes in the content tree (FYI)


Here is a brief doc about the sections feature in general,


As you can see (read the link below), the script you mention, does not provide options related to the feature you describe. So in short when you use 'ezsubtreecopy.php' you can not 'force' the script to keep the original sections.


You might be able to create a modified copy which does, what you desire. I think you could 're-assign' the sections as an alternative after the copy was complete.

Hmm after further review it seems you can comment out this line to retain sections in your modified copy of the above mentioned script.

$newObject->setAttribute( 'section_id', 0 );


Note that this suggestion has not been tested at this time by the author ... your results may vary. 

Also note that while you could simply comment out the above line in the modified copy, it would be better to add a new script parameter called '--retain-sections' which conditionally suppressed the execution of the above line in a more dynamic manner.


As for the gui admin, this also i'm afraid by default is not a supported feature either. You could create a design extension, custom templates and a custom modified copy of the content/copy module view and create an alternative which does respect your section related needs within an extension. I've actually done something quite similar recently and it worked out great, see an example in bcimagealias on


I hope this helps ...




Modified on Wednesday 14 December 2011 6:50:42 pm by // Heath

Wednesday 14 December 2011 7:43:47 pm

It helps blunk.gif Emoticon

I made this post to ensure there was no easiest way to do this (I only know eZ for two months). Now I'll create a modified copy of ezsubtreecopy. It sounds to be the best solution.

Thanks for your helpful answers.

Wednesday 14 December 2011 8:19:39 pm

Hello Vincent,

I'm glad my suggestions have helped you. This is why I am here, to help users reach their goals quickly and effectively (especially the new users who are still learning the basics of using eZ Publish).

After I ate lunch today, I took a few minutes to create a modified copy of the script as I described above.

Please feel free to test and use this script as a basis for your own modified copy it should help you get even closer to your goal without requiring you to write your own modified copy.


Update: The following solution graduated today from a GitHub Gist (pastebin+) to a full fledged GitHub repository containing an eZ Publish script extension now called 'bcsubtreecopyretainsections'.

Get your copy of 'bcsubtreecopyretainsections.php' script today!


Example usage of 'bcsubtreecopyretainsections.php'

cd /path/to/ezpublish; php ./bcsubtreecopyretainsections/bin/php/bcsubtreecopyretainsections.php --src-node-id=41 --dst-node-id=42 --retain-sections


Brookins Consulting has has tested the above extension script 'bcsubtreecopyretainsections.php' and found it to reliabily perform the desired task consistently.


We hope this helps both you now and others in the future!




Modified on Thursday 15 December 2011 5:00:25 am by // Heath

Thursday 15 December 2011 9:07:24 am

Hello Heath,

I took a look at the source code, the trick is pretty simple but works like a charm : I tested it over 1620 nodes happy.gif Emoticon

Many thanks !!



You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from