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.

eZ debug

Timing: Jan 30 2025 01:02:15
Script start
Timing: Jan 30 2025 01:02:15
Module start 'layout'
Timing: Jan 30 2025 01:02:15
Module start 'content'
Timing: Jan 30 2025 01:02:15
Module end 'content'
Timing: Jan 30 2025 01:02:15
Script end

Main resources:

Total runtime0.0136 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0046 588.2500151.2266
Module start 'layout' 0.00460.0026 739.476636.6875
Module start 'content' 0.00720.0050 776.164194.2969
Module end 'content' 0.01220.0013 870.460933.9766
Script end 0.0136  904.4375 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002216.4330140.0002
Check MTime0.00107.6995140.0001
Mysql Total
Database connection0.00075.352610.0007
Mysqli_queries0.002518.625630.0008
Looping result0.00000.066610.0000
Template Total0.00107.710.0010
Template load0.00085.799610.0008
Template processing0.00031.866610.0003
Override
Cache load0.00053.822610.0005
General
dbfile0.001612.082980.0002
String conversion0.00000.052640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs