Пример #1
0
function checkNodeMovements( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $FromLanguage, &$validation )
{
    $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;

    $ObjectID = $object->attribute( 'id' );
    // Move to another node
    if ( $module->isCurrentAction( 'MoveNodeAssignment' ) )
    {
        $selectedNodeIDArray = eZContentBrowse::result( 'MoveNodeAssignment' );
        $fromNodeID = $http->postVariable( "FromNodeID" );
        $oldAssignmentParentID = $http->postVariable( 'OldAssignmentParentID' );

        if ( $selectedNodeIDArray != null )
        {
            $assignedNodes = $version->nodeAssignments();
            $assignedIDArray = array();
            foreach ( $assignedNodes as  $assignedNode )
            {
                $assignedNodeID = $assignedNode->attribute( 'parent_node' );
                $assignedIDArray[] = $assignedNodeID;
            }
            foreach ( $selectedNodeIDArray as $nodeID )
            {
                if ( !in_array( $nodeID, $assignedIDArray ) )
                {
                    $isPermitted = true;
                    // Check access
                    $newNode = eZContentObjectTreeNode::fetch( $nodeID );
                    $newNodeObject = $newNode->attribute( 'object' );

                    $canCreate = $newNodeObject->checkAccess( 'create', $class->attribute( 'id' ), $newNodeObject->attribute( 'contentclass_id' ) ) == 1;
                    eZDebug::writeDebug( $canCreate,"can create");
                    if ( !$canCreate )
                    {
                        $isPermitted = false;
                    }
                    else
                    {
                        $canCreateClassList = $newNodeObject->attribute( 'can_create_class_list' );
                        $canCreateClassIDList = array();
                        foreach ( array_keys( $canCreateClassList ) as $key )
                        {
                            $canCreateClassIDList[] = $canCreateClassList[$key]['id'];
                        }
                        $objectClassID = $object->attribute( 'contentclass_id' );
                        if ( !in_array( $objectClassID, $canCreateClassIDList ) )
                             $isPermitted = false;
                    }
                    if ( !$isPermitted )
                    {
                        eZDebug::writeError( $newNode->pathWithNames(), "You are not allowed to place this object under:" );
                        $validation[ 'placement' ][] = array( 'text' => ezpI18n::tr( 'kernel/content', "You are not allowed to place this object under: %1", null, array( $newNode->pathWithNames() ) ) );
                        $validation[ 'processed' ] = true;
                        // Error message.
                    }
                    else
                    {
                        $oldAssignment = eZPersistentObject::fetchObject( eZNodeAssignment::definition(),
                                                                           null,
                                                                           array( 'contentobject_id' => $object->attribute( 'id' ),
                                                                                  'parent_node' => $oldAssignmentParentID,
                                                                                  'contentobject_version' => $version->attribute( 'version' )
                                                                                  ),
                                                                           true );

                        $realNode = eZContentObjectTreeNode::fetchNode( $version->attribute( 'contentobject_id' ), $oldAssignment->attribute( 'parent_node' ) );

                        $db = eZDB::instance();
                        $db->begin();
                        // No longer remove then add assignment, instead change the existing one
                        if ( $realNode  === null )
                        {
                            $fromNodeID = 0;
                        }
                        if ( $oldAssignment->attribute( 'is_main' ) == '1' )
                        {
                            $oldAssignment->setAttribute( 'parent_node', $nodeID );
                            $oldAssignment->setAttribute( 'is_main', 1 );
                            $oldAssignment->setAttribute( 'from_node_id', $fromNodeID );
//                            $version->assignToNode( $nodeID, 1, $fromNodeID, $oldAssignment->attribute( 'sort_field' ), $oldAssignment->attribute( 'sort_order' ) );
                        }
                        else
                        {
                            $oldAssignment->setAttribute( 'parent_node', $nodeID );
                            $oldAssignment->setAttribute( 'is_main', 0 );
                            $oldAssignment->setAttribute( 'from_node_id', $fromNodeID );
//                            $version->assignToNode( $nodeID, 0, $fromNodeID, $oldAssignment->attribute( 'sort_field' ), $oldAssignment->attribute( 'sort_order' ) );
                        }
                        $oldAssignment->setAttribute( 'op_code', eZNodeAssignment::OP_CODE_MOVE );
                        $oldAssignment->store();
                        //$version->removeAssignment( $oldAssignmentParentID );
                        $db->commit();
                    }
                }
            }
        }
    }
}
    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] );
        }
    }
 static function unserialize($contentNodeDOMNode, $contentObject, $version, $isMain, &$nodeList, &$options, $handlerType = 'ezcontentobject')
 {
     $parentNodeID = -1;
     $remoteID = $contentNodeDOMNode->getAttribute('remote-id');
     $parentNodeRemoteID = $contentNodeDOMNode->getAttribute('parent-node-remote-id');
     $node = eZContentObjectTreeNode::fetchByRemoteID($remoteID);
     if (is_object($node)) {
         $description = "Node with remote ID {$remoteID} already exists.";
         $choosenAction = eZPackageHandler::errorChoosenAction(eZContentObject::PACKAGE_ERROR_EXISTS, $options, $description, $handlerType, false);
         switch ($choosenAction) {
             // In case user have choosen "Keep existing object and create new"
             case eZContentObject::PACKAGE_NEW:
                 $newRemoteID = eZRemoteIdUtility::generate('node');
                 $node->setAttribute('remote_id', $newRemoteID);
                 $node->store();
                 $nodeInfo = array('contentobject_id' => $node->attribute('contentobject_id'), 'contentobject_version' => $node->attribute('contentobject_version'), 'parent_remote_id' => $remoteID);
                 $nodeAssignment = eZPersistentObject::fetchObject(eZNodeAssignment::definition(), null, $nodeInfo);
                 if (is_object($nodeAssignment)) {
                     $nodeAssignment->setAttribute('parent_remote_id', $newRemoteID);
                     $nodeAssignment->store();
                 }
                 break;
                 // When running non-interactively with ezpm.php
             // When running non-interactively with ezpm.php
             case eZPackage::NON_INTERACTIVE:
             case eZContentObject::PACKAGE_UPDATE:
                 // Update existing node settigns.
                 if (!$parentNodeRemoteID) {
                     // when top node of subtree export, only update node sort field and sort order
                     $node->setAttribute('sort_field', eZContentObjectTreeNode::sortFieldID($contentNodeDOMNode->getAttribute('sort-field')));
                     $node->setAttribute('sort_order', $contentNodeDOMNode->getAttribute('sort-order'));
                     $node->store();
                     return true;
                 }
                 break;
             default:
                 // This error may occur only if data integrity is broken
                 $options['error'] = array('error_code' => eZContentObject::PACKAGE_ERROR_NODE_EXISTS, 'element_id' => $remoteID, 'description' => $description);
                 return false;
                 break;
         }
     }
     if ($parentNodeRemoteID) {
         $parentNode = eZContentObjectTreeNode::fetchByRemoteID($parentNodeRemoteID);
         if ($parentNode !== null) {
             $parentNodeID = $parentNode->attribute('node_id');
         }
     } else {
         if (isset($options['top_nodes_map'][$contentNodeDOMNode->getAttribute('node-id')]['new_node_id'])) {
             $parentNodeID = $options['top_nodes_map'][$contentNodeDOMNode->getAttribute('node-id')]['new_node_id'];
         } else {
             if (isset($options['top_nodes_map']['*'])) {
                 $parentNodeID = $options['top_nodes_map']['*'];
             } else {
                 eZDebug::writeError('New parent node not set ' . $contentNodeDOMNode->getAttribute('name'), __METHOD__);
             }
         }
     }
     $isMain = $isMain && $contentNodeDOMNode->getAttribute('is-main-node');
     $nodeInfo = array('contentobject_id' => $contentObject->attribute('id'), 'contentobject_version' => $version, 'is_main' => $isMain, 'parent_node' => $parentNodeID, 'parent_remote_id' => $remoteID, 'sort_field' => eZContentObjectTreeNode::sortFieldID($contentNodeDOMNode->getAttribute('sort-field')), 'sort_order' => $contentNodeDOMNode->getAttribute('sort-order'));
     if ($parentNodeID == -1 && $parentNodeRemoteID) {
         if (!isset($options['suspended-nodes'])) {
             $options['suspended-nodes'] = array();
         }
         $options['suspended-nodes'][$parentNodeRemoteID] = array('nodeinfo' => $nodeInfo, 'priority' => $contentNodeDOMNode->getAttribute('priority'));
         return true;
     }
     $existNodeAssignment = eZPersistentObject::fetchObject(eZNodeAssignment::definition(), null, $nodeInfo);
     $nodeInfo['priority'] = $contentNodeDOMNode->getAttribute('priority');
     if (!is_object($existNodeAssignment)) {
         $nodeAssignment = eZNodeAssignment::create($nodeInfo);
         $nodeList[] = $nodeInfo;
         $nodeAssignment->store();
     }
     return true;
 }
