Forums / Developer / Script to change an object's location after X days

Script to change an object's location after X days

Author Message

Alex Jones

Wednesday 19 May 2004 12:59:26 pm

I need to set up a script which will go through all of the items in a folder and based on the contents of a specific field determine if the item should be moved to an archive folder. This plain text field contains a string consisting of the date that the item sold, in the format year month day: 2004 05 19. Before I sit down to write the script from scratch, I thought I would ask the community if anyone else has anything I could use as a foundation for my work. Any help would be greatly appreciated!

Alex

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

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

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>