コード例 #1
0
 if ($http->hasPostVariable('BrowseActionName') and $http->postVariable('BrowseActionName') == 'AssignRole') {
     $selectedObjectIDArray = $http->postVariable('SelectedObjectIDArray');
     $role = eZRole::fetch($roleID);
     $db = eZDB::instance();
     $db->begin();
     foreach ($selectedObjectIDArray as $objectID) {
         $role->assignToUser($objectID, $limitIdent, $limitValue);
     }
     // Clear role caches.
     eZRole::expireCache();
     $db->commit();
     if (count($selectedObjectIDArray) > 0) {
         eZContentCacheManager::clearAllContentCache();
     }
     /* Clean up policy cache */
     eZUser::cleanupCache();
     $Module->redirectTo('/role/view/' . $roleID);
 } else {
     if (is_string($limitIdent) && !isset($limitValue)) {
         switch ($limitIdent) {
             case 'subtree':
                 eZContentBrowse::browse(array('action_name' => 'SelectObjectRelationNode', 'from_page' => '/role/assign/' . $roleID . '/' . $limitIdent, 'cancel_page' => '/role/view/' . $roleID), $Module);
                 return;
                 break;
             case 'section':
                 $sectionArray = eZSection::fetchList();
                 $tpl = eZTemplate::factory();
                 $tpl->setVariable('section_array', $sectionArray);
                 $tpl->setVariable('role_id', $roleID);
                 $tpl->setVariable('limit_ident', $limitIdent);
                 $Result = array();
コード例 #2
0
    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 );
    }
 /**
  * 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;
 }
コード例 #4
0
 static function expireCache()
 {
     $http = eZHTTPTool::instance();
     $http->removeSessionVariable('CanInstantiateClassList');
     $http->removeSessionVariable('ClassesCachedForUser');
     // Expire user (role) cache
     eZUser::cleanupCache();
 }
コード例 #5
0
 /**
  * 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);
         }
     }
     // Give other search engines that the default one a chance to reindex
     // when removing locations.
     if (!eZSearch::getEngine() instanceof eZSearchEngine) {
         foreach ($objectIdList as $objectId => $object) {
             eZContentOperationCollection::registerSearchObject($objectId, $object->attribute('current_version'));
         }
     }
     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'));
     }
     $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::cleanupCache();
         }
     }
     // we don't clear template block cache here since it's cleared in eZContentObjectTreeNode::removeNode()
     return array('status' => true);
 }