public static function fetchContentNode($nodeID, $nodePath, $languageCode, $remoteID = false)
 {
     $contentNode = null;
     if ($nodeID) {
         if (!isset($languageCode)) {
             $languageCode = false;
         }
         $contentNode = eZContentObjectTreeNode::fetch($nodeID, $languageCode);
     } else {
         if ($nodePath) {
             $nodeID = eZURLAliasML::fetchNodeIDByPath($nodePath);
             if ($nodeID) {
                 $contentNode = eZContentObjectTreeNode::fetch($nodeID);
             }
         } else {
             if ($remoteID) {
                 $contentNode = eZContentObjectTreeNode::fetchByRemoteID($remoteID);
             }
         }
     }
     if ($contentNode === null) {
         $retVal = array('error' => array('error_type' => 'kernel', 'error_code' => eZError::KERNEL_NOT_FOUND));
     } else {
         $retVal = array('result' => $contentNode);
     }
     return $retVal;
 }
Beispiel #2
0
 /**
  * test if the new node remote id is available (or already used by this node)
  * @param string $remoteID
  * @param int $currentNodeID
  * @param array $errors
  * @param boolean $allowBlank
  * @return boolean
  */
 public static function isValidNodeRemoteID($remoteID, $currentNodeID = false, &$errors = array(), $allowBlank = false)
 {
     if (!self::isValidRemoteIDText($remoteID, $errors, $allowBlank)) {
         return false;
     }
     if ($existingNode = eZContentObjectTreeNode::fetchByRemoteID($remoteID, false)) {
         $existingNodeIDList = array();
         if (isset($existingNode['node_id'])) {
             $existingNodeIDList[] = $existingNode['node_id'];
         } else {
             foreach ($existingNode as $node) {
                 $existingNodeIDList[] = $node['node_id'];
             }
         }
         if (!in_array($currentNodeID, $existingNodeIDList)) {
             $errors[] = ezpI18n::tr('remoteid/update', 'Node Remote ID %1 already used by node %2', '', array('%1' => $remoteID, '%2' => join(', ', $existingNodeIDList)));
             eZDebug::writeDebug('Node Remote ID ' . $remoteID . ' used by node ' . join(', ', $existingNodeIDList), '', __CLASS__);
             return false;
         }
     }
     return true;
 }
 public static function publishNode($parentNodeID, $objectID, $versionNum, $mainNodeID)
 {
     $object = eZContentObject::fetch($objectID);
     $nodeAssignment = eZNodeAssignment::fetch($objectID, $versionNum, $parentNodeID);
     $version = $object->version($versionNum);
     $fromNodeID = $nodeAssignment->attribute('from_node_id');
     $originalObjectID = $nodeAssignment->attribute('contentobject_id');
     $nodeID = $nodeAssignment->attribute('parent_node');
     $opCode = $nodeAssignment->attribute('op_code');
     $parentNode = eZContentObjectTreeNode::fetch($nodeID);
     // if parent doesn't exist, return. See issue #18320
     if (!$parentNode instanceof eZContentObjectTreeNode) {
         eZDebug::writeError("Parent node doesn't exist. object id: {$objectID}, node_assignment id: " . $nodeAssignment->attribute('id'), __METHOD__);
         return;
     }
     $parentNodeID = $parentNode->attribute('node_id');
     $existingNode = null;
     $db = eZDB::instance();
     $db->begin();
     if (strlen($nodeAssignment->attribute('parent_remote_id')) > 0) {
         $existingNode = eZContentObjectTreeNode::fetchByRemoteID($nodeAssignment->attribute('parent_remote_id'));
     }
     if (!$existingNode) {
     }
     $existingNode = eZContentObjectTreeNode::findNode($nodeID, $object->attribute('id'), true);
     $updateSectionID = false;
     // now we check the op_code to see what to do
     if (($opCode & 1) == eZNodeAssignment::OP_CODE_NOP) {
         // There is nothing to do so just return
         $db->commit();
         if ($mainNodeID == false) {
             return $object->attribute('main_node_id');
         }
         return;
     }
     $updateFields = false;
     if ($opCode == eZNodeAssignment::OP_CODE_MOVE || $opCode == eZNodeAssignment::OP_CODE_CREATE) {
         //            if ( $fromNodeID == 0 || $fromNodeID == -1)
         if ($opCode == eZNodeAssignment::OP_CODE_CREATE || $opCode == eZNodeAssignment::OP_CODE_SET) {
             // If the node already exists it means we have a conflict (for 'CREATE').
             // We resolve this by leaving node-assignment data be.
             if ($existingNode == null) {
                 $parentNode = eZContentObjectTreeNode::fetch($nodeID);
                 $user = eZUser::currentUser();
                 if (!eZSys::isShellExecution() and !$user->isAnonymous()) {
                     eZContentBrowseRecent::createNew($user->id(), $parentNode->attribute('node_id'), $parentNode->attribute('name'));
                 }
                 $updateFields = true;
                 $existingNode = $parentNode->addChild($object->attribute('id'), true);
                 if ($fromNodeID == -1) {
                     $updateSectionID = true;
                 }
             } elseif ($opCode == eZNodeAssignment::OP_CODE_SET) {
                 $updateFields = true;
             }
         } elseif ($opCode == eZNodeAssignment::OP_CODE_MOVE) {
             if ($fromNodeID == 0 || $fromNodeID == -1) {
                 eZDebug::writeError("NodeAssignment '" . $nodeAssignment->attribute('id') . "' is marked with op_code='{$opCode}' but has no data in from_node_id. Cannot use it for moving node.", __METHOD__);
             } else {
                 // clear cache for old placement.
                 $additionalNodeIDList = array($fromNodeID);
                 eZContentCacheManager::clearContentCacheIfNeeded($objectID, $versionNum, $additionalNodeIDList);
                 $originalNode = eZContentObjectTreeNode::fetchNode($originalObjectID, $fromNodeID);
                 if ($originalNode->attribute('main_node_id') == $originalNode->attribute('node_id')) {
                     $updateSectionID = true;
                 }
                 $originalNode->move($parentNodeID);
                 $existingNode = eZContentObjectTreeNode::fetchNode($originalObjectID, $parentNodeID);
                 $updateFields = true;
             }
         }
     } elseif ($opCode == eZNodeAssignment::OP_CODE_REMOVE) {
         $db->commit();
         return;
     }
     if ($updateFields) {
         if (strlen($nodeAssignment->attribute('parent_remote_id')) > 0) {
             $existingNode->setAttribute('remote_id', $nodeAssignment->attribute('parent_remote_id'));
         }
         $existingNode->setAttribute('sort_field', $nodeAssignment->attribute('sort_field'));
         $existingNode->setAttribute('sort_order', $nodeAssignment->attribute('sort_order'));
     }
     $existingNode->setAttribute('contentobject_is_published', 1);
     eZDebug::createAccumulatorGroup('nice_urls_total', 'Nice urls');
     if ($mainNodeID > 0) {
         $existingNodeID = $existingNode->attribute('node_id');
         if ($existingNodeID != $mainNodeID) {
             eZContentBrowseRecent::updateNodeID($existingNodeID, $mainNodeID);
         }
         $existingNode->setAttribute('main_node_id', $mainNodeID);
     } else {
         $existingNode->setAttribute('main_node_id', $existingNode->attribute('node_id'));
     }
     $existingNode->store();
     if ($updateSectionID) {
         eZContentOperationCollection::updateSectionID($objectID, $versionNum);
     }
     $db->commit();
     if ($mainNodeID == false) {
         return $existingNode->attribute('node_id');
     }
 }
    function installFetchAliases( $fetchAliasListNode, &$parameters )
    {
        if ( !$fetchAliasListNode )
        {
            return true;
        }

        $fetchAliasINIArray = array();
        foreach( $fetchAliasListNode->getElementsByTagName( 'fetch-alias' ) as $blockNode )
        {
            if ( isset( $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )] ) )
            {
                $newSiteAccess = $parameters['site_access_map'][$blockNode->getAttribute( 'site-access' )];
            }
            else
            {
                $newSiteAccess = $parameters['site_access_map']['*'];
            }

            if ( !isset( $fetchAliasINIArray[$newSiteAccess] ) )
            {
                $fetchAliasINIArray[$newSiteAccess] = eZINI::instance( 'fetchalias.ini.append.php', "settings/siteaccess/$newSiteAccess", null, null, true );
            }

            $blockArray = array();
            $blockName = $blockNode->getAttribute( 'name' );
            $blockArray[$blockName] = eZContentObjectPackageHandler::createArrayFromDOMNode( $blockNode->getElementsByTagName( $blockName )->item( 0 ) );

            //$blockArray[$blockName] = $blockArray[$blockName][0];

            if ( isset( $blockArray[$blockName]['Constant'] ) && is_array( $blockArray[$blockName]['Constant'] ) && count( $blockArray[$blockName]['Constant'] ) > 0 )
            {
                foreach( $blockArray[$blockName]['Constant'] as $matchKey => $value )
                {
                    if ( strpos( $matchKey, 'class_' ) === 0 &&
                         is_int( $value ) )
                    {
                        $contentClass = eZContentClass::fetchByRemoteID( $blockArray[$blockName]['Constant']['class_remote_id'] );
                        $blockArray[$blockName]['Constant'][$matchKey] = $contentClass->attribute( 'id' );
                        unset( $blockArray[$blockName]['Constant']['class_remote_id'] );
                    }
                    if( strpos( $matchKey, 'node_' ) === 0 &&
                        is_int( $value ) )
                    {
                        $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['node_remote_id'] );
                        $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
                        unset( $blockArray[$blockName]['Constant']['node_remote_id'] );
                    }
                    if( strpos( $matchKey, 'parent_node_' ) === 0 &&
                        is_int( $value ) )
                    {
                        $contentTreeNode = eZContentObjectTreeNode::fetchByRemoteID( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
                        $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'node_id' );
                        unset( $blockArray[$blockName]['Constant']['parent_node_remote_id'] );
                    }
                    if( strpos( $matchKey, 'object_' ) === 0 &&
                        is_int( $value ) )
                    {
                        $contentObject = eZContentObject::fetchByRemoteID( $blockArray[$blockName]['Constant']['object_remote_id'] );
                        $blockArray[$blockName]['Constant'][$matchKey] = $contentTreeNode->attribute( 'id' );
                        unset( $blockArray[$blockName]['Constant']['object_remote_id'] );
                    }
                }
            }

            $fetchAliasINIArray[$newSiteAccess]->setVariables( $blockArray );
        }

        foreach( $fetchAliasINIArray as $siteAccess => $iniFetchAlias )
        {
            $fetchAliasINIArray[$siteAccess]->save();
        }

        return true;
    }
 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;
 }
