API
Version 7.x > API > Create, Move, Stage ... not keeping parent View modes: 
User avatar
Member
Member
JAA - 1/17/2014 2:42:45 PM
   
Create, Move, Stage ... not keeping parent
I have some (of my first ;)) rapid prototype code. What /should/ be happening here is:
1. Create a Document (this will create as a child)
2. Move Document (too the root)
3. Stage the Document

What I am seeing is that functionally everything works, but the document gets staged as a child to "/test1" and not "/". Any ideas?


private static bool CreateDocument(CMS.SiteProvider.SiteInfo siteInfo)
{
// Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// Get the parent node - the API Example folder
TreeNode parentNode = tree.SelectSingleNode(siteInfo.SiteName, "/test1", "en-us");
TreeNode rootNode = tree.SelectSingleNode(siteInfo.SiteName, "/", "en-us");

if ((rootNode != null) && (parentNode != null))
{
// Create a new instance of the Tree node
TreeNode newNode = TreeNode.New("CMS.MenuItem", tree);

// Set the document's properties
newNode.DocumentName = "test1-API-copy " + DateTime.Now.ToString();
newNode.DocumentCulture = "en-us";

// Insert the document into the content tree
newNode.Insert(parentNode);
tree.MoveNode(newNode, rootNode.NodeID);
return true;
}
return false;
}


private static bool GetAndSynchronizeTasks(CMS.SiteProvider.SiteInfo siteInfo)
{
// Get server
ServerInfo server = ServerInfoProvider.GetServerInfo("stage2", siteInfo.SiteID);

if (server != null)
{
// Get tasks for the server
DataSet tasks = TaskInfoProvider.SelectTaskList(siteInfo.SiteID, server.ServerID, null, null);

if (!DataHelper.DataSourceIsEmpty(tasks))
{
foreach (DataRow taskDr in tasks.Tables[0].Rows)
{
// Create task info object from data row
TaskInfo task = new TaskInfo(taskDr);
Console.WriteLine(task.TaskID + "\t" + task.TaskTitle);

// Synchronize the task
if (!string.IsNullOrEmpty(StagingHelper.RunSynchronization(task.TaskID, server.ServerID)))
{
Console.WriteLine("GetAndSynchronizeTasks return false");
return false;
}
}

return true;
}
Console.WriteLine("GetAndSynchronizeTasks no tasks found");
}
return false;
}

User avatar
Member
Member
JAA - 1/17/2014 2:44:33 PM
   
RE:Create, Move, Stage ... not keeping parent
code formatted properly

private static bool CreateDocument(CMS.SiteProvider.SiteInfo siteInfo)
{
// Create an instance of the Tree provider first
TreeProvider tree = new TreeProvider(CMSContext.CurrentUser);

// Get the parent node - the API Example folder
TreeNode parentNode = tree.SelectSingleNode(siteInfo.SiteName, "/test1", "en-us");
TreeNode rootNode = tree.SelectSingleNode(siteInfo.SiteName, "/", "en-us");

if ((rootNode != null) && (parentNode != null))
{
// Create a new instance of the Tree node
TreeNode newNode = TreeNode.New("CMS.MenuItem", tree);

// Set the document's properties
newNode.DocumentName = "test1-API-copy " + DateTime.Now.ToString();
newNode.DocumentCulture = "en-us";

// Insert the document into the content tree
newNode.Insert(parentNode);
tree.MoveNode(newNode, rootNode.NodeID);
return true;
}
return false;
}

private static bool GetAndSynchronizeTasks(CMS.SiteProvider.SiteInfo siteInfo)
{
// Get server
ServerInfo server = ServerInfoProvider.GetServerInfo("stage2", siteInfo.SiteID);

if (server != null)
{
// Get tasks for the server
DataSet tasks = TaskInfoProvider.SelectTaskList(siteInfo.SiteID, server.ServerID, null, null);

if (!DataHelper.DataSourceIsEmpty(tasks))
{
foreach (DataRow taskDr in tasks.Tables[0].Rows)
{
// Create task info object from data row
TaskInfo task = new TaskInfo(taskDr);
Console.WriteLine(task.TaskID + "\t" + task.TaskTitle);

// Synchronize the task
if (!string.IsNullOrEmpty(StagingHelper.RunSynchronization(task.TaskID, server.ServerID)))
{
Console.WriteLine("GetAndSynchronizeTasks return false");
return false;
}
}

return true;
}
Console.WriteLine("GetAndSynchronizeTasks no tasks found");
}
return false;
}

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/20/2014 2:50:47 PM
   
RE:Create, Move, Stage ... not keeping parent
It looks like this line: newNode.Insert(parentNode); is inserting the node under the parentnode, ("test1"), if you don't want it under that node, try putting in the rootnode instead. This would insert the document under the ("/") root node.

User avatar
Member
Member
JAA - 1/20/2014 4:33:35 PM
   
RE:Create, Move, Stage ... not keeping parent
josha-bpstudios wrote: It looks like this line: newNode.Insert(parentNode); is inserting the node under the parentnode, ("test1"), if you don't want it under that node, try putting in the rootnode instead. This would insert the document under the ("/") root node.

Im demo'ing out the Move method and it looks like when a content stage happens the Move reverts on the target. Is this a bug?

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 2/3/2014 10:10:51 PM
   
RE:Create, Move, Stage ... not keeping parent
Hello,

I will try to reproduce this behaviour if it is a possible bug, so could you please provide me with the exact steps I should follow to be able to reproduce it? As from your previous posts I'm not sure what exactly is the issue in this scenario...

Best Regards,
Martin Danko

User avatar
Member
Member
JAA - 2/4/2014 8:16:05 AM
   
RE:Create, Move, Stage ... not keeping parent
Hi,

All of my code is above. Let me know if it doesnt work for you.

Thanks,
Jason