/**
  * Update a node's main assignment
  *
  * @param int $mainAssignmentID
  * @param int $objectID
  * @param int $mainAssignmentParentID
  *
  * @return array An array with operation status, always true
  */
 public static function updateMainAssignment($mainAssignmentID, $ObjectID, $mainAssignmentParentID)
 {
     eZContentObjectTreeNode::updateMainNodeID($mainAssignmentID, $ObjectID, false, $mainAssignmentParentID);
     eZContentCacheManager::clearContentCacheIfNeeded($ObjectID);
     return array('status' => true);
 }
    function installSuspendedNodeAssignment( &$installParameters )
    {
        if ( !isset( $installParameters['suspended-nodes'] ) )
        {
            return;
        }
        foreach ( $installParameters['suspended-nodes'] as $parentNodeRemoteID => $suspendedNodeInfo )
        {
            $parentNode = eZContentObjectTreeNode::fetchByRemoteID( $parentNodeRemoteID );
            if ( $parentNode !== null )
            {
                $nodeInfo = $suspendedNodeInfo['nodeinfo'];
                $nodeInfo['parent_node'] = $parentNode->attribute( 'node_id' );

                $existNodeAssignment = eZPersistentObject::fetchObject( eZNodeAssignment::definition(),
                                                           null,
                                                           $nodeInfo );
                $nodeInfo['priority'] = $suspendedNodeInfo['priority'];
                if( !is_object( $existNodeAssignment ) )
                {
                    $nodeAssignment = eZNodeAssignment::create( $nodeInfo );
                    $nodeAssignment->store();
                }

                $contentObject = eZContentObject::fetch( $nodeInfo['contentobject_id'] );
                if ( is_object( $contentObject ) && $contentObject->attribute( 'current_version' ) == $nodeInfo['contentobject_version'] )
                {
                   eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $nodeInfo['contentobject_id'],
                                                                              'version' =>  $nodeInfo['contentobject_version'] ) );
                }
                if ( isset( $nodeInfo['is_main'] ) && $nodeInfo['is_main'] )
                {
                    $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $nodeInfo['parent_remote_id'], false );
                    if ( $existingMainNode )
                    {
                        eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
                                                                   $nodeInfo['contentobject_id'],
                                                                   $nodeInfo['contentobject_version'],
                                                                   $nodeInfo['parent_node'] );
                    }
                }
            }
            else
            {
                eZDebug::writeError( 'Can not find parent node by remote-id ID = ' . $parentNodeRemoteID, __METHOD__ );
            }
            unset( $installParameters['suspended-nodes'][$parentNodeRemoteID] );
        }
    }
 function removeNodeFromTree($moveToTrash = true)
 {
     $nodeID = $this->attribute('node_id');
     $object = $this->object();
     $assignedNodes = $object->attribute('assigned_nodes');
     if ($nodeID == $this->attribute('main_node_id')) {
         if (count($assignedNodes) > 1) {
             $newMainNode = false;
             foreach ($assignedNodes as $assignedNode) {
                 $assignedNodeID = $assignedNode->attribute('node_id');
                 if ($assignedNodeID == $nodeID) {
                     continue;
                 }
                 $newMainNode = $assignedNode;
                 break;
             }
             // We need to change the main node ID before we remove the current node
             $db = eZDB::instance();
             $db->begin();
             eZContentObjectTreeNode::updateMainNodeID($newMainNode->attribute('node_id'), $object->attribute('id'), $object->attribute('current_version'), $newMainNode->attribute('parent_node_id'));
             $this->removeThis();
             eZSearch::addObject($object);
             $db->commit();
         } else {
             // This is the last assignment so we remove the object too
             $db = eZDB::instance();
             $db->begin();
             $this->removeThis();
             if ($moveToTrash) {
                 // saving information about this node in ..trash_node table
                 $trashNode = eZContentObjectTrashNode::createFromNode($this);
                 $db = eZDB::instance();
                 $db->begin();
                 $trashNode->storeToTrash();
                 $db->commit();
                 $object->removeThis();
             } else {
                 $object->purge();
             }
             $db->commit();
         }
     } else {
         $this->removeThis();
         if (count($assignedNodes) > 1) {
             eZSearch::addObject($object);
         }
     }
 }
    /**
     * Unserialize xml structure. Creates an object from xml input.
     *
     * Transaction unsafe. If you call several transaction unsafe methods you must enclose
     * the calls within a db transaction; thus within db->begin and db->commit.
     *
     * @param mixed $package
     * @param DOMElement $domNode
     * @param array $options
     * @param int|bool $ownerID Override owner ID, null to use XML owner id (optional)
     * @param string $handlerType
     * @return array|bool|eZContentObject|null created object, false if could not create object/xml invalid
     */
    static function unserialize( $package, $domNode, &$options, $ownerID = false, $handlerType = 'ezcontentobject' )
    {
        if ( $domNode->localName != 'object' )
        {
            $retValue = false;
            return $retValue;
        }

        $initialLanguage = eZContentObject::mapLanguage( $domNode->getAttribute( 'initial_language' ), $options );
        if( $initialLanguage === 'skip' )
        {
            $retValue = true;
            return $retValue;
        }

        $sectionID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'section_id' );
        if ( $ownerID === false )
        {
            $ownerID = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'owner_id' );
        }
        $remoteID = $domNode->getAttribute( 'remote_id' );
        $name = $domNode->getAttribute( 'name' );
        $classRemoteID = $domNode->getAttribute( 'class_remote_id' );
        $classIdentifier = $domNode->getAttributeNS( 'http://ez.no/ezobject', 'class_identifier' );
        $alwaysAvailable = ( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'always_available' ) == '1' );

        $contentClass = eZContentClass::fetchByRemoteID( $classRemoteID );
        if ( !$contentClass )
        {
            $contentClass = eZContentClass::fetchByIdentifier( $classIdentifier );
        }

        if ( !$contentClass )
        {
            $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_NO_CLASS,
                                       'element_id' => $remoteID,
                                       'description' => "Can't install object '$name': Unable to fetch class with remoteID: $classRemoteID." );
            $retValue = false;
            return $retValue;
        }

        /** @var DOMElement $versionListNode */
        $versionListNode = $domNode->getElementsByTagName( 'version-list' )->item( 0 );

        $importedLanguages = array();
        foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode )
        {
            /** @var DOMElement $versionDOMNode */
            foreach ( $versionDOMNode->getElementsByTagName( 'object-translation' ) as $versionDOMNodeChild )
            {
                /** @var DOMElement $versionDOMNodeChild */
                $importedLanguage = eZContentObject::mapLanguage( $versionDOMNodeChild->getAttribute( 'language' ), $options );
                $language = eZContentLanguage::fetchByLocale( $importedLanguage );
                // Check if the language is allowed in this setup.
                if ( $language )
                {
                    $hasTranslation = true;
                }
                else
                {
                    if ( $importedLanguage == 'skip' )
                        continue;

                    // if there is no needed translation in system then add it
                    $locale = eZLocale::instance( $importedLanguage );
                    $translationName = $locale->internationalLanguageName();
                    $translationLocale = $locale->localeCode();

                    if ( $locale->isValid() )
                    {
                        eZContentLanguage::addLanguage( $locale->localeCode(), $locale->internationalLanguageName() );
                        $hasTranslation = true;
                    }
                    else
                        $hasTranslation = false;
                }
                if ( $hasTranslation )
                {
                    $importedLanguages[] = $importedLanguage;
                    $importedLanguages = array_unique( $importedLanguages );
                }
            }
        }

        // If object exists we return a error.
        // Minimum install element is an object now.

        $contentObject = eZContentObject::fetchByRemoteID( $remoteID );
        // Figure out initial language
        if ( !$initialLanguage ||
             !in_array( $initialLanguage, $importedLanguages ) )
        {
            $initialLanguage = false;
            foreach ( eZContentLanguage::prioritizedLanguages() as $language )
            {
                if ( in_array( $language->attribute( 'locale' ), $importedLanguages ) )
                {
                    $initialLanguage = $language->attribute( 'locale' );
                    break;
                }
            }
        }
        if ( !$contentObject )
        {
            $firstVersion = true;
            $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
        }
        else
        {
            $firstVersion = false;
            $description = "Object '$name' already exists.";

            $choosenAction = eZPackageHandler::errorChoosenAction( self::PACKAGE_ERROR_EXISTS,
                                                                   $options, $description, $handlerType, false );

            switch( $choosenAction )
            {
                case eZPackage::NON_INTERACTIVE:
                case self::PACKAGE_UPDATE:
                {
                    // Keep existing contentobject.
                } break;

                case self::PACKAGE_REPLACE:
                {
                    eZContentObjectOperations::remove( $contentObject->attribute( 'id' ) );

                    unset( $contentObject );
                    $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
                    $firstVersion = true;
                } break;

                case self::PACKAGE_SKIP:
                {
                    $retValue = true;
                    return $retValue;
                } break;

                case self::PACKAGE_NEW:
                {
                    $contentObject->setAttribute( 'remote_id', eZRemoteIdUtility::generate( 'object' ) );
                    $contentObject->store();
                    unset( $contentObject );
                    $contentObject = $contentClass->instantiateIn( $initialLanguage, $ownerID, $sectionID );
                    $firstVersion = true;
                } break;

                default:
                {
                    $options['error'] = array( 'error_code' => self::PACKAGE_ERROR_EXISTS,
                                               'element_id' => $remoteID,
                                               'description' => $description,
                                               'actions' => array( self::PACKAGE_REPLACE => ezpI18n::tr( 'kernel/classes', 'Replace existing object' ),
                                                                   self::PACKAGE_SKIP    => ezpI18n::tr( 'kernel/classes', 'Skip object' ),
                                                                   self::PACKAGE_NEW     => ezpI18n::tr( 'kernel/classes', 'Keep existing and create a new one' ),
                                                                   self::PACKAGE_UPDATE  => ezpI18n::tr( 'kernel/classes', 'Update existing object' ) ) );
                    $retValue = false;
                    return $retValue;
                } break;
            }
        }

        $db = eZDB::instance();
        $db->begin();

        if ( $alwaysAvailable )
        {
            // Make sure always available bit is set.
            $contentObject->setAttribute( 'language_mask', (int)$contentObject->attribute( 'language_mask' ) | 1 );
        }

        $contentObject->setAttribute( 'section_id', $sectionID );
        $contentObject->store();
        $activeVersion = false;
        $lastVersion = false;
        $versionListActiveVersion = $versionListNode->getAttribute( 'active_version' );

        $contentObject->setAttribute( 'remote_id', $remoteID );
        $contentObject->setAttribute( 'contentclass_id', $contentClass->attribute( 'id' ) );
        $contentObject->store();

        $sectionObject = eZSection::fetch( $sectionID );
        if ( $sectionObject instanceof eZSection )
        {
            $updateWithParentSection = false;
        }
        else
        {
            $updateWithParentSection = true;
        }

        $options['language_array'] = $importedLanguages;
        $versionList = array();
        foreach( $versionListNode->getElementsByTagName( 'version' ) as $versionDOMNode )
        {
            unset( $nodeList );
            $nodeList = array();
            $contentObjectVersion = eZContentObjectVersion::unserialize( $versionDOMNode,
                                                                         $contentObject,
                                                                         $ownerID,
                                                                         $sectionID,
                                                                         $versionListActiveVersion,
                                                                         $firstVersion,
                                                                         $nodeList,
                                                                         $options,
                                                                         $package,
                                                                         'ezcontentobject',
                                                                         $initialLanguage );

            if ( !$contentObjectVersion )
            {
                $db->commit();

                $retValue = false;
                return $retValue;
            }

            $versionStatus = $versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'status' );
            $versionList[$versionDOMNode->getAttributeNS( 'http://ez.no/ezobject', 'version' )] = array( 'node_list' => $nodeList,
                                                                                                         'status' =>    $versionStatus );
            unset( $versionStatus );

            $firstVersion = false;
            $lastVersion = $contentObjectVersion->attribute( 'version' );
            if ( $versionDOMNode->getAttribute( 'version' ) == $versionListActiveVersion )
            {
                $activeVersion = $contentObjectVersion->attribute( 'version' );
            }
            eZNodeAssignment::setNewMainAssignment( $contentObject->attribute( 'id' ), $lastVersion );

            eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ),
                                                                      'version' => $lastVersion ) );

            $mainNodeInfo = null;
            foreach ( $nodeList as $nodeInfo )
            {
                if ( $nodeInfo['is_main'] )
                {
                    $mainNodeInfo =& $nodeInfo;
                    break;
                }
            }
            if ( $mainNodeInfo )
            {
                $existingMainNode = eZContentObjectTreeNode::fetchByRemoteID( $mainNodeInfo['parent_remote_id'], false );
                if ( $existingMainNode )
                {
                    eZContentObjectTreeNode::updateMainNodeID( $existingMainNode['node_id'],
                                                               $mainNodeInfo['contentobject_id'],
                                                               $mainNodeInfo['contentobject_version'],
                                                               $mainNodeInfo['parent_node'],
                                                               $updateWithParentSection );
                }
            }
            unset( $mainNodeInfo );
            // Refresh $contentObject from DB.
            $contentObject = eZContentObject::fetch( $contentObject->attribute( 'id' ) );
        }
        if ( !$activeVersion )
        {
            $activeVersion = $lastVersion;
        }

        /*
        $contentObject->setAttribute( 'current_version', $activeVersion );
        */
        $contentObject->setAttribute( 'name', $name );
        if ( isset( $options['use_dates_from_package'] ) && $options['use_dates_from_package'] )
        {
            $contentObject->setAttribute( 'published', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'published' ) ) );
            $contentObject->setAttribute( 'modified', eZDateUtils::textToDate( $domNode->getAttributeNS( 'http://ez.no/ezobject', 'modified' ) ) );
        }
        $contentObject->store();

        $versions   = $contentObject->versions();
        $objectName = $contentObject->name();
        $objectID   = $contentObject->attribute( 'id' );
        foreach ( $versions as $version )
        {
            $versionNum       = $version->attribute( 'version' );
            $oldVersionStatus = $version->attribute( 'status' );
            $newVersionStatus = isset( $versionList[$versionNum] ) ? $versionList[$versionNum]['status'] : null;

            // set the correct status for non-published versions
            if ( isset( $newVersionStatus ) && $oldVersionStatus != $newVersionStatus && $newVersionStatus != eZContentObjectVersion::STATUS_PUBLISHED )
            {
                $version->setAttribute( 'status', $newVersionStatus );
                $version->store( array( 'status' ) );
            }

            // when translation does not have object name set then we copy object name from the current object version
            $translations = $version->translations( false );
            if ( !$translations )
                continue;
            foreach ( $translations as $translation )
            {
                if ( ! $contentObject->name( $versionNum, $translation ) )
                {
                    eZDebug::writeNotice( "Setting name '$objectName' for version ($versionNum) of the content object ($objectID) in language($translation)" );
                    $contentObject->setName( $objectName, $versionNum, $translation );
                }
            }
        }

        foreach ( $versionList[$versionListActiveVersion]['node_list'] as $nodeInfo )
        {
            unset( $parentNode );
            $parentNode = eZContentObjectTreeNode::fetchNode( $contentObject->attribute( 'id' ),
                                                               $nodeInfo['parent_node'] );
            if ( is_object( $parentNode ) )
            {
                $parentNode->setAttribute( 'priority', $nodeInfo['priority'] );
                $parentNode->store( array( 'priority' ) );
            }
        }

        $db->commit();

        return $contentObject;
    }
