示例#1
0
        private void MoveUpContentVersion(int siteId, int contentId, int userId, AbstractItemData item, string siteName)
        {
            _logger.LogDebug($"moveUpContentVersion. siteId: {siteId}, contentId: {contentId}, userId: {userId}, siteName: {siteName}, item: {SerializeData(new { item.Id, item.Alias, item.ParentId })}");

            var columnNames = GetColumnNamesByNetNames(siteId, new List <string> {
                "Name", "Parent", "VersionOf", "IsPage"
            });

            if (!columnNames.ContainsKey("Name"))
            {
                throw new Exception("NetName for field Name not found");
            }
            if (!columnNames.ContainsKey("Parent"))
            {
                throw new Exception("NetName for field Parent not found");
            }
            if (!columnNames.ContainsKey("VersionOf"))
            {
                throw new Exception("NetName for field VersionOf not found");
            }
            if (!columnNames.ContainsKey("IsPage"))
            {
                throw new Exception("NetName for field IsPage not found");
            }

            _logger.LogDebug($"moveUpContentVersion. column names: {string.Join(";", columnNames.Select(x => $"key: {x.Key}, value: ${x.Value}"))}");

            var value = new Dictionary <string, string> {
                { ContentItemIdFieldName, item.Id.ToString(CultureInfo.InvariantCulture) }
            };

            foreach (var x in columnNames)
            {
                switch (x.Key)
                {
                case "Name":
                    value.Add(x.Value, item.Alias);
                    break;

                case "Parent":
                    value.Add(x.Value, item.ParentId.ToString());
                    break;

                case "VersionOf":
                    value.Add(x.Value, null);
                    break;

                case "IsPage":
                    value.Add(x.Value, "1");
                    break;

                default:
                    break;
                }
            }

            _logger.LogDebug($"restore. mass update. contentId: {contentId}, values: {SerializeData(value)}");

            _qpDbConnector.DbConnector.MassUpdate(contentId, new[] { value }, userId);
        }
示例#2
0
        public void Remove(int siteId, int contentId, int userId, IEnumerable <AbstractItemData> items, AbstractItemData moveContentVersion)
        {
            _logger.LogDebug($"remove. siteId: {siteId}, contentId: {contentId}, userId: {userId}, items: {SerializeData(items.Select(x => new { x.Id, x.ExtensionId }))}, moveContentVersion: {SerializeData(moveContentVersion == null ? null : new { moveContentVersion.Id, moveContentVersion.Alias, moveContentVersion.ParentId })}");

            _qpDbConnector.BeginTransaction(IsolationLevel.Serializable);

            try
            {
                var siteName = _qpMetadataManager.GetSiteName(siteId);

                if (items.Any())
                {
                    // update content
                    var values = items.Select(x => new Dictionary <string, string>
                    {
                        { ContentItemIdFieldName, x.Id.ToString(CultureInfo.InvariantCulture) },
                        { ArchiveFieldName, "1" }
                    });

                    _logger.LogDebug($"remove. mass update. contentId: {contentId}, values: {SerializeData(values)}");

                    _qpDbConnector.DbConnector.MassUpdate(contentId, values, userId);

                    //update extantion
                    var extantionValues = items
                                          .Where(x => x.ExtensionId.HasValue)
                                          .GroupBy(x => x.ExtensionId.Value, x => x.Id);
                    foreach (var item in extantionValues)
                    {
                        var contentName = _qpMetadataManager.GetContentName(item.Key);
                        _qpContentManager
                        .Connect()
                        .SiteName(siteName)
                        .IsIncludeArchive(true)
                        .IsShowSplittedArticle(true)
                        .StatusName(_statusNames)
                        .ContentId(item.Key)
                        .ContentName(contentName)
                        .Where($"ItemId in ({string.Join(",", item.Select(x => x))})")
                        .Archive(userId);
                    }
                }

                if (moveContentVersion != null)
                {
                    MoveUpContentVersion(siteId, contentId, userId, moveContentVersion, siteName);
                }

                _qpDbConnector.CommitTransaction();
            }
            catch
            {
                _qpDbConnector.RollbackTransaction();
                throw;
            }
        }
