Fabio Carissimi
|
Tuesday 11 July 2006 1:58:47 am
Hello,
I have an error when I use the fonction setEZXMLAttribute() which is defined in rssimport.php (in cronjobs) to import
xmlblock datatype in an object within a php CLI script. here the function function setEZXMLAttribute( &$attribute, &$attributeValue, $link = false )
{
include_once( "kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinput.php" );
$inputData = "<?xml version=\"1.0\"?>";
$inputData .= "<section>";
$inputData .= "<paragraph>";
$inputData .= $attributeValue;
$inputData .= "</paragraph>";
$inputData .= "</section>";
$dumpdata = "";
$simplifiedXMLInput = new eZSimplifiedXMLInput( $dumpdata, null, null );
$inputData = $simplifiedXMLInput->convertInput( &$inputData );
$domString = eZXMLTextType::domString( $inputData[0]);
$domString = str_replace( "<paragraph> </paragraph>", "", $domString );
$domString = str_replace ( "<paragraph />" , "", $domString );
$domString = str_replace ( "<line />" , "", $domString );
$domString = str_replace ( "<paragraph></paragraph>" , "", $domString );
$domString = str_replace( "<paragraph> </paragraph>", "", $domString );
$domString = str_replace( "<paragraph></paragraph>", "", $domString );
$domString = preg_replace( "#[\n]+#", "", $domString );
$domString = preg_replace( "#</line>#", "\n", $domString );
$domString = preg_replace( "#<paragraph>#", "\n\n", $domString );
$xml = new eZXML();
$tmpDom =& $xml->domTree( $domString, array( 'CharsetConversion' => false ) );
$description = eZXMLTextType::domString( $tmpDom );
$attribute->setAttribute( 'data_text', $description );
$attribute->store();
}
the error message is Fatal error: Call to a member function on a non-object in /var/www/ezpublish/kernel/classes/datatypes/ezxmltext/ezxmltexttype.php on line 340
the line 340 of ezxmltexttype.php is $domString = $domDocument->toString( $charset ); in the domString() function
so it refers to $domString = eZXMLTextType::domString( $inputData[0]); and it happens because $inputData[0] is empty. it seems that in these 2 lines $simplifiedXMLInput = new eZSimplifiedXMLInput( $dumpdata, null, null );
$inputData = $simplifiedXMLInput->convertInput( &$inputData );
the inputData has been lost (I have verified it with debug outputs) and I don't know why.
In a first time, I thought that it was an encoding problem and I used utf8_encode() to give
utf8 data to the function but the problem remains. I also tried to insert data without using dom and xml treatment,
only putting the data in the xml body (<?xml version=\"1.0\"?><section><paragraph>$attributeValue</paragraph></section>)
and set the attribute ($attribute->setAttribute( 'data_text', $description );) and it works,
but I believe there are reasons to do this xml treatment. So, somebody knows where is the problem ? Thanks for help
|
Kirill Subbotin
|
Wednesday 12 July 2006 3:46:01 am
I verified that fix, and found that it's not ok too. See my report http://ez.no/community/bugs/rss_import_to_xml_text_block_is_broken Here is the correct function for 3.8 :
function setEZXMLAttribute( &$attribute, &$attributeValue, $link = false )
{
include_once( 'kernel/classes/datatypes/ezxmltext/handlers/input/ezsimplifiedxmlinputparser.php' );
$contentObjectID = $attribute->attribute( "contentobject_id" );
$parser = new eZSimplifiedXMLInputParser( $contentObjectID, false, 0 );
$attributeValue = str_replace( "\r", '', $attributeValue );
$attributeValue = str_replace( "\n", '', $attributeValue );
$attributeValue = str_replace( "\t", ' ', $attributeValue );
$document = $parser->process( $attributeValue );
if ( !is_object( $document ) )
{
$cli =& eZCLI::instance();
$cli->output( 'Error in xml parsing' );
return;
}
$domString = eZXMLTextType::domString( $document );
$attribute->setAttribute( 'data_text', $domString );
$attribute->store();
}
|