Esempio n. 1
0
    /// <summary>
    /// Copies the document under workflow to a different section. Called when the "Copy document" button is pressd.
    /// Expects the "CreateExampleObjects" and "CreateDocument" methods to be run first.
    /// </summary>
    private bool CopyDocument()
    {
        // Create an instance of the Tree provider first
        TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

        // Prepare parameters
        string siteName  = CMSContext.CurrentSiteName;
        string aliasPath = "/API-Example/My-new-document";
        string culture   = "en-us";
        bool   combineWithDefaultCulture = false;
        string classNames = TreeProvider.ALL_CLASSNAMES;

        string where = null;
        string orderBy             = null;
        int    maxRelativeLevel    = -1;
        bool   selectOnlyPublished = false;
        string columns             = null;

        // Get the example folder
        TreeNode node = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        aliasPath = "/API-Example/Source";

        // Get the new parent document
        TreeNode parentNode = DocumentHelper.GetDocument(siteName, aliasPath, culture, combineWithDefaultCulture, classNames, where, orderBy, maxRelativeLevel, selectOnlyPublished, columns, tree);

        if ((node != null) && (parentNode != null))
        {
            // Copy the document
            DocumentHelper.CopyDocument(node, parentNode.NodeID, false, tree);

            return(true);
        }

        return(false);
    }
 /// <summary>
 /// Copy documents section.
 /// </summary>
 /// <param name="source">Source document</param>
 /// <param name="target">Target document</param>
 /// <param name="tree">Tree provider</param>
 private void CopyDocumentSection(TreeNode source, TreeNode target, TreeProvider tree)
 {
     DocumentHelper.CopyDocument(source, target, true, tree);
 }
Esempio n. 3
0
    /// <summary>
    /// Copies the node to the specified target.
    /// </summary>
    /// <param name="node">Node to copy</param>
    /// <param name="targetNode">Target node</param>
    /// <param name="tree">Tree provider</param>
    /// <param name="childNodes">Copy also child nodes</param>
    /// <param name="copyPermissions">Indicates if node permissions should be copied</param>
    /// <param name="newDocumentName">New document name</param>
    protected TreeNode CopyNode(TreeNode node, TreeNode targetNode, bool childNodes, TreeProvider tree, bool copyPermissions, string newDocumentName)
    {
        string encodedAliasPath = " (" + HTMLHelper.HTMLEncode(node.NodeAliasPath) + ")";
        int    targetId         = targetNode.NodeID;

        // Do not copy child nodes in case of no child nodes
        childNodes = childNodes && (node.NodeChildNodesCount > 0);

        // Get the document to copy
        int nodeId = node.NodeID;

        if ((nodeId == targetId) && childNodes)
        {
            AddError(GetString("ContentRequest.CannotCopyToItself") + encodedAliasPath);
            return(null);
        }

        // Check move permission
        if (!IsUserAuthorizedToCopyOrLink(node, targetId, node.NodeClassName))
        {
            AddError(GetString("ContentRequest.NotAllowedToCopy") + encodedAliasPath);
            return(null);
        }

        // Check cyclic copying (copying of the node to some of its child nodes)
        if (childNodes && (targetNode.NodeSiteID == node.NodeSiteID) && targetNode.NodeAliasPath.StartsWith(node.NodeAliasPath + "/", StringComparison.CurrentCultureIgnoreCase))
        {
            AddError(GetString("ContentRequest.CannotCopyToChild"));
            return(null);
        }

        string domainToCheck = null;

        if (targetNode.NodeSiteID == node.NodeSiteID)
        {
            domainToCheck = URLHelper.GetCurrentDomain();
        }
        else
        {
            SiteInfo targetSite = SiteInfoProvider.GetSiteInfo(targetNode.NodeSiteID);
            domainToCheck = targetSite.DomainName;
        }

        // Check the licence limitations
        if ((node.NodeClassName.ToLower() == "cms.blog") && !LicenseHelper.LicenseVersionCheck(domainToCheck, FeatureEnum.Blogs, VersionActionEnum.Insert))
        {
            AddError(GetString("cmsdesk.bloglicenselimits"));
            return(null);
        }

        // Check allowed child class
        int targetClassId = ValidationHelper.GetInteger(targetNode.GetValue("NodeClassID"), 0);
        int nodeClassId   = ValidationHelper.GetInteger(node.GetValue("NodeClassID"), 0);

        if (!DataClassInfoProvider.IsChildClassAllowed(targetClassId, nodeClassId) || (ClassSiteInfoProvider.GetClassSiteInfo(nodeClassId, targetNode.NodeSiteID) == null))
        {
            AddError(String.Format(GetString("ContentRequest.ErrorDocumentTypeNotAllowed"), node.NodeAliasPath, node.NodeClassName));
            return(null);
        }

        // Copy the document
        AddLog(HTMLHelper.HTMLEncode(node.NodeAliasPath + " (" + node.DocumentCulture + ")"));

        node = DocumentHelper.CopyDocument(node, targetId, childNodes, tree, 0, 0, copyPermissions, newDocumentName);
        SetExpandedNode(node.NodeParentID);

        return(node);
    }