Forums / Developer / import ezxml datatype in PHP CLI script

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

eZ debug

Timing: Jan 21 2025 02:49:35
Script start
Timing: Jan 21 2025 02:49:35
Module start 'content'
Timing: Jan 21 2025 02:49:35
Module end 'content'
Timing: Jan 21 2025 02:49:35
Script end

Main resources:

Total runtime0.1559 sec
Peak memory usage2,048.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0053 587.8281180.8281
Module start 'content' 0.00530.0053 768.6563101.9141
Module end 'content' 0.01060.1452 870.5703537.3281
Script end 0.1559  1,407.8984 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00362.3399200.0002
Check MTime0.00150.9825200.0001
Mysql Total
Database connection0.00070.441810.0007
Mysqli_queries0.111771.64411410.0008
Looping result0.00120.77361390.0000
Template Total0.144892.910.1448
Template load0.00090.563010.0009
Template processing0.143992.321010.1439
Override
Cache load0.00060.384710.0006
Sytem overhead
Fetch class attribute can translate value0.00110.720210.0011
XML
Image XML parsing0.00030.167410.0003
General
dbfile0.00181.1233200.0001
String conversion0.00000.004930.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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