New Backoffice: Package controller (#13578)
* Adding migration to update the default GUID value of created packages * Updating the GUID if it is the default value when a package is saved * Adding PackageDefinitionViewModel for representing a package * Adding a mapping for package representation * Adding PackageControllerBase, GetAllCreated and GetEmpty endpoints * Adding GetCreatedByKey endpoint * Adding GetByKey implementation for created packages * Include MapAll comment * Adding Download package endpoint * Saving created package endpoint * Adding a factory to create a PackageDefinition from view model * Cleanup * Fix error message * Check for duplicate package name * Remove commented out DuplicateNameException * Moving created packages to /created folder/base * Implement delete endpoint * Update OpenApi.json * Fix package route * Fix OpenApi.json * Add Ok() around the result * Create PackageBuilderExtensions * Adding suppression changes * Cleanup * Use ProblemDetailsBuilder * Extract collecting installed packages from package migration plans into its own method * Use GetInstalledPackagesFromMigrationPlans to return all migration statuses * Add Status to DictionaryControllerBase ProblemDetails * Implement RunMigrationPackageController * Adding more information to the log message * Update OpenApi.json * Change param name * Fix OpenApi.json * Fix response type for Log viewer endpoint * Remove EmptyPackageController * Rename to RunPendingPackageMigrations * Introduce new PackageOperationStatus * Making methods async and introducing new Create, Update and Delete methods * Fix async calls * Fix Mapper - multiple enumeration and cleanup * Creating special action models * Fixing the factory with new models changes * Service implementation changes * Removing SaveCreatedPackageController as the functionality is split between Create and UpdateCreatedPackageController * Utilize the new DeleteCreatedPackageAsync * Refactor DownloadCreatedPackageController as some responsibility is moved to the service * Refactor PackagingService to use auditService * Refactor PackagingService to use skip/take * Refactor services to return pagedmodel * Refactor controller to use new return value * update OpenApi.json --------- Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
committed by
GitHub
parent
b96302a9da
commit
c2ecc8dc33
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Globalization;
|
||||
using System.IO.Compression;
|
||||
using System.Xml.Linq;
|
||||
@@ -88,12 +89,9 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
List<CreatedPackageSchemaDto> xmlSchemas = _umbracoDatabase.Fetch<CreatedPackageSchemaDto>(query);
|
||||
foreach (CreatedPackageSchemaDto packageSchema in xmlSchemas)
|
||||
{
|
||||
var packageDefinition = _xmlParser.ToPackageDefinition(XElement.Parse(packageSchema.Value));
|
||||
PackageDefinition? packageDefinition = CreatePackageDefinitionFromSchema(packageSchema);
|
||||
if (packageDefinition is not null)
|
||||
{
|
||||
packageDefinition.Id = packageSchema.Id;
|
||||
packageDefinition.Name = packageSchema.Name;
|
||||
packageDefinition.PackageId = packageSchema.PackageId;
|
||||
packageDefinitions.Add(packageDefinition);
|
||||
}
|
||||
}
|
||||
@@ -107,6 +105,7 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
.Select<CreatedPackageSchemaDto>()
|
||||
.From<CreatedPackageSchemaDto>()
|
||||
.Where<CreatedPackageSchemaDto>(x => x.Id == id);
|
||||
|
||||
List<CreatedPackageSchemaDto> schemaDtos = _umbracoDatabase.Fetch<CreatedPackageSchemaDto>(query);
|
||||
|
||||
if (schemaDtos.IsCollectionEmpty())
|
||||
@@ -114,16 +113,24 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
return null;
|
||||
}
|
||||
|
||||
CreatedPackageSchemaDto packageSchema = schemaDtos.First();
|
||||
var packageDefinition = _xmlParser.ToPackageDefinition(XElement.Parse(packageSchema.Value));
|
||||
if (packageDefinition is not null)
|
||||
return CreatePackageDefinitionFromSchema(schemaDtos.First());
|
||||
}
|
||||
|
||||
public PackageDefinition? GetByKey(Guid key)
|
||||
{
|
||||
Sql<ISqlContext> query = new Sql<ISqlContext>(_umbracoDatabase!.SqlContext)
|
||||
.Select<CreatedPackageSchemaDto>()
|
||||
.From<CreatedPackageSchemaDto>()
|
||||
.Where<CreatedPackageSchemaDto>(x => x.PackageId == key);
|
||||
|
||||
List<CreatedPackageSchemaDto> schemaDtos = _umbracoDatabase.Fetch<CreatedPackageSchemaDto>(query);
|
||||
|
||||
if (schemaDtos.IsCollectionEmpty())
|
||||
{
|
||||
packageDefinition.Id = packageSchema.Id;
|
||||
packageDefinition.Name = packageSchema.Name;
|
||||
packageDefinition.PackageId = packageSchema.PackageId;
|
||||
return null;
|
||||
}
|
||||
|
||||
return packageDefinition;
|
||||
return CreatePackageDefinitionFromSchema(schemaDtos.First());
|
||||
}
|
||||
|
||||
public void Delete(int id)
|
||||
@@ -149,7 +156,7 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
throw new NullReferenceException("PackageDefinition cannot be null when saving");
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(definition.Name) || definition.PackagePath == null)
|
||||
if (string.IsNullOrEmpty(definition.Name))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -159,6 +166,17 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
|
||||
if (definition.Id == default)
|
||||
{
|
||||
Sql<ISqlContext> query = new Sql<ISqlContext>(_umbracoDatabase!.SqlContext)
|
||||
.SelectCount()
|
||||
.From<CreatedPackageSchemaDto>()
|
||||
.Where<CreatedPackageSchemaDto>(x => x.Name == definition.Name);
|
||||
var exists = _umbracoDatabase.ExecuteScalar<int>(query);
|
||||
|
||||
if (exists > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create dto from definition
|
||||
var dto = new CreatedPackageSchemaDto
|
||||
{
|
||||
@@ -173,6 +191,11 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
definition.Id = dto.Id;
|
||||
}
|
||||
|
||||
if (definition.PackageId == default)
|
||||
{
|
||||
definition.PackageId = Guid.NewGuid();
|
||||
}
|
||||
|
||||
// Save snapshot locally, we do this to the updated packagePath
|
||||
ExportPackage(definition);
|
||||
|
||||
@@ -749,4 +772,18 @@ public class CreatedPackageSchemaRepository : ICreatedPackagesRepository
|
||||
mediaTypes.Add(mediaType);
|
||||
}
|
||||
}
|
||||
|
||||
private PackageDefinition? CreatePackageDefinitionFromSchema(CreatedPackageSchemaDto packageSchema)
|
||||
{
|
||||
var packageDefinition = _xmlParser.ToPackageDefinition(XElement.Parse(packageSchema.Value));
|
||||
|
||||
if (packageDefinition is not null)
|
||||
{
|
||||
packageDefinition.Id = packageSchema.Id;
|
||||
packageDefinition.Name = packageSchema.Name;
|
||||
packageDefinition.PackageId = packageSchema.PackageId;
|
||||
}
|
||||
|
||||
return packageDefinition;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user