Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Tom 713 posts 954 karma points
    Jul 22, 2010 @ 09:08
    Tom
    1

    Move all children to another parent

    Hi All,

    just wondering I have a bunch of products that are children of a product category.. I now want to move all those child products into a subcategory is there a way to bulk move all the children into the subcategory..

    I can't right click on the parent and move it as the parent is the category!

  • Folkert 82 posts 212 karma points
    Jul 22, 2010 @ 09:21
    Folkert
    1

    You can use a sql script(useable if nodes are on the same level, otherwise you have to replace double values because this script only replaces parentID's):

    drop table #temp
    set nocount on

    declare @OldParentId int
    declare @ParentId int
    declare @Id int
    declare @Path nvarchar(150)

    select @OldParentId = 1360 -- Set to the existing parent node
    select @ParentId = 1412 -- Set to the new parent node

    -- First update the parentid column
    update umbracoNode set parentid=@ParentId where parentId=@OldParentId

    -- Next update all the path columns for the children.
    SELECT id,[path] into #temp FROM [umbracoNode] where parentid=@ParentId

    while exists(select Id from #temp)
    begin
        select @Id=Id,@Path=[Path] from #temp

        select @Path = REPLACE(@Path,@OldParentId,@ParentId)
        update umbracoNode set path=@Path where id=@Id

        print cast(@Id as varchar)+': ' +@Path

        delete from #temp where Id=@Id
    end

    Otherwise, you can use the umbracoAPI to replace nodes:

    Document doc = new Document(docID);
    doc.Move(newParentID);

    doc.Save();

    // only publish document if document has been published allready
    if (doc.Published)
    {
        doc.Publish(new User(0));               
        umbraco.cms.businesslogic.cache.Cache.ClearCacheItem("ApplicationTreeCache");
        umbraco.library.UpdateDocumentCache(doc.Id);
    }
Please Sign in or register to post replies

Write your reply to:

Draft