Share » Forums » Developer » Script to change an object's location...

Script to change an object's location after X days

Script to change an object's location after X days

Wednesday 19 May 2004 12:59:26 pm - 4 replies

Modified on Thursday 20 May 2004 6:59:58 am by Alex Jones

Author Message

Dominik Pich

Friday 21 May 2004 1:25:30 am

Maybe the sheet extension?

Alex Jones

Friday 21 May 2004 6:44:56 am

Thanks for the reply Dominik. What is the sheet extension? A quick search of ez.no didn't return any info.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

Silke Fox

Wednesday 26 May 2004 1:16:53 am

Here's a code snippet to change an object's node assignment

// get max version
$maxVersion =& $object->getVersionCount();
$version =& $object->version( $maxVersion );
$nodeAssignments = $version->nodeAssignments();
// remove wrong nodeassignments
foreach ($nodeAssignments as $assignment) 
{
    $parentObject = $assignment->getParentNode();
    if ($parentObject->attribute('main_node_id') == 12) 
    {
	$version->removeAssignment(12);
    }
    else 
    {
	if ($assignment->attribute( 'is_main' ) == '1') 
        {
	    $nodeId = $assignment->getParentNode();
	    $version->removeAssignment($nodeId);
	    $version->assignToNode($nodeId, 0);
	}
    }
}
$version->removeAssignment(546);
$version->assignToNode(546, 1, 12);
$version->store();
		    
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $objectId, 'version' => $maxVersion ) );

Where 12 and 546 are node ids. This was used to move users from one group to another or to add them to a second group.

As far as I remember you have to remove the main node before assigning another node
(which you want to be the new main node), otherwise there will be some trouble with two main nodes.

Hope this helps,
Silke

Alex Jones

Wednesday 26 May 2004 7:55:36 am

Thanks for the code Silke! I'll try it out shortly.

Alex

Alex
[ bald_technologist on the IRC channel (irc.freenode.net): #eZpublish ]

<i>When in doubt, clear the cache.</i>

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

36 542 Users on board!

Forums menu