public void Publish(PublishMode mode, string languageName, List <string> publishingTargets, bool deep, string sourceDatabaseName = "master", string targetDatabaseName = "web", string rootItemPath = null)
        {
            //TODO : This option doesn't work yet

            using (new SecurityDisabler())
            {
                var sourceDatabase = Database.GetDatabase(sourceDatabaseName);
                var targetDatabase = Database.GetDatabase(targetDatabaseName);
                var language       = string.IsNullOrEmpty(languageName) ? null : LanguageManager.GetLanguage(languageName);
                var rootItem       = rootItemPath == null ? null : sourceDatabase.SelectSingleItem(rootItemPath);

                Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(sourceDatabase,
                                                                                                           targetDatabase,
                                                                                                           mode,
                                                                                                           language,
                                                                                                           System.DateTime.Now /*, publishingTargets*/); // Create a publisher with the publishoptions


                // The publishOptions determine the source and target database,
                // the publish mode and language, and the publish date
                var publisher = new Sitecore.Publishing.Publisher(publishOptions);

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

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

                // Do the publish!
                publisher.Publish();
            }
        }
        private void PublishItem(Item item)
        {
            using (new UserSwitcher("sitecore\\admin", true))
            {
                // The publishOptions determine the source and target database,
                // the publish mode and language, and the publish date
                var publishOptions = new Sitecore.Publishing.PublishOptions(item.Database,
                                                                            Database.GetDatabase("web"),
                                                                            PublishMode.SingleItem,
                                                                            item.Language,
                                                                            DateTime.Now);

                // Create a publisher with the publishoptions
                var 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.PublishAsync();

                item.Publishing.ClearPublishingCache();
            }
        }
        public void PublihsingMethod(Item rootItem, Sitecore.Publishing.PublishMode publishMode, bool deepOption, bool relatedItem = false)
        {
            Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(masterDb,
                                                                                                       targetDb,
                                                                                                       publishMode,
                                                                                                       rootItem.Language,
                                                                                                       System.DateTime.Now);

            Sitecore.Publishing.Publisher publisher = new Sitecore.Publishing.Publisher(publishOptions);
            publisher.Options.RootItem            = rootItem;
            publisher.Options.Deep                = deepOption;
            publisher.Options.PublishRelatedItems = relatedItem;
            publisher.Publish();
            Sitecore.Diagnostics.Log.Audit("Blog - Published item - " + rootItem.Paths.FullPath + " (Publish Subitems: " + deepOption.ToString() + ")", this);
        }
Esempio n. 4
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();
                }
            }
        }
Esempio n. 5
0
        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();
        }
Esempio n. 6
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 void Publish(PublishMode mode, string languageName, List<string> publishingTargets, bool deep, string sourceDatabaseName = "master", string targetDatabaseName = "web", string rootItemPath = null)
        {
            //TODO : This option doesn't work yet

            using (new SecurityDisabler())
            {
                var sourceDatabase = Database.GetDatabase(sourceDatabaseName);
                var targetDatabase = Database.GetDatabase(targetDatabaseName);
                var language = string.IsNullOrEmpty(languageName) ? null : LanguageManager.GetLanguage(languageName);
                var rootItem = rootItemPath == null ? null : sourceDatabase.SelectSingleItem(rootItemPath);

                Sitecore.Publishing.PublishOptions publishOptions = new Sitecore.Publishing.PublishOptions(sourceDatabase,
                                                        targetDatabase,
                                                        mode,
                                                        language,
                                                        System.DateTime.Now/*, publishingTargets*/);  // Create a publisher with the publishoptions

                // The publishOptions determine the source and target database,
                // the publish mode and language, and the publish date
                var publisher = new Sitecore.Publishing.Publisher(publishOptions);

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

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

                // Do the publish!
                publisher.Publish();
            }
        }