Ejemplo n.º 1
0
        /// <summary>
        /// Organizes the item in the configurd year, [month], [day] structure.
        /// It will also remove any empty folders
        /// </summary>
        /// <param name="item">The item.</param>
        /// <param name="config">The config.</param>
        /// <param name="articleDate">The article date.</param>
        protected void OrganizeItem(Item item, TemplateConfiguration config, DateTime articleDate)
        {
            Item root = GetRoot(item, config);

            // get/create the year folder
            root = GetOrCreateChild(root, config.YearFolder.Template, config.YearFolder.GetName(articleDate), config.SortOrder);

            // get/create any month -> day structure we need
            if (config.MonthFolder != null)
            {
                root = GetOrCreateChild(root, config.MonthFolder.Template, config.MonthFolder.GetName(articleDate), config.SortOrder);

                if (config.DayFolder != null)
                {
                    root = GetOrCreateChild(root, config.DayFolder.Template, config.DayFolder.GetName(articleDate), config.SortOrder);
                }
            }

            // if the item is already where it should be, then bail out
            if (string.Equals(item.Parent.Paths.FullPath, root.Paths.FullPath, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            // save the original location so we can clean up
            Item originalParent = item.Parent;

            // move the item to the proper location
            item.MoveTo(root);

            // delete the original parent if there are no children.
            // keep walking up while we are a year/month/day
            while ((!originalParent.HasChildren) && IsItemYearMonthOrDay(originalParent, config))
            {
                Item parent = originalParent.Parent;
                originalParent.Delete();
                originalParent = parent;
            }

            if ((!Sitecore.Context.IsBackgroundThread) && Sitecore.Context.ClientPage.IsEvent)
            {
                var args = new MoveCompletedArgs() { Article = item, Root = item.Database.GetRootItem() };
                CorePipeline.Run("NewsMover.MoveCompleted", args);
            }
        }
 protected virtual void MoveItemToDisabledFolder(Item item, ref LevelLogger logger)
 {
     item.Editing.BeginEdit();
     item.MoveTo(DisableItemsFolderItem);
     logger.IncrementCounter(IncrementConstants.DisabledItems);
     item.Editing.EndEdit();
 }
    public virtual void FixPostLocation(Item bloggrPost)
    {
      Assert.ArgumentNotNull(bloggrPost, "bloggrPost");

      if (this.ValidatePostLocation(bloggrPost))
      {
        return;
      }

      var statistics = bloggrPost.Statistics;
      Assert.IsNotNull(statistics, "statistics");

      var created = statistics.Created;
      if (created == DateTime.MinValue)
      {
        // in Sitecore 8.0 is used UTC, in previous versions - local time.
        created = DateTime.UtcNow;
      }

      var createdYear = created.ToString("yyyy");
      var createdMonth = created.ToString("MM");
      var createdDay = created.ToString("dd");

      var home = BloggrContext.GetHomeSure(bloggrPost);
      var year = home.GetChild(createdYear) ?? this.CreateDateFolder(home, home, createdYear);
      var month = year.GetChild(createdMonth) ?? this.CreateDateFolder(year, home, createdMonth);
      var day = month.GetChild(createdDay) ?? this.CreateDateFolder(month, home, createdDay);
      bloggrPost.MoveTo(day);
    }
 protected virtual void MoveItem(Item item, Item targetParentItem, ref LevelLogger logger)
 {
     using (new SecurityDisabler())
     {
         item.Editing.BeginEdit();
         logger.AddInfo("Moved Item", String.Format("Moved item from '{0}' to '{1}'.", GetItemDebugInfo(item), GetItemDebugInfo(targetParentItem)));
         item.MoveTo(targetParentItem);
         item.Editing.EndEdit();
         //Logger.MovedItems += 1;
         logger.IncrementCounter(IncrementConstants.MovedItems);
     }
 }