import ezxml datatype in PHP CLI script

Author Message

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>&nbsp;</paragraph>", "", $domString );
    $domString = str_replace( "<paragraph></paragraph>", "", $domString );
    $domString = preg_replace( "#[\n]+#", "", $domString );
    $domString = preg_replace( "#&lt;/line&gt;#", "\n", $domString );
    $domString = preg_replace( "#&lt;paragraph&gt;#", "\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 12:29:52 am

Which eZp version are you using?

Fabio Carissimi

Wednesday 12 July 2006 2:13:22 am

Hello,

This is eZpublish 3.8.0 with php 4.4.2, MySql 4.1.18, Apache 2.0.55 (on a Mandriva Linux Limited Edition 2005).

Thanks for help

Fabio Carissimi

Wednesday 12 July 2006 2:48:34 am

Your question helps me to find the problem,
I have upgraded to eZpublish 3.8.1 and it works fine

it was a bug and it has been fixed: see http://ez.no/bugs/view/8343

Thanks for your 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();
}

Fabio Carissimi

Wednesday 12 July 2006 9:06:24 am

ok
I am using this one now and everything is ok

Thanks

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 21 2025 04:28:45
Script start
Timing: Jan 21 2025 04:28:45
Module start 'layout'
Timing: Jan 21 2025 04:28:45
Module start 'content'
Timing: Jan 21 2025 04:28:45
Module end 'content'
Timing: Jan 21 2025 04:28:45
Script end

Main resources:

Total runtime0.0170 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0068 594.2891151.2266
Module start 'layout' 0.00680.0030 745.515636.6797
Module start 'content' 0.00980.0053 782.195398.1719
Module end 'content' 0.01510.0017 880.367237.9922
Script end 0.0168  918.3594 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002414.2549140.0002
Check MTime0.00116.4207140.0001
Mysql Total
Database connection0.00084.827810.0008
Mysqli_queries0.003922.666730.0013
Looping result0.00000.158410.0000
Template Total0.00137.410.0013
Template load0.00105.822010.0010
Template processing0.00031.581710.0003
Override
Cache load0.00074.105710.0007
General
dbfile0.00148.193180.0002
String conversion0.00000.064540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs