static function move($nodeID, $newParentNodeID) { $result = false; if (!is_numeric($nodeID) || !is_numeric($newParentNodeID)) { return false; } $node = eZContentObjectTreeNode::fetch($nodeID); if (!$node) { return false; } $object = $node->object(); if (!$object) { return false; } $objectID = $object->attribute('id'); $oldParentNode = $node->fetchParent(); $oldParentObject = $oldParentNode->object(); // clear user policy cache if this is a user object if (in_array($object->attribute('contentclass_id'), eZUser::contentClassIDs())) { eZUser::purgeUserCacheByUserId($object->attribute('id')); } // clear cache for old placement. eZContentCacheManager::clearContentCacheIfNeeded($objectID); $db = eZDB::instance(); $db->begin(); $node->move($newParentNodeID); $newNode = eZContentObjectTreeNode::fetchNode($objectID, $newParentNodeID); if ($newNode) { $newNode->updateSubTreePath(true, true); if ($newNode->attribute('main_node_id') == $newNode->attribute('node_id')) { // If the main node is moved we need to check if the section ID must change $newParentNode = $newNode->fetchParent(); $newParentObject = $newParentNode->object(); if ($object->attribute('section_id') != $newParentObject->attribute('section_id')) { eZContentObjectTreeNode::assignSectionToSubTree($newNode->attribute('main_node_id'), $newParentObject->attribute('section_id'), $oldParentObject->attribute('section_id')); } } // modify assignment $curVersion = $object->attribute('current_version'); $nodeAssignment = eZNodeAssignment::fetch($objectID, $curVersion, $oldParentNode->attribute('node_id')); if ($nodeAssignment) { $nodeAssignment->setAttribute('parent_node', $newParentNodeID); $nodeAssignment->setAttribute('op_code', eZNodeAssignment::OP_CODE_MOVE); $nodeAssignment->store(); // update search index $nodeIDList = array($nodeID); eZSearch::removeNodeAssignment($node->attribute('main_node_id'), $newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList); eZSearch::addNodeAssignment($newNode->attribute('main_node_id'), $object->attribute('id'), $nodeIDList); } $result = true; } else { eZDebug::writeError("Node {$nodeID} was moved to {$newParentNodeID} but fetching the new node failed"); } $db->commit(); // clear cache for new placement. eZContentCacheManager::clearContentCacheIfNeeded($objectID); return $result; }
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 checkNodeActions( $module, $class, $object, $version, $contentObjectAttributes, $editVersion, $editLanguage, $fromLanguage ) { // If the object has been previously published we do not allow node assignment operations if ( $object->attribute( 'status' ) != eZContentObject::STATUS_DRAFT ) { if ( !$module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { return; } } $http = eZHTTPTool::instance(); if ( $module->isCurrentAction( 'BrowseForNodes' ) || $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); $ignoreNodesSelect = array(); $ignoreNodesClick = array(); $assigned = $version->nodeAssignments(); $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->attribute( 'parent_node' ) == $element['parent_node_id'] ) $append = true; } /* If the current version (draft) has no assigned nodes then * we should disallow adding assignments under nodes * the previous published version is assignned to. * Thus we avoid fatal errors in eZ Publish. */ if ( count($assigned) == 0 ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; } if ( $append ) { $ignoreNodesSelect[] = $element['node_id']; $ignoreNodesClick[] = $element['node_id']; $ignoreNodesSelect[] = $element['parent_node_id']; } } if ( !$isTopLevel ) { $ignoreNodesSelect = array_unique( $ignoreNodesSelect ); $objectID = $object->attribute( 'id' ); $action = 'AddNodeAssignment'; if ( $module->isCurrentAction( 'BrowseForPrimaryNodes' ) ) { $action = 'AddPrimaryNodeAssignment'; } eZContentBrowse::browse( array( 'action_name' => $action, 'description_template' => 'design:content/browse_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'ignore_nodes_select' => $ignoreNodesSelect, 'ignore_nodes_click' => $ignoreNodesClick, 'content' => array( 'object_id' => $objectID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage/$fromLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } // If node assignment handling is diabled we return $useNodeAssigments = true; if ( $http->hasPostVariable( 'UseNodeAssigments' ) ) $useNodeAssigments = (bool)$http->postVariable( 'UseNodeAssigments' ); if ( !$useNodeAssigments ) return; // Remove custom actions from attribute editing. $http->removeSessionVariable( 'BrowseCustomAction' ); if ( $module->isCurrentAction( 'ConfirmAssignmentDelete' ) && $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } if ( $module->isCurrentAction( 'DeleteNode' ) ) { if ( $http->hasPostVariable( 'RemoveNodeID' ) ) { $nodeID = $http->postVariable( 'RemoveNodeID' ); } $mainNodeID = $http->postVariable( 'MainNodeID' ); // if ( $nodeID != $mainNodeID ) { $objectID = $object->attribute( 'id' ); $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeID ); if ( $publishedNode != null ) { $publishParentNodeID = $publishedNode->attribute( 'parent_node_id' ); if ( $publishParentNodeID > 1 ) { $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } else { $nodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $nodeID ); if ( $nodeAssignment->attribute( 'from_node_id' ) != 0 ) { $publishedNode = eZContentObjectTreeNode::fetchNode( $objectID, $nodeAssignment->attribute( 'from_node_id' ) ); $childrenCount = 0; if ( $publishedNode !== null ) $childrenCount = $publishedNode->childrenCount(); if ( $childrenCount != 0 ) { $module->redirectToView( 'removenode', array( $objectID, $editVersion, $editLanguage, $nodeID ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } $db = eZDB::instance(); $db->begin(); $version->removeAssignment( $nodeID ); $db->commit(); } } } if ( $module->isCurrentAction( 'RemoveAssignments' ) ) { if( $http->hasPostVariable( 'AssignmentIDSelection' ) ) { $selected = $http->postVariable( 'AssignmentIDSelection' ); $objectID = $object->attribute( 'id' ); $versionInt = $version->attribute( 'version' ); $hasChildren = false; $assignmentsIDs = array(); $assignments = array(); // Determine if at least one node of ones we remove assignments for has children. foreach ( $selected as $parentNodeID ) { $assignment = eZNodeAssignment::fetch( $objectID, $versionInt, $parentNodeID ); if( !$assignment ) { eZDebug::writeWarning( "No assignment found for object $objectID version $versionInt, parent node $parentNodeID" ); continue; } $assignmentID = $assignment->attribute( 'id' ); $assignmentsIDs[] = $assignmentID; $assignments[] = $assignment; $node = $assignment->attribute( 'node' ); if( !$node ) continue; if( $node->childrenCount( false ) > 0 ) $hasChildren = true; unset( $assignment ); } if ( $hasChildren ) { // We need user confirmation if at least one node we want to remove assignment for contains children. // Aactual removal is done in content/removeassignment in this case. $http->setSessionVariable( 'AssignmentRemoveData', array( 'remove_list' => $assignmentsIDs, 'object_id' => $objectID, 'edit_version' => $versionInt, 'edit_language' => $editLanguage, 'from_language' => $fromLanguage ) ); $module->redirectToView( 'removeassignment' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } else { // Just remove all the selected locations. $mainNodeChanged = false; $db = eZDB::instance(); $db->begin(); foreach ( $assignments as $assignment ) { $assignmentID = $assignment->attribute( 'id' ); if ( $assignment->attribute( 'is_main' ) ) $mainNodeChanged = true; eZNodeAssignment::removeByID( $assignmentID ); } if ( $mainNodeChanged ) eZNodeAssignment::setNewMainAssignment( $objectID, $versionInt ); $db->commit(); unset( $mainNodeChanged ); } unset( $assignmentsIDs, $assignments ); } else { eZDebug::writeNotice( 'No nodes to remove selected' ); } } if ( $module->isCurrentAction( 'MoveNode' ) ) { $objectID = $object->attribute( 'id' ); if ( $http->hasPostVariable( 'MoveNodeID' ) ) { $fromNodeID = $http->postVariable( 'MoveNodeID' ); //$sourceNodeID[0]; $oldAssignmentParentID = $fromNodeID; $fromNodeAssignment = eZNodeAssignment::fetch( $objectID, $version->attribute( 'version' ), $fromNodeID ); $publishParentNodeID = $fromNodeAssignment->attribute( 'parent_node' ); if ( $publishParentNodeID > 1 ) { if( $fromNodeAssignment->attribute( 'from_node_id' ) != 0 ) { $fromNodeID = $fromNodeAssignment->attribute( 'from_node_id' ); $oldAssignmentParentID = $fromNodeAssignment->attribute( 'parent_node' ); } // we don't allow moving object to itself, to its descendants or parent object(s) $objectAssignedNodes = $object->attribute( 'assigned_nodes' ); // nodes that are not allowed to select (via checkbox or radiobutton) when browsing $ignoreNodesSelectArray = array(); // nodes that are not allowed to click on $ignoreNodesClickArray = array(); foreach( $objectAssignedNodes as $curAN ) { // current node should be neither selectable, nor clickable $ignoreNodesClickArray[] = $curAN->NodeID; $ignoreNodesSelectArray[] = $curAN->NodeID; // parent node should be only clickable, but not selectable $ignoreNodesSelectArray[] = $curAN->ParentNodeID; } eZContentBrowse::browse( array( 'action_name' => 'MoveNodeAssignment', 'description_template' => 'design:content/browse_move_placement.tpl', 'keys' => array( 'class' => $class->attribute( 'id' ), 'class_id' => $class->attribute( 'identifier' ), 'classgroup' => $class->attribute( 'ingroup_id_list' ), 'section' => $object->attribute( 'section_id' ) ), 'start_node' => $fromNodeID, 'persistent_data' => array( 'FromNodeID' => $fromNodeID, 'OldAssignmentParentID' => $oldAssignmentParentID ), 'ignore_nodes_select' => $ignoreNodesSelectArray, 'ignore_nodes_click' => $ignoreNodesClickArray, 'content' => array( 'object_id' => $objectID, 'previous_node_id' => $fromNodeID, 'object_version' => $editVersion, 'object_language' => $editLanguage ), 'from_page' => "/content/edit/$objectID/$editVersion/$editLanguage" ), $module ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } } }
/** * 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; }
$Module = $Params['Module']; $ObjectID = $Params['ObjectID']; $NodeID = $Params['NodeID']; if ( !isset( $EditVersion ) ) $EditVersion = $Params['EditVersion']; $object = eZContentObject::fetch( $ObjectID ); if ( $object === null ) return $Module->handleError( eZError::KERNEL_NOT_AVAILABLE, 'kernel' ); if ( !$object->attribute( 'can_remove' ) ) return $Module->handleError( eZError::KERNEL_ACCESS_DENIED, 'kernel' ); $version = $object->version( $EditVersion ); $node = eZContentObjectTreeNode::fetchNode( $ObjectID, $NodeID ); if ( $node !== null ) $ChildObjectsCount = $node->subTreeCount(); else $ChildObjectsCount = 0; $ChildObjectsCount .= " "; if ( $ChildObjectsCount == 1 ) $ChildObjectsCount .= ezpI18n::tr( 'kernel/content/removenode', 'child', '1 child' ); else $ChildObjectsCount .= ezpI18n::tr( 'kernel/content/removenode', 'children', 'several children' ); if ( $Module->isCurrentAction( 'ConfirmAssignmentRemove' ) )
function fetchNode() { return eZContentObjectTreeNode::fetchNode($this->ContentobjectID, $this->ParentNode); }
static function publishUpdateUser($parentNodeIDs, $defaultUserPlacement, $userAttributes, $isUtf8Encoding = false) { if (!is_array($userAttributes) or !isset($userAttributes['login']) or empty($userAttributes['login'])) { eZDebug::writeWarning('Empty user login passed.', __METHOD__); return false; } if ((!is_array($parentNodeIDs) or count($parentNodeIDs) < 1) and !is_numeric($defaultUserPlacement)) { eZDebug::writeWarning('No one parent node IDs was passed for publishing new user (login = "******")', __METHOD__); return false; } $parentNodeIDs[] = $defaultUserPlacement; $parentNodeIDs = array_unique($parentNodeIDs); $login = $userAttributes['login']; $first_name = $userAttributes['first_name']; $last_name = $userAttributes['last_name']; $email = $userAttributes['email']; if ($isUtf8Encoding) { $first_name = utf8_decode($first_name); $last_name = utf8_decode($last_name); } $user = eZUser::fetchByName($login); $createNewUser = is_object($user) ? false : true; if ($createNewUser) { if (!isset($first_name) or empty($first_name) or !isset($last_name) or empty($last_name) or !isset($email) or empty($email)) { eZDebug::writeWarning('Cannot create user with empty first name (last name or email).', __METHOD__); return false; } $ini = eZINI::instance(); $userClassID = $ini->variable("UserSettings", "UserClassID"); $userCreatorID = $ini->variable("UserSettings", "UserCreatorID"); $defaultSectionID = $ini->variable("UserSettings", "DefaultSectionID"); $class = eZContentClass::fetch($userClassID); $contentObject = $class->instantiate($userCreatorID, $defaultSectionID); $contentObject->store(); $userID = $contentObjectID = $contentObject->attribute('id'); $version = $contentObject->version(1); $version->setAttribute('modified', time()); $version->setAttribute('status', eZContentObjectVersion::STATUS_DRAFT); $version->store(); $user = eZLDAPUser::create($userID); $user->setAttribute('login', $login); } else { $userID = $contentObjectID = $user->attribute('contentobject_id'); $contentObject = eZContentObject::fetch($userID); $version = $contentObject->attribute('current'); } //================= common part 1: start ======================== $contentObjectAttributes = $version->contentObjectAttributes(); // find and set 'name' and 'description' attributes (as standard user group class) $firstNameIdentifier = 'first_name'; $lastNameIdentifier = 'last_name'; $firstNameAttribute = null; $lastNameAttribute = null; foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } //================= common part 1: end ========================== // If we are updating an existing user, we must find out if some data should be changed. // In that case, we must create a new version and publish it. if (!$createNewUser) { $userDataChanged = false; $firstNameChanged = false; $lastNameChanged = false; $emailChanged = false; if ($firstNameAttribute and $firstNameAttribute->attribute('data_text') != $first_name) { $firstNameChanged = true; } $firstNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($lastNameAttribute and $lastNameAttribute->attribute('data_text') != $last_name) { $lastNameChanged = true; } $lastNameAttribute = false; // We will load this again from the new version we will create, if it has changed if ($user->attribute('email') != $email) { $emailChanged = true; } if ($firstNameChanged or $lastNameChanged or $emailChanged) { $userDataChanged = true; // Create new version $version = $contentObject->createNewVersion(); $contentObjectAttributes = $version->contentObjectAttributes(); foreach ($contentObjectAttributes as $attribute) { if ($attribute->attribute('contentclass_attribute_identifier') == $firstNameIdentifier) { $firstNameAttribute = $attribute; } else { if ($attribute->attribute('contentclass_attribute_identifier') == $lastNameIdentifier) { $lastNameAttribute = $attribute; } } } } } //================= common part 2: start ======================== if ($firstNameAttribute) { $firstNameAttribute->setAttribute('data_text', $first_name); $firstNameAttribute->store(); } if ($lastNameAttribute) { $lastNameAttribute->setAttribute('data_text', $last_name); $lastNameAttribute->store(); } if (!isset($userDataChanged) or $userDataChanged === true) { $contentClass = $contentObject->attribute('content_class'); $name = $contentClass->contentObjectName($contentObject); $contentObject->setName($name); } if (!isset($emailChanged) or $emailChanged === true) { $user->setAttribute('email', $email); } $user->setAttribute('password_hash', ""); $user->setAttribute('password_hash_type', 0); $user->store(); $debugArray = array('Updating user data', 'createNewUser' => $createNewUser, 'userDataChanged' => isset($userDataChanged) ? $userDataChanged : null, 'login' => $login, 'first_name' => $first_name, 'last_name' => $last_name, 'email' => $email, 'firstNameAttribute is_object' => is_object($firstNameAttribute), 'lastNameAttribute is_object' => is_object($lastNameAttribute), 'content object id' => $contentObjectID, 'version id' => $version->attribute('version')); eZDebug::writeNotice(var_export($debugArray, true), __METHOD__); //================= common part 2: end ========================== if ($createNewUser) { reset($parentNodeIDs); // prepare node assignments for publishing new user foreach ($parentNodeIDs as $parentNodeID) { $newNodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $contentObjectID, 'contentobject_version' => 1, 'parent_node' => $parentNodeID, 'parent_remote_id' => uniqid('LDAP_'), 'is_main' => $defaultUserPlacement == $parentNodeID ? 1 : 0)); $newNodeAssignment->store(); } $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => 1)); } else { if ($userDataChanged) { // Publish object $operationResult = eZOperationHandler::execute('content', 'publish', array('object_id' => $contentObjectID, 'version' => $version->attribute('version'))); // Refetch object $contentObject = eZContentObject::fetch($contentObjectID); $version = $contentObject->attribute('current'); } $LDAPIni = eZINI::instance('ldap.ini'); $keepGroupAssignment = $LDAPIni->hasVariable('LDAPSettings', 'KeepGroupAssignment') ? $LDAPIni->variable('LDAPSettings', 'KeepGroupAssignment') == "enabled" : false; if ($keepGroupAssignment == false) { $objectIsChanged = false; $db = eZDB::instance(); $db->begin(); // First check existing assignments, remove any that should not exist $assignedNodesList = $contentObject->assignedNodes(); $existingParentNodeIDs = array(); foreach ($assignedNodesList as $node) { $parentNodeID = $node->attribute('parent_node_id'); if (!in_array($parentNodeID, $parentNodeIDs)) { $node->removeThis(); $objectIsChanged = true; } else { $existingParentNodeIDs[] = $parentNodeID; } } // Then check assignments that should exist, add them if they are missing foreach ($parentNodeIDs as $parentNodeID) { if (!in_array($parentNodeID, $existingParentNodeIDs)) { $newNode = $contentObject->addLocation($parentNodeID, true); $newNode->updateSubTreePath(); $newNode->setAttribute('contentobject_is_published', 1); $newNode->sync(); $existingParentNodeIDs[] = $parentNodeID; $objectIsChanged = true; } } // Then ensure that the main node is correct $currentMainParentNodeID = $contentObject->attribute('main_parent_node_id'); if ($currentMainParentNodeID != $defaultUserPlacement) { $existingNode = eZContentObjectTreeNode::fetchNode($contentObjectID, $defaultUserPlacement); if (!is_object($existingNode)) { eZDebug::writeError("Cannot find assigned node as {$defaultUserPlacement}'s child.", __METHOD__); } else { $existingNodeID = $existingNode->attribute('node_id'); $versionNum = $version->attribute('version'); eZContentObjectTreeNode::updateMainNodeID($existingNodeID, $contentObjectID, $versionNum, $defaultUserPlacement); $objectIsChanged = true; } } $db->commit(); // Finally, clear object view cache if something was changed if ($objectIsChanged) { eZContentCacheManager::clearObjectViewCache($contentObjectID, true); } } } eZUser::updateLastVisit($userID); //eZUser::setCurrentlyLoggedInUser( $user, $userID ); // Reset number of failed login attempts eZUser::setFailedLoginAttempts($userID, 0); return $user; }
function getExtractableNodesCount() { $classList = eZContentObjectAkismet::getExtractableClassList(); $params = array('ClassFilterType' => 'include', 'ClassFilterArray' => $classList); $node = eZContentObjectTreeNode::fetchNode(1, 1); $nodeCount = $node->subTreeCount($params, 1); return $nodeCount; }