eZ Community » Forums » Developer » Writing Import scrip Ez 4 problems
expandshrink

Writing Import scrip Ez 4 problems

Writing Import scrip Ez 4 problems

Wednesday 14 May 2008 5:16:30 pm - 7 replies

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 ) );

Monday 19 May 2008 7:31:40 am

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.

Monday 19 May 2008 10: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

Monday 19 May 2008 11: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 );
}

Monday 19 May 2008 5:42:19 pm

Bingo!!!!!!!!

Thanks a lot folks

PiR

Thursday 03 July 2008 11: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 ) );

Modified on Thursday 03 July 2008 1:56:57 pm by Ole Morten Halvorsen

Wednesday 27 July 2011 12:56:37 pm

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.

Tuesday 29 September 2015 12:12:50 pm

Thank you very much !

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from