Esempio n. 1
0
        public void UpdateSortOrder(int ParentId, string SortOrder)
        {

            try
            {
                if (BasePage.ValidateUserContextID(BasePage.umbracoUserContextID))
                {

                    if (SortOrder.Trim().Length > 0)
                    {
                        string[] tmp = SortOrder.Split(',');

                        bool isContent = false;
                        if (helper.Request("app") == "content" | helper.Request("app") == "")
                            isContent = true;

                        //CHANGE:Allan Stegelmann Laustsen, we need to know if the node is in media.
                        bool isMedia = false;
                        if (helper.Request("app") == "media")
                        {
                            isMedia = true;
                        }
                        //CHANGE:End

                        for (int i = 0; i < tmp.Length; i++)
                        {
                            if (tmp[i] != "" && tmp[i].Trim() != "")
                            {
                                new cms.businesslogic.CMSNode(int.Parse(tmp[i])).sortOrder = i;

                                if (isContent)
                                {
                                    Document d = new Document(int.Parse(tmp[i]));
                                    // refresh the xml for the sorting to work
                                    if (d.Published)
                                    {
                                        d.refreshXmlSortOrder();
                                        library.UpdateDocumentCache(int.Parse(tmp[i]));
                                    }
                                }
                                //CHANGE:Allan Laustsen, to update the sortorder of the media node in the XML, re-save the node....
                                else if (isMedia)
                                {
                                    new cms.businesslogic.media.Media(int.Parse(tmp[i])).Save();
                                }
                                //CHANGE:End
                            }
                        }

                        // Refresh sort order on cached xml
                        if (isContent)
                        {
                            System.Xml.XmlNode parentNode;

                            if (ParentId == -1)
                                parentNode = content.Instance.XmlContent.DocumentElement;
                            else
                                parentNode = content.Instance.XmlContent.GetElementById(ParentId.ToString());

                            //only try to do the content sort if the the parent node is available... 
                            if (parentNode != null)
                                content.SortNodes(ref parentNode);


                            // Load balancing - then refresh entire cache
                            if (UmbracoSettings.UseDistributedCalls)
                                library.RefreshContent();
                        }
                       

                        // fire actionhandler, check for content
                        if ((helper.Request("app") == "content" | helper.Request("app") == "") && ParentId > 0)
                            global::umbraco.BusinessLogic.Actions.Action.RunActionHandlers(new Document(ParentId), ActionSort.Instance);                        
                    }
                }

            }
            catch (Exception ex)
            {
                BusinessLogic.Log.Add(global::umbraco.BusinessLogic.LogTypes.Debug, ParentId, ex.ToString());
            }

        }