How To use eZOperationHandler::execute again ...

Author Message

Petr Mrzena

Tuesday 06 May 2003 6:36:00 am

Sorry for reposting, but it looks like nobody read old messages :(

I asked:
I need to create new object instance and publish it in some existing node. Someone told me to use eZOperationHandler, but when I do so, I get this error:

Warning: Invalid argument supplied for foreach() in c:\program files\ez systems\ezpublish\lib\ezutils\classes\ezmoduleoperationinfo.php on line 82

Is there some extra initialization necessary?

Then somebody asked me for source, so here it is:

include_once( "kernel/classes/ezcontentclass.php" );
include_once( "kernel/classes/eznodeassignment.php");
include_once( "kernel/content/ezcontentoperationcollection.php" );

$node =& eZContentObjectTreeNode::fetch( 2 );
$parentContentObject =& $node->attribute( 'object' );
$sectionID = $parentContentObject->attribute( 'section_id' );

$class =& eZContentClass::fetch( 1 );
$contentObject =& $class->instantiate( 14, $sectionID );
$contentObject->setName( "MyNewFolder" );

$contentObject->store();

$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => $node->attribute( 'node_id' ),
'is_main' => 1
)
);
$nodeAssignment->store();
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult =& eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
'version' =>1 ) );

$contentObject =& eZContentObject::fetch( $contentObject->attribute( 'id' ) );

Sergiy Pushchin

Friday 09 May 2003 12:39:36 am

If you run that script as shell script or smth. like that i.e. without index.php you need to do some initialization.

// Initialize module loading
include_once( "lib/ezutils/classes/ezmodule.php" );

$moduleINI =& eZINI::instance( 'module.ini' );
$globalModuleRepositories = $moduleINI->variable( 'ModuleSettings', 'ModuleRepositories' );
$extensionRepositories = $moduleINI->variable( 'ModuleSettings', 'ExtensionRepositories' );
$extensionDirectory = eZExtension::baseDirectory();
$globalExtensionRepositories = array();
foreach ( $extensionRepositories as $extensionRepository )
{
$modulePath = $extensionDirectory . '/' . $extensionRepository . '/modules';
if ( file_exists( $modulePath ) )
{
$globalExtensionRepositories[] = $modulePath;
}
}
$moduleRepositories = array_merge( $moduleRepositories, $globalModuleRepositories, $globalExtensionRepositories );
eZModule::setGlobalPathList( $moduleRepositories );

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