Monday 18 August 2008 7:14:15 am
Im trying to write a short command line script to import pdf-documents located in a folder on my hard drive, but I have some problems working through the documentation This is what i came up with:
function import ($nodeID, $filePath, $name) {
if ( file_exists( $filePath ) )
{
$classID = 28; // file class id
$creatorID = 14; // user object id > default administrator
$class =& eZContentClass::fetch( $classID );
$parentNodeID = $nodeID;
$contentObject =& $class->instantiate( $creatorID, 1 );
$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( 'modified', eZDateTime::currentTimeStamp() );
$version->setAttribute( 'status', EZ_VERSION_STATUS_DRAFT );
$version->store();
$contentObjectID = $contentObject->attribute( 'id' );
$dataMap =& $contentObject->dataMap();
$dataMap['name']->setAttribute( 'data_text', $name );
$dataMap['name']->store();
$fileContent =& $dataMap['binary']->attribute( 'content' );
$fileContent->initializeFromFile( $filePath , $name);
$dataMap['file']->store();
$operationResult = eZOperationHandler::execute (
'content',
'publish',
array (
'object_id' => $contentObjectID,
'version' => 1
));
}
}
I get an error message like
Call to a member function initializeFromFile() on a non-object in
I guess the datamap is wrong, but I don't know how to set it. Any hints?
|