示例#3
0
 public FlatRegionFilter(AbstractItemData rootPage, List <RegionData> regions)
     : base(rootPage, regions)
 {
 }
 internal static RegionFilter Create(AbstractItemData rootPage, List <RegionData> regions, bool useHierarchyRegionsFilter)
 {
     return(useHierarchyRegionsFilter ? new HierarchyRegionFilter(rootPage, regions) : new FlatRegionFilter(rootPage, regions) as RegionFilter);
 }
        public void RemoveSiteMapItems(
            int siteId, int userId, int itemId,
            bool isDeleteAllVersions, bool isDeleteContentVersion, int?contentVersionId)
        {
            if (itemId <= 0)
            {
                throw new ArgumentException("itemId <= 0");
            }
            if (!isDeleteContentVersion && contentVersionId == null)
            {
                throw new InvalidOperationException("Field contentVersionId is required if isDeleteContentVersion is false");
            }

            var item = _siteMapProvider.GetByIds(siteId, false, new[] { itemId })?.FirstOrDefault();

            if (item == null || item.Id == 0)
            {
                throw new InvalidOperationException($"Element {itemId} not found");
            }

            if (contentVersionId.HasValue)
            {
                var contentVersion = _siteMapProvider.GetByIds(siteId, false, new[] { contentVersionId.Value })?.FirstOrDefault();
                if (contentVersion == null || contentVersion.Id == 0)
                {
                    throw new InvalidOperationException($"Element {contentVersionId} not found");
                }
            }

            var rootPageId = _siteMapProvider.GetRootPage(siteId)?.Id;

            if (itemId == rootPageId)
            {
                throw new InvalidOperationException("Cannot delete the root page");
            }

            var itemsToArchive = new List <AbstractItemData>();
            AbstractItemData moveContentVersion = null;

            var allItems        = _siteMapProvider.GetAllItems(siteId, false, false);
            var pages           = allItems.Where(x => x.IsPage).Select(x => _mapper.Map <PageModel>(x)).OrderBy(x => x.IndexOrder).ToList();
            var widgets         = allItems.Where(x => !x.IsPage).Select(x => _mapper.Map <WidgetModel>(x)).OrderBy(x => x.IndexOrder).ToList();
            var pageStructure   = item.IsPage ? SiteMapStructureBuilder.GetPageSubTree(itemId, pages, widgets) : new List <PageModel>();
            var widgetStructure = !item.IsPage ? SiteMapStructureBuilder.GetWidgetSubTree(itemId, widgets) : new List <WidgetModel>();

            void funcWidgets(List <WidgetModel> items)
            {
                foreach (var i in items)
                {
                    itemsToArchive.AddRange(allItems.Where(x => x.Id == i.Id));

                    if (i.HasChildren)
                    {
                        funcWidgets(i.Children);
                    }
                }
            }

            void func(List <PageModel> items)
            {
                foreach (var i in items)
                {
                    itemsToArchive.AddRange(allItems.Where(x => x.Id == i.Id));

                    if (!isDeleteAllVersions & !isDeleteContentVersion)
                    {
                        moveContentVersion = allItems.FirstOrDefault(x => x.Id == contentVersionId);
                        if (moveContentVersion != null && moveContentVersion.VersionOfId != null)
                        {
                            moveContentVersion.Alias       = item.Alias;
                            moveContentVersion.ParentId    = item.ParentId;
                            moveContentVersion.VersionOfId = null;
                        }
                    }
                    else
                    {
                        if (i.HasContentVersion)
                        {
                            itemsToArchive.AddRange(allItems.Where(x => i.ContentVersions.Any(y => x.Id == y.Id)));
                        }
                    }

                    if (i.HasWidgets)
                    {
                        funcWidgets(i.Widgets);
                    }

                    if (i.HasChildren)
                    {
                        func(i.Children);
                    }
                }
            }

            if (isDeleteAllVersions)
            {
                var structuralVersions = allItems.Where(x => x.ParentId == item.ParentId && x.Alias == item.Alias && x.Id != item.Id).ToList();
                foreach (var structuralVersion in structuralVersions)
                {
                    if (!structuralVersion.IsPage)
                    {
                        continue;
                    }
                    var structuralVersionPageStructure = SiteMapStructureBuilder.GetPageSubTree(structuralVersion.Id, pages, widgets);
                    func(structuralVersionPageStructure);
                }
            }

            func(pageStructure);
            funcWidgets(widgetStructure);

            var contentId = _settingsProvider.GetContentId(siteId);

            _qpDataProvider.Remove(siteId, contentId, userId, itemsToArchive, moveContentVersion);
        }
示例#6
0
 public HierarchyRegionFilter(AbstractItemData rootPage, List <RegionData> regions)
     : base(rootPage, regions)
 {
 }
示例#7
0
 public RegionFilter(AbstractItemData rootPage, List <RegionData> regions)
 {
     RootPage = rootPage;
     Regions  = regions;
 }