- 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:
suhacan
2009-12-11 23:10:54 +00:00
parent 1338e5b3eb
commit dc197390d8
9 changed files with 67 additions and 10 deletions

View File

@@ -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]

View File

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

View File

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

View File

@@ -76,6 +76,10 @@ namespace Orchard.Core.Themes.Services {
_extensionManager.InstallExtension("Theme", file);
}
public void UninstallTheme(string themeName) {
_extensionManager.UninstallExtension("Theme", themeName);
}
#endregion
}
}

View File

@@ -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>
<% }

View File

@@ -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()) {

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

View File

@@ -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" />

View File

@@ -8,5 +8,6 @@ namespace Orchard.Themes {
IEnumerable<ITheme> GetInstalledThemes();
void SetCurrentTheme(string themeName);
void InstallTheme(HttpPostedFileBase file);
void UninstallTheme(string themeName);
}
}