Пример #4
0
 static function fetchListByID($idList, $asObject = true)
 {
     $cond = array('id' => array($idList));
     return eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, $cond, null, null, $asObject);
 }
$cli->warning("For more details about this cleanup, see https://jira.ez.no/browse/EZP-22260");
$cli->output();
$cli->output("Found total of {$totalCount} node assignments to be updated");
$cli->output();
if ($totalCount == 0) {
    $cli->output("Nothing to process, exiting");
    $script->shutdown(0);
}
if (!isset($options['n'])) {
    $cli->warning("You have 30 seconds to break the script before actual processing starts (press Ctrl-C)");
    $cli->warning("(execute the script with '-n' switch to skip this delay)");
    sleep(30);
    $cli->output();
}
$db = eZDB::instance();
while ($nodeAssignments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, $condition, null, $limit)) {
    $db->begin();
    /** @var $nodeAssignments \ezNodeAssignment[] */
    foreach ($nodeAssignments as $nodeAssignment) {
        $currentParentRemoteId = $nodeAssignment->attribute("parent_remote_id");
        if (!empty($currentParentRemoteId)) {
            $cli->output("Skipped: node assignment #{$nodeAssignment->ID}");
            continue;
        }
        $currentRemoteId = $nodeAssignment->attribute("remote_id");
        if (!empty($currentRemoteId)) {
            $nodeAssignment->setAttribute("remote_id", 0);
            $nodeAssignment->setAttribute("parent_remote_id", $currentRemoteId);
            $cli->output("Updated node assignment #{$nodeAssignment->ID}: copied 'parent_remote_id' from 'remote_id'");
        } else {
            $nodeAssignment->setAttribute("parent_remote_id", eZRemoteIdUtility::generate("eznode_assignment"));
Пример #6
0
 /**
  * Change node`s visibility
  *
  * @private
  * @param eZContentObject $object
  * @param bool $visibility
  * @return void
  */
 private function updateVisibility($object, $visibility = true)
 {
     $action = $visibility ? 'show' : 'hide';
     $nodeAssigments = eZPersistentObject::fetchObjectList(eZNodeAssignment::definition(), null, array('contentobject_id' => $object->attribute('id'), 'contentobject_version' => $object->attribute('current_version')), null, null, true);
     foreach ($nodeAssigments as $nodeAssigment) {
         $node = $nodeAssigment->attribute('node');
         if ($node instanceof eZContentObjectTreeNode === false) {
             continue;
         }
         if ((bool) (!$node->attribute('is_hidden')) === (bool) $visibility) {
             continue;
         }
         if ($action == 'show') {
             eZContentObjectTreeNode::unhideSubTree($node);
         } else {
             eZContentObjectTreeNode::hideSubTree($node);
         }
         eZSearch::updateNodeVisibility($node->attribute('node_id'), $action);
     }
 }