This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » eZContentFunctions::updateAndPublishO...
expandshrink

eZContentFunctions::updateAndPublishObject and nesting level

eZContentFunctions::updateAndPublishObject and nesting level

Wednesday 23 November 2011 2:19:13 pm - 3 replies

Hi there,

I would like to link an object to an another object who have been just created, but wherever the code looks correct to me, I have error messages. ($object is a correct eZContentObject and $objet_cree->ID is a correct ObjectID) :

$params = array();
$params['attributes']['my_informations'] = $objet_cree->ID;
 
eZContentFunctions::updateAndPublishObject( $object, $params );

And I have the following error :

Fatal error: Maximum function nesting level of '100' reached, aborting!

Any idea ?

Thursday 24 November 2011 6:04:20 pm

You seem to be struggling with this series of functions happy.gif Emoticon

Could you share the whole snippet ?

Cheers,

Friday 25 November 2011 10:15:48 am

Hi Nicolas,

You'll laugh : it is the same piece of code !

So, here is the full code :

<?php
 
class Inscription extends eZWorkflowEventType
{
 
    const WORKFLOW_TYPE_STRING = "inscription";
 
    function Inscription()
    {
        $this->eZWorkflowEventType(
            Inscription::WORKFLOW_TYPE_STRING, 
            ezpI18n::tr( 'st_martin/workflow', 'Registering a partner' ) );
        $this->setTriggerTypes( array( 'content' => array( 'publish' => array( 'after' ) ) ) );
    }
 
    function execute( $process, $event )
    {
 
        $parameters = $process->attribute( 'parameter_list' );
        $object = eZContentObject::fetch( $parameters['object_id'] );
 
        if ( is_object( $object ) )
        {
 
            // die( "Creation" );
 
            // On vérifie qu'il s'agit bien d'un utilisateur dans le groupe 'partners'
            // Autrement on ne fait rien.
            if ( $object->ClassName == 'User' && $object->mainParentNodeID() == "78" )
            {
 
                $dm = $object->DataMap();
 
                $params = array();
                $params['parent_node_id'] = 64;
                $params['class_identifier'] = 'partner';
 
                $attributesData = array();
                $attributesData['name'] = $dm['partner_name']->DataText;
 
                $params['attributes'] = $attributesData;
                
                $objet_cree = eZContentFunctions::createAndPublishObject($params);
 
                // On met à jours l'utilisateur qui viens d'être créé afin de le
                // rattacher au partenaire qui viens lui aussi d'être créé
                $params = array();
                $params['attributes']['my_informations'] = $objet_cree->ID;
 
                eZContentFunctions::updateAndPublishObject( $object, $params );
 
            }
 
        }
 
        return eZWorkflowType::STATUS_ACCEPTED;
 
    }
 
}
 
eZWorkflowEventType::registerEventType( Inscription::WORKFLOW_TYPE_STRING, 'Inscription' );
 
?>

Friday 25 November 2011 2:15:01 pm

I solved my problem using another method :

 Partner::save_eZ_attribute( $dmu['my_informations'], $objet_cree->ID );

with :

Mugo Web Copyright (C) 2008 => extension data_import (http://projects.ez.no/data_import)
    public static function save_eZ_attribute( $contentObjectAttribute, $value ){
                        
        //print_r($contentObjectAttribute);
        
        switch( $contentObjectAttribute->attribute( 'data_type_string' ) ){
                
            case 'ezobjectrelation':
 
                // Remove any exisiting value first from ezobjectrelation
                        
                eZContentObject::removeContentObjectRelation(
                    $contentObjectAttribute->attribute('data_int'),
                    $this->current_eZ_object->attribute('current_version'),
                    $this->current_eZ_object->attribute('id'),
                    $contentObjectAttribute->attribute('contentclassattribute_id')
                );
                        
                $contentObjectAttribute->setAttribute( 'data_int', 0 );
                $contentObjectAttribute->store();
                        
                break;
                
            case 'ezobjectrelationlist':
                
                // Remove any exisiting value first from ezobjectrelationlist
                        
                $content = $contentObjectAttribute->content();
                $relationList =& $content['relation_list'];
                $newRelationList = array();
                for ( $i = 0; $i < count( $relationList ); ++$i )
                {
                    $relationItem = $relationList[$i];
                    eZObjectRelationListType::removeRelationObject( $contentObjectAttribute, $relationItem );
                }
                $content['relation_list'] =& $newRelationList;
                $contentObjectAttribute->setContent( $content );
                $contentObjectAttribute->store();
                        
                break;
 
        }
        
        // fromString returns false - even when it is successfull
        // create a bug report for that
        $contentObjectAttribute->fromString( $value );
        $contentObjectAttribute->store();
            
    }

Modified on Friday 25 November 2011 2:15:28 pm by Damien MARTIN

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from