/**
  * Removes nodes
  *
  * This function does not check about permissions, this is the responsibility of the caller!
  *
  * @param array $removeNodeIdList Array of Node ID to remove
  *
  * @return array An array with operation status, always true
  */
 public static function removeNodes(array $removeNodeIdList)
 {
     $mainNodeChanged = array();
     $nodeAssignmentIdList = array();
     $objectIdList = array();
     $db = eZDB::instance();
     $db->begin();
     foreach ($removeNodeIdList as $nodeId) {
         $node = eZContentObjectTreeNode::fetch($nodeId);
         $objectId = $node->attribute('contentobject_id');
         foreach (eZNodeAssignment::fetchForObject($objectId, eZContentObject::fetch($objectId)->attribute('current_version'), 0, false) as $nodeAssignmentKey => $nodeAssignment) {
             if ($nodeAssignment['parent_node'] == $node->attribute('parent_node_id')) {
                 $nodeAssignmentIdList[$nodeAssignment['id']] = 1;
             }
         }
         if ($nodeId == $node->attribute('main_node_id')) {
             $mainNodeChanged[$objectId] = 1;
         }
         $node->removeThis();
         if (!isset($objectIdList[$objectId])) {
             $objectIdList[$objectId] = eZContentObject::fetch($objectId);
         }
     }
     eZNodeAssignment::purgeByID(array_keys($nodeAssignmentIdList));
     foreach (array_keys($mainNodeChanged) as $objectId) {
         $allNodes = $objectIdList[$objectId]->assignedNodes();
         // Registering node that will be promoted as 'main'
         $mainNodeChanged[$objectId] = $allNodes[0];
         eZContentObjectTreeNode::updateMainNodeID($allNodes[0]->attribute('node_id'), $objectId, false, $allNodes[0]->attribute('parent_node_id'));
     }
     // Give other search engines that the default one a chance to reindex
     // when removing locations.
     if (!eZSearch::getEngine() instanceof eZSearchEngine) {
         foreach (array_keys($objectIdList) as $objectId) {
             eZContentOperationCollection::registerSearchObject($objectId);
         }
     }
     $db->commit();
     //call appropriate method from search engine
     eZSearch::removeNodes($removeNodeIdList);
     $userClassIdList = eZUser::contentClassIDs();
     foreach ($objectIdList as $objectId => $object) {
         eZContentCacheManager::clearObjectViewCacheIfNeeded($objectId);
         // clear user policy cache if this was a user object
         if (in_array($object->attribute('contentclass_id'), $userClassIdList)) {
             eZUser::purgeUserCacheByUserId($object->attribute('id'));
         }
     }
     // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::removeNode()
     return array('status' => true);
 }
