Copied to clipboard

Flag this post as spam?

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


  • Yves Kircher 21 posts 69 karma points
    Feb 10, 2016 @ 13:45
    Yves Kircher
    0

    Moving a node after Publishing -> doesn't redirect

    Hey i need some Help. I just wrote an ApplicationEventHandler in c# with a CustomPublishedEventHandler.

    If a node is being published, this node will be moved under another node.

    Document doc = new Document( nodeId ); doc.Move( otherNode.Id );

    This works fine, but when i click "save and publish" in the umbraco backend, the node is being moved, but i need to refresh the backend and redirect to the moved node again.

    umbraco.library.RefreshContent(); doesnt work.

    Is there any way to redirect over api to the id of the moved node ?

    Hope anyone can help me :)

  • Yves Kircher 21 posts 69 karma points
    Feb 19, 2016 @ 13:58
    Yves Kircher
    0

    push

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 19, 2016 @ 15:54
    Jan Skovgaard
    0

    Hi Yves

    Do you mind sharing the whole code snippet? It might make it easer for people to give you some suggestions about what could be wrong. I can't remember how to do the refresh but I think that umbraco.library.RefreshContent() is obsolete by now since you're using Umbraco 7.

    Have you checked the API documentation? https://our.umbraco.org/documentation/Reference/Management/Services/

    /Jan

  • Yves Kircher 21 posts 69 karma points
    Feb 22, 2016 @ 10:19
    Yves Kircher
    0

    public class GuestbookEntryPublishHandler : ApplicationEventHandler {

    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        ContentService.Published += CustomPublishedEventHandler;
    }
    
    private void CustomPublishedEventHandler(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<Umbraco.Core.Models.IContent> e)
    {
        IContentService contentService = ApplicationContext.Current.Services.ContentService;
        foreach (var n in e.PublishedEntities)
        {
            if (n.ContentType.Alias == "GaestebuchEintrag")
            {
                Document doc = new Document(n.Id);
                int gbVerwaltungId = new Node(n.ParentId).Parent.Id;
                foreach (Node childNode in new Node(gbVerwaltungId).Children)
                {
                    if (childNode.NodeTypeAlias == "GaestebuchAktiveEintraege")
                    {
                        doc.Move(childNode.Id);
                        umbraco.library.RefreshContent();
                        // redirect ?
                    } 
                }
            }
        }
    
    
    }
    

    }

  • Yves Kircher 21 posts 69 karma points
    Feb 22, 2016 @ 10:21
    Yves Kircher
    0

    Yes i checked the API documentation, but didn't find anything helpfully.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 10x admin c-trib
    Feb 22, 2016 @ 18:16
    Jan Skovgaard
    0

    Hi Yves

    Yeah, I was not able to find it either but if I remember correctly you should be able to use doc.SaveAndPublish(childeNode) instead of umbraco.library.RefreshContent() - But not at dev machine currently so don't have any examples I can test. But found this old blogpost about how to use the content service API - The information is still valid. https://umbraco.com/follow-us/blog-archive/2013/1/22/introducing-contentservice-aka-the-v6-api/

    Hope this helps!

    /Jan

  • Yves Kircher 21 posts 69 karma points
    Feb 23, 2016 @ 13:18
    Yves Kircher
    0

    Hey, i changed to using content service api, but this didnt fix the problem.

    Actually i try to modify the umbraco.ressource.js file.

            publishById: function(id){
    
            if (!id) {
                throw "id cannot be null";
            }
    
            return umbRequestHelper.resourcePromise(
                           $http.post(
                               umbRequestHelper.getApiUrl(
                                   "contentApiBaseUrl",
                                   "PostPublishById",
                                   [{ id: id }]))
                                .success(function () {
                                    console.log(id);
                                    location.reload();
                                }),
                           'Failed to publish content with id ' + id);
    
        }
    

    but i dont know how the get the doc-type-alias by the id.

    i want to do something like:

    if ( getNodeById(id).DocTypeAlias === "Example") location.reload()

Please Sign in or register to post replies

Write your reply to:

Draft