Wednesday 08 October 2003 4:43:22 am
Hello again!
It seems to be working even vith some errors, but.... after trying out this code to import some content objects (using version 3.2-1), I get an error when I try to remove these objects. It says:
Fatal error: Undefined class name 'ezurlalias' in /data/ezpublish/3.2-1_Metadata/kernel/classes/ezcontentobjecttreenode.php on line 1902 Fatal error: eZ publish did not finish it's request
And some debug says:
Warning: PHP
Oct 08 2003 14:54:23 Undefined index: real_translation in /data/ezpublish/3.2-1_Metadata/kernel/classes/ezcontentobjecttreenode.php on line 1990
Did any of you encounter this? Here is my code, its partly from wenyue yu's script and another import.php script I found:
#!/usr/bin/php
<?php
set_time_limit( 0 );
//print( "Starting metadata import\n" );
include_once( "lib/ezutils/classes/ezdebug.php" );
//eZDebug::setHandleType( EZ_HANDLE_FROM_PHP );
include_once( "lib/ezutils/classes/ezmodule.php" );
eZModule::setGlobalPathList( array( "kernel" ) );
include_once( 'lib/ezutils/classes/ezexecution.php' );
include_once( 'kernel/classes/ezcontentobjecttreenode.php' );
eZDebug::setHandleType( EZ_HANDLE_TO_PHP );
eZDebug::setLogFileEnabled( false );
eZINI::setIsCacheEnabled( false );
function eZDBCleanup()
{
if ( class_exists( 'ezdb' )
and eZDB::hasInstance() )
{
$db =& eZDB::instance();
$db->setIsSQLOutputEnabled( false );
}
// session_write_close();
}
function eZFatalError()
{
eZDebug::setHandleType( EZ_HANDLE_NONE );
print( "Fatal error: eZ publish did not finish it's request\n" );
print( "The execution of eZ publish was abruptly ended." );
}
eZExecution::addCleanupHandler( 'eZDBCleanup' );
eZExecution::addFatalErrorHandler( 'eZFatalError' );
$db =& eZDB::instance(); $db->setIsSQLOutputEnabled( false ); $contentClassId = 28; //For metadata bruk 28
//fetch this class $class =& eZContentClass::fetch( $contentClassId ); $userID = 1; //The userId creating it. Root = 1
// Instantiate the object with user $userID and put it in section 1. $contentObject =& $class->instantiate( $userID, 1 );
$name = "Blah? blablablablabla"; //What should this be? //Answer: Object name $contentObject->setAttribute( 'name', $name ); $parentNodeID = 164; // choose where to put the object
$nodeAssignment =& eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => $parentNodeID,
'sort_field' => 2,
'sort_order' => 0,
'is_main' => 1
)
); $nodeAssignment->store(); $version =& $contentObject->version( 1 );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT ); $version->store();
$contentObjectID = $contentObject->attribute( 'id' ); $contentObjectAttributes =& $version->contentObjectAttributes();
// Set attribute values for this class depending on attributes it has and its attribute datatype
// Should be setAttribute( 'data_int', $attributeValue ) if the attribute is integer.
// If user, image, binary file, you also need to stort something in extra tables.
//You need to know how does // eZ publish store these kind of content. $attributeValue = 'Testing testing...claus';
$contentObjectAttributes[0]->setAttribute( 'data_text', $attributeValue ); $contentObjectAttributes[0]->store();
//$contentObjectAttributes[1]->setAttribute( 'data_text', $attributeValue ); //$contentObjectAttributes[1]->store();
//$contentObjectAttributes[2]->setAttribute( 'data_text', $attributeValue ); //$contentObjectAttributes[2]->store();
//$contentObjectAttributes[3]->setAttribute( 'data_text', $attributeValue ); //$contentObjectAttributes[3]->store();
$contentObjectAttributes[4]->setAttribute( 'data_text', $attributeValue ); $contentObjectAttributes[4]->store();
$contentObjectAttributes[5]->setAttribute( 'data_text', $attributeValue ); $contentObjectAttributes[5]->store();
$contentObjectAttributes[6]->setAttribute( 'data_text', $attributeValue ); $contentObjectAttributes[6]->store(); $contentObject->store();
// Publish it
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObjectID, 'version' => 1 ) ); ?>
Cheers, claÜs
|