Skip to content

Commit

Permalink
Issue #539
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamNaj committed Dec 14, 2015
1 parent 31a2fb2 commit ce57a16
Show file tree
Hide file tree
Showing 3 changed files with 533 additions and 36 deletions.
53 changes: 47 additions & 6 deletions Cognifide.PowerShell/Commandlets/Data/PublishItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
using System.Management.Automation;
using Cognifide.PowerShell.Core.Extensions;
using Cognifide.PowerShell.Core.Utility;
using Cognifide.PowerShell.Core.VersionDecoupling;
using Sitecore.Configuration;
using Sitecore.Data;
using Sitecore.Data.Items;
using Sitecore.Publishing;
using Sitecore.Publishing.Pipelines.Publish;

namespace Cognifide.PowerShell.Commandlets.Data
{
Expand All @@ -23,6 +25,21 @@ public class PublishItemCommand : BaseItemCommand

[Parameter]
public PublishMode PublishMode { get; set; }

[Parameter]
public SwitchParameter PublishRelatedItems { get; set; }

[Parameter]
public SwitchParameter RepublishAll { get; set; }

[Parameter]
public SwitchParameter CompareRevisions { get; set; }

[Parameter]
public DateTime FromDate { get; set; }

[Parameter]
public SwitchParameter Synchronous { get; set; }

protected override void ProcessItem(Item item)
{
Expand Down Expand Up @@ -77,14 +94,38 @@ private void PublishToTarget(Item item, Database source, Database target)
var optionsArgs = new PublishOptions[1];
optionsArgs[0] = options;

var handle = PublishManager.Publish(optionsArgs);

if (handle == null) return;

var publishStatus = PublishManager.GetStatus(handle) ?? new PublishStatus();
// new
options.RepublishAll = RepublishAll;
options.CompareRevisions = CompareRevisions;
options.FromDate = FromDate;
if (this.VersionSupportThreshold("PublishRelatedItems", VersionResolver.SitecoreVersion72, true))
{
PublishRelatedItems72(options);
}

WriteVerbose($"Publish Job submitted, current state={publishStatus.State}.");
if (!Synchronous)
{
var handle = PublishManager.Publish(optionsArgs);
if (handle == null) return;
var publishStatus = PublishManager.GetStatus(handle) ?? new PublishStatus();
WriteVerbose($"Publish Job submitted, current state={publishStatus.State}.");
}
else
{
var publishContext = PublishManager.CreatePublishContext(options);
var stats = PublishPipeline.Run(publishContext)?.Statistics;
WriteVerbose("Publish Finished.");
if (stats != null)
{
WriteVerbose($"Items Created={stats.Created}, Deleted={stats.Deleted}, Skipped={stats.Skipped}, Updated={stats.Updated}.");
}
}
}
}

private void PublishRelatedItems72(PublishOptions options)
{
options.PublishRelatedItems = PublishRelatedItems;
}
}
}
Loading

0 comments on commit ce57a16

Please sign in to comment.