mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Improving package uninstall help. Extracting BuildPackageId method. Cleaning up code for uninstall. Fixing out of sync help.
--HG-- branch : 1.x
This commit is contained in:
@@ -28,9 +28,9 @@ namespace Orchard.Packaging.Commands {
|
||||
Create a package for the extension <extensionName>
|
||||
(an extension being a module or a theme).
|
||||
The package will be output at the <path> specified.
|
||||
The default filename is Orchard.[Module|Theme].<extensionName>.<extensionVersion>.nupkg.
|
||||
The default filename is Orchard.[Modules|Themes].<extensionName>.<extensionVersion>.nupkg.
|
||||
For example, ""package create SampleModule c:\temp"" will create the package
|
||||
""c:\temp\Orchard.Module.SampleModule.1.0.0.nupkg"".")]
|
||||
""c:\temp\Orchard.Modules.SampleModule.1.0.0.nupkg"".")]
|
||||
[CommandName("package create")]
|
||||
public void CreatePackage(string extensionName, string path) {
|
||||
var packageData = _packageManager.Harvest(extensionName);
|
||||
@@ -76,7 +76,8 @@ namespace Orchard.Packaging.Commands {
|
||||
}
|
||||
}
|
||||
|
||||
[CommandHelp("package uninstall <packageId> \r\n\t" + "Uninstall a module or a theme.")]
|
||||
[CommandHelp(@"package uninstall <packageId>
|
||||
Uninstall a module or a theme.
|
||||
The <packageId> should take the format Orchard.[Modules|Themes].<extensionName>.
|
||||
For example, ""package uninstall Orchard.Modules.SampleModule"" will uninstall the Module under the ""~/Modules/SampleModule"" directory and
|
||||
""package uninstall Orchard.Themes.SampleTheme"" will uninstall the Theme under the ""~/Themes/SampleTheme"" directory.")]
|
||||
|
@@ -39,7 +39,7 @@ namespace Orchard.Packaging.Services {
|
||||
|
||||
public override IQueryable<IPackage> GetPackages() {
|
||||
IEnumerable<IPackage> packages = from extension in _extensionManager.AvailableExtensions()
|
||||
let id = "Orchard." + extension.ExtensionType + "." + extension.Id
|
||||
let id = PackageBuilder.BuildPackageId(extension.Id, extension.ExtensionType)
|
||||
let version = Version.Parse(extension.Version)
|
||||
let package = SourceRepository.FindPackage(id, version)
|
||||
where package != null
|
||||
|
@@ -20,6 +20,7 @@ namespace Orchard.Packaging.Services {
|
||||
private static readonly string[] _ignoredThemeExtensions = new[] {
|
||||
"obj", "pdb", "exclude"
|
||||
};
|
||||
|
||||
private static readonly string[] _ignoredThemePaths = new[] {
|
||||
"/obj/"
|
||||
};
|
||||
@@ -61,9 +62,13 @@ namespace Orchard.Packaging.Services {
|
||||
|
||||
return context.Stream;
|
||||
}
|
||||
|
||||
|
||||
public static string BuildPackageId(string extensionName, string extensionType) {
|
||||
return PackagingSourceManager.GetExtensionPrefix(extensionType) + extensionName;
|
||||
}
|
||||
|
||||
private static void SetCoreProperties(CreateContext context, ExtensionDescriptor extensionDescriptor) {
|
||||
context.Builder.Id = PackagingSourceManager.GetExtensionPrefix(extensionDescriptor.ExtensionType) + extensionDescriptor.Id;
|
||||
context.Builder.Id = BuildPackageId(extensionDescriptor.Id, extensionDescriptor.ExtensionType);
|
||||
context.Builder.Version = new Version(extensionDescriptor.Version);
|
||||
context.Builder.Title = extensionDescriptor.Name ?? extensionDescriptor.Id;
|
||||
context.Builder.Description = extensionDescriptor.Description;
|
||||
|
@@ -99,15 +99,27 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
|
||||
public void Uninstall(string packageId, string applicationPath) {
|
||||
bool removed = false;
|
||||
|
||||
// this logger is used to render NuGet's log on the notifier
|
||||
var logger = new NugetLogger(_notifier);
|
||||
|
||||
string solutionPath;
|
||||
string extensionFullPath = string.Empty;
|
||||
|
||||
if (packageId.StartsWith(PackagingSourceManager.ThemesPrefix)) {
|
||||
extensionFullPath = HostingEnvironment.MapPath("~/Themes/" + packageId.Substring(PackagingSourceManager.ThemesPrefix.Length));
|
||||
} else if (packageId.StartsWith(PackagingSourceManager.ModulesPrefix)) {
|
||||
extensionFullPath = HostingEnvironment.MapPath("~/Modules/" + packageId.Substring(PackagingSourceManager.ModulesPrefix.Length));
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(extensionFullPath) ||
|
||||
!Directory.Exists(extensionFullPath)) {
|
||||
|
||||
throw new OrchardException(T("Package not found: {0}", packageId));
|
||||
}
|
||||
|
||||
// if we can access the parent directory, and the solution is inside, NuGet-uninstall the package here
|
||||
if (TryGetSolutionPath(applicationPath, out solutionPath)) {
|
||||
|
||||
// this logger is used to render NuGet's log on the notifier
|
||||
var logger = new NugetLogger(_notifier);
|
||||
|
||||
var installedPackagesPath = Path.Combine(solutionPath, PackagesPath);
|
||||
var sourcePackageRepository = new LocalPackageRepository(installedPackagesPath);
|
||||
|
||||
@@ -135,7 +147,6 @@ namespace Orchard.Packaging.Services {
|
||||
) {Logger = logger};
|
||||
|
||||
packageManager.UninstallPackage(packageId);
|
||||
removed = true;
|
||||
}
|
||||
catch {
|
||||
// Package doesnt exist anymore
|
||||
@@ -143,29 +154,8 @@ namespace Orchard.Packaging.Services {
|
||||
}
|
||||
|
||||
// If the package was not installed through nuget we still need to try to uninstall it by removing its directory
|
||||
|
||||
// Remove theme if found
|
||||
string extensionFullPath = packageId.StartsWith(PackagingSourceManager.ThemesPrefix)
|
||||
? HostingEnvironment.MapPath("~/Themes/" + packageId.Substring(PackagingSourceManager.ThemesPrefix.Length))
|
||||
: HostingEnvironment.MapPath("~/Themes/" + packageId);
|
||||
|
||||
if (Directory.Exists(extensionFullPath)) {
|
||||
if(Directory.Exists(extensionFullPath)) {
|
||||
Directory.Delete(extensionFullPath, true);
|
||||
removed = true;
|
||||
}
|
||||
|
||||
// Remove module if found
|
||||
extensionFullPath = packageId.StartsWith(PackagingSourceManager.ModulesPrefix)
|
||||
? HostingEnvironment.MapPath("~/Modules/" + packageId.Substring(PackagingSourceManager.ModulesPrefix.Length))
|
||||
: HostingEnvironment.MapPath("~/Modules/" + packageId);
|
||||
|
||||
if (Directory.Exists(extensionFullPath)) {
|
||||
Directory.Delete(extensionFullPath, true);
|
||||
removed = true;
|
||||
}
|
||||
|
||||
if (!removed) {
|
||||
throw new OrchardException(T("Package not found: {0}", packageId));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user