Example #2
0
function storeNodeAssignments( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage )
{
    $http = eZHTTPTool::instance();

    // If the object has been previously published we do not allow node assignment operations
    if ( $object->attribute( 'status' ) != eZContentObject::STATUS_DRAFT )
    {
        return;
    }

    // If node assignment handling is diabled we return immedieately
    $useNodeAssigments = true;
    if ( $http->hasPostVariable( 'UseNodeAssigments' ) )
        $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' );

    if ( !$useNodeAssigments )
        return;

    $setPlacementNodeIDArray = array();
    if ( $http->hasPostVariable( 'SetPlacementNodeIDArray' ) )
        $setPlacementNodeIDArray = $http->postVariable( 'SetPlacementNodeIDArray' );

    // We will quit if some important POST variables are missing
    if ( !$http->hasPostVariable( 'MainNodeID' ) and
         !$http->hasPostVariable( 'SortOrderMap' ) and
         !$http->hasPostVariable( 'SortFieldMap' ) )
        return;

    $mainNodeID = false;
    if ( $http->hasPostVariable( 'MainNodeID' ) )
    {
        $mainNodeID = trim( $http->postVariable( 'MainNodeID' ) );
        if ( strlen( $mainNodeID ) == 0 )
            return;
    }

    // Check if dropdown placement is used
    if ( $http->hasPostVariable( 'MainAssignmentElementNumber' ) )
    {
        $elementNumber = $http->postVariable( 'MainAssignmentElementNumber' );

        $mainNodeID = $setPlacementNodeIDArray[$elementNumber];
    }

    $nodeID = eZContentObjectTreeNode::findNode( $mainNodeID, $object->attribute('id') );
    eZDebugSetting::writeDebug( 'kernel-content-edit', $nodeID, 'nodeID' );
//    $object->setAttribute( 'main_node_id', $nodeID );
    $nodeAssignments = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), $version->attribute( 'version' ) ) ;
    eZDebugSetting::writeDebug( 'kernel-content-edit', $mainNodeID, "mainNodeID" );


    $setPlacementNodeIDArray = array_unique( $setPlacementNodeIDArray );
    eZDebugSetting::writeDebug( 'kernel-content-edit', $setPlacementNodeIDArray, '$setPlacementNodeIDArray' );
    $remoteIDFieldMap = array();
    if ( $http->hasPostVariable( 'SetRemoteIDFieldMap' ) )
        $remoteIDFieldMap = $http->postVariable( 'SetRemoteIDFieldMap' );
    $remoteIDOrderMap = array();
    if ( $http->hasPostVariable( 'SetRemoteIDOrderMap' ) )
        $remoteIDOrderMap = $http->postVariable( 'SetRemoteIDOrderMap' );

    $db = eZDB::instance();
    $db->begin();
    if ( count( $setPlacementNodeIDArray ) > 0 )
    {
        foreach ( $setPlacementNodeIDArray as $setPlacementRemoteID => $setPlacementNodeID )
        {
            $hasAssignment = false;
            foreach ( $nodeAssignments as $nodeAssignment )
            {
                if ( $nodeAssignment->attribute( 'remote_id' ) == $setPlacementRemoteID )
                {
                    eZDebugSetting::writeDebug( 'kernel-content-edit', "Remote ID $setPlacementRemoteID already in use for node " . $nodeAssignment->attribute( 'parent_node' ), 'node_edit' );
                    if ( isset( $remoteIDFieldMap[$setPlacementRemoteID] ) )
                        $nodeAssignment->setAttribute( 'sort_field',  $remoteIDFieldMap[$setPlacementRemoteID] );
                    if ( isset( $remoteIDOrderMap[$setPlacementRemoteID] ) )
                        $nodeAssignment->setAttribute( 'sort_order', $remoteIDOrderMap[$setPlacementRemoteID] );
                    $nodeAssignment->setAttribute( 'parent_node', $setPlacementNodeID );
                    $nodeAssignment->sync();
                    $hasAssignment = true;
                    break;
                }
            }
            if ( !$hasAssignment )
            {
                eZDebugSetting::writeDebug( 'kernel-content-edit', "Adding to node $setPlacementNodeID", 'node_edit' );
                $sortField = null;
                $sortOrder = null;
                if ( isset( $remoteIDFieldMap[$setPlacementRemoteID] ) )
                    $sortField = $remoteIDFieldMap[$setPlacementRemoteID];
                if ( isset( $remoteIDOrderMap[$setPlacementRemoteID] ) )
                    $sortOrder = $remoteIDOrderMap[$setPlacementRemoteID];
                $version->assignToNode( $setPlacementNodeID, 0, 0, $sortField, $sortOrder, $setPlacementRemoteID );
            }
        }
        $nodeAssignments = eZNodeAssignment::fetchForObject( $object->attribute( 'id' ), $version->attribute( 'version' ) );
    }

    $sortOrderMap = false;
    if ( $http->hasPostVariable( 'SortOrderMap' ) )
        $sortOrderMap = $http->postVariable( 'SortOrderMap' );
    $sortFieldMap = false;
    if ( $http->hasPostVariable( 'SortFieldMap' ) )
        $sortFieldMap = $http->postVariable( 'SortFieldMap' );

