Exemple #1
0
        public void PublishItem(int changeId, string approvalStatus)
        {
            List <ItemChangeHistory> changeList = GetItemChangeHistory(changeId, approvalStatus);

            if (changeList.Count > 0)
            {
                ItemChangeHistory change = GetItemChangeHistory(changeId, approvalStatus)[0];

                string itemId     = change.ItemId;
                string changeType = change.ChangeType;


                ETDataExtension etd = new ETDataExtension();

                etd.InsertIntoDataExtension(change.ItemHtml, change.ChangeType, change.ProductCategory);

                Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
                Sitecore.Data.Database web    = Sitecore.Configuration.Factory.GetDatabase("web");

                Sitecore.Data.Items.Item           item           = master.Items.GetItem(itemId);
                Sitecore.Publishing.PublishOptions publishOptions =
                    new Sitecore.Publishing.PublishOptions(item.Database,
                                                           web,
                                                           Sitecore.Publishing.PublishMode.SingleItem,
                                                           item.Language,
                                                           System.DateTime.Now);
                Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                publisher.Options.RootItem = item;
                publisher.Options.Deep     = true;

                publisher.Publish();
            }
        }
        public void removeProgramsWhite(object sender, EventArgs e)
        {
            ProgramsWhite(sender, e);
            foreach (Sitecore.Data.Items.Item result in ProgramList)
            {
                using (new Sitecore.SecurityModel.SecurityDisabler())
                {
                    Domain.Pages.Program program = Domain.Context.Get <Domain.Pages.Program>(result.ID);
                    result.Editing.BeginEdit();
                    try
                    {
                        result.Fields["Title"].Value = program.Title.Trim();
                        result.Editing.EndEdit();
                    }
                    catch (System.Exception ex)
                    {
                        Sitecore.Diagnostics.Log.Error("Could not update item " + result.Paths.FullPath + ": " + ex.Message, this);
                        result.Editing.CancelEdit();
                    }

                    Sitecore.Publishing.PublishOptions publishOptions =
                        new Sitecore.Publishing.PublishOptions(result.Database, Sitecore.Data.Database.GetDatabase("web"), Sitecore.Publishing.PublishMode.SingleItem,
                                                               result.Language, System.DateTime.Now); // Create a publisher with the publishoptions
                    Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                    // Choose where to publish from
                    publisher.Options.RootItem = result;

                    // Do the publish!
                    publisher.Publish();
                }
            }
            Programs.Text += ProgramList.Count.ToString() + " Program Titles Trimed";
        }
        /// <summary>
        /// Publishes a Sitecore <see cref="Item"/>.
        /// </summary>
        private static void PublishItem(Item item)
        {
            if (item == null)
            {
                throw new ArgumentNullException(nameof(item));
            }

            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Database master = Sitecore.Configuration.Factory.GetDatabase("master");
                Database web    = Sitecore.Configuration.Factory.GetDatabase("web");

                var publishOptions = new Sitecore.Publishing.PublishOptions(
                    master,
                    web,
                    Sitecore.Publishing.PublishMode.SingleItem,
                    item.Language,
                    DateTime.Now);

                Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                publisher.Options.RootItem = item;

                publisher.Options.Deep = true;

                publisher.Publish();
            }
        }
        public static void Publish(Item itemToPublish, Sitecore.Data.Database publishDatabase)
        {
            var publishOptions =
                new Sitecore.Publishing.PublishOptions(itemToPublish.Database,
                                                       publishDatabase,
                                                       Sitecore.Publishing.PublishMode.SingleItem,
                                                       itemToPublish.Language,
                                                       DateTime.Now);
            var publisher = new Sitecore.Publishing.Publisher(publishOptions);

            publisher.Options.RootItem = itemToPublish;
            publisher.Options.Deep     = true;
            publisher.Publish();
        }
    /// <summary>
    /// Publish an item to all publishing targets
    /// </summary>
    /// <param name="item"></param>
    /// <param name="mode">The publishing mode</param>
    /// <param name="publishSubItems">Specify whether to publish sub items</param>
    public static void Publish(this Item item, Sitecore.Publishing.PublishMode mode, bool publishSubItems)
    {
        Assert.ArgumentNotNull(item, "item");

        try
        {
            //get all publishing targets
            var publishingTargetsFolder = item.Database.GetItem("/sitecore/system/Publishing targets");

            if (publishingTargetsFolder != null)
            {
                var targetDBs = new List <Database>();
                var languages = item.Languages;
                var targets   = publishingTargetsFolder.Children.Where(o => string.Compare(o.TemplateName, "Publishing target", true) == 0);

                //get all defined databases
                foreach (var t in targets)
                {
                    var db = Sitecore.Data.Database.GetDatabase(t["Target database"]);
                    if (db != null)
                    {
                        targetDBs.Add(db);
                    }
                }

                if (targetDBs.Any())
                {
                    foreach (var targetDB in targetDBs)
                    {
                        var publishOptions = new Sitecore.Publishing.PublishOptions(
                            item.Database,
                            targetDB,
                            mode,
                            item.Language,
                            DateTime.Now);
                        var publisher = new Sitecore.Publishing.Publisher(publishOptions);


                        publisher.Options.RootItem = item;
                        publisher.Options.Deep     = publishSubItems;
                        publisher.Publish();
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Sitecore.Diagnostics.Log.Error("Sitecore - unable to auto-publish item", ex, typeof(ItemExtensions));
        }
    }
        //public string SaveNewEvent(string parentId, EventViewModel eventToSave)
        //{
        //    using (new Sitecore.SecurityModel.SecurityDisabler())
        //    {
        //        try
        //        {
        //            var masterDB = Database.GetDatabase("master");
        //            TemplateItem templateItem = masterDB.GetItem(Templates.Event.Id);
        //            var parentItem = masterDB.GetItem(new ID(parentId));
        //            if (parentItem != null)
        //            {
        //                var eventName =
        //                    $"{eventToSave.Name.Replace(@"\", "").Replace(@"/", "").Replace(@":", "").Replace(@"?", "").Replace(@"<", "").Replace(@">", "").Replace(@"|", "").Replace(@"[", "").Replace(@"]", "").Replace(@"-", "").Replace("\"", "").Replace(@"(", "").Replace(@")", "")}";

        //                var newEvent = parentItem.Add(eventName, templateItem);
        //                newEvent.Editing.BeginEdit();
        //                newEvent.Fields["ModuleTitle"].Value = projectModel.ModuleTitle;
        //                newEvent.Editing.EndEdit();
        //                PublishItem(newEvent);
        //                return LinkManager.GetItemUrl(newEvent, new ItemUrlBuilderOptions());
        //            }
        //        }
        //        catch (Exception e)
        //        {
        //            Console.WriteLine(e);
        //            throw;
        //        }

        //    }
        //}


        private static void PublishItem(Item item)
        {
            var publishOptions =
                new Sitecore.Publishing.PublishOptions(item.Database,
                                                       Database.GetDatabase("web"),
                                                       Sitecore.Publishing.PublishMode.SingleItem,
                                                       item.Language,
                                                       DateTime.Now);
            var publisher = new Sitecore.Publishing.Publisher(publishOptions);

            publisher.Options.RootItem = item;
            publisher.Options.Deep     = true;
            publisher.Publish();
        }
Exemple #7
0
        /// <summary>
        /// Publishes the item.
        /// </summary>
        /// <param name="targetItem">The target item.</param>
        public static void PublishItem(Item targetItem, bool childs = false)
        {
            DateTime publishDate = DateTime.Now;
            Sitecore.Data.Database master = GetContentDatabase();
            var targetDBs = GetPublishingTargets(master);

            foreach (var db in targetDBs)
            {
                foreach (Sitecore.Globalization.Language language in master.Languages)
                {
                    Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(master, db, Sitecore.Publishing.PublishMode.SingleItem, language, publishDate);
                    publishOptions.RootItem = targetItem;
                    publishOptions.Deep = childs;
                    Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions); publisher.Publish();
                }
            }
        }
Exemple #8
0
        private void PublishItem(Item item)
        {
            try
            {
                Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(item.Database, Database.GetDatabase(ModuleUtilsConstant.WebDatabase),
                                                                                                           Sitecore.Publishing.PublishMode.SingleItem, item.Language,
                                                                                                           System.DateTime.Now);

                Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                publisher.Options.RootItem = item;
                publisher.Options.Mode     = Sitecore.Publishing.PublishMode.Full;

                publisher.Publish();
            }
            catch (System.Exception ex)
            {
                Sitecore.Diagnostics.Log.Error($"Failed to publish item {item.ID}", ex, this);
            }
        }
        private void PublishItem(Item item)
        {
            Sitecore.Publishing.PublishOptions publishOptions =
                new Sitecore.Publishing.PublishOptions(item.Database,
                                                       Database.GetDatabase(publishDB),
                                                       Sitecore.Publishing.PublishMode.SingleItem,
                                                       item.Language,
                                                       System.DateTime.Now);  // Create a publisher with the publishoptions

            Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

            // Choose where to publish from
            publisher.Options.RootItem = item;

            // Publish children as well?
            publisher.Options.Deep = true;

            // Do the publish!
            publisher.Publish();
        }
Exemple #10
0
        public void CreateComment(CivilCommentsSectionViewModel model)
        {
            using (new Sitecore.SecurityModel.SecurityDisabler())
            {
                Database masterDb   = Sitecore.Configuration.Factory.GetDatabase("master");
                var      dataSource = model.DatasourceItem;
                dataSource = masterDb.GetItem(dataSource.ID);
                var commentsFolder = masterDb.GetItem("{A0660FA6-D500-453A-A807-4FFE7997F83C}");
                if (commentsFolder == null)
                {
                    return;
                }
                TemplateItem template   = masterDb.GetTemplate("{F0A8C4E9-FEE1-407E-99DB-A7F2D16024D1}");
                var          newComment =
                    commentsFolder.Add(String.Format("Comment {0}", DateTime.Now.ToString("g")).SanitizeToItemName(),
                                       template);

                var user     = Sitecore.Context.User;
                var username = user == null ? "anon" : user.Name;

                if (newComment == null)
                {
                    return;
                }
                newComment.Editing.BeginEdit();
                newComment.Fields["Comment"].Value  = model.Comment;
                newComment.Fields["Username"].Value = username;
                newComment.Editing.EndEdit();

                Sitecore.Publishing.PublishOptions publishOptions =
                    new Sitecore.Publishing.PublishOptions(newComment.Database,
                                                           Database.GetDatabase("web"),
                                                           Sitecore.Publishing.PublishMode.SingleItem,
                                                           newComment.Language,
                                                           System.DateTime.Now); // Create a publisher with the publishoptions
                Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                publisher.Options.RootItem = newComment;
                publisher.Publish();
            }
        }
Exemple #11
0
        /// <summary>
        /// Publishing this item to 'web' database
        /// </summary>
        /// <param name="item">item to be published</param>
        private void PublishItem(Sitecore.Data.Items.Item item)
        {
            // The publishOptions determine the source and target database,
            // the publish mode and language, and the publish date
            Sitecore.Publishing.PublishOptions publishOptions =
                new Sitecore.Publishing.PublishOptions(item.Database,
                                                       Database.GetDatabase("web"),
                                                       Sitecore.Publishing.PublishMode.SingleItem,
                                                       item.Language,
                                                       System.DateTime.Now); // Create a publisher with the publishoptions
            Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

            // Choose where to publish from
            publisher.Options.RootItem = item;

            // Publish children as well?
            publisher.Options.Deep = false;

            // Do the publish!
            publisher.Publish();
        }
Exemple #12
0
        private void ExecutePublishItem(string sourceDBName, string targetDBName, Sitecore.Data.Items.Item rootItem, bool withChildren, bool isRepubish)
        {
            try
            {
                using (new UserSwitcher(@"sitecore\admin", true))
                {
                    var sourceDB = Database.GetDatabase(sourceDBName);
                    var targetDB = Database.GetDatabase(targetDBName);

                    Sitecore.Publishing.PublishOptions publishOptions = null;
                    if (!isRepubish)
                    {
                        publishOptions =
                            new Sitecore.Publishing.PublishOptions(sourceDB,
                                                                   targetDB,
                                                                   Sitecore.Publishing.PublishMode.Smart,
                                                                   rootItem.Language,
                                                                   System.DateTime.Now);
                    }
                    else
                    {
                        publishOptions =
                            new Sitecore.Publishing.PublishOptions(sourceDB,
                                                                   targetDB,
                                                                   Sitecore.Publishing.PublishMode.Full,
                                                                   rootItem.Language,
                                                                   System.DateTime.Now);
                    }
                    Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);
                    publisher.Options.RootItem = rootItem;
                    publisher.Options.Deep     = withChildren;
                    publisher.Publish();
                }
            }
            catch (Exception x)
            {
                Log.Error(x.Message, this);
            }
        }
        public void CreateComment(string comment)
        {
            Database masterDb   = Sitecore.Configuration.Factory.GetDatabase("master");
            var      dataSource = GetDataSourceItem();

            dataSource = masterDb.GetItem(dataSource.ID);
            var commentsFolder = dataSource.Axes.GetDescendants().FirstOrDefault(x => x.TemplateName == "Comments Folder");

            if (commentsFolder == null)
            {
                return;
            }
            TemplateItem template   = masterDb.GetTemplate("{F0A8C4E9-FEE1-407E-99DB-A7F2D16024D1}");
            var          newComment = commentsFolder.Add(String.Format("Comment {0}", DateTime.Now.ToString("g")).SanitizeToItemName(), template);

            var user     = Sitecore.Context.User;
            var username = user == null ? "anon" : user.Name;

            if (newComment == null)
            {
                return;
            }
            newComment.Editing.BeginEdit();
            newComment.Fields["Comment"].Value  = comment;
            newComment.Fields["Username"].Value = username;
            newComment.Editing.EndEdit();

            Sitecore.Publishing.PublishOptions publishOptions =
                new Sitecore.Publishing.PublishOptions(newComment.Database,
                                                       Database.GetDatabase("web"),
                                                       Sitecore.Publishing.PublishMode.SingleItem,
                                                       newComment.Language,
                                                       System.DateTime.Now); // Create a publisher with the publishoptions
            Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

            publisher.Options.RootItem = newComment;
            publisher.Publish();
        }
Exemple #14
0
        protected void Unnamed_Click(object sender, EventArgs e)
        {
            var db       = Sitecore.Configuration.Factory.GetDatabase("master");
            var homeItem = db.GetItem(new Sitecore.Data.ID("{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}"));

            // duplicate new home item
            var newHomeItem = homeItem.Duplicate(homeItem.DisplayName + countryCode.Text);

            if (UpdateRendering(db, homeItem, newHomeItem) && UpdateConfig(newHomeItem) && UpdateIISSite())
            {
                if (IsPublish.Checked)
                {
                    Sitecore.Publishing.PublishOptions publishOptions =
                        new Sitecore.Publishing.PublishOptions(newHomeItem.Database,
                                                               Database.GetDatabase("web"),
                                                               Sitecore.Publishing.PublishMode.Smart,
                                                               newHomeItem.Language,
                                                               System.DateTime.Now); // Create a publisher with the publishoptions
                    Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

                    // Choose where to publish from
                    publisher.Options.RootItem = newHomeItem;

                    // Publish children as well?
                    publisher.Options.Deep = true;

                    // Do the publish!
                    publisher.Publish();
                    SetMesasgeInCookie("Done", 1);
                }
                else
                {
                    SetMesasgeInCookie("Done. Please publish new site", 1);
                }
                Response.Redirect("http://sc8mvc/duplicateitems.aspx");
            }
        }
Exemple #15
0
        /// <summary>
        /// Publish the item and recursivley any ancestors that haven't yet been published
        /// </summary>
        /// <param name="item">The item to publish</param>
        public static void PublishItemAndRequiredAncestors(Item item, Database targetDatabase)
        {
            if (item != null)
            {
                var ancestorInTarget = targetDatabase.GetItem(item.ParentID);
                if (ancestorInTarget == null)
                {
                    PublishItemAndRequiredAncestors(item.Parent, targetDatabase);
                }

                ancestorInTarget = targetDatabase.GetItem(item.ParentID);
                if (ancestorInTarget != null)
                {
                    foreach (Sitecore.Globalization.Language language in item.Database.Languages)
                    {
                        Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(item.Database, targetDatabase, Sitecore.Publishing.PublishMode.SingleItem, language, DateTime.Now);
                        publishOptions.RootItem = item;
                        publishOptions.Deep     = false;
                        Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);
                        publisher.Publish();
                    }
                }
            }
        }
        public bool publish()
        {
            Sitecore.Data.Database master = Sitecore.Data.Database.GetDatabase("master");
            Sitecore.Data.Database web = Sitecore.Data.Database.GetDatabase("web");
            var options = new Sitecore.Publishing.PublishOptions(master, web, Sitecore.Publishing.PublishMode.Smart, Sitecore.Globalization.Language.Parse("en"), System.DateTime.Now);
            var publisher = new Sitecore.Publishing.Publisher(options);

            publisher.Options.RootItem = master.GetItem("/sitecore/content/home");
            publisher.Options.Deep = true;
            publisher.Publish();
            return true;
        }
        /// <summary>
        /// Function taken from http://briancaos.wordpress.com/2011/01/14/create-and-publish-items-in-sitecore/
        /// </summary>
        /// <param name="item"></param>
        private void PublishItem(Sitecore.Data.Items.Item item)
        {
            // The publishOptions determine the source and target database,
            // the publish mode and language, and the publish date
            Sitecore.Publishing.PublishOptions publishOptions =
              new Sitecore.Publishing.PublishOptions(item.Database,
                                                     Sitecore.Data.Database.GetDatabase("web"),
                                                     Sitecore.Publishing.PublishMode.SingleItem,
                                                     item.Language,
                                                     System.DateTime.Now);  // Create a publisher with the publishoptions
            Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);

            // Choose where to publish from
            publisher.Options.RootItem = item;

            // Publish children as well?
            publisher.Options.Deep = true;

            // Do the publish!
            publisher.Publish();
        }
