Skip to content

Commit

Permalink
Fixes #6356 Content step in a migration recipe fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech committed Jul 13, 2020
1 parent 725fa64 commit 534f675
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static async Task UsingChildScopeAsync(string tenant, Func<ShellScope, Ta
/// <summary>
/// Execute a delegate using this shell scope.
/// </summary>
public async Task UsingAsync(Func<ShellScope, Task> execute)
public async Task UsingAsync(Func<ShellScope, Task> execute, bool activateShell = true)
{
if (Current == this)
{
Expand All @@ -199,7 +199,10 @@ public async Task UsingAsync(Func<ShellScope, Task> execute)
{
StartAsyncFlow();

await ActivateShellAsync();
if (activateShell)
{
await ActivateShellAsync();
}

await execute(this);

Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore/OrchardCore.Data/SessionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SessionHelper(ISession session)
{
if (_loaded.TryGetValue(typeof(T), out var loaded))
{
_session.Detach(loaded);
throw new ArgumentException("Can't get for caching an object being mutated in the same scope");
}

var document = await _session.Query<T>().FirstOrDefaultAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class RecipeDescriptor
public DateTime? ExportUtc { get; set; }
public string[] Categories { get; set; }
public string[] Tags { get; set; }
public bool RequireNewScope { get; set; } = true;
public bool ActivateShell { get; set; } = true;

/// <summary>
/// The path of the recipe file for the <see cref="RecipeDescriptor.FileProvider"/> property
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OrchardCore.Environment.Shell;
using OrchardCore.Environment.Shell.Scope;
using OrchardCore.Modules;
using OrchardCore.Recipes.Events;
using OrchardCore.Recipes.Models;
Expand Down Expand Up @@ -147,9 +146,7 @@ public async Task<string> ExecuteAsync(string executionId, RecipeDescriptor reci

private async Task ExecuteStepAsync(RecipeExecutionContext recipeStep)
{
var shellScope = recipeStep.RecipeDescriptor.RequireNewScope
? await _shellHost.GetScopeAsync(_shellSettings)
: ShellScope.Current;
var shellScope = await _shellHost.GetScopeAsync(_shellSettings);

await shellScope.UsingAsync(async scope =>
{
Expand Down Expand Up @@ -179,7 +176,8 @@ await shellScope.UsingAsync(async scope =>
_logger.LogInformation("Finished executing recipe step '{RecipeName}'.", recipeStep.Name);
}
}
});
},
activateShell: recipeStep.RecipeDescriptor.ActivateShell);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.Hosting;
using OrchardCore.Data.Migration;
using OrchardCore.Environment.Extensions;
using OrchardCore.Environment.Shell.Scope;

namespace OrchardCore.Recipes.Services
{
Expand Down Expand Up @@ -35,10 +36,16 @@ public async Task<string> ExecuteAsync(string recipeFileName, IDataMigration mig
var recipeFilePath = Path.Combine(recipeBasePath, recipeFileName).Replace('\\', '/');
var recipeFileInfo = _hostingEnvironment.ContentRootFileProvider.GetFileInfo(recipeFilePath);
var recipeDescriptor = await _recipeReader.GetRecipeDescriptor(recipeBasePath, recipeFileInfo, _hostingEnvironment.ContentRootFileProvider);
recipeDescriptor.RequireNewScope = false;
recipeDescriptor.ActivateShell = false;

var executionId = Guid.NewGuid().ToString("n");
return await _recipeExecutor.ExecuteAsync(executionId, recipeDescriptor, new object(), CancellationToken.None);

ShellScope.AddDeferredTask(scope =>
{
return _recipeExecutor.ExecuteAsync(executionId, recipeDescriptor, new object(), CancellationToken.None);
});

return executionId;
}
}
}

0 comments on commit 534f675

Please sign in to comment.