Added RemoveContent execution step.

This commit is contained in:
Sipke Schoorstra
2015-08-13 13:44:26 +01:00
parent d2c622dac6
commit 25fa422a5e
2 changed files with 57 additions and 0 deletions

View File

@@ -93,6 +93,7 @@
<Compile Include="Providers\Builders\SettingsStep.cs" />
<Compile Include="Providers\Executors\ActivateSweepGeneratorStep.cs" />
<Compile Include="Providers\Executors\CommandStep.cs" />
<Compile Include="Providers\Executors\RemoveContentStep.cs" />
<Compile Include="Providers\Executors\RecipesStep.cs" />
<Compile Include="ViewModels\ContentExecutionStepViewModel.cs" />
<Compile Include="Providers\Executors\ContentStep.cs" />

View File

@@ -0,0 +1,56 @@
using System;
using System.Linq;
using Orchard.ContentManagement;
using Orchard.Localization;
using Orchard.Logging;
using Orchard.Recipes.Models;
using Orchard.Recipes.Services;
namespace Orchard.Recipes.Providers.Executors {
public class RemoveContentStep : RecipeExecutionStep {
private readonly IContentManager _contentManager;
public RemoveContentStep(
RecipeExecutionLogger logger, IContentManager contentManager) : base(logger) {
_contentManager = contentManager;
}
public override string Name {
get { return "RemoveContent"; }
}
public override LocalizedString DisplayName {
get { return T("Remove Content"); }
}
public override LocalizedString Description {
get { return T("Removes a list of content items."); }
}
// <RemoveContent>
// <Page Id="{identifier}" />
// <BlogPost Id="{identifier}" />
// ...
// </RemoveContent>
public override void Execute(RecipeExecutionContext context) {
var identitiesQuery =
from element in context.RecipeStep.Step.Elements()
let id = element.Attr("Id")
where !String.IsNullOrWhiteSpace(id)
select new ContentIdentity(id);
foreach (var identity in identitiesQuery) {
Logger.Information("Removing content item with identity '{0}'...", identity);
var contentItem = _contentManager.ResolveIdentity(identity);
if (contentItem == null) {
Logger.Warning("No content item with identity '{0}' could be found.", identity);
continue;
}
_contentManager.Remove(contentItem);
Logger.Information("Content item with identity '{0}' was found with id '{1}' and has been successfully removed.", identity, contentItem.Id);
}
}
}
}