Skip to content

Commit ee132af

Browse files
authored
Merge pull request #11102 from umbraco/v9/bugfix/packagedatainstallation-macropartialviews
Use IFileService to save macro partial views in package migration
2 parents 241b303 + d120714 commit ee132af

File tree

6 files changed

+167
-200
lines changed

6 files changed

+167
-200
lines changed

src/Umbraco.Core/Packaging/InstallationSummary.cs

Lines changed: 39 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,17 @@ namespace Umbraco.Cms.Core.Packaging
1313
public class InstallationSummary
1414
{
1515
public InstallationSummary(string packageName)
16-
{
17-
PackageName = packageName;
18-
}
16+
=> PackageName = packageName;
17+
18+
public string PackageName { get; }
1919

2020
public InstallWarnings Warnings { get; set; } = new InstallWarnings();
2121

2222
public IEnumerable<IDataType> DataTypesInstalled { get; set; } = Enumerable.Empty<IDataType>();
2323
public IEnumerable<ILanguage> LanguagesInstalled { get; set; } = Enumerable.Empty<ILanguage>();
2424
public IEnumerable<IDictionaryItem> DictionaryItemsInstalled { get; set; } = Enumerable.Empty<IDictionaryItem>();
2525
public IEnumerable<IMacro> MacrosInstalled { get; set; } = Enumerable.Empty<IMacro>();
26+
public IEnumerable<IPartialView> MacroPartialViewsInstalled { get; set; } = Enumerable.Empty<IPartialView>();
2627
public IEnumerable<ITemplate> TemplatesInstalled { get; set; } = Enumerable.Empty<ITemplate>();
2728
public IEnumerable<IContentType> DocumentTypesInstalled { get; set; } = Enumerable.Empty<IContentType>();
2829
public IEnumerable<IMediaType> MediaTypesInstalled { get; set; } = Enumerable.Empty<IMediaType>();
@@ -31,73 +32,55 @@ public InstallationSummary(string packageName)
3132
public IEnumerable<IPartialView> PartialViewsInstalled { get; set; } = Enumerable.Empty<IPartialView>();
3233
public IEnumerable<IContent> ContentInstalled { get; set; } = Enumerable.Empty<IContent>();
3334
public IEnumerable<IMedia> MediaInstalled { get; set; } = Enumerable.Empty<IMedia>();
34-
public string PackageName { get; }
3535

3636
public override string ToString()
3737
{
3838
var sb = new StringBuilder();
39-
var macroConflicts = Warnings.ConflictingMacros.ToList();
40-
if (macroConflicts.Count > 0)
41-
{
42-
sb.Append("Conflicting macros found, they will be overwritten:");
43-
foreach(IMacro m in macroConflicts)
44-
{
45-
sb.Append(m.Alias);
46-
sb.Append(',');
47-
}
48-
sb.AppendLine(". ");
49-
}
50-
var templateConflicts = Warnings.ConflictingTemplates.ToList();
51-
if (templateConflicts.Count > 0)
39+
40+
void WriteConflicts<T>(IEnumerable<T> source, Func<T, string> selector, string message, bool appendLine = true)
5241
{
53-
sb.Append("Conflicting templates found, they will be overwritten:");
54-
foreach (ITemplate m in templateConflicts)
42+
var result = source?.Select(selector).ToList();
43+
if (result?.Count > 0)
5544
{
56-
sb.Append(m.Alias);
57-
sb.Append(',');
45+
sb.Append(message);
46+
sb.Append(string.Join(", ", result));
47+
48+
if (appendLine)
49+
{
50+
sb.AppendLine();
51+
}
5852
}
59-
sb.AppendLine(". ");
6053
}
61-
var stylesheetConflicts = Warnings.ConflictingStylesheets.ToList();
62-
if (stylesheetConflicts.Count > 0)
54+
55+
void WriteCount<T>(string message, IEnumerable<T> source, bool appendLine = true)
6356
{
64-
sb.Append("Conflicting stylesheets found, they will be overwritten:");
65-
foreach (IFile m in stylesheetConflicts)
57+
sb.Append(message);
58+
sb.Append(source?.Count() ?? 0);
59+
60+
if (appendLine)
6661
{
67-
sb.Append(m.Alias);
68-
sb.Append(',');
62+
sb.AppendLine();
6963
}
70-
sb.AppendLine(". ");
7164
}
7265

73-
sb.Append("Content items installed: ");
74-
sb.Append(ContentInstalled.Count());
75-
sb.AppendLine(". ");
76-
sb.Append("Media items installed: ");
77-
sb.Append(MediaInstalled.Count());
78-
sb.AppendLine(". ");
79-
sb.Append("Dictionary items installed: ");
80-
sb.Append(DictionaryItemsInstalled.Count());
81-
sb.AppendLine(". ");
82-
sb.Append("Macros installed: ");
83-
sb.Append(MacrosInstalled.Count());
84-
sb.AppendLine(". ");
85-
sb.Append("Stylesheets installed: ");
86-
sb.Append(StylesheetsInstalled.Count());
87-
sb.AppendLine(". ");
88-
sb.Append("Templates installed: ");
89-
sb.Append(TemplatesInstalled.Count());
90-
sb.AppendLine();
91-
sb.Append("Document types installed: ");
92-
sb.Append(DocumentTypesInstalled.Count());
93-
sb.AppendLine(". ");
94-
sb.Append("Media types installed: ");
95-
sb.Append(MediaTypesInstalled.Count());
96-
sb.AppendLine(". ");
97-
sb.Append("Data types items installed: ");
98-
sb.Append(DataTypesInstalled.Count());
66+
WriteConflicts(Warnings?.ConflictingMacros, x => x.Alias, "Conflicting macros found, they will be overwritten: ");
67+
WriteConflicts(Warnings?.ConflictingTemplates, x => x.Alias, "Conflicting templates found, they will be overwritten: ");
68+
WriteConflicts(Warnings?.ConflictingStylesheets, x => x.Alias, "Conflicting stylesheets found, they will be overwritten: ");
69+
WriteCount("Data types installed: ", DataTypesInstalled);
70+
WriteCount("Languages installed: ", LanguagesInstalled);
71+
WriteCount("Dictionary items installed: ", DictionaryItemsInstalled);
72+
WriteCount("Macros installed: ", MacrosInstalled);
73+
WriteCount("Macro partial views installed: ", MacroPartialViewsInstalled);
74+
WriteCount("Templates installed: ", TemplatesInstalled);
75+
WriteCount("Document types installed: ", DocumentTypesInstalled);
76+
WriteCount("Media types installed: ", MediaTypesInstalled);
77+
WriteCount("Stylesheets installed: ", StylesheetsInstalled);
78+
WriteCount("Scripts installed: ", ScriptsInstalled);
79+
WriteCount("Partial views installed: ", PartialViewsInstalled);
80+
WriteCount("Content items installed: ", ContentInstalled);
81+
WriteCount("Media items installed: ", MediaInstalled, false);
82+
9983
return sb.ToString();
10084
}
10185
}
102-
10386
}

