Opposite of eZContentObject::addLocation() ?

Author Message

Heiko Irrgang

Wednesday 09 March 2011 7:43:24 am

I can add a content object to other locations by calling:

$this->contentObject->addLocation( $NewLocationNodeID );

but how can i remove it again?

I have tried the following and it does remove... something, but the node still remains in the tree (i have deleted the cache)

public function removeLocationByNodeID( $nid ) {
$assignments = eZNodeAssignment::fetchForObject( $this->contentObject->ID );
foreach ( $assignments as $a ) {
if ( $a->ParentNode == $nid ) {
$a->purge();
}
}
}

Sebastiaan van der Vliet

Wednesday 09 March 2011 8:14:51 am

A long time ago I wrote some code to remove users from user groups. Don't know if it is still useful. $groupID would be the nodeID of the assigned node.

$object = eZContentObject::fetch( $userObjectID );
if ($object)
{
$nodeID = $object->attribute('main_node_id');
$version = $object->currentVersion();
$versionNumber = $version->attribute('version');
$newVersion = $object->createNewVersion();
//TODO: make sure this is not the main node.
$newVersion->removeAssignment($groupID);
$newVersionNr = $newVersion->attribute( 'version' );
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute(
'content', 'publish', array(
'object_id' => $userObjectID,
'version' => $newVersionNr
)
);
}

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Damien Pobel

Wednesday 09 March 2011 1:44:36 pm

Hi,

I think the right method to use is eZContentObjectTreeNode::removeNodeFromTree(). if the node you're removing is the only assignment of a content object it also removes the associated content object, otherwise, it just removes the location.

@Sebastiaan : you're code seems a bit complicated, you don't need to create a new version to remove a location

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Heiko Irrgang

Wednesday 09 March 2011 11:38:54 pm

thanx, removeNodeFromTree does the trick

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.