mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#16840: Implementing module installation from local uploaded file. Removing hard dependency between Orchard.Modules and Orchard.Packaging by delegating module installation to Orchard.Packaging.
--HG-- branch : dev
This commit is contained in:
@@ -26,8 +26,8 @@ namespace Orchard.Modules.Controllers {
|
|||||||
IReportsCoordinator reportsCoordinator,
|
IReportsCoordinator reportsCoordinator,
|
||||||
IExtensionManager extensionManager,
|
IExtensionManager extensionManager,
|
||||||
IFeatureManager featureManager,
|
IFeatureManager featureManager,
|
||||||
ShellDescriptor shellDescriptor) {
|
ShellDescriptor shellDescriptor)
|
||||||
|
{
|
||||||
Services = services;
|
Services = services;
|
||||||
_moduleService = moduleService;
|
_moduleService = moduleService;
|
||||||
_dataMigrationManager = dataMigrationManager;
|
_dataMigrationManager = dataMigrationManager;
|
||||||
@@ -47,47 +47,10 @@ namespace Orchard.Modules.Controllers {
|
|||||||
return new HttpUnauthorizedResult();
|
return new HttpUnauthorizedResult();
|
||||||
|
|
||||||
var modules = _extensionManager.AvailableExtensions().Where(x => x.ExtensionType == "Module");
|
var modules = _extensionManager.AvailableExtensions().Where(x => x.ExtensionType == "Module");
|
||||||
return View(new ModulesIndexViewModel { Modules = modules });
|
|
||||||
}
|
|
||||||
|
|
||||||
public ActionResult Add() {
|
return View(new ModulesIndexViewModel {
|
||||||
return View(new ModuleAddViewModel());
|
Modules = modules,
|
||||||
}
|
InstallModules = _featureManager.GetEnabledFeatures().FirstOrDefault(f => f.Id == "Gallery") != null });
|
||||||
|
|
||||||
[HttpPost, ActionName("Add")]
|
|
||||||
public ActionResult AddPOST() {
|
|
||||||
// module not used for anything other than display (and that only to not have object in the view 'T')
|
|
||||||
var viewModel = new ModuleAddViewModel();
|
|
||||||
try {
|
|
||||||
UpdateModel(viewModel);
|
|
||||||
if (!Services.Authorizer.Authorize(Permissions.ManageModules, T("Couldn't upload module package.")))
|
|
||||||
return new HttpUnauthorizedResult();
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(Request.Files[0].FileName)) {
|
|
||||||
ModelState.AddModelError("File", T("Select a file to upload.").ToString());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ModelState.IsValid)
|
|
||||||
return View("add", viewModel);
|
|
||||||
|
|
||||||
foreach (string fileName in Request.Files) {
|
|
||||||
var file = Request.Files[fileName];
|
|
||||||
#if REFACTORING
|
|
||||||
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));
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return RedirectToAction("index");
|
|
||||||
}
|
|
||||||
catch (Exception exception) {
|
|
||||||
for (var scan = exception; scan != null; scan = scan.InnerException) {
|
|
||||||
Services.Notifier.Error(T("Uploading module package failed: {0}", exception.Message));
|
|
||||||
}
|
|
||||||
return View("add", viewModel);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ActionResult Features() {
|
public ActionResult Features() {
|
||||||
|
@@ -62,12 +62,10 @@
|
|||||||
<Compile Include="Permissions.cs" />
|
<Compile Include="Permissions.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="Services\ModuleService.cs" />
|
<Compile Include="Services\ModuleService.cs" />
|
||||||
<Compile Include="ViewModels\ModuleAddViewModel.cs" />
|
|
||||||
<Compile Include="ViewModels\ModulesIndexViewModel.cs" />
|
<Compile Include="ViewModels\ModulesIndexViewModel.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Module.txt" />
|
<Content Include="Module.txt" />
|
||||||
<Content Include="Views\Admin\Add.cshtml" />
|
|
||||||
<Content Include="Views\Admin\Index.cshtml" />
|
<Content Include="Views\Admin\Index.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@@ -75,10 +73,6 @@
|
|||||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||||
<Name>Orchard.Framework</Name>
|
<Name>Orchard.Framework</Name>
|
||||||
</ProjectReference>
|
</ProjectReference>
|
||||||
<ProjectReference Include="..\Orchard.Packaging\Orchard.Packaging.csproj">
|
|
||||||
<Project>{DFD137A2-DDB5-4D22-BE0D-FA9AD4C8B059}</Project>
|
|
||||||
<Name>Orchard.Packaging</Name>
|
|
||||||
</ProjectReference>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Content\Admin\images\disabled.gif" />
|
<Content Include="Content\Admin\images\disabled.gif" />
|
||||||
|
@@ -1,4 +0,0 @@
|
|||||||
namespace Orchard.Modules.ViewModels {
|
|
||||||
public class ModuleAddViewModel {
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,6 +3,7 @@ using Orchard.Environment.Extensions.Models;
|
|||||||
|
|
||||||
namespace Orchard.Modules.ViewModels {
|
namespace Orchard.Modules.ViewModels {
|
||||||
public class ModulesIndexViewModel {
|
public class ModulesIndexViewModel {
|
||||||
|
public bool InstallModules { get; set; }
|
||||||
public IEnumerable<ExtensionDescriptor> Modules { get; set; }
|
public IEnumerable<ExtensionDescriptor> Modules { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -97,4 +97,3 @@
|
|||||||
}</ul>
|
}</ul>
|
||||||
</li>}
|
</li>}
|
||||||
}</ul>}
|
}</ul>}
|
||||||
|
|
||||||
|
@@ -8,7 +8,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
<h1>@Html.TitleForPage(T("Installed Modules").ToString())</h1>
|
<h1>@Html.TitleForPage(T("Installed Modules").ToString())</h1>
|
||||||
<div class="manage">@Html.ActionLink(T("Install a module").ToString(), "Add", null, new { @class = "button primaryAction" })</div>
|
|
||||||
|
@if (Model.InstallModules) {
|
||||||
|
<div class="manage">@Html.ActionLink(T("Install a module").ToString(), "AddModule", "Gallery", new { area = "Orchard.Packaging", returnUrl = HttpContext.Current.Request.RawUrl }, new { @class = "button primaryAction" })</div>
|
||||||
|
}
|
||||||
|
|
||||||
@if (Model.Modules.Count() > 0) {
|
@if (Model.Modules.Count() > 0) {
|
||||||
<ul class="contentItems">
|
<ul class="contentItems">
|
||||||
@foreach (var module in Model.Modules.OrderBy(m => m.Name)) {
|
@foreach (var module in Model.Modules.OrderBy(m => m.Name)) {
|
||||||
|
@@ -1,15 +1,20 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Web;
|
||||||
using System.Web.Hosting;
|
using System.Web.Hosting;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
using NuGet;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Packaging.Services;
|
using Orchard.Packaging.Services;
|
||||||
using Orchard.Packaging.ViewModels;
|
using Orchard.Packaging.ViewModels;
|
||||||
using Orchard.Themes;
|
using Orchard.Themes;
|
||||||
using Orchard.UI.Admin;
|
using Orchard.UI.Admin;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
|
using IPackageManager = Orchard.Packaging.Services.IPackageManager;
|
||||||
|
|
||||||
namespace Orchard.Packaging.Controllers {
|
namespace Orchard.Packaging.Controllers {
|
||||||
[OrchardFeature("Gallery")]
|
[OrchardFeature("Gallery")]
|
||||||
@@ -18,18 +23,19 @@ namespace Orchard.Packaging.Controllers {
|
|||||||
|
|
||||||
private readonly IPackageManager _packageManager;
|
private readonly IPackageManager _packageManager;
|
||||||
private readonly IPackagingSourceManager _packagingSourceManager;
|
private readonly IPackagingSourceManager _packagingSourceManager;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IAppDataFolderRoot _appDataFolderRoot;
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
|
|
||||||
public GalleryController(
|
public GalleryController(
|
||||||
IPackageManager packageManager,
|
IPackageManager packageManager,
|
||||||
IPackagingSourceManager packagingSourceManager,
|
IPackagingSourceManager packagingSourceManager,
|
||||||
IExtensionManager extensionManager,
|
INotifier notifier,
|
||||||
INotifier notifier) {
|
IAppDataFolderRoot appDataFolderRoot) {
|
||||||
_packageManager = packageManager;
|
_packageManager = packageManager;
|
||||||
_packagingSourceManager = packagingSourceManager;
|
_packagingSourceManager = packagingSourceManager;
|
||||||
_extensionManager = extensionManager;
|
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
|
_appDataFolderRoot = appDataFolderRoot;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +101,6 @@ namespace Orchard.Packaging.Controllers {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ActionResult Modules(int? sourceId) {
|
public ActionResult Modules(int? sourceId) {
|
||||||
var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
var selectedSource = _packagingSourceManager.GetSources().Where(s => s.Id == sourceId).FirstOrDefault();
|
||||||
|
|
||||||
@@ -137,5 +142,43 @@ namespace Orchard.Packaging.Controllers {
|
|||||||
|
|
||||||
return RedirectToAction(redirectTo == "Themes" ? "Themes" : "Modules");
|
return RedirectToAction(redirectTo == "Themes" ? "Themes" : "Modules");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ActionResult AddModule(string returnUrl) {
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
|
||||||
|
[HttpPost, ActionName("AddModule")]
|
||||||
|
public ActionResult AddModulePOST(string returnUrl) {
|
||||||
|
// module not used for anything o2ther than display (and that only to not have object in the view 'T')
|
||||||
|
try {
|
||||||
|
if (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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!string.IsNullOrEmpty(returnUrl))
|
||||||
|
return Redirect(returnUrl);
|
||||||
|
|
||||||
|
return RedirectToAction("Modules");
|
||||||
|
} catch (Exception exception) {
|
||||||
|
for (var scan = exception; scan != null; scan = scan.InnerException) {
|
||||||
|
_notifier.Error(T("Uploading module package failed: {0}", exception.Message));
|
||||||
|
}
|
||||||
|
|
||||||
|
return View("AddModule");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -35,7 +35,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="NuGet.Core, Version=0.5.0.0, Culture=neutral, processorArchitecture=MSIL">
|
<Reference Include="NuGet.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||||
<SpecificVersion>False</SpecificVersion>
|
<SpecificVersion>False</SpecificVersion>
|
||||||
<HintPath>..\..\..\..\lib\nuget\NuGet.Core.dll</HintPath>
|
<HintPath>..\..\..\..\lib\nuget\NuGet.Core.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
@@ -93,7 +93,9 @@
|
|||||||
<Content Include="Views\Gallery\Sources.cshtml" />
|
<Content Include="Views\Gallery\Sources.cshtml" />
|
||||||
<Content Include="Views\Web.config" />
|
<Content Include="Views\Web.config" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup />
|
<ItemGroup>
|
||||||
|
<Content Include="Views\Gallery\AddModule.cshtml" />
|
||||||
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
<ProjectReference Include="..\..\..\Orchard\Orchard.Framework.csproj">
|
||||||
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
<Project>{2D1D92BB-4555-4CBE-8D0E-63563D6CE4C6}</Project>
|
||||||
@@ -118,6 +120,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="Views\Gallery\Themes.cshtml" />
|
<Content Include="Views\Gallery\Themes.cshtml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup />
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
using NuGet;
|
||||||
|
|
||||||
namespace Orchard.Packaging.Services {
|
namespace Orchard.Packaging.Services {
|
||||||
public class PackageInfo {
|
public class PackageInfo {
|
||||||
public string ExtensionName { get; set; }
|
public string ExtensionName { get; set; }
|
||||||
@@ -7,6 +9,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public interface IPackageInstaller : IDependency {
|
public interface IPackageInstaller : IDependency {
|
||||||
|
PackageInfo Install(IPackage package, string location, string applicationPath);
|
||||||
PackageInfo Install(string packageId, string version, string location, string applicationFolder);
|
PackageInfo Install(string packageId, string version, string location, string applicationFolder);
|
||||||
void Uninstall(string packageId, string applicationFolder);
|
void Uninstall(string packageId, string applicationFolder);
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
|
using NuGet;
|
||||||
|
|
||||||
namespace Orchard.Packaging.Services {
|
namespace Orchard.Packaging.Services {
|
||||||
public interface IPackageManager : IDependency {
|
public interface IPackageManager : IDependency {
|
||||||
PackageData Harvest(string extensionName);
|
PackageData Harvest(string extensionName);
|
||||||
|
PackageInfo Install(IPackage package, string location, string applicationPath);
|
||||||
PackageInfo Install(string packageId, string version, string location, string applicationPath);
|
PackageInfo Install(string packageId, string version, string location, string applicationPath);
|
||||||
void Uninstall(string packageId, string applicationPath);
|
void Uninstall(string packageId, string applicationPath);
|
||||||
}
|
}
|
||||||
|
@@ -2,25 +2,26 @@ using System;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using NuGet;
|
using NuGet;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
|
using Orchard.FileSystems.AppData;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.UI.Notify;
|
using Orchard.UI.Notify;
|
||||||
using NuGetPackageManager = NuGet.PackageManager;
|
using NuGetPackageManager = NuGet.PackageManager;
|
||||||
using System.Security.Permissions;
|
|
||||||
using System.Security;
|
|
||||||
using System.Web.Hosting;
|
|
||||||
|
|
||||||
namespace Orchard.Packaging.Services {
|
namespace Orchard.Packaging.Services {
|
||||||
[OrchardFeature("PackagingServices")]
|
[OrchardFeature("PackagingServices")]
|
||||||
public class PackageInstaller : IPackageInstaller {
|
public class PackageInstaller : IPackageInstaller {
|
||||||
private const string PackagesPath = "packages";
|
private const string PackagesPath = "packages";
|
||||||
private const string SolutionFilename = "Orchard.sln";
|
|
||||||
|
|
||||||
private readonly INotifier _notifier;
|
private readonly INotifier _notifier;
|
||||||
private readonly IExtensionManager _extensionManager;
|
private readonly IExtensionManager _extensionManager;
|
||||||
|
private readonly IAppDataFolderRoot _appDataFolderRoot;
|
||||||
|
|
||||||
public PackageInstaller(INotifier notifier, IExtensionManager extensionManager) {
|
public PackageInstaller(INotifier notifier,
|
||||||
|
IExtensionManager extensionManager,
|
||||||
|
IAppDataFolderRoot appDataFolderRoot) {
|
||||||
_notifier = notifier;
|
_notifier = notifier;
|
||||||
_extensionManager = extensionManager;
|
_extensionManager = extensionManager;
|
||||||
|
_appDataFolderRoot = appDataFolderRoot;
|
||||||
|
|
||||||
T = NullLocalizer.Instance;
|
T = NullLocalizer.Instance;
|
||||||
}
|
}
|
||||||
@@ -28,28 +29,37 @@ namespace Orchard.Packaging.Services {
|
|||||||
public Localizer T { get; set; }
|
public Localizer T { get; set; }
|
||||||
|
|
||||||
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
||||||
// this logger is used to render NuGet's log on the notifier
|
|
||||||
var logger = new NugetLogger(_notifier);
|
|
||||||
|
|
||||||
// instantiates the appropriate package repository
|
// instantiates the appropriate package repository
|
||||||
var packageRepository = PackageRepositoryFactory.Default.CreateRepository(new PackageSource("Default", location));
|
IPackageRepository packageRepository = PackageRepositoryFactory.Default.CreateRepository(new PackageSource(location, "Default"));
|
||||||
|
|
||||||
// gets an IPackage instance from the repository
|
// gets an IPackage instance from the repository
|
||||||
var packageVersion = String.IsNullOrEmpty(version) ? null : new Version(version);
|
var packageVersion = String.IsNullOrEmpty(version) ? null : new Version(version);
|
||||||
var package = packageRepository.FindPackage(packageId, packageVersion);
|
var package = packageRepository.FindPackage(packageId, packageVersion);
|
||||||
|
if (package == null)
|
||||||
if (package == null) {
|
{
|
||||||
throw new ArgumentException(T("The specified package could not be found, id:{0} version:{1}", packageId, String.IsNullOrEmpty(version) ? T("No version").Text : version).Text);
|
throw new ArgumentException(T("The specified package could not be found, id:{0} version:{1}", packageId, String.IsNullOrEmpty(version) ? T("No version").Text : version).Text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return Install(package, packageRepository, location, applicationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PackageInfo Install(IPackage package, string location, string applicationPath) {
|
||||||
|
// instantiates the appropriate package repository
|
||||||
|
IPackageRepository packageRepository = PackageRepositoryFactory.Default.CreateRepository(new PackageSource(location, "Default"));
|
||||||
|
return Install(package, packageRepository, location, applicationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PackageInfo Install(IPackage package, IPackageRepository packageRepository, string location, string applicationPath) {
|
||||||
|
// this logger is used to render NuGet's log on the notifier
|
||||||
|
var logger = new NugetLogger(_notifier);
|
||||||
|
|
||||||
bool installed = false;
|
bool installed = false;
|
||||||
|
|
||||||
// if we can access the parent directory, and the solution is inside, NuGet-install the package here
|
// if we can access the parent directory, and the solution is inside, NuGet-install the package here
|
||||||
string solutionPath;
|
var installedPackagesPath = Path.Combine(_appDataFolderRoot.RootFolder, PackagesPath);
|
||||||
var installedPackagesPath = String.Empty;
|
|
||||||
if (TryGetSolutionPath(applicationPath, out solutionPath)) {
|
try
|
||||||
installedPackagesPath = Path.Combine(solutionPath, PackagesPath);
|
{
|
||||||
try {
|
|
||||||
var packageManager = new NuGetPackageManager(
|
var packageManager = new NuGetPackageManager(
|
||||||
packageRepository,
|
packageRepository,
|
||||||
new DefaultPackagePathResolver(location),
|
new DefaultPackagePathResolver(location),
|
||||||
@@ -59,9 +69,9 @@ namespace Orchard.Packaging.Services {
|
|||||||
packageManager.InstallPackage(package, ignoreDependencies: true);
|
packageManager.InstallPackage(package, ignoreDependencies: true);
|
||||||
installed = true;
|
installed = true;
|
||||||
}
|
}
|
||||||
catch {
|
catch
|
||||||
// installing the package at the solution level failed
|
{
|
||||||
}
|
// installing the package in the appdata folder failed
|
||||||
}
|
}
|
||||||
|
|
||||||
// if the package got installed successfully, use it, otherwise use the previous repository
|
// if the package got installed successfully, use it, otherwise use the previous repository
|
||||||
@@ -75,12 +85,13 @@ namespace Orchard.Packaging.Services {
|
|||||||
new DefaultPackagePathResolver(applicationPath),
|
new DefaultPackagePathResolver(applicationPath),
|
||||||
project,
|
project,
|
||||||
new ExtensionReferenceRepository(project, sourceRepository, _extensionManager)
|
new ExtensionReferenceRepository(project, sourceRepository, _extensionManager)
|
||||||
) {Logger = logger};
|
) { Logger = logger };
|
||||||
|
|
||||||
// add the package to the project
|
// add the package to the project
|
||||||
projectManager.AddPackageReference(packageId, packageVersion);
|
projectManager.AddPackageReference(package.Id, package.Version);
|
||||||
|
|
||||||
return new PackageInfo {
|
return new PackageInfo
|
||||||
|
{
|
||||||
ExtensionName = package.Title ?? package.Id,
|
ExtensionName = package.Title ?? package.Id,
|
||||||
ExtensionVersion = package.Version.ToString(),
|
ExtensionVersion = package.Version.ToString(),
|
||||||
ExtensionType = package.Id.StartsWith("Orchard.Theme") ? "Theme" : "Module",
|
ExtensionType = package.Id.StartsWith("Orchard.Theme") ? "Theme" : "Module",
|
||||||
@@ -92,11 +103,7 @@ namespace Orchard.Packaging.Services {
|
|||||||
// this logger is used to render NuGet's log on the notifier
|
// this logger is used to render NuGet's log on the notifier
|
||||||
var logger = new NugetLogger(_notifier);
|
var logger = new NugetLogger(_notifier);
|
||||||
|
|
||||||
string solutionPath;
|
var installedPackagesPath = Path.Combine(_appDataFolderRoot.RootFolder, PackagesPath);
|
||||||
// if we can access the parent directory, and the solution is inside, NuGet-uninstall the package here
|
|
||||||
if (TryGetSolutionPath(applicationPath, out solutionPath)) {
|
|
||||||
var installedPackagesPath = Path.Combine(solutionPath, PackagesPath);
|
|
||||||
|
|
||||||
var sourcePackageRepository = new LocalPackageRepository(installedPackagesPath);
|
var sourcePackageRepository = new LocalPackageRepository(installedPackagesPath);
|
||||||
var project = new FileBasedProjectSystem(applicationPath) { Logger = logger };
|
var project = new FileBasedProjectSystem(applicationPath) { Logger = logger };
|
||||||
var projectManager = new ProjectManager(
|
var projectManager = new ProjectManager(
|
||||||
@@ -117,34 +124,5 @@ namespace Orchard.Packaging.Services {
|
|||||||
|
|
||||||
packageManager.UninstallPackage(packageId);
|
packageManager.UninstallPackage(packageId);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
// otherwise delete the folder
|
|
||||||
|
|
||||||
string extensionPath = packageId.StartsWith("Orchard.Themes.")
|
|
||||||
? "~/Themes/" + packageId.Substring("Orchard.Theme.".Length)
|
|
||||||
: "~/Modules/" + packageId.Substring("Orchard.Module.".Length);
|
|
||||||
|
|
||||||
string extensionFullPath = HostingEnvironment.MapPath(extensionPath);
|
|
||||||
|
|
||||||
if (Directory.Exists(extensionFullPath)) {
|
|
||||||
Directory.Delete(extensionFullPath, true);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new OrchardException(T("Package not found: ", packageId));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool TryGetSolutionPath(string applicationPath, out string parentPath) {
|
|
||||||
try {
|
|
||||||
parentPath = Directory.GetParent(applicationPath).Parent.FullName;
|
|
||||||
var solutionPath = Path.Combine(parentPath, SolutionFilename);
|
|
||||||
return File.Exists(solutionPath);
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
parentPath = null;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,4 +1,5 @@
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using NuGet;
|
||||||
using Orchard.Environment.Extensions;
|
using Orchard.Environment.Extensions;
|
||||||
using Orchard.Environment.Extensions.Models;
|
using Orchard.Environment.Extensions.Models;
|
||||||
|
|
||||||
@@ -33,6 +34,11 @@ namespace Orchard.Packaging.Services {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PackageInfo Install(IPackage package, string location, string applicationPath)
|
||||||
|
{
|
||||||
|
return _packageExpander.Install(package, location, applicationPath);
|
||||||
|
}
|
||||||
|
|
||||||
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
public PackageInfo Install(string packageId, string version, string location, string applicationPath) {
|
||||||
return _packageExpander.Install(packageId, version, location, applicationPath);
|
return _packageExpander.Install(packageId, version, location, applicationPath);
|
||||||
}
|
}
|
||||||
|
@@ -1,12 +1,6 @@
|
|||||||
@model ModuleAddViewModel
|
@{
|
||||||
@using Orchard.Modules.ViewModels;
|
|
||||||
@{
|
|
||||||
Style.Require("ModulesAdmin");
|
|
||||||
}
|
|
||||||
|
|
||||||
@{
|
|
||||||
<h1>@Html.TitleForPage(T("Install a Module").ToString())</h1>
|
<h1>@Html.TitleForPage(T("Install a Module").ToString())</h1>
|
||||||
using (Html.BeginFormAntiForgeryPost(Url.Action("add", new { area = "Orchard.Modules" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
|
using (Html.BeginFormAntiForgeryPost(Url.Action("AddModule", new { area = "Orchard.Gallery" }), FormMethod.Post, new { enctype = "multipart/form-data" })) {
|
||||||
Html.ValidationSummary();
|
Html.ValidationSummary();
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="ModulePackage">@T("Module Package")</label>
|
<label for="ModulePackage">@T("Module Package")</label>
|
Reference in New Issue
Block a user