Copied to clipboard

Flag this post as spam?

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


  • NightWolf 41 posts 44 karma points
    Dec 24, 2009 @ 05:08
    NightWolf
    0

    Synchronize nodes

    I have a structure as outlined below:

    • Parent 1
    • Parent 2
    • Parent 3
    • Parent 4
    • Parent 5
      • Child 1
      • Child 2
    • Parent 6

    This structure is used because of the menu system used on our site. When I publish a node in Parent 1 I have some code which check to make sure it's the correct document type and then copies it to other nodes in the structure based on values set.

    static void Document_AfterPublish(Document sender, umbraco.cms.businesslogic.PublishEventArgs e) {
    if(sender.ContentType.Alias == "AliasName") {
    if(sender.getProperty("property").Value.ToString() == "1") {
    sender.Copy(nodeID, new User(0), true);
    }
    }
    }

    My questions are below:

    1. How do I automatically publish this new 'copied' node?
    2. How do I automatically synchronize the content between all instances of this node?
    3. How can I delete all instances of this node should it be deleted?

    This is required for two reasons, the menu structure and to keep the process uniform as the content editor is not tech savvy at all. I could create a new template to make it easier for myself but this would mean the client has limited ability to change the menu structure as it would be hard coded and they can't edit the templates.

    Any help, idea, sugguestions would be much appreciated.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 24, 2009 @ 10:00
    Dirk De Grave
    0

    Hi NightWolf,

    1/ You publish the node as you'd normally would, but think you have issues getting the node that's being created in the copy process, right? It would be nice if the Copy method would return the just created node, wouldn't it? It doesn't, so you'll have to use other techniques. You could subscribe to the AfterCopy event on documents to find out what node has been copied and act upon (eg. publish the node). I agree it's not the most elegant solution, but it will work. Publishing a node is as simple as

    node.Publish();
    umbraco.library.UpdateDocumentCache(node);

    2/ Subscribe to save/publish events for documents, check whether saved/published documents has related nodes (you've set 3rd parameter of Copy method to true, so each copied node is related to its 'parent' node) and update those nodes.

    3/ Again, subscribe to delete events on documents, and find all related nodes and delete those as well.

     

    Hope this helps.

    Regards,

    /Dirk

     

     

  • NightWolf 41 posts 44 karma points
    Dec 27, 2009 @ 10:03
    NightWolf
    0

    Cheer, this was a good help all though not an elegant solution.

Please Sign in or register to post replies

Write your reply to:

Draft