function copyObject($Module, $object, $allVersions, $newParentNodeID) { if (!$newParentNodeID) { return $Module->redirectToView('view', array('full', 2)); } // check if we can create node under the specified parent node if (($newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID)) === null) { return $Module->redirectToView('view', array('full', 2)); } $classID = $object->attribute('contentclass_id'); if (!$newParentNode->checkAccess('create', $classID)) { $objectID = $object->attribute('id'); eZDebug::writeError("Cannot copy object {$objectID} to node {$newParentNodeID}, " . "the current user does not have create permission for class ID {$classID}", 'content/copy'); return $Module->handleError(eZError::KERNEL_ACCESS_DENIED, 'kernel'); } $db = eZDB::instance(); $db->begin(); $newObject = $object->copy($allVersions); // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 then the object has been newly created $newObject->setAttribute('section_id', 0); $newObject->store(); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); unset($curVersionObject); // remove old node assignments foreach ($newObjAssignments as $assignment) { $assignment->purge(); } // and create a new one $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1)); $nodeAssignment->store(); // publish the newly created object eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); return $Module->redirectToView('view', array('full', $newParentNodeID)); }
function checkContentActions( $module, $class, $object, $version, $contentObjectAttributes, $EditVersion, $EditLanguage, $FromLanguage, &$Result ) { if ( $module->isCurrentAction( 'Preview' ) ) { $module->redirectToView( 'versionview', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Translate' ) ) { $module->redirectToView( 'translate', array( $object->attribute( 'id' ), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'VersionEdit' ) ) { if ( isset( $GLOBALS['eZRequestedURI'] ) and is_object( $GLOBALS['eZRequestedURI'] ) ) { $uri = $GLOBALS['eZRequestedURI']; $uri = $uri->originalURIString(); $http = eZHTTPTool::instance(); $http->setSessionVariable( 'LastAccessesVersionURI', $uri ); } $module->redirectToView( 'history', array( $object->attribute( 'id' ), $EditVersion, $EditLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'EditLanguage' ) ) { if ( $module->hasActionParameter( 'SelectedLanguage' ) ) { $EditLanguage = $module->actionParameter( 'SelectedLanguage' ); // We reset the from language to disable the translation look $FromLanguage = false; $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ( $module->isCurrentAction( 'TranslateLanguage' ) ) { if ( $module->hasActionParameter( 'SelectedLanguage' ) ) { $FromLanguage = $EditLanguage; $EditLanguage = $module->actionParameter( 'SelectedLanguage' ); $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } if ( $module->isCurrentAction( 'FromLanguage' ) ) { $FromLanguage = $module->actionParameter( 'FromLanguage' ); $module->redirectToView( 'edit', array( $object->attribute('id'), $EditVersion, $EditLanguage, $FromLanguage ) ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Discard' ) ) { $http = eZHTTPTool::instance(); $objectID = $object->attribute( 'id' ); $discardConfirm = true; if ( $http->hasPostVariable( 'DiscardConfirm' ) ) $discardConfirm = $http->postVariable( 'DiscardConfirm' ); $http->setSessionVariable( 'DiscardObjectID', $objectID ); $http->setSessionVariable( 'DiscardObjectVersion', $EditVersion ); $http->setSessionVariable( 'DiscardObjectLanguage', $EditLanguage ); $http->setSessionVariable( 'DiscardConfirm', $discardConfirm ); $module->redirectTo( $module->functionURI( 'removeeditversion' ) . '/' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } // helper function which computes the redirect after // publishing and final store of a draft. function computeRedirect( $module, $object, $version, $EditLanguage = false ) { $http = eZHTTPTool::instance(); $node = $object->mainNode(); if ( $http->hasSessionVariable( 'RedirectIfDiscarded' ) ) { $http->removeSessionVariable( 'RedirectIfDiscarded' ); } $hasRedirected = false; if ( $http->hasSessionVariable( 'ParentObject' ) && $http->sessionVariable( 'NewObjectID' ) == $object->attribute( 'id' ) ) { $parentArray = $http->sessionVariable( 'ParentObject' ); $parentURL = $module->redirectionURI( 'content', 'edit', $parentArray ); $parentObject = eZContentObject::fetch( $parentArray[0] ); $db = eZDB::instance(); $db->begin(); $parentObject->addContentObjectRelation( $object->attribute( 'id' ), $parentArray[1] ); $db->commit(); $http->removeSessionVariable( 'ParentObject' ); $http->removeSessionVariable( 'NewObjectID' ); $module->redirectTo( $parentURL ); $hasRedirected = true; } if ( $http->hasSessionVariable( 'RedirectURIAfterPublish' ) && !$hasRedirected ) { $uri = $http->sessionVariable( 'RedirectURIAfterPublish' ); $http->removeSessionVariable( 'RedirectURIAfterPublish' ); $module->redirectTo( $uri ); $hasRedirected = true; } if ( $http->hasPostVariable( 'RedirectURIAfterPublish' ) && !$hasRedirected ) { $uri = $http->postVariable( 'RedirectURIAfterPublish' ); $module->redirectTo( $uri ); $hasRedirected = true; } if ( $http->hasPostVariable( "BackToEdit" ) && $http->postVariable( "BackToEdit" ) ) { $uri = $module->redirectionURI( 'content', 'edit', array( $object->attribute( 'id'), 'f', $EditLanguage ) ); $module->redirectTo( $uri ); eZDebug::writeDebug( $uri, "uri " . $object->attribute( 'id') ); $hasRedirected = true; } if ( !$hasRedirected ) { if ( $http->hasPostVariable( 'RedirectURI' ) ) { $uri = $http->postVariable( 'RedirectURI' ); $module->redirectTo( $uri ); } else if ( $node !== null ) { $parentNode = $node->attribute( 'parent_node_id' ); if ( $parentNode == 1 ) { $parentNode = $node->attribute( 'node_id' ); } $module->redirectToView( 'view', array( 'full', $parentNode ) ); } else { $module->redirectToView( 'view', array( 'full', $version->attribute( 'main_parent_node_id' ) ) ); } } } if( $module->isCurrentAction( 'StoreExit' ) ) { computeRedirect( $module, $object, $version, $EditLanguage ); return eZModule::HOOK_STATUS_CANCEL_RUN; } if ( $module->isCurrentAction( 'Publish' ) ) { // Checking the source and destination language from the url, // if they are the same no confirmation is needed. if ( $EditLanguage != $FromLanguage ) { $conflictingVersions = $version->hasConflicts( $EditLanguage ); if ( $conflictingVersions ) { $tpl = eZTemplate::factory(); $res = eZTemplateDesignResource::instance(); $res->setKeys( array( array( 'object', $object->attribute( 'id' ) ), array( 'remote_id', $object->attribute( 'remote_id' ) ), array( 'class', $class->attribute( 'id' ) ), array( 'class_identifier', $class->attribute( 'identifier' ) ), array( 'class_group', $class->attribute( 'match_ingroup_id_list' ) ) ) ); $tpl->setVariable( 'edit_language', $EditLanguage ); $tpl->setVariable( 'current_version', $version->attribute( 'version' ) ); $tpl->setVariable( 'object', $object ); $tpl->setVariable( 'draft_versions', $conflictingVersions ); $Result = array(); $Result['content'] = $tpl->fetch( 'design:content/edit_conflict.tpl' ); return eZModule::HOOK_STATUS_CANCEL_RUN; } } eZDebug::accumulatorStart( 'publish', '', 'publish' ); $oldObjectName = $object->name(); $behaviour = new ezpContentPublishingBehaviour(); $behaviour->isTemporary = true; $behaviour->disableAsynchronousPublishing = false; ezpContentPublishingBehaviour::setBehaviour( $behaviour ); $operationResult = eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $object->attribute( 'id' ), 'version' => $version->attribute( 'version' ) ) ); eZDebug::accumulatorStop( 'publish' ); if ( ( array_key_exists( 'status', $operationResult ) && $operationResult['status'] != eZModuleOperationInfo::STATUS_CONTINUE ) ) { eZDebug::writeDebug( $operationResult, __FILE__ ); switch( $operationResult['status'] ) { case eZModuleOperationInfo::STATUS_REPEAT: { eZContentOperationCollection::setVersionStatus( $object->attribute( 'id' ), $version->attribute( 'version' ), eZContentObjectVersion::STATUS_REPEAT ); } case eZModuleOperationInfo::STATUS_HALTED: { if ( isset( $operationResult['redirect_url'] ) ) { $module->redirectTo( $operationResult['redirect_url'] ); return; } else if ( isset( $operationResult['result'] ) ) { $result = $operationResult['result']; $resultContent = false; if ( is_array( $result ) ) { if ( isset( $result['content'] ) ) { $resultContent = $result['content']; } if ( isset( $result['path'] ) ) { $Result['path'] = $result['path']; } } else { $resultContent = $result; } // Temporary fix to make approval workflow work with edit. if ( strpos( $resultContent, 'Deffered to cron' ) === 0 ) { $Result = null; } else { $Result['content'] = $resultContent; } } }break; case eZModuleOperationInfo::STATUS_CANCELLED: { $Result = array(); $Result['content'] = "Content publish cancelled<br/>"; } } /* If we already have a correct module result * we don't need to continue module execution. */ if ( is_array( $Result ) ) return eZModule::HOOK_STATUS_CANCEL_RUN; } // update content object attributes array by refetching them from database $object = eZContentObject::fetch( $object->attribute( 'id' ) ); $contentObjectAttributes = $object->attribute( 'contentobject_attributes' ); // set chosen hidden/invisible attributes for object nodes $http = eZHTTPTool::instance(); $assignedNodes = $object->assignedNodes( true ); foreach ( $assignedNodes as $node ) { $nodeID = $node->attribute( 'node_id' ); $parentNodeID = $node->attribute( 'parent_node_id' ); $updateNodeVisibility = false; $postVarName = "FutureNodeHiddenState_$parentNodeID"; if ( !$http->hasPostVariable( $postVarName ) ) $updateNodeVisibility = true; else { $futureNodeHiddenState = $http->postVariable( $postVarName ); $db = eZDB::instance(); $db->begin(); if ( $futureNodeHiddenState == 'hidden' ) eZContentObjectTreeNode::hideSubTree( $node ); else if ( $futureNodeHiddenState == 'visible' ) eZContentObjectTreeNode::unhideSubTree( $node ); else if ( $futureNodeHiddenState == 'unchanged' ) $updateNodeVisibility = true; else eZDebug::writeWarning( "Unknown value for the future node hidden state: '$futureNodeHiddenState'" ); $db->commit(); } if ( $updateNodeVisibility ) { // this might be redundant $db = eZDB::instance(); $db->begin(); $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID ); eZContentObjectTreeNode::updateNodeVisibility( $node, $parentNode, /* $recursive = */ false ); $db->commit(); unset( $node, $parentNode ); } } unset( $assignedNodes ); $object = eZContentObject::fetch( $object->attribute( 'id' ) ); $newObjectName = $object->name(); $http = eZHTTPTool::instance(); computeRedirect( $module, $object, $version, $EditLanguage ); // we have set redirection URI for module so we don't need to continue module execution return eZModule::HOOK_STATUS_CANCEL_RUN; } }
function move($newParentNodeID, $nodeID = 0) { if ($nodeID == 0) { $node = $this; $nodeID = $node->attribute('node_id'); } else { $node = eZContentObjectTreeNode::fetch($nodeID); } $oldPath = $node->attribute('path_string'); $oldParentNodeID = $node->attribute('parent_node_id'); $newParentNodeID = (int) $newParentNodeID; if ($oldParentNodeID != $newParentNodeID) { $node->updateAndStoreModified(); // Who moves which content should be logged. $object = $node->object(); eZAudit::writeAudit('content-move', array('Node ID' => $node->attribute('node_id'), 'Old parent node ID' => $oldParentNodeID, 'New parent node ID' => $newParentNodeID, 'Object ID' => $object->attribute('id'), 'Content Name' => $object->attribute('name'), 'Comment' => 'Moved the node to the given node: eZContentObjectTreeNode::move()')); $newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID); $newParentPath = $newParentNode->attribute('path_string'); $newParentDepth = $newParentNode->attribute('depth'); $newPath = $newParentPath . $nodeID; $oldDepth = $node->attribute('depth'); $oldPathLength = strlen($oldPath); $moveQuery = "UPDATE\n ezcontentobject_tree\n SET\n parent_node_id = {$newParentNodeID}\n WHERE\n node_id = {$nodeID}"; $db = eZDB::instance(); $subStringString = $db->subString('path_string', $oldPathLength); $newPathString = $db->concatString(array("'{$newPath}'", $subStringString)); $moveQuery1 = "UPDATE\n ezcontentobject_tree\n SET\n path_identification_string = " . $db->concatString(array("'" . $db->escapeString($newParentNode->PathIdentificationString) . "'", $db->subString("path_identification_string", mb_strlen($node->PathIdentificationString) + 1))) . ",\n path_string = {$newPathString},\n depth = depth + {$newParentDepth} - {$oldDepth} + 1\n WHERE\n path_string LIKE '{$oldPath}%'"; $db->begin(); $db->query($moveQuery); $db->query($moveQuery1); /// role system clean up // Clean up policies and limitations $expireRoleCache = false; $limitationsToFix = eZPolicyLimitation::findByType('SubTree', $node->attribute('path_string'), false); if (count($limitationsToFix) > 0) { $limitationIDString = $db->generateSQLINStatement($limitationsToFix, 'limitation_id'); $subStringString = $db->subString('value', $oldPathLength); $newValue = $db->concatString(array("'{$newPath}'", $subStringString)); $query = "UPDATE\n ezpolicy_limitation_value\n SET\n value = {$newValue}\n WHERE\n value LIKE '{$oldPath}%' AND {$limitationIDString}"; $db->query($query); $expireRoleCache = true; } // clean up limitations on role assignment level $countRows = $db->arrayQuery("SELECT COUNT(*) AS row_count FROM ezuser_role WHERE limit_identifier='Subtree' AND limit_value LIKE '{$oldPath}%'"); $assignmentsToFixCount = $countRows[0]['row_count']; if ($assignmentsToFixCount > 0) { $subStringString = $db->subString('limit_value', $oldPathLength); $newValue = $db->concatString(array("'{$newPath}'", $subStringString)); $db->query("UPDATE\n ezuser_role\n SET\n limit_value = {$newValue}\n WHERE\n limit_identifier='Subtree' AND limit_value LIKE '{$oldPath}%'"); $expireRoleCache = true; } if ($expireRoleCache) { eZRole::expireCache(); } // Update "is_invisible" node attribute. $newNode = eZContentObjectTreeNode::fetch($nodeID); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); } }
function copyPublishContentObject($sourceObject, $sourceSubtreeNodeIDList, &$syncNodeIDListSrc, &$syncNodeIDListNew, &$syncObjectIDListSrc, &$syncObjectIDListNew, $allVersions = false, $keepCreator = false, $keepTime = false) { global $cli; $sourceObjectID = $sourceObject->attribute('id'); $key = array_search($sourceObjectID, $syncObjectIDListSrc); if ($key !== false) { return 1; // object already copied } $srcNodeList = $sourceObject->attribute('assigned_nodes'); // check if all parent nodes for given contentobject are already published: foreach ($srcNodeList as $srcNode) { $sourceParentNodeID = $srcNode->attribute('parent_node_id'); // if parent node for this node is outside // of subtree being copied, then skip this node. $key = array_search($sourceParentNodeID, $sourceSubtreeNodeIDList); if ($key === false) { continue; } $key = array_search($sourceParentNodeID, $syncNodeIDListSrc); if ($key === false) { return 2; // one of parent nodes is not published yet - have to try to publish later. } else { $newParentNodeID = $syncNodeIDListNew[$key]; if (($newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID)) === null) { return 3; // cannot fetch one of parent nodes - must be error somewhere above. } } } // make copy of source object $newObject = $sourceObject->copy($allVersions); // insert source and new object's ids in $syncObjectIDList // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 than the object has been newly created $newObject->setAttribute('section_id', 0); $newObject->store(); $syncObjectIDListSrc[] = $sourceObjectID; $syncObjectIDListNew[] = $newObject->attribute('id'); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); // copy nodeassigments: $assignmentsForRemoving = array(); $foundMainAssignment = false; foreach ($newObjAssignments as $assignment) { $parentNodeID = $assignment->attribute('parent_node'); // if assigment is outside of subtree being copied then do not copy this assigment $key = array_search($parentNodeID, $sourceSubtreeNodeIDList); if ($key === false) { $assignmentsForRemoving[] = $assignment->attribute('id'); continue; } $key = array_search($parentNodeID, $syncNodeIDListSrc); if ($key === false) { $cli->error("Subtree Copy Error!\nOne of parent nodes for contentobject (ID = {$sourceObjectID}) is not published yet."); return 4; } if ($assignment->attribute('is_main')) { $foundMainAssignment = true; } $newParentNodeID = $syncNodeIDListNew[$key]; $assignment->setAttribute('parent_node', $newParentNodeID); $assignment->store(); } // remove assigments which are outside of subtree being copied: eZNodeAssignment::purgeByID($assignmentsForRemoving); // JB valid // if main nodeassigment was not copied then set as main first nodeassigment if ($foundMainAssignment == false) { $newObjAssignments = $curVersionObject->attribute('node_assignments'); // JB start // We need to check if it has any assignments before changing the data. if (isset($newObjAssignments[0])) { $newObjAssignments[0]->setAttribute('is_main', 1); $newObjAssignments[0]->store(); } // JB end } // publish the newly created object $result = eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // JB start // Refetch the object data since it might change in the database. $newObjectID = $newObject->attribute('id'); $newObject = eZContentObject::fetch($newObjectID); // JB end $newNodeList = $newObject->attribute('assigned_nodes'); if (count($newNodeList) == 0) { $newObject->purge(); $cli->error("Subtree Copy Error!\nCannot publish contentobject."); return 5; } $objAssignments = $curVersionObject->attribute('node_assignments'); foreach ($newNodeList as $newNode) { $newParentNodeID = $newNode->attribute('parent_node_id'); $keyA = array_search($newParentNodeID, $syncNodeIDListNew); if ($keyA === false) { die("Copy Subtree Error: Algoritm ERROR! Cannot find new parent node ID in new ID's list"); } $srcParentNodeID = $syncNodeIDListSrc[$keyA]; // Update attributes of node $bSrcParentFound = false; foreach ($srcNodeList as $srcNode) { if ($srcNode->attribute('parent_node_id') == $srcParentNodeID) { $newNode->setAttribute('priority', $srcNode->attribute('priority')); $newNode->setAttribute('is_hidden', $srcNode->attribute('is_hidden')); $newNode->setAttribute('is_invisible', $srcNode->attribute('is_invisible')); $syncNodeIDListSrc[] = $srcNode->attribute('node_id'); $syncNodeIDListNew[] = $newNode->attribute('node_id'); $bSrcParentFound = true; break; } } if ($bSrcParentFound == false) { die("Copy Subtree Error: Algoritm ERROR! Cannot find source parent node ID in source parent node ID's list of contentobject being copied."); } // Create unique remote_id $newRemoteID = eZRemoteIdUtility::generate('node'); $oldRemoteID = $newNode->attribute('remote_id'); $newNode->setAttribute('remote_id', $newRemoteID); // Change parent_remote_id for object assignments foreach ($objAssignments as $assignment) { if ($assignment->attribute('parent_remote_id') == $oldRemoteID) { $assignment->setAttribute('parent_remote_id', $newRemoteID); $assignment->store(); } } $newNode->store(); } // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); // ??? do we need this here? // if $keepCreator == true then keep owner of contentobject being // copied and creator of its published version Unchaged $isModified = false; if ($keepTime) { $srcPublished = $sourceObject->attribute('published'); $newObject->setAttribute('published', $srcPublished); $srcModified = $sourceObject->attribute('modified'); $newObject->setAttribute('modified', $srcModified); $isModified = true; } if ($keepCreator) { $srcOwnerID = $sourceObject->attribute('owner_id'); $newObject->setAttribute('owner_id', $srcOwnerID); $isModified = true; } if ($isModified) { $newObject->store(); } if ($allVersions) { // copy time of creation and modification and creator id for // all versions of content object being copied. $srcVersionsList = $sourceObject->versions(); foreach ($srcVersionsList as $srcVersionObject) { $newVersionObject = $newObject->version($srcVersionObject->attribute('version')); if (!is_object($newVersionObject)) { continue; } $isModified = false; if ($keepTime) { $srcVersionCreated = $srcVersionObject->attribute('created'); $newVersionObject->setAttribute('created', $srcVersionCreated); $srcVersionModified = $srcVersionObject->attribute('modified'); $newVersionObject->setAttribute('modified', $srcVersionModified); $isModified = true; } if ($keepCreator) { $srcVersionCreatorID = $srcVersionObject->attribute('creator_id'); $newVersionObject->setAttribute('creator_id', $srcVersionCreatorID); $isModified = true; } if ($isModified) { $newVersionObject->store(); } } } else { $srcVersionObject = $sourceObject->attribute('current'); $newVersionObject = $newObject->attribute('current'); $isModified = false; if ($keepTime) { $srcVersionCreated = $srcVersionObject->attribute('created'); $newVersionObject->setAttribute('created', $srcVersionCreated); $srcVersionModified = $srcVersionObject->attribute('modified'); $newVersionObject->setAttribute('modified', $srcVersionModified); $isModified = true; } if ($keepCreator) { $srcVersionCreatorID = $srcVersionObject->attribute('creator_id'); $newVersionObject->setAttribute('creator_id', $srcVersionCreatorID); $isModified = true; } if ($isModified) { $newVersionObject->store(); } } return 0; // source object was copied successfully. }
/** * Copies the specified object to the same folder, with optional $destinationName. * * @param eZContentObject $object * @param eZContentObject $newParentNode * @param string $destinationName * @return bool */ protected function copyObjectSameDirectory($object, $newParentNode, $destinationName = null) { $object = $object->ContentObject; $newParentNodeID = $newParentNode->attribute('node_id'); $classID = $object->attribute('contentclass_id'); if (!$newParentNode->checkAccess('create', $classID)) { $objectID = $object->attribute('id'); return false; } $db = eZDB::instance(); $db->begin(); $newObject = $object->copy(true); // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 than the object has been newly created $newObject->setAttribute('section_id', 0); // @as 2009-01-08 - Added check for destination name the same as the source name // (this was causing problems with nodes disappearing after renaming) $newName = $destinationName; if ($destinationName === null || strtolower($destinationName) === strtolower($object->attribute('name'))) { $newName = 'Copy of ' . $object->attribute('name'); } // @todo @as avoid using [0] (could be another index in some classes) $contentObjectAttributes = $newObject->contentObjectAttributes(); $contentObjectAttributes[0]->setAttribute('data_text', $newName); $contentObjectAttributes[0]->store(); $newObject->store(); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); unset($curVersionObject); // remove old node assignments foreach ($newObjAssignments as $assignment) { $assignment->purge(); } // and create a new one $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1)); $nodeAssignment->store(); // publish the newly created object eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); return true; }
/** * Create a copy of an object. * * The basis for this method is taken from kernel/content/copy.php * * @todo Merge this method into kernel wrapper's object class. * * @param eZContentObject $object * @param int $newParentNodeID * @return eZContentObject */ public static function copyObject($object, $newParentNodeID) { $newParentNode = eZContentObjectTreeNode::fetch($newParentNodeID); $db = eZDB::instance(); $db->begin(); $newObject = $object->copy(true); // We should reset section that will be updated in updateSectionID(). // If sectionID is 0 than the object has been newly created $newObject->setAttribute('section_id', 0); $newObject->store(); $curVersion = $newObject->attribute('current_version'); $curVersionObject = $newObject->attribute('current'); $newObjAssignments = $curVersionObject->attribute('node_assignments'); unset($curVersionObject); // remove old node assignments foreach ($newObjAssignments as $assignment) { $assignment->purge(); } // and create a new one $nodeAssignment = eZNodeAssignment::create(array('contentobject_id' => $newObject->attribute('id'), 'contentobject_version' => $curVersion, 'parent_node' => $newParentNodeID, 'is_main' => 1)); $nodeAssignment->store(); // publish the newly created object eZOperationHandler::execute('content', 'publish', array('object_id' => $newObject->attribute('id'), 'version' => $curVersion)); // Update "is_invisible" attribute for the newly created node. $newNode = $newObject->attribute('main_node'); eZContentObjectTreeNode::updateNodeVisibility($newNode, $newParentNode); $db->commit(); return $newObject; }
function editContentObject( $objectInformation ) { $db = eZDB::instance(); $contentObjectVersion = false; $contentObject = $objectInformation['object']; if ( $objectInformation['ownerID'] ) { $userID = $objectInformation['ownerID']; } else { $userID = $contentObject->attribute( 'owner_id' ); } if ( $contentObject ) { $contentObjectVersion = $contentObject->createNewVersion(); } if ( $contentObjectVersion ) { $db->begin(); $versionNumber = $contentObjectVersion->attribute( 'version' ); $dataMap = $contentObjectVersion->dataMap(); foreach ( $objectInformation['attributes'] as $attributeName => $attributesContent ) { if ( array_key_exists( $attributeName, $dataMap ) ) { $attribute = $dataMap[$attributeName]; $classAttributeID = $attribute->attribute( 'contentclassattribute_id' ); $dataType = $attribute->attribute( 'data_type_string' ); switch ( $dataType ) { case 'ezstring': case 'eztext': case 'ezselection': case 'ezemail': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attribute->setAttribute( 'data_text', $this->parseAndReplaceStringReferences( $attributesContent['content'] ) ); } else { $attribute->setAttribute( 'data_text', $attributesContent['content'] ); } } break; case 'ezboolean': case 'ezinteger': { $attribute->setAttribute( 'data_int', (int)$attributesContent['content'] ); } break; case 'ezxmltext': { if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $attributesContent['content'] = $this->parseAndReplaceStringReferences( $attributesContent['content'] ); } if ( array_key_exists( 'htmlDecode', $attributesContent ) && $attributesContent['htmlDecode'] == "true" ) { $content = html_entity_decode( $attributesContent['content'] ); } else { $content = $attributesContent['content']; } $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n". '<section xmlns:image="http://ez.no/namespaces/ezpublish3/image/"'."\n". ' xmlns:xhtml="http://ez.no/namespaces/ezpublish3/xhtml/"'."\n". ' xmlns:custom="http://ez.no/namespaces/ezpublish3/custom/">'."\n". ' <section>'."\n"; $xml .= ' <paragraph>' . $content . "</paragraph>\n"; $xml .= " </section>\n</section>\n"; $attribute->setAttribute( 'data_text', $xml ); } break; case 'ezprice': case 'ezfloat': { $attribute->setAttribute( 'data_float', (float)$attributesContent['content'] ); } break; case 'ezimage': { $imagePath = $this->setting( 'data_source' ) . '/' . $attributesContent['src']; $imageName = $attributesContent['title']; $path = realpath( $imagePath ); if ( file_exists( $path ) ) { $content = $attribute->content(); $content->initializeFromFile( $path, $imageName, basename( $attributesContent['src'] ) ); $content->store( $attribute ); } else { $this->writeMessage( "\tFile " . $path . " not found.", 'warning' ); } } break; case 'ezobjectrelation': { $objectID = $this->getReferenceID( $attributesContent['content'] ); if ( $objectID ) { $attribute->setAttribute( 'data_int', $objectID ); eZContentObject::fetch( $objectID )->addContentObjectRelation( $objectID, $versionNumber, $contentObject->attribute( 'id' ), $attribute->attribute( 'contentclassattribute_id' ), eZContentObject::RELATION_ATTRIBUTE ); } else { $this->writeMessage( "\tReference " . $attributesContent['content'] . " not set.", 'warning' ); } } break; case 'ezurl': { $url = ''; $title = ''; if ( array_key_exists( 'url', $attributesContent ) ) $url = $attributesContent['url']; if ( array_key_exists( 'title', $attributesContent ) ) $title = $attributesContent['title']; if ( array_key_exists( 'parseReferences', $attributesContent ) && $attributesContent['parseReferences'] == "true" ) { $title = $this->parseAndReplaceStringReferences( $title ); $url = $this->parseAndReplaceStringReferences( $url ); } $attribute->setAttribute( 'data_text', $title ); $attribute->setContent( $url ); } break; case 'ezuser': { $login = ''; $email = ''; $password = ''; if ( array_key_exists( 'login', $attributesContent ) ) $login = $attributesContent['login']; if ( array_key_exists( 'email', $attributesContent ) ) $email = $attributesContent['email']; if ( array_key_exists( 'password', $attributesContent ) ) $password = $attributesContent['password']; $contentObjectID = $attribute->attribute( "contentobject_id" ); $user =& $attribute->content(); if ( $user === null ) { $user = eZUser::create( $contentObjectID ); } $ini =& eZINI::instance(); $generatePasswordIfEmpty = $ini->variable( "UserSettings", "GeneratePasswordIfEmpty" ); if ( $password == "" ) { if ( $generatePasswordIfEmpty == 'true' ) { $passwordLength = $ini->variable( "UserSettings", "GeneratePasswordLength" ); $password = $user->createPassword( $passwordLength ); } else { $password = null; } } if ( $password == "_ezpassword" ) { $password = false; $passwordConfirm = false; } $user->setInformation( $contentObjectID, $login, $email, $password, $password ); $attribute->setContent( $user ); } break; case 'ezkeyword': { $keyword = new eZKeyword(); $keyword->initializeKeyword( $attributesContent['content'] ); $attribute->setContent( $keyword ); } break; case 'ezmatrix': { if ( is_array( $attributesContent ) ) { $matrix = $attribute->attribute( 'content' ); $cells = array(); $matrix->Matrix['rows']['sequential'] = array(); $matrix->NumRows = 0; foreach( $attributesContent as $key => $value ) { $cells = array_merge( $cells, $value ); $newRow['columns'] = $value; $newRow['identifier'] = 'row_' . ( $matrix->NumRows + 1 ); $newRow['name'] = 'Row_' . ( $matrix->NumRows + 1 ); $matrix->NumRows++; $matrix->Matrix['rows']['sequential'][] = $newRow; } $matrix->Cells = $cells; $attribute->setAttribute( 'data_text', $matrix->xmlString() ); $matrix->decodeXML( $attribute->attribute( 'data_text' ) ); $attribute->setContent( $matrix ); } } break; case 'ezauthor': case 'ezbinaryfile': case 'ezcountry': case 'ezdate': case 'ezdatetime': case 'ezenum': case 'ezidentifier': case 'ezinisetting': case 'ezisbn': case 'ezmedia': case 'ezmultioption': case 'ezmultiprice': case 'ezobjectrelationlist': case 'ezoption': case 'ezpackage': case 'ezproductcategory': case 'ezrangeoption': case 'ezsubtreesubscription': case 'eztime': { $this->writeMessage( "\tDatatype " . $dataType . " not supported yet.", 'warning' ); } break; } $attribute->store(); } } if ( isset($objectInformation['sectionID']) && $objectInformation['sectionID'] != '' && $objectInformation['sectionID'] != 0 ) { $contentObject->setAttribute( 'section_id', $objectInformation['sectionID'] ); } if ( isset($objectInformation['creatorID']) && $objectInformation['creatorID'] != '' && $objectInformation['creatorID'] != 0 ) { $contentObjectVersion->setAttribute( 'creator_id', $objectInformation['creatorID'] ); } if ( isset($objectInformation['ownerID']) && $objectInformation['ownerID'] != '' && $objectInformation['ownerID'] != 0 ) { $contentObject->setAttribute( 'owner_id', $objectInformation['ownerID'] ); } $contentObjectVersion->store(); $contentObject->store(); $db->commit(); eZOperationHandler::execute( 'content', 'publish', array( 'object_id' => $contentObject->attribute( 'id' ), 'version' => $versionNumber ) ); // set chosen hidden/invisible attributes for object nodes $http = eZHTTPTool::instance(); $assignedNodes = $contentObject->assignedNodes( true ); foreach ( $assignedNodes as $node ) { $nodeID = $node->attribute( 'node_id' ); $parentNodeID = $node->attribute( 'parent_node_id' ); $db = eZDB::instance(); $db->begin(); $parentNode = eZContentObjectTreeNode::fetch( $parentNodeID ); eZContentObjectTreeNode::updateNodeVisibility( $node, $parentNode, /* $recursive = */ false ); $db->commit(); unset( $node, $parentNode ); } unset( $assignedNodes ); eZContentCacheManager::clearObjectViewCacheIfNeeded( $contentObject->attribute( 'id' ) ); $newNodeArray = eZContentObjectTreeNode::fetchByContentObjectID( $contentObject->attribute( 'id' ) ); $refArray = false; if ( $newNodeArray && count($newNodeArray) >= 1 ) { $newNode = $newNodeArray[0]; if ( $newNode ) { $refArray = array( "node_id" => $newNode->attribute( 'node_id' ), "name" => $contentObject->attribute( 'name' ), "object_id" => $contentObject->attribute( 'id' ) ); } } unset($contentObjectVersion); unset($contentObject); return $refArray; } return false; }