From b8c23d0f82c3a2be7f8e830cf2850ff585536d0a Mon Sep 17 00:00:00 2001
From: Andre Rodrigues
Date: Mon, 6 Dec 2010 11:43:00 -0800
Subject: [PATCH] #1694: Moving module / theme install from gallery to
packaging services and changing themes / module modules dependencies.
--HG--
branch : dev
---
.../Controllers/AdminController.cs | 5 +-
.../Orchard.Modules/Views/Admin/Index.cshtml | 2 +-
.../Controllers/GalleryController.cs | 83 +-------------
.../PackagingServicesController.cs | 108 ++++++++++++++++++
.../Orchard.Packaging.csproj | 5 +-
.../AddModule.cshtml | 2 +-
.../AddTheme.cshtml | 2 +-
.../Controllers/AdminController.cs | 3 +-
.../Orchard.Themes/Views/Admin/Index.cshtml | 4 +-
9 files changed, 122 insertions(+), 92 deletions(-)
create mode 100644 src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs
rename src/Orchard.Web/Modules/Orchard.Packaging/Views/{Gallery => PackagingServices}/AddModule.cshtml (73%)
rename src/Orchard.Web/Modules/Orchard.Packaging/Views/{Gallery => PackagingServices}/AddTheme.cshtml (73%)
diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs
index 812c5cecf..fa8031bff 100644
--- a/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs
+++ b/src/Orchard.Web/Modules/Orchard.Modules/Controllers/AdminController.cs
@@ -50,8 +50,9 @@ namespace Orchard.Modules.Controllers {
var modules = _extensionManager.AvailableExtensions().Where(x => DefaultExtensionTypes.IsModule(x.ExtensionType));
return View(new ModulesIndexViewModel {
- Modules = modules,
- InstallModules = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "Gallery") != null });
+ Modules = modules,
+ InstallModules = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null
+ });
}
public ActionResult Features() {
diff --git a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Index.cshtml
index 54645d17f..fbfe4d9d9 100644
--- a/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Index.cshtml
+++ b/src/Orchard.Web/Modules/Orchard.Modules/Views/Admin/Index.cshtml
@@ -10,7 +10,7 @@
@Html.TitleForPage(T("Installed Modules").ToString())
@if (Model.InstallModules) {
- @Html.ActionLink(T("Install a module").ToString(), "AddModule", "Gallery", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
+ @Html.ActionLink(T("Install a module").ToString(), "AddModule", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
}
@if (Model.Modules.Count() > 0) {
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs
index 1e4607f00..b2fe8d8bd 100644
--- a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs
+++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/GalleryController.cs
@@ -1,14 +1,9 @@
using System;
-using System.IO;
using System.Linq;
-using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Xml.Linq;
-using NuGet;
-using Orchard.Environment;
using Orchard.Environment.Extensions;
-using Orchard.FileSystems.AppData;
using Orchard.Localization;
using Orchard.Packaging.Services;
using Orchard.Packaging.ViewModels;
@@ -24,21 +19,15 @@ namespace Orchard.Packaging.Controllers {
private readonly IPackageManager _packageManager;
private readonly IPackagingSourceManager _packagingSourceManager;
- private readonly IAppDataFolderRoot _appDataFolderRoot;
private readonly INotifier _notifier;
- private readonly IHostEnvironment _hostEnvironment;
public GalleryController(
IPackageManager packageManager,
IPackagingSourceManager packagingSourceManager,
- INotifier notifier,
- IAppDataFolderRoot appDataFolderRoot,
- IHostEnvironment hostEnvironment) {
+ INotifier notifier) {
_packageManager = packageManager;
_packagingSourceManager = packagingSourceManager;
_notifier = notifier;
- _appDataFolderRoot = appDataFolderRoot;
- _hostEnvironment = hostEnvironment;
T = NullLocalizer.Instance;
}
@@ -143,75 +132,5 @@ namespace Orchard.Packaging.Controllers {
return RedirectToAction(redirectTo == "Themes" ? "Themes" : "Modules");
}
-
- public ActionResult AddTheme(string returnUrl) {
- return View();
- }
-
- [HttpPost, ActionName("AddTheme")]
- public ActionResult AddThemePOST(string returnUrl) {
- return InstallPackage(returnUrl, Request.RawUrl);
- }
-
- [HttpPost, ActionName("RemoveTheme")]
- public ActionResult RemoveThemePOST(string themeId, string returnUrl, string retryUrl) {
- return UninstallPackage(PackagingSourceManager.ThemesFilter + themeId, returnUrl, retryUrl);
- }
-
- public ActionResult AddModule(string returnUrl) {
- return View();
- }
-
- [HttpPost, ActionName("AddModule")]
- public ActionResult AddModulePOST(string returnUrl) {
- return InstallPackage(returnUrl, Request.RawUrl);
- }
-
- public ActionResult InstallPackage(string returnUrl, string retryUrl) {
- try {
- if (Request.Files != null &&
- Request.Files.Count > 0 &&
- !string.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
- ModelState.AddModelError("File", T("Select a file to upload.").ToString());
- }
-
- foreach (string fileName in Request.Files) {
- HttpPostedFileBase file = Request.Files[fileName];
- if (file != null) {
- string fullFileName = Path.Combine(_appDataFolderRoot.RootFolder, fileName + ".nupkg").Replace(Path.DirectorySeparatorChar, '/');
- file.SaveAs(fullFileName);
- PackageInfo info = _packageManager.Install(new ZipPackage(fullFileName), _appDataFolderRoot.RootFolder, HostingEnvironment.MapPath("~/"));
- System.IO.File.Delete(fullFileName);
-
- _notifier.Information(T("Installed package \"{0}\", version {1} of type \"{2}\" at location \"{3}\"",
- info.ExtensionName, info.ExtensionVersion, info.ExtensionType, info.ExtensionPath));
- }
- }
-
- return Redirect(returnUrl);
- } catch (Exception exception) {
- for (Exception scan = exception; scan != null; scan = scan.InnerException) {
- _notifier.Error(T("Uploading module package failed: {0}", exception.Message));
- }
-
- return Redirect(retryUrl);
- }
- }
-
- public ActionResult UninstallPackage(string id, string returnUrl, string retryUrl) {
- try {
- _packageManager.Uninstall(id, HostingEnvironment.MapPath("~/"));
-
- _notifier.Information(T("Uninstalled package \"{0}\"", id));
-
- return Redirect(returnUrl);
- } catch (Exception exception) {
- for (Exception scan = exception; scan != null; scan = scan.InnerException) {
- _notifier.Error(T("Uninstall failed: {0}", exception.Message));
- }
-
- return Redirect(retryUrl);
- }
- }
}
}
\ No newline at end of file
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs
new file mode 100644
index 000000000..b38a3a331
--- /dev/null
+++ b/src/Orchard.Web/Modules/Orchard.Packaging/Controllers/PackagingServicesController.cs
@@ -0,0 +1,108 @@
+using System;
+using System.IO;
+using System.Web;
+using System.Web.Hosting;
+using System.Web.Mvc;
+using NuGet;
+using Orchard.Environment.Extensions;
+using Orchard.FileSystems.AppData;
+using Orchard.Localization;
+using Orchard.Packaging.Services;
+using Orchard.Themes;
+using Orchard.UI.Admin;
+using Orchard.UI.Notify;
+using IPackageManager = Orchard.Packaging.Services.IPackageManager;
+
+namespace Orchard.Packaging.Controllers {
+ [OrchardFeature("PackagingServices")]
+ [Themed, Admin]
+ public class PackagingServicesController : Controller {
+
+ private readonly IPackageManager _packageManager;
+ private readonly IAppDataFolderRoot _appDataFolderRoot;
+ private readonly INotifier _notifier;
+
+ public PackagingServicesController(
+ IPackageManager packageManager,
+ INotifier notifier,
+ IAppDataFolderRoot appDataFolderRoot) {
+ _packageManager = packageManager;
+ _notifier = notifier;
+ _appDataFolderRoot = appDataFolderRoot;
+
+ T = NullLocalizer.Instance;
+ }
+
+ public Localizer T { get; set; }
+
+ public ActionResult AddTheme(string returnUrl) {
+ return View();
+ }
+
+ [HttpPost, ActionName("AddTheme")]
+ public ActionResult AddThemePOST(string returnUrl) {
+ return InstallPackage(returnUrl, Request.RawUrl);
+ }
+
+ [HttpPost, ActionName("RemoveTheme")]
+ public ActionResult RemoveThemePOST(string themeId, string returnUrl, string retryUrl) {
+ return UninstallPackage(PackagingSourceManager.ThemesFilter + themeId, returnUrl, retryUrl);
+ }
+
+ public ActionResult AddModule(string returnUrl) {
+ return View();
+ }
+
+ [HttpPost, ActionName("AddModule")]
+ public ActionResult AddModulePOST(string returnUrl) {
+ return InstallPackage(returnUrl, Request.RawUrl);
+ }
+
+ public ActionResult InstallPackage(string returnUrl, string retryUrl) {
+ try {
+ if (Request.Files != null &&
+ Request.Files.Count > 0 &&
+ !string.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
+ ModelState.AddModelError("File", T("Select a file to upload.").ToString());
+ }
+
+ foreach (string fileName in Request.Files) {
+ HttpPostedFileBase file = Request.Files[fileName];
+ if (file != null) {
+ string fullFileName = Path.Combine(_appDataFolderRoot.RootFolder, fileName + ".nupkg").Replace(Path.DirectorySeparatorChar, '/');
+ file.SaveAs(fullFileName);
+ PackageInfo info = _packageManager.Install(new ZipPackage(fullFileName), _appDataFolderRoot.RootFolder, HostingEnvironment.MapPath("~/"));
+ System.IO.File.Delete(fullFileName);
+
+ _notifier.Information(T("Installed package \"{0}\", version {1} of type \"{2}\" at location \"{3}\"",
+ info.ExtensionName, info.ExtensionVersion, info.ExtensionType, info.ExtensionPath));
+ }
+ }
+
+ return Redirect(returnUrl);
+ } catch (Exception exception) {
+ for (Exception scan = exception; scan != null; scan = scan.InnerException) {
+ _notifier.Error(T("Uploading module package failed: {0}", exception.Message));
+ }
+
+ return Redirect(retryUrl);
+ }
+ }
+
+ public ActionResult UninstallPackage(string id, string returnUrl, string retryUrl) {
+ try {
+ _packageManager.Uninstall(id, HostingEnvironment.MapPath("~/"));
+
+ _notifier.Information(T("Uninstalled package \"{0}\"", id));
+
+ return Redirect(returnUrl);
+ } catch (Exception exception) {
+ for (Exception scan = exception; scan != null; scan = scan.InnerException) {
+ _notifier.Error(T("Uninstall failed: {0}", exception.Message));
+ }
+
+ return Redirect(retryUrl);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj b/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj
index 33679069e..dcb802462 100644
--- a/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj
+++ b/src/Orchard.Web/Modules/Orchard.Packaging/Orchard.Packaging.csproj
@@ -59,6 +59,7 @@
+
@@ -94,7 +95,7 @@
-
+
@@ -121,7 +122,7 @@
-
+
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddModule.cshtml b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml
similarity index 73%
rename from src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddModule.cshtml
rename to src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml
index 70087bb14..094b3c35a 100644
--- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddModule.cshtml
+++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddModule.cshtml
@@ -1,6 +1,6 @@
@{
@Html.TitleForPage(T("Install a Module").ToString())
- using (Html.BeginFormAntiForgeryPost(Url.Action("AddModule", new { area = "Orchard.Gallery" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
+ using (Html.BeginFormAntiForgeryPost(Url.Action("AddModule", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary();
@T("Module Package")
diff --git a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddTheme.cshtml b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml
similarity index 73%
rename from src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddTheme.cshtml
rename to src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml
index 01bff8201..acdc44e37 100644
--- a/src/Orchard.Web/Modules/Orchard.Packaging/Views/Gallery/AddTheme.cshtml
+++ b/src/Orchard.Web/Modules/Orchard.Packaging/Views/PackagingServices/AddTheme.cshtml
@@ -1,6 +1,6 @@
@{
@Html.TitleForPage(T("Install a Theme").ToString())
- using (Html.BeginFormAntiForgeryPost(Url.Action("AddTheme", new { area = "Orchard.Gallery" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
+ using (Html.BeginFormAntiForgeryPost(Url.Action("AddTheme", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request["returnUrl"] }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
Html.ValidationSummary();
@T("Theme Package")
diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs
index 8cfa24d2f..b5834ddd6 100644
--- a/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs
+++ b/src/Orchard.Web/Modules/Orchard.Themes/Controllers/AdminController.cs
@@ -69,7 +69,8 @@ namespace Orchard.Themes.Controllers {
return View(new ThemesIndexViewModel {
CurrentTheme = currentTheme, Themes = themes,
- InstallThemes = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "Gallery") != null });
+ InstallThemes = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "PackagingServices") != null
+ });
}
catch (Exception exception) {
Services.Notifier.Error(T("Listing themes failed: " + exception.Message));
diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml
index e84d5c3e9..13b199089 100644
--- a/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml
+++ b/src/Orchard.Web/Modules/Orchard.Themes/Views/Admin/Index.cshtml
@@ -19,7 +19,7 @@
if (Model.InstallThemes) {
- @Html.ActionLink(T("Install a new Theme").ToString(), "AddTheme", "Gallery", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
+ @Html.ActionLink(T("Install a new Theme").ToString(), "AddTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })
}
}
@@ -57,7 +57,7 @@
}
@if (Model.InstallThemes) {
- using (Html.BeginFormAntiForgeryPost(Url.Action("RemoveTheme", "Gallery", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl, retryUrl = HttpContext.Current.Request.RawUrl, themeId = theme.Id }), FormMethod.Post, new { @class = "inline link" })) {
+ using (Html.BeginFormAntiForgeryPost(Url.Action("RemoveTheme", "PackagingServices", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl, retryUrl = HttpContext.Current.Request.RawUrl, themeId = theme.Id }), FormMethod.Post, new { @class = "inline link" })) {
@T("Uninstall")
}
}