#1694: Moving module / theme install from gallery to packaging services and changing themes / module modules dependencies.

--HG--
branch : dev
This commit is contained in:
Andre Rodrigues
2010-12-06 11:43:00 -08:00
parent 8a9b41a3be
commit b8c23d0f82
9 changed files with 122 additions and 92 deletions

View File

@@ -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);
}
}
}
}