AnsweredAssumed Answered

Node deep copy with permissions intact

Question asked by ejholmgren on May 26, 2009
Latest reply on Apr 29, 2010 by mabayona
I am attempting to use the copy() method on a node that contains several child folders each with different permissions. The folder structure comes through intact, but the nested permissions get trashed. Is there correct way to do this?


var message = "createTitleContentFolderByNameAndTitleId failed";
var exception = "";
var success = false;

var folderName = args.folderName;
var titleId = args.titleId;

try
{
   
    if((folderName == null) || (folderName == "") || (titleId == null) || (titleId == ""))
    {
        message = "Expected folderName and titleId as arguments";
    }
    else
    {
        // Locate content folder for use as a template
        var templateQuery = "//.[@cm:name='Title Content Folders']/*[@cm:name='" + folderName + "']";
        message = "Searching against XPath query: " + templateQuery;
        var templateResults = companyhome.childrenByXPath(templateQuery);
       
        // Locate title folder (target parent)
        var titleQuery = "//.[@bm:title_id=" + titleId + "]";
        message = "Searching against XPath query: " + titleQuery;
        var titleResults = companyhome.childrenByXPath(titleQuery);
   
        if((templateResults.length > 0) && (titleResults.length > 0))
        {       
       var templateFolder = templateResults[0];
            var titleFolder = titleResults[0];
            var newContentFolder = templateFolder.copy(titleFolder, true);
            newContentFolder.name = templateFolder.name;
            if(newContentFolder != null)
            {
                 message = "Content folder created";
                 success = true;
            }
        }
        else
        {
            message = "Could not locate content folder or title folder";
        }
    }   
}
catch (e)
{
    exception = e.description;
}

model.message = message;
model.exception = exception;
model.success = success;

Outcomes