public override void Execute([NotNull] CommandContext context)
        {
            Assert.ArgumentNotNull(context, "context");

            var items = context.Items;

            Assert.IsNotNull(items, "items");

            var item = items.SingleOrDefault();

            Assert.IsNotNull(item, "item");

            var home      = BloggrContext.GetHome(item);
            var structure = home != null?BloggrContext.GetPostsStructureItem(home) : null;

            var bloggrPostTemplate = item.GetItem("{2BDE036E-3503-4BF0-B978-213F46541B21}");

            if (structure == null || structure.Get("Bloggr Post AutoName") != "1")
            {
                context.Parameters.Add("master", bloggrPostTemplate.ID.ToString());

                base.Execute(context);
                return;
            }

            var template = (TemplateItem)bloggrPostTemplate;

            Context.Workflow.AddItem("Bloggr Post", template, item);
        }
Ejemplo n.º 2
0
        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 void OnItemRenamed([NotNull] object sender, [NotNull] EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            var item = Event.ExtractParameter(args, 0) as Item;

            Assert.IsNotNull(item, "item");

            if (item.TemplateName != "Bloggr Post")
            {
                return;
            }

            try
            {
                using (new SecurityDisabler())
                {
                    var structure = BloggrContext.GetPostsStructureSure(item);

                    // fix post name because item was renamed and new name may be invalid according to current site IBloggrStructure rules
                    structure.FixPostName(item);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unhandled exception occurred in Alienlab.Bloggr.EventHandler.OnItemRenamed(sender, args)", ex, this);
            }
        }
        protected void OnItemMoved([NotNull] object sender, [NotNull] EventArgs args)
        {
            Assert.ArgumentNotNull(sender, "sender");
            Assert.ArgumentNotNull(args, "args");

            var item = Event.ExtractParameter(args, 0) as Item;

            Assert.IsNotNull(item, "item");

            if (item.TemplateName != "Bloggr Post")
            {
                return;
            }

            try
            {
                using (new SecurityDisabler())
                {
                    var structure = BloggrContext.GetPostsStructureSure(item);

                    structure.FixPostLocation(item);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Unhandled exception occurred in Alienlab.Bloggr.EventHandler.OnItemMoved(sender, args)", ex, this);
            }
        }
Ejemplo n.º 5
0
        public void FixPostLocation(Item bloggrPost)
        {
            Assert.ArgumentNotNull(bloggrPost, "bloggrPost");

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

            var home             = BloggrContext.GetHomeSure(bloggrPost);
            var itemPathOriginal = bloggrPost.Paths.FullPath;

            using (new SecurityDisabler())
            {
                bloggrPost.MoveTo(home);
            }

            var validLocation = this.ValidatePostLocation(bloggrPost);

            Assert.IsTrue(validLocation, "After an attempt of fixing location of the blog post ({0}) it still remains invalid ({1})", itemPathOriginal, bloggrPost.Paths.FullPath);
        }
Ejemplo n.º 6
0
        public virtual bool ValidatePostLocation([NotNull] Item bloggrPost)
        {
            Assert.ArgumentNotNull(bloggrPost, "bloggrPost");

            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 day = bloggrPost.Parent;

            if (day == null || day.Name != created.ToString("dd"))
            {
                return(false);
            }

            var month = day.Parent;

            if (month == null || month.Name != created.ToString("MM"))
            {
                return(false);
            }

            var year = month.Parent;

            if (year == null || year.Name != created.ToString("yyyy"))
            {
                return(false);
            }

            return(BloggrContext.GetHome(year) != null);
        }