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.