mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Support installing packages from "Modules" admin UI
--HG-- branch : dev
This commit is contained in:
@@ -1,23 +1,29 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Web;
|
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Orchard.Data.Migration;
|
using Orchard.Data.Migration;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Modules.ViewModels;
|
using Orchard.Modules.ViewModels;
|
||||||
using Orchard.Mvc.Results;
|
using Orchard.Mvc.Results;
|
||||||
|
using Orchard.Packaging;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using Orchard.Utility.Extensions;
|
|
||||||
|
|
||||||
namespace Orchard.Modules.Controllers {
|
namespace Orchard.Modules.Controllers {
|
||||||
public class AdminController : Controller {
|
public class AdminController : Controller {
|
||||||
private readonly IModuleService _moduleService;
|
private readonly IModuleService _moduleService;
|
||||||
private readonly IDataMigrationManager _dataMigrationManager;
|
private readonly IDataMigrationManager _dataMigrationManager;
|
||||||
|
private readonly IPackageManager _packageManager;
|
||||||
|
|
||||||
|
public AdminController(IOrchardServices services,
|
||||||
|
IModuleService moduleService,
|
||||||
|
IDataMigrationManager dataMigrationManager,
|
||||||
|
IPackageManager packageManager) {
|
||||||
|
|
||||||
public AdminController(IOrchardServices services, IModuleService moduleService, IDataMigrationManager dataMigrationManager) {
|
|
||||||
Services = services;
|
Services = services;
|
||||||
_moduleService = moduleService;
|
_moduleService = moduleService;
|
||||||
_dataMigrationManager = dataMigrationManager;
|
_dataMigrationManager = dataMigrationManager;
|
||||||
|
_packageManager = packageManager;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,11 +35,11 @@ namespace Orchard.Modules.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var modules = _moduleService.GetInstalledModules().ToList();
|
var modules = _moduleService.GetInstalledModules().ToList();
|
||||||
return View(new ModulesIndexViewModel {Modules = modules});
|
return View(new ModulesIndexViewModel { Modules = modules });
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Add() {
|
public ActionResult Add() {
|
||||||
return View(new ModuleAddViewModel());
|
return View(new ModuleAddViewModel());
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost, ActionName("Add")]
|
[HttpPost, ActionName("Add")]
|
||||||
@@ -54,14 +60,18 @@ namespace Orchard.Modules.Controllers {
|
|||||||
|
|
||||||
foreach (string fileName in Request.Files) {
|
foreach (string fileName in Request.Files) {
|
||||||
var file = Request.Files[fileName];
|
var file = Request.Files[fileName];
|
||||||
//todo: upload & process module package
|
|
||||||
|
var info = _packageManager.Install(file.InputStream);
|
||||||
|
Services.Notifier.Information(T("Installed package \"{0}\", version {1} of type \"{2}\" at location \"{3}\"",
|
||||||
|
info.ExtensionName, info.ExtensionVersion, info.ExtensionType, info.ExtensionPath));
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: add success message
|
|
||||||
return RedirectToAction("index");
|
return RedirectToAction("index");
|
||||||
}
|
}
|
||||||
catch (Exception exception) {
|
catch (Exception exception) {
|
||||||
Services.Notifier.Error(T("Uploading module package failed: {0}", exception.Message));
|
for (var scan = exception; scan != null; scan = scan.InnerException) {
|
||||||
|
Services.Notifier.Error(T("Uploading module package failed: {0}", exception.Message));
|
||||||
|
}
|
||||||
return View("add", viewModel);
|
return View("add", viewModel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,7 +94,7 @@ namespace Orchard.Modules.Controllers {
|
|||||||
if (string.IsNullOrEmpty(id))
|
if (string.IsNullOrEmpty(id))
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
_moduleService.EnableFeatures(new[] {id}, force != null && (bool) force);
|
_moduleService.EnableFeatures(new[] { id }, force != null && (bool)force);
|
||||||
|
|
||||||
return RedirectToAction("Features");
|
return RedirectToAction("Features");
|
||||||
}
|
}
|
||||||
@@ -97,24 +107,24 @@ namespace Orchard.Modules.Controllers {
|
|||||||
if (string.IsNullOrEmpty(id))
|
if (string.IsNullOrEmpty(id))
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
_moduleService.DisableFeatures(new[] {id}, force != null && (bool) force);
|
_moduleService.DisableFeatures(new[] { id }, force != null && (bool)force);
|
||||||
|
|
||||||
return RedirectToAction("Features");
|
return RedirectToAction("Features");
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult Update(string id, bool? force) {
|
public ActionResult Update(string id, bool? force) {
|
||||||
if ( !Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")) )
|
if (!Services.Authorizer.Authorize(Permissions.ManageFeatures, T("Not allowed to manage features")))
|
||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
if ( string.IsNullOrEmpty(id) )
|
if (string.IsNullOrEmpty(id))
|
||||||
return new NotFoundResult();
|
return new NotFoundResult();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_dataMigrationManager.Update(id);
|
_dataMigrationManager.Update(id);
|
||||||
Services.Notifier.Information(T("The feature {0} was updated succesfuly", id));
|
Services.Notifier.Information(T("The feature {0} was updated succesfuly", id));
|
||||||
}
|
}
|
||||||
catch(Exception ex) {
|
catch (Exception ex) {
|
||||||
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, ex.Message));
|
Services.Notifier.Error(T("An error occured while updating the feature {0}: {1}", id, ex.Message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,20 +28,19 @@ namespace Orchard.Modules.Services {
|
|||||||
public IOrchardServices Services { get; set; }
|
public IOrchardServices Services { get; set; }
|
||||||
|
|
||||||
public IModule GetModuleByName(string moduleName) {
|
public IModule GetModuleByName(string moduleName) {
|
||||||
return
|
return _extensionManager
|
||||||
_extensionManager.AvailableExtensions().Where(
|
.AvailableExtensions()
|
||||||
e =>
|
.Where(e => string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase))
|
||||||
string.Equals(e.Name, moduleName, StringComparison.OrdinalIgnoreCase) &&
|
.Where(e => string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||||
string.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase)).Select(
|
.Select(descriptor => AssembleModuleFromDescriptor(descriptor))
|
||||||
descriptor => AssembleModuleFromDescriptor(descriptor)).FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<IModule> GetInstalledModules() {
|
public IEnumerable<IModule> GetInstalledModules() {
|
||||||
return
|
return _extensionManager
|
||||||
_extensionManager.AvailableExtensions().Where(
|
.AvailableExtensions()
|
||||||
e => String.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase)).Select
|
.Where(e => String.Equals(e.ExtensionType, ModuleExtensionType, StringComparison.OrdinalIgnoreCase))
|
||||||
(
|
.Select(descriptor => AssembleModuleFromDescriptor(descriptor));
|
||||||
descriptor => AssembleModuleFromDescriptor(descriptor));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void InstallModule(HttpPostedFileBase file) {
|
public void InstallModule(HttpPostedFileBase file) {
|
||||||
@@ -56,13 +55,8 @@ namespace Orchard.Modules.Services {
|
|||||||
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
|
var enabledFeatures = _shellDescriptorManager.GetShellDescriptor().Features;
|
||||||
return GetInstalledModules()
|
return GetInstalledModules()
|
||||||
.SelectMany(m => _extensionManager.LoadFeatures(m.Features))
|
.SelectMany(m => _extensionManager.LoadFeatures(m.Features))
|
||||||
.Select(
|
.Select(f => AssembleModuleFromDescriptor(f, enabledFeatures
|
||||||
f =>
|
.FirstOrDefault(sf => string.Equals(sf.Name, f.Descriptor.Name, StringComparison.OrdinalIgnoreCase)) != null));
|
||||||
AssembleModuleFromDescriptor(f,
|
|
||||||
enabledFeatures.FirstOrDefault(
|
|
||||||
sf =>
|
|
||||||
string.Equals(sf.Name, f.Descriptor.Name,
|
|
||||||
StringComparison.OrdinalIgnoreCase)) != null));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void EnableFeatures(IEnumerable<string> featureNames) {
|
public void EnableFeatures(IEnumerable<string> featureNames) {
|
||||||
|
|||||||
Reference in New Issue
Block a user