mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
Implementation of migration/update handler for recipes.
Updating blog.recipe.xml with some features/migrations. Refactoring a recipe step queue utility method. --HG-- branch : recipe
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Orchard.Data.Migration;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Recipes.Models;
|
||||
@@ -8,7 +9,10 @@ using Orchard.Recipes.Services;
|
||||
|
||||
namespace Orchard.Recipes.RecipeHandlers {
|
||||
public class MigrationRecipeHandler : IRecipeHandler {
|
||||
public MigrationRecipeHandler() {
|
||||
private readonly IDataMigrationManager _dataMigrationManager;
|
||||
|
||||
public MigrationRecipeHandler(IDataMigrationManager dataMigrationManager) {
|
||||
_dataMigrationManager = dataMigrationManager;
|
||||
Logger = NullLogger.Instance;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
@@ -37,6 +41,15 @@ namespace Orchard.Recipes.RecipeHandlers {
|
||||
}
|
||||
}
|
||||
|
||||
if (runAll) {
|
||||
foreach (var feature in _dataMigrationManager.GetFeaturesThatNeedUpdate()) {
|
||||
_dataMigrationManager.Update(feature);
|
||||
}
|
||||
}
|
||||
else {
|
||||
_dataMigrationManager.Update(features);
|
||||
}
|
||||
|
||||
// run migrations
|
||||
recipeContext.Executed = true;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using Orchard.FileSystems.AppData;
|
||||
using Orchard.Localization;
|
||||
@@ -65,17 +66,11 @@ namespace Orchard.Recipes.Services {
|
||||
|
||||
private int GetFirstStepIndex(string executionId) {
|
||||
var stepFiles = new List<string>(_appDataFolder.ListFiles(Path.Combine(_recipeQueueFolder, executionId)));
|
||||
int firstIndex = stepFiles.Count;
|
||||
if (firstIndex == 0)
|
||||
if (stepFiles.Count == 0)
|
||||
return -1;
|
||||
// we always have only a handful of steps.
|
||||
foreach (var stepFile in stepFiles) {
|
||||
int stepOrder = Int32.Parse(stepFile.Substring(stepFile.LastIndexOf('/') + 1));
|
||||
if (firstIndex > stepOrder)
|
||||
firstIndex = stepOrder;
|
||||
}
|
||||
|
||||
return firstIndex;
|
||||
var currentSteps = stepFiles.Select(stepFile => Int32.Parse(stepFile.Substring(stepFile.LastIndexOf('/') + 1))).ToList();
|
||||
currentSteps.Sort();
|
||||
return currentSteps[0];
|
||||
}
|
||||
|
||||
private int GetLastStepIndex(string executionId) {
|
||||
|
||||
@@ -25,4 +25,11 @@
|
||||
<BodyPart BodyPartSettings.FlavorDefault="html" />
|
||||
</Parts>
|
||||
</Metadata>
|
||||
|
||||
<Command>
|
||||
feature enable Orchard.Experimental
|
||||
feature enable Orchard.Experimental.TestingLists
|
||||
</Command>
|
||||
|
||||
<Migration features="Orchard.Experimental.TestingLists" />
|
||||
</Orchard>
|
||||
|
||||
@@ -176,7 +176,7 @@ namespace Orchard.Setup.Services {
|
||||
var dataMigrationManager = environment.Resolve<IDataMigrationManager>();
|
||||
dataMigrationManager.Update("Settings");
|
||||
|
||||
foreach ( var feature in context.EnabledFeatures ) {
|
||||
foreach (var feature in context.EnabledFeatures) {
|
||||
dataMigrationManager.Update(feature);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user