Exemple #18
0
        /// <summary>
        /// Publishes the item.
        /// </summary>
        /// <param name="targetItem">The target item.</param>
        public static void PublishItem(Item targetItem, bool childs = false)
        {
            DateTime publishDate = DateTime.Now;

            Sitecore.Data.Database master = GetContentDatabase();
            var targetDBs = GetPublishingTargets(master);

            foreach (var db in targetDBs)
            {
                foreach (Sitecore.Globalization.Language language in master.Languages)
                {
                    Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(master, db, Sitecore.Publishing.PublishMode.SingleItem, language, publishDate);
                    publishOptions.RootItem = targetItem;
                    publishOptions.Deep     = childs;
                    Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions); publisher.Publish();
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// Publish the item and recursivley any ancestors that haven't yet been published
        /// </summary>
        /// <param name="item">The item to publish</param>
        public static void PublishItemAndRequiredAncestors(Item item, Database targetDatabase)
        {
            if (item != null)
            {
                var ancestorInTarget = targetDatabase.GetItem(item.ParentID);
                if (ancestorInTarget == null)
                {
                    PublishItemAndRequiredAncestors(item.Parent, targetDatabase);
                }

                ancestorInTarget = targetDatabase.GetItem(item.ParentID);
                if (ancestorInTarget != null)
                {
                    foreach (Sitecore.Globalization.Language language in item.Database.Languages)
                    {
                        Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(item.Database, targetDatabase, Sitecore.Publishing.PublishMode.SingleItem, language, DateTime.Now);
                        publishOptions.RootItem = item;
                        publishOptions.Deep = false;
                        Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);
                        publisher.Publish();
                    }
                }
            }
        }