mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-11-28 17:32:44 +08:00
- Themes: uninstalling themes from the admin.
- ExtensionManager: UninstallExtension API --HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4043841
This commit is contained in:
@@ -59,6 +59,10 @@ namespace Orchard.Tests.Environment {
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
||||
@@ -57,6 +57,10 @@ namespace Orchard.Tests.Mvc.Routes {
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,7 +67,20 @@ namespace Orchard.Core.Themes.Controllers {
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error("Installing theme failed: " + exception.Message);
|
||||
_notifier.Error(T("Installing theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Uninstall(string themeName) {
|
||||
try {
|
||||
if (!_authorizer.Authorize(Permissions.InstallUninstallTheme, T("Couldn't uninstall theme")))
|
||||
return new HttpUnauthorizedResult();
|
||||
_themeService.UninstallTheme(themeName);
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
catch (Exception exception) {
|
||||
_notifier.Error(T("Uninstalling theme failed: " + exception.Message));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,10 @@ namespace Orchard.Core.Themes.Services {
|
||||
_extensionManager.InstallExtension("Theme", file);
|
||||
}
|
||||
|
||||
public void UninstallTheme(string themeName) {
|
||||
_extensionManager.UninstallExtension("Theme", themeName);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<%= theme.Version %><br />
|
||||
<%= theme.Description %><br />
|
||||
<%= theme.HomePage %><br />
|
||||
<%=Html.ActionLink("Activate", "Activate", new {themeName = theme.ThemeName}) %>
|
||||
<%=Html.ActionLink("Activate", "Activate", new {themeName = theme.ThemeName}) %> | <%=Html.ActionLink("Uninstall", "Uninstall", new {themeName = theme.ThemeName}) %>
|
||||
</p>
|
||||
</li>
|
||||
<% }
|
||||
|
||||
@@ -5,24 +5,22 @@ using System.Linq;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using Orchard.Extensions.Helpers;
|
||||
using Orchard.Extensions.Loaders;
|
||||
using Orchard.Localization;
|
||||
using Yaml.Grammar;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Extensions {
|
||||
public interface IExtensionManager {
|
||||
IEnumerable<ExtensionDescriptor> AvailableExtensions();
|
||||
IEnumerable<ExtensionEntry> ActiveExtensions();
|
||||
void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle);
|
||||
}
|
||||
|
||||
public class ExtensionManager : IExtensionManager {
|
||||
private readonly IEnumerable<IExtensionFolders> _folders;
|
||||
private readonly IEnumerable<IExtensionLoader> _loaders;
|
||||
private IEnumerable<ExtensionEntry> _activeExtensions;
|
||||
|
||||
public Localizer T { get; set; }
|
||||
|
||||
public ExtensionManager(IEnumerable<IExtensionFolders> folders, IEnumerable<IExtensionLoader> loaders) {
|
||||
_folders = folders;
|
||||
_loaders = loaders.OrderBy(x => x.Order);
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +71,7 @@ namespace Orchard.Extensions {
|
||||
|
||||
public void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException("extensionType");
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
@@ -83,7 +81,7 @@ namespace Orchard.Extensions {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Packages");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException("extensionType");
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
int postedFileLength = extensionBundle.ContentLength;
|
||||
Stream postedFileStream = extensionBundle.InputStream;
|
||||
@@ -109,6 +107,27 @@ namespace Orchard.Extensions {
|
||||
}
|
||||
}
|
||||
|
||||
public void UninstallExtension(string extensionType, string extensionName) {
|
||||
if (String.IsNullOrEmpty(extensionType)) {
|
||||
throw new ArgumentException(T("extensionType was null or empty").ToString());
|
||||
}
|
||||
string targetFolder;
|
||||
if (String.Equals(extensionType, "Theme", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Themes");
|
||||
}
|
||||
else if (String.Equals(extensionType, "Package", StringComparison.OrdinalIgnoreCase)) {
|
||||
targetFolder = PathHelpers.GetPhysicalPath("~/Packages");
|
||||
}
|
||||
else {
|
||||
throw new ArgumentException(T("extensionType was not recognized").ToString());
|
||||
}
|
||||
targetFolder = Path.Combine(targetFolder, extensionName);
|
||||
if (!Directory.Exists(targetFolder)) {
|
||||
throw new ArgumentException(T("extension was not found").ToString());
|
||||
}
|
||||
Directory.Delete(targetFolder, true);
|
||||
}
|
||||
|
||||
private IEnumerable<ExtensionEntry> BuildActiveExtensions() {
|
||||
//TODO: this component needs access to some "current settings" to know which are active
|
||||
foreach (var descriptor in AvailableExtensions()) {
|
||||
|
||||
11
src/Orchard/Extensions/IExtensionManager.cs
Normal file
11
src/Orchard/Extensions/IExtensionManager.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
|
||||
namespace Orchard.Extensions {
|
||||
public interface IExtensionManager {
|
||||
IEnumerable<ExtensionDescriptor> AvailableExtensions();
|
||||
IEnumerable<ExtensionEntry> ActiveExtensions();
|
||||
void InstallExtension(string extensionType, HttpPostedFileBase extensionBundle);
|
||||
void UninstallExtension(string extensionType, string extensionName);
|
||||
}
|
||||
}
|
||||
@@ -126,6 +126,7 @@
|
||||
<Compile Include="Extensions\ExtensionDescriptor.cs" />
|
||||
<Compile Include="Extensions\ExtensionEntry.cs" />
|
||||
<Compile Include="Extensions\Helpers\PathHelpers.cs" />
|
||||
<Compile Include="Extensions\IExtensionManager.cs" />
|
||||
<Compile Include="Extensions\PackageFolders.cs" />
|
||||
<Compile Include="Extensions\ExtensionManager.cs" />
|
||||
<Compile Include="Extensions\IExtensionFolders.cs" />
|
||||
|
||||
@@ -8,5 +8,6 @@ namespace Orchard.Themes {
|
||||
IEnumerable<ITheme> GetInstalledThemes();
|
||||
void SetCurrentTheme(string themeName);
|
||||
void InstallTheme(HttpPostedFileBase file);
|
||||
void UninstallTheme(string themeName);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user