Saturday 10 February 2007 12:07:51 am
It's me again =) I get a new error trying to insert html data like "word<br />word2" into a xml bloc attribute. I have found this page : http://ez.no/ezpublish/documentation/development/importing_attribute_data and here is how I use it :
$classID = 17;
$nodeID = 79;
if ( !$class = eZContentClass::fetch( $classID ) )
{
$cli->output('Error: Could not fetch class');
}
$node = eZContentObjectTreeNode::fetch($nodeID);
if (!$node)
{
$cli->output('Error: no mapped parent node');
}
$object =& $class->instantiate();
if (!$object)
{
$cli->output('Error: could not create object');
}
$objectID = $object->attribute( 'id' );
$cli->output('Object ID: ' . $objectID);
$cli->output('Node ID: ' . $nodeID);
$cli->output();
$nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $objectID,
'contentobject_version' => 1,
'parent_node' => $nodeID,
'is_main' => 1 )
);
$nodeAssignment->store();
$dataMap =& $object->dataMap();
foreach( array_keys( $dataMap ) as $key )
{
$cli->output($key);
$attribute =& $dataMap[$key];
$classAttributeID = $attribute->attribute( 'contentclassattribute_id' );
switch ($key){
case 'titre':
$attribute->setAttribute( 'data_text',$title );
break;
case 'contenu':
$contentClassAttribute = $attribute->attribute( 'contentclass_attribute' );
$dummy = "";
$converter = new text2xml( $dummy, 0, $contentClassAttribute );
$converter->validateText( $introtext, $contentClassAttribute );
$attribute->SetAttribute( 'data_int', EZ_XMLTEXT_VERSION_TIMESTAMP );
break;
}
$attribute->store();
}
if ( !eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $objectID, 'version' => 1 ) ) )
{
// TODO:
// add to the list of errors
$cli->output('Error: Could not execute');
}
$introtext is my html text queried in a database, and the definition of the text2xml class is included at bottom of the script.(I have paste them into an external php file). So I get this error : Fatal error: Call to a member function on a non-object in /var/www/eztest/convert.php on line 97
And here is the line 97 : $objects =& $dom->elementsByName( 'object' );
If I don't try to set this xml bloc attribute my object is nicely created, so the rest of the code is ok (I get it on eZpedia ;-)) Sorry for all this questions !
eZ Publish Freelance
web : http://www.webaxis.fr
|