Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to configure item Publish options, such as deep, smart or related items options, when publishing a list of items. #50

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/Sitecore.Ship.Core/Domain/ItemsToPublish.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,23 @@

namespace Sitecore.Ship.Core.Domain
{
public class ItemsToPublish
{
public List<Guid> Items { get; set; }
public string[] TargetDatabases { get; set; }
public string[] TargetLanguages { get; set; }
public class ItemsToPublish
{
public List<Guid> Items { get; set; }
public string[] TargetDatabases { get; set; }
public string[] TargetLanguages { get; set; }
public bool SmartPublish { get; set; }
public bool DeepPublish { get; set; }
public bool PublishRelatedItems { get; set; }

public ItemsToPublish()
{
Items = new List<Guid>();
TargetDatabases = new string[] { };
TargetLanguages = new string[] { };
SmartPublish = true;
DeepPublish = true;
PublishRelatedItems = false;
}
}
}
}
}
148 changes: 74 additions & 74 deletions src/Sitecore.Ship.Infrastructure/PublishService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@

namespace Sitecore.Ship.Infrastructure
{
public class PublishService : IPublishService
{
private readonly Dictionary<string, Func<Database, Database[], Language[], Handle>> _publishingActions;

public PublishService()
{
_publishingActions = new Dictionary<string, Func<Database, Database[], Language[], Handle>>
{
{ "full", Publishing.PublishManager.Republish },
{ "smart", Publishing.PublishManager.PublishSmart },
{ "incremental", Publishing.PublishManager.PublishIncremental }
};
}

public void Run(ItemsToPublish itemsToPublish)
{
public class PublishService : IPublishService
{
private readonly Dictionary<string, Func<Database, Database[], Language[], Handle>> _publishingActions;

public PublishService()
{
_publishingActions = new Dictionary<string, Func<Database, Database[], Language[], Handle>>
{
{ "full", Publishing.PublishManager.Republish },
{ "smart", Publishing.PublishManager.PublishSmart },
{ "incremental", Publishing.PublishManager.PublishIncremental }
};
}

public void Run(ItemsToPublish itemsToPublish)
{
if (itemsToPublish == null)
{
throw new ArgumentNullException("itemsToPublish");
Expand All @@ -38,62 +38,62 @@ public void Run(ItemsToPublish itemsToPublish)
return;
}

using (new SecurityModel.SecurityDisabler())
{
var master = Sitecore.Configuration.Factory.GetDatabase("master");
var languages = itemsToPublish.TargetLanguages.Select(LanguageManager.GetLanguage).ToArray();

foreach (var itemToPublish in itemsToPublish.Items)
{
var item = master.GetItem(new ID(itemToPublish));
if (item != null)
{
Publishing.PublishManager.PublishItem(item, itemsToPublish.TargetDatabases.Select(Sitecore.Configuration.Factory.GetDatabase).ToArray(), languages, true, true);
}
}
}
}

public void Run(PublishParameters publishParameters)
{
var publishingMode = publishParameters.Mode.ToLower();

if (!_publishingActions.ContainsKey(publishingMode))
{
throw new InvalidOperationException(string.Format("Invalid publishing mode ({0})", publishingMode));
}

PublishingTask(_publishingActions[publishingMode], publishParameters);
}

public DateTime GetLastCompletedRun(PublishLastCompleted completeParameters)
{
// please note http://stackoverflow.com/questions/12416141/get-the-date-time-that-sitecore-last-published

var source = Sitecore.Configuration.Factory.GetDatabase(completeParameters.Source);
var target = Sitecore.Configuration.Factory.GetDatabase(completeParameters.Target);
var language = LanguageManager.GetLanguage(completeParameters.Language);


Assert.IsNotNull(source, "Source database {0} cannot be found".Formatted(completeParameters.Source));
Assert.IsNotNull(source, "Target database {0} cannot be found".Formatted(completeParameters.Target));
Assert.IsNotNull(language, "Language {0} cannot be found".Formatted(completeParameters.Language));

var date = source.Properties.GetLastPublishDate(target, language);
return date;
}

private static void PublishingTask(Func<Database, Database[], Language[], Handle> publishType, PublishParameters publishParameters)
{
using (new SecurityModel.SecurityDisabler())
{
var master = Sitecore.Configuration.Factory.GetDatabase(publishParameters.Source);
var targetDBs = publishParameters.Targets.Select(Sitecore.Configuration.Factory.GetDatabase).ToArray();
var languages = publishParameters.Languages.Select(LanguageManager.GetLanguage).ToArray();

publishType(master, targetDBs, languages);
}
}
}
using (new SecurityModel.SecurityDisabler())
{
var master = Sitecore.Configuration.Factory.GetDatabase("master");
var languages = itemsToPublish.TargetLanguages.Select(LanguageManager.GetLanguage).ToArray();

foreach (var itemToPublish in itemsToPublish.Items)
{
var item = master.GetItem(new ID(itemToPublish));
if (item != null)
{
Publishing.PublishManager.PublishItem(item, itemsToPublish.TargetDatabases.Select(Sitecore.Configuration.Factory.GetDatabase).ToArray(), languages, itemsToPublish.DeepPublish, itemsToPublish.SmartPublish, itemsToPublish.PublishRelatedItems);
}
}
}
}

public void Run(PublishParameters publishParameters)
{
var publishingMode = publishParameters.Mode.ToLower();

if (!_publishingActions.ContainsKey(publishingMode))
{
throw new InvalidOperationException(string.Format("Invalid publishing mode ({0})", publishingMode));
}

PublishingTask(_publishingActions[publishingMode], publishParameters);
}

public DateTime GetLastCompletedRun(PublishLastCompleted completeParameters)
{
// please note http://stackoverflow.com/questions/12416141/get-the-date-time-that-sitecore-last-published

var source = Sitecore.Configuration.Factory.GetDatabase(completeParameters.Source);
var target = Sitecore.Configuration.Factory.GetDatabase(completeParameters.Target);
var language = LanguageManager.GetLanguage(completeParameters.Language);


Assert.IsNotNull(source, "Source database {0} cannot be found".Formatted(completeParameters.Source));
Assert.IsNotNull(source, "Target database {0} cannot be found".Formatted(completeParameters.Target));
Assert.IsNotNull(language, "Language {0} cannot be found".Formatted(completeParameters.Language));

var date = source.Properties.GetLastPublishDate(target, language);
return date;
}

private static void PublishingTask(Func<Database, Database[], Language[], Handle> publishType, PublishParameters publishParameters)
{
using (new SecurityModel.SecurityDisabler())
{
var master = Sitecore.Configuration.Factory.GetDatabase(publishParameters.Source);
var targetDBs = publishParameters.Targets.Select(Sitecore.Configuration.Factory.GetDatabase).ToArray();
var languages = publishParameters.Languages.Select(LanguageManager.GetLanguage).ToArray();

publishType(master, targetDBs, languages);
}
}
}
}