//     $assigedNodes = eZContentObjectTreeNode::fetchByContentObjectID( $object->attribute('id') );
    foreach ( $nodeAssignments as $nodeAssignment )
    {
        eZDebugSetting::writeDebug( 'kernel-content-edit', $nodeAssignment, "nodeAssignment" );
        if ( $sortFieldMap !== false )
        {
            if ( isset( $sortFieldMap[$nodeAssignment->attribute( 'id' )] ) )
                $nodeAssignment->setAttribute( 'sort_field', $sortFieldMap[$nodeAssignment->attribute( 'id' )] );
        }

        if ( $sortOrderMap !== false )
        {
            $sortOrder = 1;
            if ( isset( $sortOrderMap[$nodeAssignment->attribute( 'id' )] ) and
                 $sortOrderMap[$nodeAssignment->attribute( 'id' )] == 1 )
                $sortOrder = $sortOrderMap[$nodeAssignment->attribute( 'id' )];
            else
                $sortOrder = 0;

            $nodeAssignment->setAttribute( 'sort_order', $sortOrder );
        }


        if ( $nodeAssignment->attribute( 'is_main' ) == 1 and
             $nodeAssignment->attribute( 'parent_node' ) != $mainNodeID )
        {
            $nodeAssignment->setAttribute( 'is_main', 0 );
        }
        else if ( $nodeAssignment->attribute( 'is_main' ) == 0 and
                  $nodeAssignment->attribute( 'parent_node' ) == $mainNodeID )
        {
            $nodeAssignment->setAttribute( 'is_main', 1 );
        }
        $nodeAssignment->store();
    }
    $db->commit();
}
Example #3
0
 $class = $object->contentClass();
 if ($module->isCurrentAction('AddAssignment')) {
     $selectedNodeIDArray = eZContentBrowse::result('AddNodeAssignment');
     if (!is_array($selectedNodeIDArray)) {
         $selectedNodeIDArray = array();
     }
     if (eZOperationHandler::operationIsAvailable('content_addlocation')) {
         $operationResult = eZOperationHandler::execute('content', 'addlocation', array('node_id' => $nodeID, 'object_id' => $objectID, 'select_node_id_array' => $selectedNodeIDArray), null, true);
     } else {
         eZContentOperationCollection::addAssignment($nodeID, $objectID, $selectedNodeIDArray);
     }
 } else {
     if ($module->isCurrentAction('SelectAssignmentLocation')) {
         $ignoreNodesSelect = array();
         $ignoreNodesClick = array();
         $assigned = eZNodeAssignment::fetchForObject($objectID, $object->attribute('current_version'), 0, false);
         $publishedAssigned = $object->assignedNodes(false);
         $isTopLevel = false;
         foreach ($publishedAssigned as $element) {
             $append = false;
             if ($element['parent_node_id'] == 1) {
                 $isTopLevel = true;
             }
             foreach ($assigned as $ass) {
                 if ($ass['parent_node'] == $element['parent_node_id']) {
                     $append = true;
                     break;
                 }
             }
             if ($append) {
                 $ignoreNodesSelect[] = $element['node_id'];
 /**
  * @return get the CjwNewsletterList Object of the parent nl list node
  */
 function getParentListObject()
 {
     // in draft modus no node is available only node assignment
     $nodeAssignements = eZNodeAssignment::fetchForObject($this->attribute('contentobject_id'), $this->attribute('contentobject_attribute_version'), 1, true);
     if (isset($nodeAssignements[0]) && is_object($nodeAssignements[0])) {
         $parentListNodeId = $nodeAssignements[0]->attribute('parent_node');
         $parentListNode = eZContentObjectTreeNode::fetch($parentListNodeId);
     }
     if (is_object($parentListNode) && $parentListNode->attribute('class_identifier') == 'cjw_newsletter_list') {
         $parentListAttributeDataMap = $parentListNode->attribute('data_map');
         if (isset($parentListAttributeDataMap['newsletter_list'])) {
             $parentListAttribute = $parentListAttributeDataMap['newsletter_list'];
             if (!is_object($parentListAttribute)) {
                 return 0;
             }
             $parentListObject = $parentListAttribute->attribute('content');
             // CjwNewsletterListObject
             if (!is_object($parentListObject)) {
                 return 0;
             } else {
                 return $parentListObject;
             }
         } else {
             return 0;
         }
     } else {
         return 0;
     }
 }
 function checkAccess($functionName, $originalClassID = false, $parentClassID = false, $returnAccessList = false, $language = false)
 {
     $classID = $originalClassID;
     $user = eZUser::currentUser();
     $userID = $user->attribute('contentobject_id');
     // Fetch the ID of the language if we get a string with a language code
     // e.g. 'eng-GB'
     $originalLanguage = $language;
     if (is_string($language) && strlen($language) > 0) {
         $language = eZContentLanguage::idByLocale($language);
     } else {
         $language = false;
     }
     // This will be filled in with the available languages of the object
     // if a Language check is performed.
     $languageList = false;
     // This will be filled if parent object is needed.
     $parentObject = false;
     $origFunctionName = $functionName;
     // The 'move' function simply reuses 'edit' for generic access
     // but adds another top-level check below
     // The original function is still available in $origFunctionName
     if ($functionName == 'move') {
         $functionName = 'edit';
     }
     // Manage locations depends if it's removal or not.
     if ($functionName == 'can_add_location' || $functionName == 'can_remove_location') {
         $functionName = 'manage_locations';
     }
     $accessResult = $user->hasAccessTo('content', $functionName);
     $accessWord = $accessResult['accessWord'];
     if ($origFunctionName == 'can_remove_location') {
         if ($this->ParentNodeID <= 1) {
             return 0;
         }
         $currentNode = eZContentObjectTreeNode::fetch($this->ParentNodeID);
         if (!$currentNode instanceof eZContentObjectTreeNode) {
             return 0;
         }
         $contentObject = $currentNode->attribute('object');
     } else {
         $currentNode = $this;
         $contentObject = $this->attribute('object');
     }
     /*
     // Uncomment this part if 'create' permissions should become implied 'edit'.
     // Merges in 'create' policies with 'edit'
     if ( $functionName == 'edit' &&
          !in_array( $accessWord, array( 'yes', 'no' ) ) )
     {
         // Add in create policies.
         $accessExtraResult = $user->hasAccessTo( 'content', 'create' );
         if ( $accessExtraResult['accessWord'] != 'no' )
         {
             $accessWord = $accessExtraResult['accessWord'];
             if ( isset( $accessExtraResult['policies'] ) )
             {
                 $accessResult['policies'] = array_merge( $accessResult['policies'],
                                                          $accessExtraResult['policies'] );
             }
             if ( isset( $accessExtraResult['accessList'] ) )
             {
                 $accessResult['accessList'] = array_merge( $accessResult['accessList'],
                                                            $accessExtraResult['accessList'] );
             }
         }
     }
     */
     if ($origFunctionName == 'remove' or $origFunctionName == 'move' or $origFunctionName == 'can_remove_location') {
         // We do not allow these actions on top-level nodes
         // - remove
         // - move
         if ($this->ParentNodeID <= 1) {
             return 0;
         }
     }
     if ($classID === false) {
         $classID = $contentObject->attribute('contentclass_id');
     }
     if ($accessWord == 'yes') {
         return 1;
     } else {
         if ($accessWord == 'no') {
             if ($functionName == 'edit') {
                 // Check if we have 'create' access under the main parent
                 $object = $currentNode->object();
                 if ($object && $object->attribute('current_version') == 1 && !$object->attribute('status')) {
                     $mainNode = eZNodeAssignment::fetchForObject($object->attribute('id'), $object->attribute('current_version'));
                     $parentObj = $mainNode[0]->attribute('parent_contentobject');
                     if ($parentObj instanceof eZContentObject) {
                         $result = $parentObj->checkAccess('create', $object->attribute('contentclass_id'), $parentObj->attribute('contentclass_id'), false, $originalLanguage);
                         return $result;
                     } else {
                         eZDebug::writeError("Error retrieving parent object of main node for object id: " . $object->attribute('id'), __METHOD__);
                     }
                 }
             }
             return 0;
         } else {
             $policies = $accessResult['policies'];
             $access = 'denied';
             foreach ($policies as $pkey => $limitationArray) {
                 if ($access == 'allowed') {
                     break;
                 }
                 $limitationList = array();
                 if (isset($limitationArray['Subtree'])) {
                     $checkedSubtree = false;
                 } else {
                     $checkedSubtree = true;
                     $accessSubtree = false;
                 }
                 if (isset($limitationArray['Node'])) {
                     $checkedNode = false;
                 } else {
                     $checkedNode = true;
                     $accessNode = false;
                 }
                 foreach ($limitationArray as $key => $valueList) {
                     $access = 'denied';
                     switch ($key) {
                         case 'Class':
                             if ($functionName == 'create' and !$originalClassID) {
                                 $access = 'allowed';
                             } else {
                                 if ($functionName == 'create' and in_array($classID, $valueList)) {
                                     $access = 'allowed';
                                 } else {
                                     if ($functionName != 'create' and in_array($contentObject->attribute('contentclass_id'), $valueList)) {
                                         $access = 'allowed';
                                     } else {
                                         $access = 'denied';
                                         $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                                     }
                                 }
                             }
                             break;
                         case 'ParentClass':
                             if (in_array($contentObject->attribute('contentclass_id'), $valueList)) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         case 'Section':
                         case 'User_Section':
                             if (in_array($contentObject->attribute('section_id'), $valueList)) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         case 'Language':
                             $languageMask = 0;
                             // If we don't have a language list yet we need to fetch it
                             // and optionally filter out based on $language.
                             if ($functionName == 'create') {
                                 // If the function is 'create' we do not use the language_mask for matching.
                                 if ($language !== false) {
                                     $languageMask = $language;
                                 } else {
                                     // If the create is used and no language specified then
                                     // we need to match against all possible languages (which
                                     // is all bits set, ie. -1).
                                     $languageMask = -1;
                                 }
                             } else {
                                 if ($language !== false) {
                                     if ($languageList === false) {
                                         $languageMask = $contentObject->attribute('language_mask');
                                         // We are restricting language check to just one language
                                         $languageMask &= $language;
                                         // If the resulting mask is 0 it means that the user is trying to
                                         // edit a language which does not exist, ie. translating.
                                         // The mask will then become the language trying to edit.
                                         if ($languageMask == 0) {
                                             $languageMask = $language;
                                         }
                                     }
                                 } else {
                                     $languageMask = -1;
                                 }
                             }
                             // Fetch limit mask for limitation list
                             $limitMask = eZContentLanguage::maskByLocale($valueList);
                             if (($languageMask & $limitMask) != 0) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         case 'Owner':
                         case 'ParentOwner':
                             // if limitation value == 2, anonymous limited to current session.
                             if (in_array(2, $valueList) && $user->isAnonymous()) {
                                 $createdObjectIDList = eZPreferences::value('ObjectCreationIDList');
                                 if ($createdObjectIDList && in_array($contentObject->attribute('id'), unserialize($createdObjectIDList))) {
                                     $access = 'allowed';
                                 }
                             } else {
                                 if ($contentObject->attribute('owner_id') == $userID || $contentObject->attribute('id') == $userID) {
                                     $access = 'allowed';
                                 }
                             }
                             if ($access != 'allowed') {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key);
                             }
                             break;
                         case 'Group':
                         case 'ParentGroup':
                             $access = $contentObject->checkGroupLimitationAccess($valueList, $userID);
                             if ($access != 'allowed') {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         case 'State':
                             if (count(array_intersect($valueList, $contentObject->attribute('state_id_array'))) == 0) {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             } else {
                                 $access = 'allowed';
                             }
                             break;
                         case 'ParentDepth':
                             if (in_array($currentNode->attribute('depth'), $valueList)) {
                                 $access = 'allowed';
                             } else {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         case 'Node':
                             $accessNode = false;
                             $mainNodeID = $currentNode->attribute('main_node_id');
                             foreach ($valueList as $nodeID) {
                                 $node = eZContentObjectTreeNode::fetch($nodeID, false, false);
                                 $limitationNodeID = $node['main_node_id'];
                                 if ($mainNodeID == $limitationNodeID) {
                                     $access = 'allowed';
                                     $accessNode = true;
                                     break;
                                 }
                             }
                             if ($access != 'allowed' && $checkedSubtree && !$accessSubtree) {
                                 $access = 'denied';
                                 // ??? TODO: if there is a limitation on Subtree, return two limitations?
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             } else {
                                 $access = 'allowed';
                             }
                             $checkedNode = true;
                             break;
                         case 'Subtree':
                             $accessSubtree = false;
                             $path = $currentNode->attribute('path_string');
                             $subtreeArray = $valueList;
                             foreach ($subtreeArray as $subtreeString) {
                                 if (strstr($path, $subtreeString)) {
                                     $access = 'allowed';
                                     $accessSubtree = true;
                                     break;
                                 }
                             }
                             if ($access != 'allowed' && $checkedNode && !$accessNode) {
                                 $access = 'denied';
                                 // ??? TODO: if there is a limitation on Node, return two limitations?
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             } else {
                                 $access = 'allowed';
                             }
                             $checkedSubtree = true;
                             break;
                         case 'User_Subtree':
                             $path = $currentNode->attribute('path_string');
                             $subtreeArray = $valueList;
                             foreach ($subtreeArray as $subtreeString) {
                                 if (strstr($path, $subtreeString)) {
                                     $access = 'allowed';
                                 }
                             }
                             if ($access != 'allowed') {
                                 $access = 'denied';
                                 $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                             }
                             break;
                         default:
                             if (strncmp($key, 'StateGroup_', 11) === 0) {
                                 if (count(array_intersect($valueList, $contentObject->attribute('state_id_array'))) == 0) {
                                     $access = 'denied';
                                     $limitationList = array('Limitation' => $key, 'Required' => $valueList);
                                 } else {
                                     $access = 'allowed';
                                 }
                             }
                     }
                     if ($access == 'denied') {
                         break;
                     }
                 }
                 $policyList[] = array('PolicyID' => $pkey, 'LimitationList' => $limitationList);
             }
             if ($access == 'denied') {
                 $accessList = array('FunctionRequired' => array('Module' => 'content', 'Function' => $origFunctionName, 'ClassID' => $classID, 'MainNodeID' => $currentNode->attribute('main_node_id')), 'PolicyList' => $policyList);
                 return 0;
             } else {
                 return 1;
             }
         }
     }
 }
    function execute( $xmlNode )
    {
        $xmlObjectID = $xmlNode->getAttribute( 'contentObject' );
        $xmlParentNodeID = $xmlNode->getAttribute( 'addToNode' );
        $setReferenceID = $xmlNode->getAttribute( 'setReference' );
        $priority = $xmlNode->getAttribute( 'priority' );

        $objectID = $this->getReferenceID( $xmlObjectID );
        $parentNodeID = $this->getReferenceID( $xmlParentNodeID );

        if ( !$objectID )
        {
            $this->writeMessage( "\tNo object defined.", 'error' );
            return false;
        }
        if ( !$parentNodeID )
        {
            $this->writeMessage( "\tNo location defined.", 'error' );
            return false;
        }

        $object = eZContentObject::fetch( $objectID );
        if ( !$object )
        {
            $this->writeMessage( "\tObject not found.", 'error' );
            return false;
        }

        $parentNode =  eZContentObjectTreeNode::fetch( $parentNodeID );
        if ( !$parentNode )
        {
            $this->writeMessage( "\tparent node not found.", 'error' );
            return false;
        }
        $node = $object->attribute( 'main_node' );

        $nodeAssignmentList = eZNodeAssignment::fetchForObject( $objectID, $object->attribute( 'current_version' ), 0, false );
        $assignedNodes = $object->assignedNodes();

        $parentNodeIDArray = array();
        $setMainNode = false;
        $hasMainNode = false;
        foreach ( $assignedNodes as $assignedNode )
        {
            if ( $assignedNode->attribute( 'is_main' ) )
                $hasMainNode = true;
            $append = false;
            foreach ( $nodeAssignmentList as $nodeAssignment )
            {
                if ( $nodeAssignment['parent_node'] == $assignedNode->attribute( 'parent_node_id' ) )
                {
                    $append = true;
                    break;
                }
            }
            if ( $append )
            {
                $parentNodeIDArray[] = $assignedNode->attribute( 'parent_node_id' );
            }
        }
        if ( !$hasMainNode )
            $setMainNode = true;

        $mainNodeID = $parentNode->attribute( 'main_node_id' );
        $objectName = $object->attribute( 'name' );

        $db = eZDB::instance();
        $db->begin();
        $locationAdded = false;
        $destNode = null;
        if ( !in_array( $parentNodeID, $parentNodeIDArray ) )
        {
            $parentNodeObject = $parentNode->attribute( 'object' );

            $insertedNode = $object->addLocation( $parentNodeID, true );

            // Now set is as published and fix main_node_id
            $insertedNode->setAttribute( 'contentobject_is_published', 1 );
            $insertedNode->setAttribute( 'main_node_id', $node->attribute( 'main_node_id' ) );
            $insertedNode->setAttribute( 'contentobject_version', $node->attribute( 'contentobject_version' ) );
            // Make sure the url alias is set updated.
            $insertedNode->updateSubTreePath();
            $insertedNode->sync();

            $locationAdded = true;
        }
        if ( $locationAdded )
        {
            $ini = eZINI::instance();
            $userClassID = $ini->variable( "UserSettings", "UserClassID" );
            if ( $object->attribute( 'contentclass_id' ) == $userClassID )
            {
                eZUser::cleanupCache();
            }
            $this->writeMessage( "\tAdded location of " . $object->attribute( 'name' ) . "  to Node $parentNodeID", 'notice' );

            $destNode = $insertedNode;
        }
        else
        {
            $this->writeMessage( "\tLocation of " . $object->attribute( 'name' ) . "  to Node $parentNodeID already exists.", 'notice' );

            $destNode = eZContentObjectTreeNode::fetchObject( eZContentObjectTreeNode::definition(), null, array( 'parent_node_id' => $parentNodeID, 'contentobject_id' => $objectID ) );
        }
        $db->commit();

        if( $destNode && $priority )
        {
            $destNode->setAttribute( 'priority', $priority );
            $destNode->store();
        }

        if( $destNode && $setReferenceID )
        {
            $this->addReference( array( $setReferenceID => $destNode->attribute( 'node_id' ) ) );
        }

        eZContentCacheManager::clearContentCacheIfNeeded( $objectID );
    }
Example #7
0
 static function setNewMainAssignment($objectID, $version)
 {
     $assignments = eZNodeAssignment::fetchForObject($objectID, $version);
     if (count($assignments) == 0) {
         return true;
     }
     // check: if there is already main assignment for the object then we should do nothing
     // BTW choose first nonremoving assignment as new main assignment
     $newMainAssignment = null;
     foreach ($assignments as $key => $assignment) {
         if ($assignment->attribute('op_code') != eZNodeAssignment::OP_CODE_REMOVE) {
             if ($newMainAssignment === null) {
                 $newMainAssignment = $assignment;
             }
             if ($assignment->attribute('is_main')) {
                 return false;
             }
         }
     }
     $db = eZDB::instance();
     if ($newMainAssignment === null) {
         $db->query("UPDATE eznode_assignment SET is_main=0 WHERE contentobject_id={$objectID} AND contentobject_version={$version}");
         return false;
     }
     $parentMainNodeID = $newMainAssignment->attribute('parent_node');
     $db->begin();
     $db->query("UPDATE eznode_assignment SET is_main=1 WHERE contentobject_id={$objectID} AND contentobject_version={$version} AND parent_node={$parentMainNodeID}");
     $db->query("UPDATE eznode_assignment SET is_main=0 WHERE contentobject_id={$objectID} AND contentobject_version={$version} AND parent_node<>{$parentMainNodeID}");
     $db->commit();
     return true;
 }
    if (!$discardConfirm) {
        $isConfirmed = true;
    }
}
if ($isConfirmed) {
    $object = eZContentObject::fetch($objectID);
    if ($object === null) {
        return $Module->handleError(eZError::KERNEL_NOT_AVAILABLE, 'kernel');
    }
    $versionObject = $object->version($version);
    if (is_object($versionObject) and in_array($versionObject->attribute('status'), array(eZContentObjectVersion::STATUS_DRAFT, eZContentObjectVersion::STATUS_INTERNAL_DRAFT))) {
        if (!$object->attribute('can_edit')) {
            // Check if it is a first created version of an object.
            // If so, then edit is allowed if we have an access to the 'create' function.
            if ($object->attribute('current_version') == 1 && !$object->attribute('status')) {
                $mainNode = eZNodeAssignment::fetchForObject($object->attribute('id'), 1);
                $parentObj = $mainNode[0]->attribute('parent_contentobject');
                $allowEdit = $parentObj->checkAccess('create', $object->attribute('contentclass_id'), $parentObj->attribute('contentclass_id'));
            } else {
                $allowEdit = false;
            }
            if (!$allowEdit) {
                return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel', array('AccessList' => $object->accessList('edit')));
            }
        }
        $versionCount = $object->getVersionCount();
        $nodeID = $versionCount == 1 ? $versionObject->attribute('main_parent_node_id') : $object->attribute('main_node_id');
        $versionObject->removeThis();
    }
    $hasRedirected = false;
    if ($http->hasSessionVariable('RedirectIfDiscarded')) {
 function execute($process, $event)
 {
     $parameters = $process->attribute('parameter_list');
     $objectId = $parameters['object_id'];
     $object = eZContentObject::fetch($objectId);
     $subtreeNodeID = $event->attribute('target_subtree');
     $subtreeNode = eZContentObjectTreeNode::fetch($subtreeNodeID);
     eZDebug::writeDebug("Event begins execution for object {$objectId}, subtree {$subtreeNodeID}", __METHOD__);
     if ($object != null && $subtreeNode != null) {
         $is_child = false;
         $locations = $object->assignedNodes();
         if ($locations == null) {
             // pre-creation event: obj has no node on its own, but a putative parent
             //eZDebug::writeDebug( 'Obj node is new!', __METHOD__ );
             $locations = eZNodeAssignment::fetchForObject($objectId, $object->attribute("current_version"));
             foreach ($locations as $key => $location) {
                 $locations[$key] = $location->getParentNode();
             }
         }
         foreach ($locations as $node) {
             $subtreeNodePath = $node->pathArray();
             //eZDebug::writeDebug( 'Testing if obj node '.$node->NodeID.' is child of : ' . $subtreeNodeID, __METHOD__ );
             if (in_array($subtreeNodeID, $subtreeNodePath)) {
                 eZDebug::writeDebug('Found that obj node ' . $node->NodeID . ' is child of node ' . $subtreeNodeID, __METHOD__);
                 $is_child = true;
                 break;
             }
         }
         if ($is_child) {
             $workflowToRun = $event->attribute('target_workflow');
             $user = eZUser::currentUser();
             $userID = $user->id();
             $processParameters = $process->attribute('parameter_list');
             // code copy+pasted from ez multoplexer worflow...
             $childParameters = array_merge($processParameters, array('workflow_id' => $workflowToRun, 'user_id' => $userID, 'parent_process_id' => $process->attribute('id')));
             $childProcessKey = eZWorkflowProcess::createKey($childParameters);
             $childProcessArray = eZWorkflowProcess::fetchListByKey($childProcessKey);
             $childProcess =& $childProcessArray[0];
             if ($childProcess == null) {
                 $childProcess = eZWorkflowProcess::create($childProcessKey, $childParameters);
                 $childProcess->store();
             }
             $workflow = eZWorkflow::fetch($childProcess->attribute("workflow_id"));
             $workflowEvent = null;
             if ($childProcess->attribute("event_id") != 0) {
                 $workflowEvent = eZWorkflowEvent::fetch($childProcess->attribute("event_id"));
             }
             $childStatus = $childProcess->run($workflow, $workflowEvent, $eventLog);
             $childProcess->store();
             if ($childStatus == eZWorkflow::STATUS_DEFERRED_TO_CRON) {
                 $this->setActivationDate($childProcess->attribute('activation_date'));
                 $childProcess->setAttribute("status", eZWorkflow::STATUS_WAITING_PARENT);
                 $childProcess->store();
                 return eZWorkflowType::STATUS_DEFERRED_TO_CRON_REPEAT;
             } else {
                 if ($childStatus == eZWorkflow::STATUS_FETCH_TEMPLATE) {
                     $process->Template =& $childProcess->Template;
                     return eZWorkflowType::STATUS_FETCH_TEMPLATE_REPEAT;
                 } else {
                     if ($childStatus == eZWorkflow::STATUS_REDIRECT) {
                         $process->RedirectUrl =& $childProcess->RedirectUrl;
                         return eZWorkflowType::STATUS_REDIRECT_REPEAT;
                     } else {
                         if ($childStatus == eZWorkflow::STATUS_DONE) {
                             $childProcess->removeThis();
                             return eZWorkflowType::STATUS_ACCEPTED;
                         } else {
                             if ($childStatus == eZWorkflow::STATUS_CANCELLED || $childStatus == eZWorkflow::STATUS_FAILED) {
                                 $childProcess->removeThis();
                                 return eZWorkflowType::STATUS_REJECTED;
                             }
                         }
                     }
                 }
             }
             return $childProcess->attribute('event_status');
         }
         return eZWorkflowType::STATUS_ACCEPTED;
     } else {
         eZDebug::writeError("Event triggered for inexisting object ({$objectId}) or subtree ({$subtreeNodeID})", __METHOD__);
         return eZWorkflowType::STATUS_WORKFLOW_CANCELLED;
     }
 }
Example #10
0
 function nodeAssignments()
 {
     return eZNodeAssignment::fetchForObject( $this->attribute( 'contentobject_id' ), $this->attribute( 'version' ) );
 }
 /**
  * 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;
 }
Example #12
0
 /**
  * Removes content object
  *
  * @param eZContentObject $object
  * @return bool true if object was removed, otherwise false
  */
 public function removeObject(eZContentObject $object)
 {
     $objectName = $object->attribute('name');
     $this->debug('Removing "' . $objectName . '" object (class: ' . $object->attribute('class_name') . ') with remote ID ' . $object->attribute('remote_id'));
     $this->db->begin();
     $object->resetDataMap();
     eZContentObject::clearCache($object->attribute('id'));
     if (is_null($object->attribute('main_node'))) {
         $object->purge();
         $this->db->commit();
         $this->debug('[Removed] "' . $objectName . '"');
         return true;
     } else {
         $removeNodeIDs = array($object->attribute('main_node')->attribute('node_id'));
         $nodeAssigments = eZNodeAssignment::fetchForObject($object->attribute('id'));
         foreach ($nodeAssigments as $assigment) {
             $node = $assigment->attribute('node');
             if ($node instanceof eZContentObjectTreeNode) {
                 $removeNodeIDs[] = $node->attribute('node_id');
             }
         }
         $removeNodeIDs = array_unique($removeNodeIDs);
         $info = eZContentObjectTreeNode::subtreeRemovalInformation($removeNodeIDs);
         foreach ($info['delete_list'] as $deleteItem) {
             $node = $deleteItem['node'];
             if ($node === null) {
                 continue;
             }
             if ($deleteItem['can_remove']) {
                 eZContentObjectTreeNode::removeSubtrees(array($node->attribute('node_id')), false);
                 $this->debug('[Removed] "' . $objectName . '", Node ID: ' . $node->attribute('node_id'), array('red'));
             }
         }
         $this->db->commit();
     }
     return false;
 }