Esempio n. 1
0
        internal void MovePage(Guid pageId, Guid targetId, int position)
        {
            var changedItems = new List <PageIndexItem>();

            for (var i = 0; i < _pageIndex.Count; i++)
            {
                var pageIndexItem = _pageIndex[i];

                if (pageIndexItem.PageId != pageId)
                {
                    continue;
                }

                if (pageIndexItem.ParentId == targetId)
                {
                    return;
                }

                RedirectManager.StorePageLinks(new CmsPage(pageIndexItem, LanguageId));

                if (pageIndexItem.ParentId == Guid.Empty)
                {
                    i = DetachPageFromRoot(i, pageIndexItem);
                }
                else
                {
                    DetachPage(pageIndexItem, i);
                }

                if (targetId == Guid.Empty)
                {
                    pageIndexItem.UrlSegment     = PageNameBuilder.GetUniqueUrl(targetId, pageIndexItem.UrlSegment);
                    pageIndexItem.UrlSegmentHash = pageIndexItem.UrlSegment.GetHashCode();
                    pageIndexItem.ParentId       = targetId;
                    var firstSibling = _pageIndex[0];
                    pageIndexItem.NextPage = firstSibling.NextPage;
                    firstSibling.NextPage  = i;

                    UpdateNodeAfterMove(changedItems, "", pageId, 0, pageIndexItem);
                }
                else
                {
                    var targetPage = GetPageIndexItem(targetId);
                    pageIndexItem.UrlSegment     = PageNameBuilder.GetUniqueUrl(targetPage.PageId, pageIndexItem.UrlSegment);
                    pageIndexItem.UrlSegmentHash = pageIndexItem.UrlSegment.GetHashCode();
                    pageIndexItem.ParentId       = targetId;
                    pageIndexItem.NextPage       = targetPage.FirstChild;
                    targetPage.FirstChild        = i;

                    UpdateNodeAfterMove(changedItems, targetPage.PageUrl, targetPage.RootId, targetPage.TreeLevel, pageIndexItem);
                }

                break;
            }

            PageData.UpdateStructure(changedItems);
        }
        private void UnpublishCurrentVersion(DataContext context)
        {
            var pageInstance = context.PageInstances.SingleOrDefault(x => x.PageId == PageId && x.LanguageId == LanguageId && x.Status == PageInstanceStatus.Published);

            if (pageInstance == null)
            {
                return;
            }

            pageInstance.Status = PageInstanceStatus.Archived;
            context.SaveChanges();

            Data.PropertyData.RemovePropertiesFromCache(PageId, LanguageId, pageInstance.CurrentVersion);

            if (pageInstance.PageUrl != UrlSegment)
            {
                var currentPage = PageFactory.GetPage(PageId, LanguageId);
                RedirectManager.StorePageLinks(currentPage);
            }
        }