Author Topic

Betsy Gamrat

Sunday 09 July 2006 6:31:09 am

Comment40882

Hi,

Thank you to all the previous posters.  I am submitting my implementation of the move code.

I used this thread and this one: http://ez.no/community/forum/developer/moving_an_object_through_php

I also used <b>create.php</b> - <i>Copyright (C) 1999-2004 Björn. All rights reserved.</i>

include_once( 'kernel/classes/ezcontentobject.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
include_once( 'kernel/classes/ezcontentobjecttreenodeoperations.php' );

include_once( "lib/ezutils/classes/ezextension.php" );
include_once( "lib/ezutils/classes/ezmodule.php" );
include_once( 'lib/ezutils/classes/ezcli.php' );
include_once( 'kernel/classes/ezscript.php' );

$script =& eZScript::instance( array( 'debug-message' => true,
                                      'use-session' => true,
                                      'use-modules' => true,
                                      'use-extensions' => true ) );

$script->startup();
$script->initialize();
include_once("lib/ezutils/classes/ezcli.php");
$cli =& eZCLI::instance();
$cli->setUseStyles( true ); // enable colors

$params=array();
$parentNodeID=100; // For example
$newfolderNodeID=200; 

$childNodes =& eZContentObjectTreeNode::subTree($params, $parentNodeID );

if (count($childNodes) === 0)
{
      echo "No data returned\n"; die();
}
foreach( $childNodes as $child )
{
      $childObj = $child->attribute( 'object' );
      $nodeID=$child->NodeID;
      $objData = $childObj->dataMap();
      $name= $objData['name']->content();  

      $doMove = ($name === "target_value");  // For example
      // Insert code to check $name, set $doMove to true if this objects needs to be moved
      if ($doMove)
      {
            if (!eZContentObjectTreeNodeOperations::move( $nodeID, $newfolderNodeID )) 
              echo "Move failed\n";
      }
}

$cli->output("Done",true);
$script->shutdown();

I stripped out my application specific code, but this code should work, or be close enough.

I used <b>var_dump($variable);</b> to help me "see" the data - and it was very valuable.

I also created a very simple class, with only enough attributes to test the code - and ran it in a development area (different server) to reduce the risk of corrupting live data.

Good luck,

Betsy