silverstripe / silverstripe-elemental

Create pages in Silverstripe CMS using content blocks
http://dna.co.nz
BSD 3-Clause "New" or "Revised" License
110 stars 115 forks source link

Live content being deleted on page publish #18

Closed nyeholt closed 8 years ago

nyeholt commented 8 years ago

Just creating an issue for the moment because I want someone to double check it before I PR anything - basically, on the publication of a page containing an element area, other elements will be deleted. I've traced it as best as possible to https://github.com/dnadesign/silverstripe-elemental/blob/master/code/extensions/ElementPublishChildren.php#L20 - the element set that it looks up for potential deletion are those that belong to either to $this->owner->Elements() (ie where ListID = $this->owner->ID) OR where the ParentID = $this->owner->ID - which in fact is looking up elements that are attached to an ElementArea with that ID. These elements subsequently get deleted from live.

So while changing this fixes the issue, I'm just wondering if there's some other logic being expected, as in, whether the ParentID comparison has a valid reason for existing.

wilr commented 8 years ago

I wrote the original code, can't see why I went for ParentID, as the extension within the module is purely used for ElementList.. I think perhaps at some time ElementPublishChildren was also added to SiteTree or even ElementArea which used the widget ParentID. Hence why ElementPublishChildren is an extension rather than just on ElementList.

I think it might be good to simply use ListID, remove ParentID and allow the name of any additional filters be passed through the extension if needed.

private static $extensions = array( 'ElementPublishChildren("ParentID")' );

By default that can be left off for ListID.