Ejemplo n.º 5
0
 static function publishUpdateUser($parentNodeIDs, $defaultUserPlacement, $userAttributes, $isUtf8Encoding = false)
 {
     if (!is_array($userAttributes) or !isset($userAttributes['login']) or empty($userAttributes['login'])) {
         eZDebug::writeWarning('Empty user login passed.', __METHOD__);
         return false;
     }
     if ((!is_array($parentNodeIDs) or count($parentNodeIDs) < 1) and !is_numeric($defaultUserPlacement)) {
         eZDebug::writeWarning('No one parent node IDs was passed for publishing new user (login = "******")', __METHOD__);
         return false;
     }
     $parentNodeIDs[] = $defaultUserPlacement;
     $parentNodeIDs = array_unique($parentNodeIDs);
     $login = $userAttributes['login'];
     $first_name = $userAttributes['first_name'];
     $last_name = $userAttributes['last_name'];
     $email = $userAttributes['email'];
     if ($isUtf8Encoding) {
         $first_name = utf8_decode($first_name);
         $last_name = utf8_decode($last_name);
     }
     $user = eZUser::fetchByName($login);
     $createNewUser = is_object($user) ? false : true;
     if ($createNewUser) {
         if (!isset($first_name) or empty($first_name) or !isset($last_name) or empty($last_name) or !isset($email) or empty($email)) {
             eZDebug::writeWarning('Cannot create user with empty first name (last name or email).', __METHOD__);
             return false;
         }
         $ini = eZINI::instance();
         $userClassID = $ini->variable("UserSettings", "UserClassID");
         $userCreatorID = $ini->variable("UserSettings", "UserCreatorID");
         $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID");
         $class = eZContentClass::fetch($userClassID);
         $contentObject = $class->instantiate($userCreatorID, $defaultSectionID);
         $contentObject->store();
         $userID = $contentObjectID = $contentObject->attribute('id');
         $version = $contentObject->version(1);
         $version->setAttribute('modified', time());
         $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT);
         $version->store();
         $user = eZLDAPUser::create($userID);
         $user->setAttribute('login', $login);
     } else {
         $userID = $contentObjectID = $user->attribute('contentobject_id');
         $contentObject = eZContentObject::fetch($userID);
         $version = $contentObject->attribute('current');
     }
     //================= common part 1: start ========================
     $contentObjectAttributes = $version->contentObjectAttributes();
     // find and set 'name' and 'description' attributes (as standard user group class)
     $firstNameIdentifier = 'first_name';
     $lastNameIdentifier = 'last_name';
     $firstNameAttribute = null;
     $lastNameAttribute = null;
     foreach ($contentObjectAttributes as $attribute) {
         if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) {
             $firstNameAttribute = $attribute;
         } else {
             if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) {
                 $lastNameAttribute = $attribute;
             }
         }
     }
     //================= common part 1: end ==========================
     // If we are updating an existing user, we must find out if some data should be changed.
     // In that case, we must create a new version and publish it.
     if (!$createNewUser) {
         $userDataChanged = false;
         $firstNameChanged = false;
         $lastNameChanged = false;
         $emailChanged = false;
         if ($firstNameAttribute and $firstNameAttribute->attribute('data_text') != $first_name) {
             $firstNameChanged = true;
         }
         $firstNameAttribute = false;
         // We will load this again from the new version we will create, if it has changed
         if ($lastNameAttribute and $lastNameAttribute->attribute('data_text') != $last_name) {
             $lastNameChanged = true;
         }
         $lastNameAttribute = false;
         // We will load this again from the new version we will create, if it has changed
         if ($user->attribute('email') != $email) {
             $emailChanged = true;
         }
         if ($firstNameChanged or $lastNameChanged or $emailChanged) {
             $userDataChanged = true;
             // Create new version
             $version = $contentObject->createNewVersion();
             $contentObjectAttributes = $version->contentObjectAttributes();
             foreach ($contentObjectAttributes as $attribute) {
                 if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) {
                     $firstNameAttribute = $attribute;
                 } else {
                     if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) {
                         $lastNameAttribute = $attribute;
                     }
                 }
             }
         }
     }
     //================= common part 2: start ========================
     if ($firstNameAttribute) {
         $firstNameAttribute->setAttribute('data_text', $first_name);
         $firstNameAttribute->store();
     }
     if ($lastNameAttribute) {
         $lastNameAttribute->setAttribute('data_text', $last_name);
         $lastNameAttribute->store();
     }
     if (!isset($userDataChanged) or $userDataChanged === true) {
         $contentClass = $contentObject->attribute('content_class');
         $name = $contentClass->contentObjectName($contentObject);
         $contentObject->setName($name);
     }
     if (!isset($emailChanged) or $emailChanged === true) {
         $user->setAttribute('email', $email);
     }
     $user->setAttribute('password_hash', "");
     $user->setAttribute('password_hash_type', 0);
     $user->store();
     $debugArray = array('Updating user data', 'createNewUser' => $createNewUser, 'userDataChanged' => isset($userDataChanged) ? $userDataChanged : null, 'login' => $login, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'firstNameAttribute is_object' => is_object($firstNameAttribute), 'lastNameAttribute is_object' => is_object($lastNameAttribute), 'content object id' => $contentObjectID, 'version id' => $version->attribute('version'));
     eZDebug::writeNotice(var_export($debugArray, true), __METHOD__);
     //================= common part 2: end ==========================
     if ($createNewUser) {
         reset($parentNodeIDs);
         // prepare node assignments for publishing new user
         foreach ($parentNodeIDs as $parentNodeID) {
             $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => $defaultUserPlacement == $parentNodeID ? 1 : 0));
             $newNodeAssignment->store();
         }
         $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1));
     } else {
         if ($userDataChanged) {
             // Publish object
             $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version')));
             // Refetch object
             $contentObject = eZContentObject::fetch($contentObjectID);
             $version = $contentObject->attribute('current');
         }
         $LDAPIni = eZINI::instance('ldap.ini');
         $keepGroupAssignment = $LDAPIni->hasVariable('LDAPSettings', 'KeepGroupAssignment') ? $LDAPIni->variable('LDAPSettings', 'KeepGroupAssignment') == "enabled" : false;
         if ($keepGroupAssignment == false) {
             $objectIsChanged = false;
             $db = eZDB::instance();
             $db->begin();
             // First check existing assignments, remove any that should not exist
             $assignedNodesList = $contentObject->assignedNodes();
             $existingParentNodeIDs = array();
             foreach ($assignedNodesList as $node) {
                 $parentNodeID = $node->attribute('parent_node_id');
                 if (!in_array($parentNodeID, $parentNodeIDs)) {
                     $node->removeThis();
                     $objectIsChanged = true;
                 } else {
                     $existingParentNodeIDs[] = $parentNodeID;
                 }
             }
             // Then check assignments that should exist, add them if they are missing
             foreach ($parentNodeIDs as $parentNodeID) {
                 if (!in_array($parentNodeID, $existingParentNodeIDs)) {
                     $newNode = $contentObject->addLocation($parentNodeID, true);
                     $newNode->updateSubTreePath();
                     $newNode->setAttribute('contentobject_is_published', 1);
                     $newNode->sync();
                     $existingParentNodeIDs[] = $parentNodeID;
                     $objectIsChanged = true;
                 }
             }
             // Then ensure that the main node is correct
             $currentMainParentNodeID = $contentObject->attribute('main_parent_node_id');
             if ($currentMainParentNodeID != $defaultUserPlacement) {
                 $existingNode = eZContentObjectTreeNode::fetchNode($contentObjectID, $defaultUserPlacement);
                 if (!is_object($existingNode)) {
                     eZDebug::writeError("Cannot find assigned node as {$defaultUserPlacement}'s child.", __METHOD__);
                 } else {
                     $existingNodeID = $existingNode->attribute('node_id');
                     $versionNum = $version->attribute('version');
                     eZContentObjectTreeNode::updateMainNodeID($existingNodeID, $contentObjectID, $versionNum, $defaultUserPlacement);
                     $objectIsChanged = true;
                 }
             }
             $db->commit();
             // Finally, clear object view cache if something was changed
             if ($objectIsChanged) {
                 eZContentCacheManager::clearObjectViewCache($contentObjectID, true);
             }
         }
     }
     eZUser::updateLastVisit($userID);
     //eZUser::setCurrentlyLoggedInUser( $user, $userID );
     // Reset number of failed login attempts
     eZUser::setFailedLoginAttempts($userID, 0);
     return $user;
 }
 /**
  * Workflow Event Type execute method
  */
 function execute($process, $event)
 {
     /**
      * Fetch workflow process parameters
      */
     $parameters = $process->attribute('parameter_list');
     $objectID = $parameters['object_id'];
     self::writeDebug('writeNotice', "Start '" . self::WORKFLOW_TYPE_STRING . "' workflow event execute method");
     $ini = eZINI::instance('site.ini');
     $bcUserRegisterUserPlacementINI = eZINI::instance('bcuserregisteruserplacement.ini');
     /**
      * Reading the default user class id as it is required to check that we only
      * perform the workflow event on user class content and not other class of objects
      */
     $defaultUserClassID = $ini->hasVariable('UserSettings', 'UserClassID') == true ? $ini->variable('UserSettings', 'UserClassID') : false;
     /**
      * Reading the default user placement nodeID as it is the default location where new users are stored
      */
     $userGroupID = $ini->hasVariable('UserSettings', 'DefaultUserPlacement') == true ? $ini->variable('UserSettings', 'DefaultUserPlacement') : 0;
     self::writeDebug('writeNotice', "User class id is: " . $defaultUserClassID . ' Default user group is: ' . $userGroupID);
     $userGroups = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'MoveToUserGroupId') == true ? $bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'MoveToUserGroupId') : array();
     $objectSelectionAttributeIdentifier = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'UserAttributeSelectionIdentifier') == true ? $bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'UserAttributeSelectionIdentifier') : false;
     $move = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'Move') == true && strtolower($bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'Move')) == 'enabled' ? true : false;
     $setMainNode = $bcUserRegisterUserPlacementINI->hasVariable('BCUserRegisterUserPlacement', 'SetMainNode') == true && strtolower($bcUserRegisterUserPlacementINI->variable('BCUserRegisterUserPlacement', 'SetMainNode')) == 'enabled' ? true : false;
     $selectedNodeID = false;
     // Fetch content object from the workflow process provided object_id
     $object = eZContentObject::fetch($objectID);
     // Fetch content object attributes required
     $objectName = $object->attribute('name');
     self::writeDebug('writeNotice', "Object name: " . $objectName);
     $objectContentClass = $object->attribute('class_name');
     self::writeDebug('writeNotice', "Content Class is: " . $objectContentClass);
     $objectContentClassID = $object->attribute('contentclass_id');
     self::writeDebug('writeNotice', "Default user class id is: " . $defaultUserClassID . ". This object class id is: " . $objectContentClassID);
     /**
      * Test if content object class ID matches ini settings default user content object class ID
      * Only perform workflow event operations on content objects of the correct content class
      */
     if ($objectContentClassID == $defaultUserClassID) {
         // Fetch content object attributes needed
         $assignedNodes = $object->attribute('assigned_nodes');
         $objectDataMap = $object->attribute('data_map');
         $objectNodeAssignments = eZNodeAssignment::fetchForObject($objectID, $object->attribute('current_version'), 0, false);
         //$objectNodeAssignments = $object->attribute( 'assigned_nodes' );
         // Get the selection content
         $objectSelectionAttributeContent = $objectDataMap[$objectSelectionAttributeIdentifier]->attribute('content');
         $objectSelectionAttributeContentString = implode(',', $objectSelectionAttributeContent);
         self::writeDebug('writeNotice', "User object attribute " . $objectSelectionAttributeIdentifier . " content is set to: " . $objectSelectionAttributeContentString);
         /**
          * Test to ensure that object selection attribute content is greater than 0 (no selection) or
          * that object selection attribute count is less than the count of userGroups (defined in ini settings)
          */
         if ($objectSelectionAttributeContent > 0 || $objectSelectionAttributeContent < count($userGroups)) {
             // Set userGroupID from ini defined user groups based on content object selection attribute content
             $userGroupID = $userGroups[$objectSelectionAttributeContentString];
             $selectedNodeID = $userGroupID;
         }
         $parentNodeIDs = array();
         $ourNode = false;
         /**
          * Iterate over object assigned nodes and object node assignements
          * test for parent node id matches and build array of parent_node_ids
          * test for user content object selection attribute content selected node id
          * and set node to move based on match
          */
         foreach ($assignedNodes as $assignedNode) {
             $append = false;
             foreach ($objectNodeAssignments as $nodeAssignment) {
                 if ($nodeAssignment['parent_node'] == $assignedNode->attribute('parent_node_id')) {
                     $append = true;
                     break;
                 }
             }
             if ($append) {
                 $parentNodeIDs[] = $assignedNode->attribute('parent_node_id');
             }
             if ($assignedNode->attribute('parent_node_id') == $selectedNodeID) {
                 $ourNode = $assignedNode;
             }
         }
         /**
          * Test if we are to move the current main node to the selected location
          */
         if ($move) {
             self::writeDebug('writeDebug', 'Moving tactic');
             if (!is_object($ourNode)) {
                 self::writeDebug('writeDebug', 'Node not found, so moving existing main node...');
                 eZContentObjectTreeNodeOperations::move($object->attribute('main_node_id'), $selectedNodeID);
             }
         } else {
             /**
              * Create a new node location assignment
              */
             self::writeDebug('writeDebug', 'New node tactic');
             if (!is_object($ourNode)) {
                 self::writeDebug('writeDebug', 'Node not found, so creating a new one ...');
                 $parentNode = eZContentObjectTreeNode::fetch($selectedNodeID);
                 $parentNodeObject = $parentNode->attribute('object');
                 // Add user content object location
                 $ourNode = $object->addLocation($selectedNodeID, true);
                 // Now set node as published and fix main_node_id
                 $ourNode->setAttribute('contentobject_is_published', 1);
                 $ourNode->setAttribute('main_node_id', $object->attribute('main_node_id'));
                 $ourNode->setAttribute('contentobject_version', $object->attribute('current_version'));
                 // Make sure the node's path_identification_string is set correctly
                 $ourNode->updateSubTreePath();
                 $ourNode->sync();
                 eZUser::cleanupCache();
             }
             if ($setMainNode) {
                 self::writeDebug('writeDebug', "'Setting as main node is enabled'", "", true);
                 if ($object->attribute('main_node_id') != $ourNode->attribute('node_id')) {
                     self::writeDebug('writeDebug', 'Existing main node is not our node, so updating main node', "", true);
                     eZContentObjectTreeNode::updateMainNodeID($ourNode->attribute('node_id'), $objectID, false, $selectedNodeID);
                     eZContentCacheManager::clearContentCacheIfNeeded($objectID);
                 }
             }
         }
     } else {
         self::writeDebug('writeNotice', $objectName . ' is not a user class object');
     }
     if (self::WORKFLOW_TYPE_DEBUG_STOP_EXECUTION === true) {
         die("<hr />\n\nWorkflow: " . self::WORKFLOW_TYPE_STRING . " execution has been ended before normal completion for debugging");
     }
     /**
      * Return default succesful workflow event status code, by default, regardless of results of execution, always.
      * Image alias image variation image files may not always need to be created. Also returning any other status
      * will result in problems with the succesfull and normal completion of the workflow event process
      */
     return eZWorkflowType::STATUS_ACCEPTED;
 }