Move created packages out of webroot
This commit is contained in:
@@ -45,15 +45,11 @@ namespace Umbraco.Cms.Core
|
||||
|
||||
public const string AppPlugins = "/App_Plugins";
|
||||
|
||||
|
||||
[Obsolete("Use PluginIcons instead")]
|
||||
public static string AppPluginIcons => "/Backoffice/Icons";
|
||||
|
||||
public const string PluginIcons = "/backoffice/icons";
|
||||
|
||||
public const string CreatedPackages = "/created-packages";
|
||||
|
||||
|
||||
public const string MvcViews = "~/Views";
|
||||
|
||||
public const string PartialViews = MvcViews + "/Partials/";
|
||||
@@ -62,6 +58,8 @@ namespace Umbraco.Cms.Core
|
||||
|
||||
public const string Packages = Data + "/packages";
|
||||
|
||||
public const string CreatedPackages = Data + "/CreatedPackages";
|
||||
|
||||
public const string Preview = Data + "/preview";
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Umbraco.Cms.Core.Configuration.Models;
|
||||
@@ -33,7 +32,7 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
private readonly IEntityXmlSerializer _serializer;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly string _packageRepositoryFileName;
|
||||
private readonly string _mediaFolderPath;
|
||||
private readonly string _createdPackagesFolderPath;
|
||||
private readonly string _packagesFolderPath;
|
||||
private readonly string _tempFolderPath;
|
||||
private readonly PackageDefinitionXmlParser _parser;
|
||||
@@ -93,7 +92,7 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
|
||||
_tempFolderPath = tempFolderPath ?? Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles";
|
||||
_packagesFolderPath = packagesFolderPath ?? Constants.SystemDirectories.Packages;
|
||||
_mediaFolderPath = mediaFolderPath ?? Path.Combine(globalSettings.Value.UmbracoMediaPhysicalRootPath, Constants.SystemDirectories.CreatedPackages);
|
||||
_createdPackagesFolderPath = mediaFolderPath ?? Constants.SystemDirectories.CreatedPackages;
|
||||
|
||||
_parser = new PackageDefinitionXmlParser();
|
||||
_mediaService = mediaService;
|
||||
@@ -250,15 +249,8 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
var directoryName =
|
||||
_hostingEnvironment.MapPathWebRoot(Path.Combine(_mediaFolderPath, definition.Name.Replace(' ', '_')));
|
||||
|
||||
if (Directory.Exists(directoryName) == false)
|
||||
{
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
var directoryName = _hostingEnvironment.MapPathContentRoot(Path.Combine(_createdPackagesFolderPath, definition.Name.Replace(' ', '_')));
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
var finalPackagePath = Path.Combine(directoryName, fileName);
|
||||
|
||||
@@ -276,14 +268,14 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
}
|
||||
finally
|
||||
{
|
||||
//Clean up
|
||||
// Clean up
|
||||
Directory.Delete(temporaryPath, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void ValidatePackage(PackageDefinition definition)
|
||||
{
|
||||
//ensure it's valid
|
||||
// ensure it's valid
|
||||
var context = new ValidationContext(definition, serviceProvider: null, items: null);
|
||||
var results = new List<ValidationResult>();
|
||||
var isValid = Validator.TryValidateObject(definition, context, results);
|
||||
@@ -732,7 +724,6 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
private XDocument EnsureStorage(out string packagesFile)
|
||||
{
|
||||
var packagesFolder = _hostingEnvironment.MapPathContentRoot(_packagesFolderPath);
|
||||
//ensure it exists
|
||||
Directory.CreateDirectory(packagesFolder);
|
||||
|
||||
packagesFile = _hostingEnvironment.MapPathContentRoot(CreatedPackagesFile);
|
||||
@@ -740,6 +731,8 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
{
|
||||
var xml = new XDocument(new XElement("packages"));
|
||||
xml.Save(packagesFile);
|
||||
|
||||
return xml;
|
||||
}
|
||||
|
||||
var packagesXml = XDocument.Load(packagesFile);
|
||||
@@ -749,9 +742,16 @@ namespace Umbraco.Cms.Core.Packaging
|
||||
public void DeleteLocalRepositoryFiles()
|
||||
{
|
||||
var packagesFile = _hostingEnvironment.MapPathContentRoot(CreatedPackagesFile);
|
||||
File.Delete(packagesFile);
|
||||
if (File.Exists(packagesFile))
|
||||
{
|
||||
File.Delete(packagesFile);
|
||||
}
|
||||
|
||||
var packagesFolder = _hostingEnvironment.MapPathContentRoot(_packagesFolderPath);
|
||||
Directory.Delete(packagesFolder);
|
||||
if (Directory.Exists(packagesFolder))
|
||||
{
|
||||
Directory.Delete(packagesFolder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
private readonly IMacroService _macroService;
|
||||
private readonly IContentTypeService _contentTypeService;
|
||||
private readonly string _tempFolderPath;
|
||||
private readonly string _mediaFolderPath;
|
||||
private readonly string _createdPackagesFolderPath;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="CreatedPackageSchemaRepository"/> class.
|
||||
@@ -76,9 +76,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
_macroService = macroService;
|
||||
_contentTypeService = contentTypeService;
|
||||
_xmlParser = new PackageDefinitionXmlParser();
|
||||
_mediaFolderPath = mediaFolderPath ?? Path.Combine(globalSettings.Value.UmbracoMediaPhysicalRootPath, Constants.SystemDirectories.CreatedPackages);
|
||||
_tempFolderPath =
|
||||
tempFolderPath ?? Constants.SystemDirectories.TempData.EnsureEndsWith('/') + "PackageFiles";
|
||||
_createdPackagesFolderPath = mediaFolderPath ?? Constants.SystemDirectories.CreatedPackages;
|
||||
_tempFolderPath = tempFolderPath ?? Constants.SystemDirectories.TempData + "/PackageFiles";
|
||||
}
|
||||
|
||||
public IEnumerable<PackageDefinition> GetAll()
|
||||
@@ -192,17 +191,12 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
|
||||
public string ExportPackage(PackageDefinition definition)
|
||||
{
|
||||
|
||||
// Ensure it's valid
|
||||
ValidatePackage(definition);
|
||||
|
||||
// Create a folder for building this package
|
||||
var temporaryPath =
|
||||
_hostingEnvironment.MapPathContentRoot(_tempFolderPath.EnsureEndsWith('/') + Guid.NewGuid());
|
||||
if (Directory.Exists(temporaryPath) == false)
|
||||
{
|
||||
Directory.CreateDirectory(temporaryPath);
|
||||
}
|
||||
var temporaryPath = _hostingEnvironment.MapPathContentRoot(Path.Combine(_tempFolderPath, Guid.NewGuid().ToString()));
|
||||
Directory.CreateDirectory(temporaryPath);
|
||||
|
||||
try
|
||||
{
|
||||
@@ -218,8 +212,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
PackageTemplates(definition, root);
|
||||
PackageStylesheets(definition, root);
|
||||
PackageStaticFiles(definition.Scripts, root, "Scripts", "Script", _fileSystems.ScriptsFileSystem);
|
||||
PackageStaticFiles(definition.PartialViews, root, "PartialViews", "View",
|
||||
_fileSystems.PartialViewsFileSystem);
|
||||
PackageStaticFiles(definition.PartialViews, root, "PartialViews", "View", _fileSystems.PartialViewsFileSystem);
|
||||
PackageMacros(definition, root);
|
||||
PackageDictionaryItems(definition, root);
|
||||
PackageLanguages(definition, root);
|
||||
@@ -265,27 +258,25 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
}
|
||||
}
|
||||
|
||||
var directoryName =
|
||||
_hostingEnvironment.MapPathWebRoot(
|
||||
Path.Combine(_mediaFolderPath, definition.Name.Replace(' ', '_')));
|
||||
|
||||
if (Directory.Exists(directoryName) == false)
|
||||
{
|
||||
Directory.CreateDirectory(directoryName);
|
||||
}
|
||||
var directoryName = _hostingEnvironment.MapPathContentRoot(Path.Combine(_createdPackagesFolderPath, definition.Name.Replace(' ', '_')));
|
||||
Directory.CreateDirectory(directoryName);
|
||||
|
||||
var finalPackagePath = Path.Combine(directoryName, fileName);
|
||||
|
||||
if (File.Exists(finalPackagePath))
|
||||
// Clean existing XML and ZIP files
|
||||
foreach (var packagePath in new[]
|
||||
{
|
||||
File.Delete(finalPackagePath);
|
||||
}
|
||||
|
||||
if (File.Exists(finalPackagePath.Replace("zip", "xml")))
|
||||
{
|
||||
File.Delete(finalPackagePath.Replace("zip", "xml"));
|
||||
Path.ChangeExtension(finalPackagePath, "xml"),
|
||||
Path.ChangeExtension(finalPackagePath, "zip")
|
||||
})
|
||||
{
|
||||
if (File.Exists(packagePath))
|
||||
{
|
||||
File.Delete(packagePath);
|
||||
}
|
||||
}
|
||||
|
||||
// Move to final package path
|
||||
File.Move(tempPackagePath, finalPackagePath);
|
||||
|
||||
definition.PackagePath = finalPackagePath;
|
||||
|
||||
Reference in New Issue
Block a user