예제 #1
0
        public PublishResult PublishSync(PublishOptions options)
        {
            var publishContext = PublishManager.CreatePublishContext(options);

            publishContext.Languages = new[] { options.Language };

            return(PublishPipeline.Run(publishContext));
        }
예제 #2
0
        private void PublishToTarget(Item item, Database source, Database target)
        {
            if (PublishMode == PublishMode.Unknown)
            {
                PublishMode = PublishMode.Smart;
            }

            var language = item.Language;

            if (ShouldProcess(item.GetProviderPath(),
                              string.Format("{3}ublishing language '{0}', version '{1}' to target '{2}'.", language, item.Version,
                                            target.Name, Recurse.IsPresent ? "Recursively p" : "P")))
            {
                WriteVerbose($"Publishing item '{item.Name}' in language '{language}', version '{item.Version}' to target '{target.Name}'.  (Recurse={Recurse.IsPresent}).");

                var options = new PublishOptions(source, target, PublishMode, language, DateTime.Now)
                {
                    Deep             = Recurse,
                    RootItem         = (PublishMode == PublishMode.Incremental) ? null : item,
                    RepublishAll     = RepublishAll,
                    CompareRevisions = CompareRevisions || PublishMode == PublishMode.Smart
                };

                if (PublishMode == PublishMode.Incremental)
                {
                    WriteVerbose("Incremental publish causes ALL Database Items that are in the publishing queue to be published.");
                }

                if (!CompareRevisions && IsParameterSpecified(nameof(CompareRevisions)) && (PublishMode == PublishMode.Smart))
                {
                    WriteWarning($"The -{nameof(CompareRevisions)} parameter is set to $false but required to be $true when -{nameof(PublishMode)} is set to {PublishMode.Smart}, forcing {CompareRevisions} to $true.");
                }

                if (IsParameterSpecified(nameof(FromDate)))
                {
                    options.FromDate = FromDate;
                }

                if (PublishRelatedItems)
                {
                    options.PublishRelatedItems = PublishRelatedItems;
                    // Below blog explains why we're forcing Single Item
                    // http://www.sitecore.net/learn/blogs/technical-blogs/reinnovations/posts/2014/03/related-item-publishing.aspx
                    if (PublishRelatedItems && IsParameterSpecified(nameof(PublishMode)) && (PublishMode != PublishMode.SingleItem))
                    {
                        WriteWarning($"The -{nameof(PublishRelatedItems)} parameter is used which requires -{nameof(PublishMode)} to be set to set to {PublishMode.SingleItem}, forcing {PublishMode.SingleItem} PublishMode.");
                    }
                    options.Mode = PublishMode.SingleItem;
                }

                if (AsJob)
                {
                    var publisher = new Publisher(options);
                    var job       = publisher.PublishAsync();

                    if (job == null)
                    {
                        return;
                    }
                    WriteObject(job);
                }
                else
                {
                    var publishContext = PublishManager.CreatePublishContext(options);
                    publishContext.Languages = new[] { language };
                    var stats = PublishPipeline.Run(publishContext)?.Statistics;
                    if (stats != null)
                    {
                        WriteVerbose($"Items Created={stats.Created}, Deleted={stats.Deleted}, Skipped={stats.Skipped}, Updated={stats.Updated}.");
                    }

                    WriteVerbose("Publish Finished.");
                }
            }
        }