コード例 #1
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);
        }
コード例 #2
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);
        }