Remove macros (#15794)
* Remove macros! * Clean up snippets * Add migration that deletes all macros * Review comments
This commit is contained in:
@@ -48,8 +48,6 @@ public class CompiledPackageXmlParser
|
||||
// this value is irrelevant during install.
|
||||
PackageFile = null,
|
||||
Name = package.Element("name")?.Value ?? string.Empty,
|
||||
Macros = xml.Root.Element("Macros")?.Elements("macro") ?? Enumerable.Empty<XElement>(),
|
||||
MacroPartialViews = xml.Root.Element("MacroPartialViews")?.Elements("View") ?? Enumerable.Empty<XElement>(),
|
||||
PartialViews = xml.Root.Element("PartialViews")?.Elements("View") ?? Enumerable.Empty<XElement>(),
|
||||
Templates = xml.Root.Element("Templates")?.Elements("Template") ?? Enumerable.Empty<XElement>(),
|
||||
Stylesheets = xml.Root.Element("Stylesheets")?.Elements("Stylesheet") ?? Enumerable.Empty<XElement>(),
|
||||
@@ -76,7 +74,6 @@ public class CompiledPackageXmlParser
|
||||
{
|
||||
var installWarnings = new InstallWarnings
|
||||
{
|
||||
ConflictingMacros = _conflictingPackageData.FindConflictingMacros(package.Macros),
|
||||
ConflictingTemplates = _conflictingPackageData.FindConflictingTemplates(package.Templates),
|
||||
ConflictingStylesheets = _conflictingPackageData.FindConflictingStylesheets(package.Stylesheets),
|
||||
};
|
||||
|
||||
@@ -8,13 +8,9 @@ namespace Umbraco.Cms.Core.Packaging;
|
||||
public class ConflictingPackageData
|
||||
{
|
||||
private readonly IFileService _fileService;
|
||||
private readonly IMacroService _macroService;
|
||||
|
||||
public ConflictingPackageData(IMacroService macroService, IFileService fileService)
|
||||
{
|
||||
_fileService = fileService ?? throw new ArgumentNullException(nameof(fileService));
|
||||
_macroService = macroService ?? throw new ArgumentNullException(nameof(macroService));
|
||||
}
|
||||
public ConflictingPackageData(IFileService fileService)
|
||||
=> _fileService = fileService ?? throw new ArgumentNullException(nameof(fileService));
|
||||
|
||||
public IEnumerable<IFile?>? FindConflictingStylesheets(IEnumerable<XElement>? stylesheetNodes) =>
|
||||
stylesheetNodes?
|
||||
@@ -43,18 +39,4 @@ public class ConflictingPackageData
|
||||
return _fileService.GetTemplate(xElement.Value);
|
||||
})
|
||||
.WhereNotNull();
|
||||
|
||||
public IEnumerable<IMacro?>? FindConflictingMacros(IEnumerable<XElement>? macroNodes) =>
|
||||
macroNodes?
|
||||
.Select(n =>
|
||||
{
|
||||
XElement? xElement = n.Element("alias") ?? n.Element("Alias");
|
||||
if (xElement == null)
|
||||
{
|
||||
throw new FormatException("missing a \"alias\" element in alias element");
|
||||
}
|
||||
|
||||
return _macroService.GetByAlias(xElement.Value);
|
||||
})
|
||||
.Where(v => v != null);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ public class InstallationSummary
|
||||
|
||||
public IEnumerable<IDictionaryItem> DictionaryItemsInstalled { get; set; } = Enumerable.Empty<IDictionaryItem>();
|
||||
|
||||
public IEnumerable<IMacro> MacrosInstalled { get; set; } = Enumerable.Empty<IMacro>();
|
||||
|
||||
public IEnumerable<IPartialView> MacroPartialViewsInstalled { get; set; } = Enumerable.Empty<IPartialView>();
|
||||
|
||||
public IEnumerable<ITemplate> TemplatesInstalled { get; set; } = Enumerable.Empty<ITemplate>();
|
||||
|
||||
public IEnumerable<IContentType> DocumentTypesInstalled { get; set; } = Enumerable.Empty<IContentType>();
|
||||
@@ -74,14 +70,11 @@ public class InstallationSummary
|
||||
}
|
||||
}
|
||||
|
||||
WriteConflicts(Warnings?.ConflictingMacros, x => x?.Alias, "Conflicting macros found, they will be overwritten: ");
|
||||
WriteConflicts(Warnings?.ConflictingTemplates, x => x.Alias, "Conflicting templates found, they will be overwritten: ");
|
||||
WriteConflicts(Warnings?.ConflictingStylesheets, x => x?.Alias, "Conflicting stylesheets found, they will be overwritten: ");
|
||||
WriteCount("Data types installed: ", DataTypesInstalled);
|
||||
WriteCount("Languages installed: ", LanguagesInstalled);
|
||||
WriteCount("Dictionary items installed: ", DictionaryItemsInstalled);
|
||||
WriteCount("Macros installed: ", MacrosInstalled);
|
||||
WriteCount("Macro partial views installed: ", MacroPartialViewsInstalled);
|
||||
WriteCount("Templates installed: ", TemplatesInstalled);
|
||||
WriteCount("Document types installed: ", DocumentTypesInstalled);
|
||||
WriteCount("Media types installed: ", MediaTypesInstalled);
|
||||
|
||||
@@ -36,9 +36,6 @@ public class PackageDefinition
|
||||
[DataMember(Name = "contentNodeId")]
|
||||
public string? ContentNodeId { get; set; }
|
||||
|
||||
[DataMember(Name = "macros")]
|
||||
public IList<string> Macros { get; set; } = new List<string>();
|
||||
|
||||
[DataMember(Name = "languages")]
|
||||
public IList<string> Languages { get; set; } = new List<string>();
|
||||
|
||||
|
||||
@@ -30,10 +30,6 @@ public class PackageDefinitionXmlParser
|
||||
xml.Element("media")?.Elements("nodeUdi").Select(x => (GuidUdi)UdiParser.Parse(x.Value)).ToList() ??
|
||||
EmptyGuidUdiList,
|
||||
MediaLoadChildNodes = xml.Element("media")?.AttributeValue<bool>("loadChildNodes") ?? false,
|
||||
Macros =
|
||||
xml.Element("macros")?.Value
|
||||
.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
|
||||
EmptyStringList,
|
||||
Templates =
|
||||
xml.Element("templates")?.Value
|
||||
.Split(Constants.CharArrays.Comma, StringSplitOptions.RemoveEmptyEntries).ToList() ??
|
||||
@@ -92,7 +88,6 @@ public class PackageDefinitionXmlParser
|
||||
new XElement("partialViews", string.Join(",", def.PartialViews ?? Array.Empty<string>())),
|
||||
new XElement("documentTypes", string.Join(",", def.DocumentTypes ?? Array.Empty<string>())),
|
||||
new XElement("mediaTypes", string.Join(",", def.MediaTypes ?? Array.Empty<string>())),
|
||||
new XElement("macros", string.Join(",", def.Macros ?? Array.Empty<string>())),
|
||||
new XElement("languages", string.Join(",", def.Languages ?? Array.Empty<string>())),
|
||||
new XElement("dictionaryitems", string.Join(",", def.DictionaryItems ?? Array.Empty<string>())),
|
||||
new XElement(
|
||||
|
||||
@@ -28,7 +28,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
private readonly FileSystems _fileSystems;
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly ILocalizationService _languageService;
|
||||
private readonly IMacroService _macroService;
|
||||
private readonly MediaFileManager _mediaFileManager;
|
||||
private readonly IMediaService _mediaService;
|
||||
private readonly IMediaTypeService _mediaTypeService;
|
||||
@@ -45,7 +44,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
/// <param name="contentTypeService"></param>
|
||||
/// <param name="dataTypeService"></param>
|
||||
/// <param name="fileService"></param>
|
||||
/// <param name="macroService"></param>
|
||||
/// <param name="languageService"></param>
|
||||
/// <param name="hostingEnvironment"></param>
|
||||
/// <param name="serializer"></param>
|
||||
@@ -65,7 +63,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
IContentTypeService contentTypeService,
|
||||
IDataTypeService dataTypeService,
|
||||
IFileService fileService,
|
||||
IMacroService macroService,
|
||||
ILocalizationService languageService,
|
||||
IHostingEnvironment hostingEnvironment,
|
||||
IEntityXmlSerializer serializer,
|
||||
@@ -88,7 +85,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
_contentTypeService = contentTypeService;
|
||||
_dataTypeService = dataTypeService;
|
||||
_fileService = fileService;
|
||||
_macroService = macroService;
|
||||
_languageService = languageService;
|
||||
_serializer = serializer;
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
@@ -234,7 +230,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
PackageStylesheets(definition, root);
|
||||
PackageStaticFiles(definition.Scripts, root, "Scripts", "Script", _fileSystems.ScriptsFileSystem);
|
||||
PackageStaticFiles(definition.PartialViews, root, "PartialViews", "View", _fileSystems.PartialViewsFileSystem);
|
||||
PackageMacros(definition, root);
|
||||
PackageDictionaryItems(definition, root);
|
||||
PackageLanguages(definition, root);
|
||||
PackageDataTypes(definition, root);
|
||||
@@ -467,39 +462,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
}
|
||||
}
|
||||
|
||||
private void PackageMacros(PackageDefinition definition, XContainer root)
|
||||
{
|
||||
var packagedMacros = new List<IMacro>();
|
||||
var macros = new XElement("Macros");
|
||||
foreach (var macroId in definition.Macros)
|
||||
{
|
||||
if (!int.TryParse(macroId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var outInt))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
XElement? macroXml = GetMacroXml(outInt, out IMacro? macro);
|
||||
if (macroXml == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
macros.Add(macroXml);
|
||||
if (macro is not null)
|
||||
{
|
||||
packagedMacros.Add(macro);
|
||||
}
|
||||
}
|
||||
|
||||
root.Add(macros);
|
||||
|
||||
// Get the partial views for macros and package those (exclude views outside of the default directory, e.g. App_Plugins\*\Views)
|
||||
IEnumerable<string> views = packagedMacros.Where(x => x.MacroSource is not null)
|
||||
.Where(x => x.MacroSource!.StartsWith(Constants.SystemDirectories.MacroPartials))
|
||||
.Select(x => x.MacroSource![Constants.SystemDirectories.MacroPartials.Length..].Replace('/', '\\'));
|
||||
PackageStaticFiles(views, root, "MacroPartialViews", "View", _fileSystems.MacroPartialsFileSystem);
|
||||
}
|
||||
|
||||
private void PackageStylesheets(PackageDefinition definition, XContainer root)
|
||||
{
|
||||
var stylesheetsXml = new XElement("Stylesheets");
|
||||
@@ -761,19 +723,6 @@ public class PackagesRepository : ICreatedPackagesRepository
|
||||
return mediaStreams;
|
||||
}
|
||||
|
||||
// TODO: Delete this
|
||||
private XElement? GetMacroXml(int macroId, out IMacro? macro)
|
||||
{
|
||||
macro = _macroService.GetById(macroId);
|
||||
if (macro == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
XElement xml = _serializer.Serialize(macro);
|
||||
return xml;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a umbraco stylesheet to a package xml node
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user