From 2afa3cd9bf3ece441c58088e7d31acccede67af0 Mon Sep 17 00:00:00 2001 From: Suha Can Date: Fri, 18 Feb 2011 13:16:42 -0800 Subject: [PATCH] Module installation handler for the recipes: discover and find module to install from orchard or custom feed. Updating recipe with a gallery module. --HG-- branch : recipe --- .../Services/IPackagingSourceManager.cs | 1 - .../Orchard.Recipes/Orchard.Recipes.csproj | 4 ++ .../RecipeHandlers/ModuleRecipeHandler.cs | 43 +++++++++++++++++-- .../Orchard.Setup/Recipes/blog.recipe.xml | 4 +- .../Orchard.Setup/Services/SetupService.cs | 3 ++ 5 files changed, 49 insertions(+), 6 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Services/IPackagingSourceManager.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Services/IPackagingSourceManager.cs index 4df2d2653..6ad7baf67 100644 --- a/src/Orchard.Web/Modules/Orchard.Packaging/Services/IPackagingSourceManager.cs +++ b/src/Orchard.Web/Modules/Orchard.Packaging/Services/IPackagingSourceManager.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Linq.Expressions; using Orchard.Packaging.GalleryServer; using Orchard.Packaging.Models; diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj b/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj index 37ee98e5d..4a4bc027f 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj +++ b/src/Orchard.Web/Modules/Orchard.Recipes/Orchard.Recipes.csproj @@ -79,6 +79,10 @@ {17F86780-9A1F-4AA1-86F1-875EEC2730C7} Orchard.Modules + + {DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059} + Orchard.Packaging + diff --git a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs index 64c5b537e..180d59771 100644 --- a/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs +++ b/src/Orchard.Web/Modules/Orchard.Recipes/RecipeHandlers/ModuleRecipeHandler.cs @@ -1,12 +1,19 @@ using System; +using System.Collections; +using System.Collections.Generic; using Orchard.Localization; using Orchard.Logging; +using Orchard.Packaging.Models; +using Orchard.Packaging.Services; using Orchard.Recipes.Models; using Orchard.Recipes.Services; namespace Orchard.Recipes.RecipeHandlers { public class ModuleRecipeHandler : IRecipeHandler { - public ModuleRecipeHandler() { + private readonly IPackagingSourceManager _packagingSourceManager; + + public ModuleRecipeHandler(IPackagingSourceManager packagingSourceManager) { + _packagingSourceManager = packagingSourceManager; Logger = NullLogger.Instance; T = NullLocalizer.Instance; } @@ -23,7 +30,7 @@ namespace Orchard.Recipes.RecipeHandlers { } bool replace; - string source, name, version, repository; + string source = null, name = null, version = null, repository = null; foreach (var attribute in recipeContext.RecipeStep.Step.Attributes()) { if (String.Equals(attribute.Name.LocalName, "src", StringComparison.OrdinalIgnoreCase)) { @@ -42,11 +49,39 @@ namespace Orchard.Recipes.RecipeHandlers { repository = attribute.Value; } else { - Logger.Error("Unrecognized attribute {0} encountered in step Module. Skipping.", attribute.Name.LocalName); + throw new InvalidOperationException(string.Format("Unrecognized attribute {0} encountered in step Module.", attribute.Name.LocalName)); } } - // download and install module. + if (source != null) { + } + else { + if (name == null) { + throw new InvalidOperationException("Either name or source is required in a Module declaration in a recipe file."); + } + // download and install module from the orchard feed or a custom feed if repository is specified. + bool enforceVersion = version != null; + bool installed = false; + PackagingSource packagingSource = null; + if (repository != null) { + enforceVersion = false; + packagingSource = new PackagingSource {FeedTitle = repository, FeedUrl = repository}; + } + foreach (var packagingEntry in _packagingSourceManager.GetExtensionList(packagingSource)) { + if (String.Equals(packagingEntry.Title, name, StringComparison.OrdinalIgnoreCase)) { + if (enforceVersion && !String.Equals(packagingEntry.Version, version, StringComparison.OrdinalIgnoreCase)) { + continue; + } + // install. + installed = true; + } + } + + if (!installed) { + throw new InvalidOperationException(string.Format("Module {0} was not found in the specified location.", name)); + } + + } recipeContext.Executed = true; } diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Recipes/blog.recipe.xml b/src/Orchard.Web/Modules/Orchard.Setup/Recipes/blog.recipe.xml index 2ca28ee19..b9cd3cda8 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Recipes/blog.recipe.xml +++ b/src/Orchard.Web/Modules/Orchard.Setup/Recipes/blog.recipe.xml @@ -9,10 +9,12 @@ 1.0 + + + TinyMce,TheThemeMachine,Orchard.Experimental" /> diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs index 2fc335fe0..20cc783f0 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs +++ b/src/Orchard.Web/Modules/Orchard.Setup/Services/SetupService.cs @@ -100,6 +100,9 @@ namespace Orchard.Setup.Services { "Orchard.Users", "Orchard.Roles", "Orchard.Modules", + "PackagingServices", + "Orchard.Packaging", + "Gallery", "Orchard.Recipes" };