Пример #1
0
        /// <summary>
        /// Inserts the slug for Content Channel Items.
        /// </summary>
        public static void UpdateSlugForContentChannelItems()
        {
            int  recordsToProcess = 1000;
            bool isProcess        = true;

            do
            {
                using (var rockContext = new RockContext())
                {
                    var contentChannelItems = new ContentChannelItemService(rockContext)
                                              .Queryable()
                                              .AsNoTracking()
                                              .Where(a => !a.ContentChannelItemSlugs.Any())
                                              .Take(recordsToProcess)
                                              .Select(a => new
                    {
                        a.Id,
                        a.Title
                    }).ToList();

                    var slugService = new ContentChannelItemSlugService(rockContext);
                    if (contentChannelItems.Any())
                    {
                        foreach (var item in contentChannelItems)
                        {
                            slugService.SaveSlug(item.Id, item.Title, null);
                        }
                    }
                    else
                    {
                        isProcess = false;
                    }
                }
            }while (isProcess);
        }