src/Umbraco.Core/Packaging/PackageDefinition.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class PackageDefinition
2828
public string Name { get; set; } = string.Empty;
2929

3030
/// <summary>
31-
/// The full path to the package's xml file
31+
/// The full path to the package's XML file.
3232
/// </summary>
3333
[ReadOnly(true)]
3434
[DataMember(Name = "packagePath")]
@@ -71,12 +71,9 @@ public class PackageDefinition
7171
public IList<string> DataTypes { get; set; } = new List<string>();
7272

7373
[DataMember(Name = "mediaUdis")]
74-
public IList<GuidUdi> MediaUdis { get; set; } = Array.Empty<GuidUdi>();
74+
public IList<GuidUdi> MediaUdis { get; set; } = new List<GuidUdi>();
7575

7676
[DataMember(Name = "mediaLoadChildNodes")]
7777
public bool MediaLoadChildNodes { get; set; }
78-
79-
8078
}
81-
8279
}

src/Umbraco.Core/Packaging/PackagesRepository.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,10 @@ private void PackageMacros(PackageDefinition definition, XContainer root)
415415

416416
root.Add(macros);
417417

418-
// get the partial views for macros and package those
419-
IEnumerable<string> views = packagedMacros.Select(x => x.MacroSource).Where(x => x.EndsWith(".cshtml"));
420-
PackageMacroPartialViews(views, root);
418+
// Get the partial views for macros and package those (exclude views outside of the default directory, e.g. App_Plugins\*\Views)
419+
IEnumerable<string> views = packagedMacros.Where(x => x.MacroSource.StartsWith(Constants.SystemDirectories.MacroPartials))
420+
.Select(x => x.MacroSource.Substring(Constants.SystemDirectories.MacroPartials.Length).Replace('/', '\\'));
421+
PackageStaticFiles(views, root, "MacroPartialViews", "View", _fileSystems.MacroPartialsFileSystem);
421422
}
422423

423424
private void PackageStylesheets(PackageDefinition definition, XContainer root)
@@ -488,33 +489,6 @@ private void PackageTemplates(PackageDefinition definition, XContainer root)
488489
root.Add(templatesXml);
489490
}
490491

491-
private void PackageMacroPartialViews(IEnumerable<string> viewPaths, XContainer root)
492-
{
493-
var viewsXml = new XElement("MacroPartialViews");
494-
foreach (var viewPath in viewPaths)
495-
{
496-
// TODO: See TODO note in MacrosController about the inconsistencies of usages of partial views
497-
// and how paths are saved. We have no choice currently but to assume that all views are 100% always
498-
// on the content path.
499-
500-
var physicalPath = _hostingEnvironment.MapPathContentRoot(viewPath);
501-
if (!File.Exists(physicalPath))
502-
{
503-
throw new InvalidOperationException("Could not find partial view at path " + viewPath);
504-
}
505-
506-
var fileContents = File.ReadAllText(physicalPath, Encoding.UTF8);
507-
508-
viewsXml.Add(
509-
new XElement(
510-
"View",
511-
new XAttribute("path", viewPath),
512-
new XCData(fileContents)));
513-
}
514-
515-
root.Add(viewsXml);
516-
}
517-
518492
private void PackageDocumentTypes(PackageDefinition definition, XContainer root)
519493
{
520494
var contentTypes = new HashSet<IContentType>();

0 commit comments

Comments
 (0)