Forums / Developer / Writing Import scrip Ez 4 problems

Writing Import scrip Ez 4 problems

Author Message

Pierre Tissot

Wednesday 14 May 2008 8:16:30 am

Hi,

I'm importing some information from another mysql database to ez publish, i'm doing this by script but somehow the data in the table ez_contentobject_tree is not being writen, all the rest seems to be okay.

Can anybody tell me what is wrong, here a summary of the most important parts of my script:

                    $class = eZContentClass::fetchByIdentifier( $class );
          
                    $user =& eZUser::currentUser();
                    $userID =& $user->attribute( 'contentobject_id' );
                    $sectionID = $parentContentObject->attribute( 'section_id' );
                       
                    $contentObject =& $class->instantiate( $userID, $sectionID);                    
                    $contentObject->store();

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

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

                    $contentObjectID = $contentObject->attribute( 'id' );
                    $attributes = $contentObject->attribute( 'contentobject_attributes' );
                 
                    // Setting the attributes with the data under array fields
                    while ( list( $key, $attribute ) = each( $attributes ) )
                    {
                        
                        if($fields[$attribute->contentClassAttributeIdentifier()]){
                            $value=$fields[$attribute->contentClassAttributeIdentifier()];
                            $attribute->setAttribute( 'data_text', $value );
                            $attribute->store();
                        }
                    }
   
                    eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
                                                              'version'   => 1 ) );

Maxime Thomas

Sunday 18 May 2008 10:31:40 pm

Hi,

I've you checked in the database if the data are stored ? If yes, it's maybe a cache issue. You can use the ezcontentcachemanager to clear the cache if needed.
You can also put some code like the following :

eZDebug::writeDebug(eZContentObject::fetch( $contentObjectID));

And then when you are running your script, enable the debug to see what is inside your object.

Hope it helps.

Maxime Thomas
maxime.thomas@wascou.org | www.wascou.org | http://twitter.com/wascou

Company Blog : http://www.wascou.org/eng/Company/Blog
Technical Blog : http://share.ez.no/blogs/maxime-thomas

Pierre Tissot

Monday 19 May 2008 1:28:16 am

Hi

Thanks for the tip, but still I have no clues. The data is missing on the database only on the ezcontentobject_tree table all the rest is there.

My code is generating this output on error.log:

[ May 19 2008 09:53:42 ] [linux-isfb1] eZModuleOperationInfo::loadDefinition:
Missing operation definition file for module: content

[ May 19 2008 09:53:42 ] [linux-isfb1] eZOperationHandler::execute:
Cannot execute operation 'publish' in module 'content', no valid data

André R.

Monday 19 May 2008 2:21:30 am

Are you running this without the autoload.php file included or something?

I have seen a similar error so you can try adding this in the start of your script:

// Work around for:
// #012782: Invalid argument supplied for foreach() in ezmoduleoperationinfo.php
if ( eZModule::globalPathList( ) === null  )
{
    $moduleRepositories = eZModule::activeModuleRepositories();
    eZModule::setGlobalPathList( $moduleRepositories );
}

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Pierre Tissot

Monday 19 May 2008 8:42:19 am

Bingo!!!!!!!!

Thanks a lot folks

PiR

Ole Morten Halvorsen

Thursday 03 July 2008 2:20:29 am

If you get these kinds of messages in your script:

[ May 19 2008 09:53:42 ] [linux-isfb1] eZModuleOperationInfo::loadDefinition:
Missing operation definition file for module: content

[ May 19 2008 09:53:42 ] [linux-isfb1] eZOperationHandler::execute:
Cannot execute operation 'publish' in module 'content', no valid data

you do not need to add the code André posted, just make sure to initialize eZScript with 'use-modules' and eZScript will do the job for you.

$script = eZScript::instance( array( 'description' => "my description",
                                      'use-session' => true,
                                      'use-modules' => true,
                                      'use-extensions' => true ) );

Senior Software Engineer - Vision with Technology

http://www.visionwt.com
http://www.omh.cc
http://www.twitter.com/omh

eZ Certified Developer
http://ez.no/certification/verify/358441
http://ez.no/certification/verify/272578

Jitesh Rana

Wednesday 27 July 2011 3:56:37 am

"

Are you running this without the autoload.php file included or something?

I have seen a similar error so you can try adding this in the start of your script:

// Work around for:
// #012782: Invalid argument supplied for foreach() in ezmoduleoperationinfo.php
if ( eZModule::globalPathList( ) === null  )
{
    $moduleRepositories = eZModule::activeModuleRepositories();
    eZModule::setGlobalPathList( $moduleRepositories );
}
"

It works like a charm. It is the solution what i am looking for since last 6 months.

Thanks a lot André for your helpful snippet.

eZ debug

Timing: Jan 29 2025 13:44:35
Script start
Timing: Jan 29 2025 13:44:35
Module start 'content'
Timing: Jan 29 2025 13:44:35
Module end 'content'
Timing: Jan 29 2025 13:44:35
Script end

Main resources:

Total runtime0.0167 sec
Peak memory usage2,048.0000 KB
Database Queries4

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 587.9531180.8281
Module start 'content' 0.00520.0049 768.7813106.1172
Module end 'content' 0.01000.0066 874.898482.7031
Script end 0.0166  957.6016 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.001911.2112120.0002
Check MTime0.00105.7635120.0001
Mysql Total
Database connection0.00053.279210.0005
Mysqli_queries0.002716.094240.0007
Looping result0.00000.065820.0000
Template Total0.006337.910.0063
Template load0.00074.029610.0007
Template processing0.005633.785010.0056
Override
Cache load0.00042.644510.0004
General
dbfile0.003118.7029100.0003
String conversion0.00000.030030.0000
Note: percentages do not add up to 100% because some accumulators overlap

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