Merge v10/dev into infrastructure

This commit is contained in:
Nikolaj Geisle
2022-03-16 14:39:28 +01:00
481 changed files with 13916 additions and 6767 deletions

View File

@@ -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()
@@ -144,7 +143,7 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
.Delete<CreatedPackageSchemaDto>()
.Where<CreatedPackageSchemaDto>(x => x.Id == id);
_umbracoDatabase.Delete<CreatedPackageSchemaDto>(query);
_umbracoDatabase.Execute(query);
}
public bool SavePackage(PackageDefinition definition)
@@ -175,10 +174,8 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
};
// Set the ids, we have to save in database first to get the Id
definition.PackageId = dto.PackageId;
var result = _umbracoDatabase!.Insert(dto);
var decimalResult = result.SafeCast<decimal>();
definition.Id = decimal.ToInt32(decimalResult);
_umbracoDatabase!.Insert(dto);
definition.Id = dto.Id;
}
// Save snapshot locally, we do this to the updated packagePath
@@ -199,17 +196,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
{
@@ -225,8 +217,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);
@@ -272,27 +263,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 files
foreach (var packagePath in new[]
{
File.Delete(finalPackagePath);
}
if (File.Exists(finalPackagePath.Replace("zip", "xml")))
{
File.Delete(finalPackagePath.Replace("zip", "xml"));
definition.PackagePath,
finalPackagePath
})
{
if (File.Exists(packagePath))
{
File.Delete(packagePath);
}
}
// Move to final package path
File.Move(tempPackagePath, finalPackagePath);
definition.PackagePath = finalPackagePath;