New page should be created first and not last in CMS tree page view

I know its possible to modify but I cant any information about it. When creating a new page in the CMS the page should be created first and not last in the list of pages.

Litium version: 6.3.7

I solved it myself.

  public EventHandlerStartup()
        ModuleCMS.Instance.EventManager.PageCreated += EventManagerOnPageEvent;

    private void EventManagerOnPageEvent(Guid webSiteId, Guid pageId, Guid parentPageId)
        var token = ModuleCMS.Instance.AdminToken;
        var currentPage = Page.GetFromID(pageId, token);
        var parentPage = currentPage.GetParentPage(token);

            currentPage.Move(parentPage, 0, token);
        catch(Exception e)
            Solution.Instance.Log.CreateLogEntry("PageCreated could not be added first", e, LogLevels.ERROR);
1 Like

To think on is that in a multiserver setup the PageCreated event will be fired in every node, this move-command without synchronization between node may fail in some nodes that will reflect in false-positive error-logs.

@patric.forsgard Do you have any recomendations? Or should I just nog log anything?

Some alternatives can be:

  • use a distributed lock that only allowing one node to do the operation at a time
  • fetch the page when exception is thrown and check if the index of the page is the expected and if not try again or write to log
  • ignore the logging or log with a smaller severity if you what to the log information there when you tryout on local computer

Can’t you just have a startuptask with the event handler that is set to only run on one machine?

1 Like

Yes, you can. But if that machine is down for maintenance or upgrade and not catching that event the page will still be in the bottom of the list.

Thanks! :grinning:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.