Beispiel #6
0
 static function transformRemoteLinksToLinks(DOMNodeList $nodeList, $objectAttribute)
 {
     $modified = false;
     $contentObject = $objectAttribute->attribute('object');
     foreach ($nodeList as $node) {
         $objectRemoteID = $node->getAttribute('object_remote_id');
         $nodeRemoteID = $node->getAttribute('node_remote_id');
         if ($objectRemoteID) {
             $objectArray = eZContentObject::fetchByRemoteID($objectRemoteID, false);
             if (!is_array($objectArray)) {
                 eZDebug::writeWarning("Can't fetch object with remoteID = {$objectRemoteID}", __METHOD__);
                 continue;
             }
             $objectID = $objectArray['id'];
             if ($node->localName == 'object') {
                 $node->setAttribute('id', $objectID);
             } else {
                 $node->setAttribute('object_id', $objectID);
             }
             $node->removeAttribute('object_remote_id');
             $modified = true;
             // add as related object
             if ($contentObject) {
                 $relationType = $node->localName == 'link' ? eZContentObject::RELATION_LINK : eZContentObject::RELATION_EMBED;
                 $contentObject->addContentObjectRelation($objectID, $objectAttribute->attribute('version'), 0, $relationType);
             }
         } elseif ($nodeRemoteID) {
             $nodeArray = eZContentObjectTreeNode::fetchByRemoteID($nodeRemoteID, false);
             if (!is_array($nodeArray)) {
                 eZDebug::writeWarning("Can't fetch node with remoteID = {$nodeRemoteID}", __METHOD__);
                 continue;
             }
             $node->setAttribute('node_id', $nodeArray['node_id']);
             $node->removeAttribute('node_remote_id');
             $modified = true;
             // add as related object
             if ($contentObject) {
                 $relationType = $node->nodeName == 'link' ? eZContentObject::RELATION_LINK : eZContentObject::RELATION_EMBED;
                 $contentObject->addContentObjectRelation($nodeArray['contentobject_id'], $objectAttribute->attribute('version'), 0, $relationType);
             }
         }
     }
     return $modified;
 }
    /**
     * 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;
    }
    /**
     * @param string $path
     * @param MerckManualShowcase $app
     * @return bool|eZContentObjectTreeNode
     */
    public static function findNodeFromPath( $path, &$app )
    {
        /* We remove the publisher folder id at the beginning of the url as we already have it */
        $path                  = preg_replace('#^/\d+/#', '/', $path );

        $manualAppNode         = eZContentObjectTreeNode::fetch( self::rootNodeId() );
        $manualAppNodePathName = $manualAppNode->pathWithNames();
        $tabNodePath           = explode('/', substr($path, 1));
        $remoteId              = end($tabNodePath);

        if(preg_match('/^[a-f0-9]{32}$/', $remoteId))
        {
            $nodeRemote = eZContentObjectTreeNode::fetchByRemoteID($remoteId);

            if($nodeRemote instanceof eZContentObjectTreeNode)
            {
                $app->fullContext = 'topic';
                return $nodeRemote;
            }
        }

        $pathParts = explode('/', substr($path, 1));

        if ( $pathParts[0] == 'table' )
        {
            $app->fullContext = 'table';
            return eZContentObjectTreeNode::fetch($pathParts[1]);
        }

        // Url with topic
        list($sectionName, $chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts;

        // Url without topic
        $matches = array();

        if ( preg_match('/media-([a-z]+)/', $topicName, $matches) )
        {
            list($sectionName, $chapterName, $mediaType, $mediaName, $other) = $pathParts;
            $topicName = null;
        }

        // Full section
        if ( $sectionName != null && is_null( $chapterName ) && is_null( $topicName ) )
        {
            $app->fullContext = 'section';
            $app->section = MerckManualFunctionCollection::fetchSection('url', $sectionName);
            return eZContentObjectTreeNode::fetch(MerckManualShowcase::rootNodeId());
        }
        if ( $sectionName == 'about-us' )
        {
            list($chapterName, $topicName, $mediaType, $mediaName, $other) = $pathParts;
        }

        $path = $manualAppNodePathName;
        // Full of chapter
        if ( $chapterName )
        {
            $app->fullContext = 'chapter';
            $path .= '/' . $chapterName;
        }

        // Full of topic
        if ( $topicName )
        {
            $app->fullContext = 'topic';
            $path .= '/' . $topicName;
        }

        $nodeId = eZURLAliasML::fetchNodeIDByPath($path);

        if ( $nodeId )
        {
            if ( $mediaName )
            {
                $mediaType = str_replace('media-', '', $mediaType);

                // Get media node
                // Full of html table image
                // /topic_name/(media-image-file)/oscar2/filename
                if ( $mediaType == 'image-file' )
                {
                    $app->fullContext = $mediaType;
                    $app->oscarFolder = $mediaName;
                    $app->mediaName = $other;
                }

                // Full of inline audio, video, image
                elseif ( $mediaType )
                {
                    // Construct the remote_id of the media folder
                    /* @type $dataMap eZContentObjectAttribute[] */
                    $contentObject        = eZContentObject::fetchByNodeID($nodeId);
                    $dataMap              = $contentObject->dataMap();
                    $publisherAttrContent = $dataMap['publisher']->content();

                    if ( isset($publisherAttrContent['relation_list'][0]['contentobject_remote_id']) )
                    {
                        // Get media folder
                        $mediaFolderRemoteId = sprintf('%s_media_%s', $publisherAttrContent['relation_list'][0]['contentobject_remote_id'], $mediaType);
                        $mediaFolder = eZContentObject::fetchByRemoteID($mediaFolderRemoteId);

                        if ( $mediaFolder )
                        {
                            // Get media
                            $mediaFolderPathName = $mediaFolder->mainNode()->pathWithNames();
                            $nodeId = eZURLAliasML::fetchNodeIDByPath($mediaFolderPathName . '/' . $mediaName);
                            $app->fullContext = $mediaType;
                        }
                    }
                }
            }
        }

        if ( $nodeId )
        {
            // Full of chapter must not be accessible, show first topic
            if ( $app->fullContext == 'chapter' )
            {
                $params = array(
                    'Depth'         => 1,
                    'DepthOperator' => 'eq',
                    'SortBy'        => array(array('priority', 'asc')),
                    'Limit'         => 1
                );
                $children = eZContentObjectTreeNode::subTreeByNodeID($params, $nodeId);

                if ( isset($children[0]) && $children[0] instanceof eZContentObjectTreeNode )
                {
                    $node = $children[0];
                    $app->fullContext = 'topic';
                }
                else
                    $node = null;
            }
            else
            {
                $node = eZContentObjectTreeNode::fetch($nodeId);
            }

            return $node;
        }

        return false;
    }
Beispiel #9
0
<?php

require_once 'kernel/common/template.php';
include_once 'kernel/classes/ezcontentobjecttreenode.php';
include_once "lib/ezutils/classes/ezmail.php";
include_once 'extension/jajnewsletter/modules/newsletter/classes/jajsubscriptionuser.php';
$http = eZHTTPTool::instance();
$Module =& $Params['Module'];
$remoteID = $Params['RemoteID'];
$node = eZContentObjectTreeNode::fetchByRemoteID($remoteID);
if (!$node) {
    return $Module->handleError(EZ_ERROR_KERNEL_NOT_AVAILABLE, 'kernel');
}
// TODO CHECK FOR TRASH
// TODO CHECK FOR READ
$success = array();
$error = array();
$email = "";
$name = "";
do {
    if ($http->hasPostVariable('SignupButton')) {
        $email = trim($http->variable('email'));
        $name = trim($http->variable('name'));
        if (!eZMail::validate($email)) {
            $error['email'] = true;
        }
        if (strlen($name) == 0) {
            $error['name'] = true;
        }
        if (!empty($error)) {
            continue;
    /**
     * @param string $nodePath
     * @param eZContentObjectTreeNode[] $publisherFolderNodes
     * @return eZContentObjectTreeNode
     */
    static protected function getNodeFromPath ( $nodePath, $publisherFolderNodes )
    {
        // Remove view parameters
        $nodePath = preg_replace( '#/\([^\)]+\)/.*$#', '', $nodePath );
        $node = false;

        foreach ( $publisherFolderNodes as $publisherFolderNode )
        {
            $nodeFullPath = '/' . $publisherFolderNode->attribute('url_alias') . '/' . $nodePath;
            $node = eZContentObjectTreeNode::fetchByURLPath( $nodeFullPath );

            if (!$node)
            {
                $node = eZContentObjectTreeNode::fetchByPath($nodeFullPath);

                if (!$node)
                {
                    $cleanableHref  = $nodeFullPath;
                    $aliasTranslate = eZURLAliasML::translate($cleanableHref);

                    while ( $aliasTranslate !== true && $aliasTranslate !== false )
                    {
                        $cleanableHref  = $aliasTranslate;
                        $aliasTranslate = eZURLAliasML::translate($cleanableHref);
                    }

                    if ( $aliasTranslate === true )
                    {
                        $lastSlashPosition = strrpos($cleanableHref, '/');

                        if( $lastSlashPosition !== false )
                            $node = eZContentObjectTreeNode::fetch(substr($cleanableHref, $lastSlashPosition+1));
                    }
                }

                if (!$node)
                {
                    $tabNodePath    = explode('/', substr($nodeFullPath, 1));
                    $remoteId       = end($tabNodePath);
                    $nodeRemote     = eZContentObjectTreeNode::fetchByRemoteID($remoteId);

                    if($nodeRemote && $publisherFolderNode)
                    {
                        $rootNodeID     = $publisherFolderNode->attribute('node_id');
                        $tabNodeRemote  = $nodeRemote->pathArray();
                        $nodeId         = $nodeRemote->attribute('node_id');

                        if(in_array($rootNodeID, $tabNodeRemote) && $rootNodeID != $nodeId)
                            $node = $nodeRemote;
                        /*******************************************************************************
                         * TODO : Delete after PF Refactor
                         *******************************************************************************/
                        else
                        {
                            $publisherFolderPathArray = $publisherFolderNode->pathArray();
                            foreach ( $nodeRemote->object()->assignedNodes() as $location )
                            {
                                if ( in_array( $publisherFolderPathArray[2], $location->pathArray() ) )
                                {
                                    $node = $location;
                                    break;
                                }
                            }
                        }
                        /*******************************************************************************
                         * TODO : END : Delete after PF Refactor
                         *******************************************************************************/
                    }
                }
            }
            
            if ($node instanceof eZContentObjectTreeNode)
                break;
        }


        // if we still do not have a node, we try to look in the old locations
        if ( !($node instanceof eZContentObjectTreeNode) )
        {
            $pfrLocation = null;

            if ( preg_match('#node_(?P<node_id>\d+)/?$#', $nodePath, $m) )
            {
                $nodeId = $m['node_id'];
                $pfrLocation = PfrLocation::fetchByNodeId( $nodeId );
            }
            else
            {
                $remoteId = basename( rtrim($nodePath, '/') );
                $pfrLocation = PfrLocation::fetchByRemoteId( $remoteId );
            }

            if ( $pfrLocation instanceof PfrLocation )
            {
                $node = $pfrLocation->node( $publisherFolderNodes );
            }
        }
        
        return $node;
    }