Skip to content

Instantly share code, notes, and snippets.

@lolautruche
Created August 23, 2011 12:17
Show Gist options
  • Save lolautruche/1164970 to your computer and use it in GitHub Desktop.
Save lolautruche/1164970 to your computer and use it in GitHub Desktop.
<?php
public function trashSubtree( $locationId )
{
$location = $this->load( $locationId );
// Create new trashed location and remove original location from tree
$params = (array)$location;
$params['locationId'] = $locationId;
// Be sure to not overlap id
unset( $params['id'] );
$trashedLocation = $this->backend->create( 'Content\\TrashedLocation', $params );
// Remove location from tree here
// Begin recursive call on children, if any
$directChildren = $this->backend->find( 'Content\\Location', array( 'parentId' => $locationId ) );
if ( !empty( $directChildren ) )
{
foreach ( $directChildren as $child )
{
$this->trashSubtree( $child->id );
}
}
return $trashedLocation;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment