1
- using System ;
1
+ using System ;
2
2
using System . Collections . Generic ;
3
3
using System . IO ;
4
+ using System . Linq ;
4
5
using ICSharpCode . SharpZipLib . Zip ;
6
+ using Newtonsoft . Json ;
7
+ using Newtonsoft . Json . Linq ;
5
8
using Umbraco . Core ;
6
9
using Umbraco . Core . Deploy ;
10
+ using Umbraco . Core . Models ;
7
11
using Umbraco . Deploy ;
12
+ using Umbraco . Deploy . Artifacts ;
8
13
using Umbraco . Deploy . Files ;
9
14
10
15
namespace UmbracoDeploy . Contrib . Export
@@ -33,6 +38,7 @@ public static void ExportArtifacts(IEnumerable<IArtifact> artifacts, string zipA
33
38
// Export to temp directory
34
39
var exportPath = Path . Combine ( Path . GetTempPath ( ) , "Deploy" , "export-" + Guid . NewGuid ( ) ) ;
35
40
DeployComponent . DiskEntityService . WriteArtifacts ( exportPath , artifacts ) ;
41
+ AddPropertyEditorAliases ( exportPath , artifacts . OfType < ContentArtifactBase > ( ) ) ;
36
42
DeployComponent . DiskEntityService . WriteFiles ( exportPath , artifacts , fileTypes ) ;
37
43
38
44
// Create export archive and delete temp directory
@@ -43,5 +49,64 @@ public static void ExportArtifacts(IEnumerable<IArtifact> artifacts, string zipA
43
49
scope . Complete ( ) ;
44
50
}
45
51
}
52
+
53
+
54
+ private static void AddPropertyEditorAliases ( string path , IEnumerable < ContentArtifactBase > artifacts )
55
+ {
56
+ var contentTypes = ApplicationContext . Current . Services . ContentTypeService . GetAllContentTypes ( ) ;
57
+
58
+ foreach ( var artifact in artifacts )
59
+ {
60
+ var filePath = Path . Combine ( path , artifact . Udi . EntityType + "__" + artifact . Udi . Guid . ToString ( "n" ) + ".uda" ) ;
61
+
62
+ JObject json ;
63
+ using ( var file = System . IO . File . OpenText ( filePath ) )
64
+ using ( var reader = new JsonTextReader ( file ) )
65
+ {
66
+ json = ( JObject ) JToken . ReadFrom ( reader ) ;
67
+ }
68
+
69
+ json [ "PropertyEditorAliases" ] = GetPropertyEditorAliases ( contentTypes , artifact ) ;
70
+
71
+ using ( var file = System . IO . File . CreateText ( filePath ) )
72
+ using ( var writer = new JsonTextWriter ( file ) )
73
+ {
74
+ writer . Formatting = Formatting . Indented ;
75
+
76
+ json . WriteTo ( writer ) ;
77
+ }
78
+ }
79
+ }
80
+
81
+ private static JToken GetPropertyEditorAliases ( IEnumerable < IContentType > contentTypes , ContentArtifactBase artifact )
82
+ {
83
+ var propertyEditorAliases = new Dictionary < string , string > ( ) ;
84
+
85
+ foreach ( var contentType in contentTypes )
86
+ {
87
+ string prefix ;
88
+ if ( contentType . Key == artifact . ContentType . Guid )
89
+ {
90
+ // Add property editor aliases for the content type
91
+ prefix = null ;
92
+ }
93
+ else if ( artifact . Dependencies . Any ( x => x . Udi is GuidUdi guidUdi && guidUdi . EntityType == Constants . UdiEntityType . DocumentType && guidUdi . Guid == contentType . Key ) )
94
+ {
95
+ // Add prefixed property editor aliases for related content types (e.g. used by Nested Content)
96
+ prefix = contentType . Alias + "." ;
97
+ }
98
+ else
99
+ {
100
+ continue ;
101
+ }
102
+
103
+ foreach ( var propertyType in contentType . CompositionPropertyTypes )
104
+ {
105
+ propertyEditorAliases [ prefix + propertyType . Alias ] = propertyType . PropertyEditorAlias ;
106
+ }
107
+ }
108
+
109
+ return JToken . FromObject ( propertyEditorAliases ) ;
110
+ }
46
111
}
47
112
}
0 commit comments