Author Topic

Paul Leclercq

Wednesday 05 May 2010 7:38:12 am

Comment58947

There are 2 good ways of publishing new content when creating an import script:

The one you stated in your second post:

exemple:

<span>$params</span> = <a href="http://www.php.net/array" mce_href="http://www.php.net/array"><span>array</span></a><span>(</span><span>)</span>;
<span>$params</span><span>[</span><span>'parent_node_id'</span><span>]</span> = <span>52</span>; <span>// node id of /Media/Files</span>
<span>$params</span><span>[</span><span>'class_identifier'</span><span>]</span> = <span>'file'</span>;
<span>$params</span><span>[</span><span>'creator_id'</span><span>]</span> = <span>14</span>; <span>// admin</span>
<span>$params</span><span>[</span><span>'storage_dir'</span><span>]</span> = <span>'/tmp/data/'</span>; <span>// don't forget the ended /</span>
<span>$params</span><span>[</span><span>'section_id'</span><span>]</span> = <span>3</span>; <span>// section media</span>
 
<span>$attributesData</span> = <a href="http://www.php.net/array" mce_href="http://www.php.net/array"><span>array</span></a><span>(</span><span>)</span>;
<span>$attributesData</span><span>[</span><span>'name'</span><span>]</span> = <span>'My file'</span>;
<span>$attributesData</span><span>[</span><span>'file'</span><span>]</span> = <span>'my_file.txt'</span>;
 
<span>$params</span><span>[</span><span>'attributes'</span><span>]</span> = <span>$attributesData</span>;
<span>$contentObject</span> = eZContentFunctions::<span>createAndPublishObject</span><span>(</span> <span>$params</span> <span>)</span>;

But if I were you, I would base my import script on the following file you will find in your Exponential installation under:

bin/php/ezcsvimport.php

You will find Marks method in that file, which is the standard method used, and everything you need to create setup your attributes with the value you would like.

All you will need is to setup your $nodeID value.

This is also the code they give you during eZSystem's advanced Exponential training course:

-----------------------------------

$class = eZContentClass::fetchByIdentifier( 'article' );
$contentObject = $class->instantiate( $creator );
$contentObject->store();

$nodeAssignment = eZNodeAssignment::create( array(
'contentobject_id' => $contentObject->attribute( 'id' ),
'contentobject_version' => $contentObject->attribute( 'current_version' ),
'parent_node' => $nodeID,
'is_main' => 1
)
);
$nodeAssignment->store();

$version = $contentObject->version( 1 );
$version->setAttribute( 'modified', eZDateTime::currentTimeStamp() );
$version->setAttribute( 'status', eZContentObjectVersion::STATUS_DRAFT );
$version->store();

$attributes = $contentObject->attribute( 'contentobject_attributes' );
while ( list( $key, $attribute ) = each( $attributes ) )
{
$dataString = $objectData[$key];
switch ( $datatypeString = $attribute->attribute( 'data_type_string' ) )
{
case 'ezimage':
case 'ezbinaryfile':
case 'ezmedia':
{
$dataString = eZDir::path( array( $storageDir, $dataString ) );
break;
}
default:
}
$attribute->fromString( $dataString );
$attribute->store();
}

$operationResult = eZOperationHandler::execute( 'content', 'publish',
array( 'object_id' => $contentObjectID,
'version'=> 1 ) );

-----------------------------------

Well good luck with that anyway,