Skip to content

Commit 4ea50b8

Browse files
authored
Merge pull request #76 from aem-design/develop
Develop
2 parents 8627293 + e8cf52e commit 4ea50b8

File tree

29 files changed

+1919
-125
lines changed

29 files changed

+1919
-125
lines changed
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
Param(
2+
#equivalent of using localhost in docker container
3+
[string]$AEM_HOST = "localhost",
4+
# TCP port SOURCE_CQ listens on
5+
[string]$AEM_PORT = "4502",
6+
# AEM Admin user for AEM_HOST
7+
[string]$AEM_USER = "admin",
8+
# AEM Admin password for AEM_HOST
9+
[string]$AEM_PASSWORD = "admin",
10+
# Server WebDav Path
11+
#$AEM_WEBDAV_PATH = "/crx/server/crx.default/jcr:root/"
12+
[string]$AEM_WEBDAV_PATH = "/crx",
13+
[string]$AEM_SCHEMA = "http",
14+
#to set additional flags if required
15+
[string]$VLT_FLAGS = "--insecure -Xmx2g",
16+
[string]$VLT_CMD = "../tools/vault-cli/bin/vlt",
17+
# Root folder name for placing content
18+
[string]$CONTENT_DESTINATION = (Resolve-Path -Path ".\src\main\content" -Relative),
19+
[string]$FILTER_FILE = "${CONTENT_DESTINATION}\META-INF\vault\filter.xml",
20+
[string]$FILTER_FILE_LOCATION = "${CONTENT_DESTINATION}\META-INF",
21+
[string[]]$ROOT_PATHS,
22+
[switch]$Silent = $false,
23+
[string]$LOG_PATH = "..\logs"
24+
)
25+
26+
Function Format-XMLIndent
27+
{
28+
[Cmdletbinding()]
29+
[Alias("IndentXML")]
30+
param
31+
(
32+
[Parameter(ValueFromPipeline)]
33+
[xml]$Content,
34+
[int]$Indent
35+
)
36+
37+
# String Writer and XML Writer objects to write XML to string
38+
$StringWriter = New-Object System.IO.StringWriter
39+
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
40+
41+
# Default = None, change Formatting to Indented
42+
$xmlWriter.Formatting = "indented"
43+
44+
# Gets or sets how many IndentChars to write for each level in
45+
# the hierarchy when Formatting is set to Formatting.Indented
46+
$xmlWriter.Indentation = $Indent
47+
48+
$Content.WriteContentTo($XmlWriter)
49+
$XmlWriter.Flush();$StringWriter.Flush()
50+
$StringWriter.ToString()
51+
}
52+
53+
54+
Function GetFilterList
55+
{
56+
[Cmdletbinding()]
57+
[Alias("filterList")]
58+
param
59+
(
60+
[Parameter(ValueFromPipeline)]
61+
[string]$FILTER_FILE = ".\src\main\content\META-INF\vault\filter.xml"
62+
)
63+
$FILTER_PATHS = [System.Collections.ArrayList]::new()
64+
65+
$FILTER_XML = [xml](Get-Content $FILTER_FILE)
66+
$FILTER_XML_CONTENT = $FILTER_XML.SelectNodes("//workspaceFilter")
67+
$FILTER_XML_ITEMS = $FILTER_XML_CONTENT.SelectNodes('//filter')
68+
$FILTER_XML_ITEMS | ForEach-Object {
69+
[void]$FILTER_PATHS.Add($_.root)
70+
}
71+
72+
return $FILTER_PATHS
73+
}
74+
75+
if (-not($ROOT_PATHS)) {
76+
$ROOT_PATHS = GetFilterList
77+
}
78+
79+
Write-Output "------- CONFIG ----------"
80+
Write-Output "AEM_SCHEMA: $AEM_SCHEMA"
81+
Write-Output "AEM_HOST: $AEM_HOST"
82+
Write-Output "AEM_PORT: $AEM_PORT"
83+
Write-Output "AEM_USER: $AEM_USER"
84+
Write-Output "CONTENT_DESTINATION: $CONTENT_DESTINATION"
85+
Write-Output "ROOT_PATHS: $ROOT_PATHS"
86+
Write-Output "FILTER_FILE: $FILTER_FILE"
87+
Write-Output "Silent: $Silent"
88+
Write-Output "VLT_FLAGS: $VLT_FLAGS"
89+
Write-Output "VLT_CMD:"
90+
91+
$ROOT_PATHS | ForEach-Object {
92+
Write-Output "${VLT_CMD} ${VLT_FLAGS} --credentials ${AEM_USER}:****** export -v ${AEM_SCHEMA}://${AEM_HOST}:${AEM_PORT}${AEM_WEBDAV_PATH} $_ ${CONTENT_DESTINATION}"
93+
}
94+
95+
if (-not($Silent))
96+
{
97+
$START = Read-Host -Prompt 'Do you want to start export with these settings? (y/n)'
98+
99+
if ($START -ne "y")
100+
{
101+
Write-Output "Quiting..."
102+
Exit
103+
}
104+
}
105+
106+
Write-Output "------- START Exporting content ----------"
107+
$ROOT_PATHS_LAST = $ROOT_PATHS | Select-Object -Last 1
108+
$ROOT_PATHS | ForEach-Object {
109+
Write-Output "START Export $_"
110+
$LOG_FILENAME = "$_".Replace("/","-")
111+
112+
Write-Output "Remove Filer..."
113+
Copy-Item ".\src\main\content\META-INF\vault\filter-blank.xml" -Destination "$FILTER_FILE"
114+
115+
Write-Output "Create filter for: $_"
116+
$FILTER_XML = [xml](Get-Content $FILTER_FILE)
117+
$FILTER_XML_CONTENT = $FILTER_XML.SelectNodes("//workspaceFilter")
118+
$FILTER_XML_DELETE = $FILTER_XML_CONTENT.SelectNodes('//filter')
119+
$FILTER_XML_DELETE | ForEach-Object{
120+
$DELETE_STATUS = $FILTER_XML_CONTENT.RemoveChild($_)
121+
}
122+
$FILTER_XML_CONTENT_NEW = $FILTER_XML.CreateNode("element","filter","")
123+
$FILTER_XML_CONTENT_NEW.SetAttribute("root",$_)
124+
$FILTER_XML_CONTENT_NEW_ADD = $FILTER_XML_CONTENT.AppendChild($FILTER_XML_CONTENT_NEW)
125+
Write-Output "Saving..."
126+
$FILTER_XML.OuterXml | IndentXML -Indent 4 | Out-File $FILTER_FILE -encoding "UTF8"
127+
Write-Output "Done..."
128+
129+
Write-Output "Running VLT..."
130+
Invoke-Expression -Command "${VLT_CMD} ${VLT_FLAGS} --credentials ${AEM_USER}:${AEM_PASSWORD} export -v ${AEM_SCHEMA}://${AEM_HOST}:${AEM_PORT}${AEM_WEBDAV_PATH} $_ ${CONTENT_DESTINATION}" | Tee-Object -FilePath "${LOG_PATH}\filevailt-export-$LOG_FILENAME.log"
131+
132+
Write-Output "END Export $_"
133+
}
134+
135+
Write-Output "------- END Exporting content ----------"
136+
137+
Write-Output "------- START Updating ${FILTER_FILE} ----------"
138+
139+
$FILTER_XML = [xml](Get-Content $FILTER_FILE)
140+
Write-Output "Removing Existing Filters..."
141+
$FILTER_XML_CONTENT = $FILTER_XML.SelectNodes("//workspaceFilter")
142+
$FILTER_XML_DELETE = $FILTER_XML_CONTENT.SelectNodes('//filter')
143+
$FILTER_XML_DELETE | ForEach-Object{
144+
$DELETE_STATUS = $FILTER_XML_CONTENT.RemoveChild($_)
145+
}
146+
Write-Output "Adding Exported Filters..."
147+
$ROOT_PATHS | ForEach-Object {
148+
$FILTER_XML_CONTENT_NEW = $FILTER_XML.CreateNode("element","filter","")
149+
$FILTER_XML_CONTENT_NEW.SetAttribute("root",$_)
150+
$FILTER_XML_CONTENT_NEW_ADD = $FILTER_XML_CONTENT.AppendChild($FILTER_XML_CONTENT_NEW)
151+
}
152+
Write-Output "Saving..."
153+
$FILTER_XML.OuterXml | IndentXML -Indent 4 | Out-File $FILTER_FILE -encoding "UTF8"
154+
Write-Output "Done."
155+
Write-Output "------- DONE Updating ${FILTER_FILE} ----------"
156+
157+
Write-Output "------- Revert Filter.xml ----------"
158+
git checkout HEAD src/main/content/META-INF/
159+
git clean -fx src/main/content/META-INF
160+
Write-Output "------- Revert Filter.xml ----------"
Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
Param(
2+
#equivalent of using localhost in docker container
3+
[string]$AEM_HOST = "localhost",
4+
# TCP port SOURCE_CQ listens on
5+
[string]$AEM_PORT = "4502",
6+
# AEM Admin user for AEM_HOST
7+
[string]$AEM_USER = "admin",
8+
# AEM Admin password for AEM_HOST
9+
[string]$AEM_PASSWORD = "admin",
10+
# Root folder name for placing content
11+
[string]$SOURCE_CONTENT_FOLDER = "localhost-author-export",
12+
# Server WebDav Path
13+
#$AEM_WEBDAV_PATH = "/crx/server/crx.default/jcr:root/"
14+
[string]$AEM_WEBDAV_PATH = "/crx",
15+
[string]$AEM_SCHEMA = "http",
16+
#to set additional flags if required
17+
[string]$VLT_FLAGS = "--insecure -Xmx2g",
18+
[string]$VLT_CMD = "../tools/vault-cli/bin/vlt",
19+
# Root folder name for placing content
20+
[string]$CONTENT_DESTINATION = ".\src\main\content",
21+
[string]$FILTER_FILE = "${CONTENT_DESTINATION}\META-INF\vault\filter.xml",
22+
[string]$FILTER_FILE_LOCATION = "${CONTENT_DESTINATION}\META-INF",
23+
#which filter paths to import
24+
[string[]]$ROOT_PATHS,
25+
[string]$ROOT_PATH = "/",
26+
[string]$CONTENT_SOURCE = (Resolve-Path -Path "src\main\content\jcr_root" -Relative),
27+
# connection timeout
28+
[string]$TIMEOUT = "5",
29+
# host address
30+
[string]$ADDRESS = "${AEM_SCHEMA}://${AEM_HOST}:${AEM_PORT}",
31+
# Disable services before import
32+
[string[]]$SERVICES_TO_DISABLE = @(
33+
"/system/console/bundles/com.day.cq.cq-mailer",
34+
"/system/console/bundles/com.adobe.granite.workflow.core"
35+
),
36+
37+
[HashTable]$BODY_SERVICE_TO_DISABLE = @{
38+
"action"="stop"
39+
},
40+
[HashTable]$BODY_SERVICE_TO_DISABLE_ENABLE = @{
41+
"action"="start"
42+
},
43+
[switch]$Silent = $false,
44+
[string]$LOG_PATH = "..\logs"
45+
)
46+
47+
48+
Function Format-XMLIndent
49+
{
50+
[Cmdletbinding()]
51+
[Alias("IndentXML")]
52+
param
53+
(
54+
[Parameter(ValueFromPipeline)]
55+
[xml]$Content,
56+
[int]$Indent
57+
)
58+
59+
# String Writer and XML Writer objects to write XML to string
60+
$StringWriter = New-Object System.IO.StringWriter
61+
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
62+
63+
# Default = None, change Formatting to Indented
64+
$xmlWriter.Formatting = "indented"
65+
66+
# Gets or sets how many IndentChars to write for each level in
67+
# the hierarchy when Formatting is set to Formatting.Indented
68+
$xmlWriter.Indentation = $Indent
69+
70+
$Content.WriteContentTo($XmlWriter)
71+
$XmlWriter.Flush();$StringWriter.Flush()
72+
$StringWriter.ToString()
73+
}
74+
75+
76+
function doSlingPost {
77+
[CmdletBinding()]
78+
Param (
79+
80+
[Parameter(Mandatory=$true)]
81+
[string]$Url="http://localhost:4502",
82+
83+
[Parameter(Mandatory)]
84+
[ValidateNotNullOrEmpty()]
85+
[ValidateSet('Post','Delete')]
86+
[string]$Method,
87+
88+
[Parameter(Mandatory=$false)]
89+
[HashTable]$Body,
90+
91+
[Parameter(Mandatory=$false,
92+
HelpMessage="Provide Basic Auth Credentials in following format: <user>:<pass>")]
93+
[string]$BasicAuthCreds="",
94+
95+
[Parameter(Mandatory=$false)]
96+
[string]$UserAgent="",
97+
98+
[Parameter(Mandatory=$false)]
99+
[string]$Referer="",
100+
101+
[Parameter(Mandatory=$false)]
102+
[string]$Timeout="5"
103+
104+
)
105+
106+
107+
108+
$HEADERS = @{
109+
}
110+
111+
if (-not([string]::IsNullOrEmpty($UserAgent))) {
112+
$HEADERS.add("User-Agent",$UserAgent)
113+
}
114+
115+
if (-not([string]::IsNullOrEmpty($Referer))) {
116+
$HEADERS.add("Referer",$Referer)
117+
}
118+
119+
120+
if (-not([string]::IsNullOrEmpty($BasicAuthCreds))) {
121+
$BASICAUTH = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($BasicAuthCreds))
122+
$HEADERS.add("Authorization","Basic $BASICAUTH")
123+
}
124+
125+
126+
Write-Output "Performing action $Method on $Url."
127+
128+
$Response = Invoke-WebRequest -Method Post -Headers $HEADERS -TimeoutSec $Timeout -Uri "$Url" -Form $Body -ContentType "application/x-www-form-urlencoded"
129+
130+
}
131+
132+
Write-Output "------- CONFIG ----------"
133+
Write-Output "AEM_SCHEMA: $AEM_SCHEMA"
134+
Write-Output "AEM_HOST: $AEM_HOST"
135+
Write-Output "AEM_PORT: $AEM_PORT"
136+
Write-Output "AEM_USER: $AEM_USER"
137+
Write-Output "CONTENT_SOURCE: $CONTENT_SOURCE"
138+
Write-Output "ROOT_PATH: $ROOT_PATH"
139+
Write-Output "FILTER_FILE: $FILTER_FILE"
140+
Write-Output "Silent: $Silent"
141+
Write-Output "VLT_FLAGS: $VLT_FLAGS"
142+
Write-Output "VLT_CMD: $VLT_CMD"
143+
Write-Output "ROOT_PATHS:"
144+
$ROOT_PATHS | ForEach-Object {
145+
Write-Output " - $_"
146+
}
147+
Write-Output "SERVICES_TO_DISABLE:"
148+
$SERVICES_TO_DISABLE | ForEach-Object {
149+
Write-Output " - $_"
150+
}
151+
152+
if (-not($Silent))
153+
{
154+
$START = Read-Host -Prompt 'Do you want to start import with these settings? (y/n)'
155+
156+
if ($START -ne "y")
157+
{
158+
Write-Output "Quiting..."
159+
Exit
160+
}
161+
}
162+
163+
Write-Output "------- Revert META-INF ----------"
164+
git checkout HEAD src/main/content/META-INF/
165+
git clean -fx src/main/content/META-INF
166+
Write-Output "------- Revert META-INF ----------"
167+
168+
if ($ROOT_PATHS)
169+
{
170+
Write-Output "------- START Update filter ----------"
171+
$ROOT_PATHS_LAST = $ROOT_PATHS | Select-Object -Last 1
172+
$ROOT_PATHS | ForEach-Object {
173+
$LOG_FILENAME = "$_".Replace("/","-")
174+
175+
Write-Output "Remove exiting Filer..."
176+
Copy-Item ".\src\main\content\META-INF\vault\filter-blank.xml" -Destination "$FILTER_FILE"
177+
178+
Write-Output "Create filter for: $_"
179+
$FILTER_XML = [xml](Get-Content $FILTER_FILE)
180+
$FILTER_XML_CONTENT = $FILTER_XML.SelectNodes("//workspaceFilter")
181+
$FILTER_XML_DELETE = $FILTER_XML_CONTENT.SelectNodes('//filter')
182+
$FILTER_XML_DELETE | ForEach-Object{
183+
$DELETE_STATUS = $FILTER_XML_CONTENT.RemoveChild($_)
184+
}
185+
$FILTER_XML_CONTENT_NEW = $FILTER_XML.CreateNode("element","filter","")
186+
$FILTER_XML_CONTENT_NEW.SetAttribute("root",$_)
187+
$FILTER_XML_CONTENT_NEW_ADD = $FILTER_XML_CONTENT.AppendChild($FILTER_XML_CONTENT_NEW)
188+
Write-Output "Saving..."
189+
$FILTER_XML.OuterXml | IndentXML -Indent 4 | Out-File $FILTER_FILE -encoding "UTF8"
190+
Write-Output "Done..."
191+
}
192+
193+
Write-Output "------- END Update filter ----------"
194+
}
195+
196+
if ($SERVICES_TO_DISABLE)
197+
{
198+
Write-Output "------- Disable Services ----------"
199+
$SERVICES_TO_DISABLE | ForEach-Object {
200+
Write-Output "Stopping service: $_"
201+
doSlingPost -Method Post -Referer $ADDRESS -UserAgent "curl" -Body $BODY_SERVICE_TO_DISABLE -Url "${ADDRESS}$_" -BasicAuthCreds ${AEM_USER}:${AEM_PASSWORD} -Timeout $TIMEOUT
202+
}
203+
}
204+
205+
Write-Output "------- START Importing content ----------"
206+
Write-Output "${VLT_CMD} ${VLT_FLAGS} --credentials ${AEM_USER}:****** import -v ${ADDRESS}${AEM_WEBDAV_PATH} ${CONTENT_SOURCE} ${ROOT_PATH}"
207+
208+
Invoke-Expression -Command "${VLT_CMD} ${VLT_FLAGS} --credentials ${AEM_USER}:${AEM_PASSWORD} import -v ${ADDRESS}${AEM_WEBDAV_PATH} ${CONTENT_SOURCE} ${ROOT_PATH} " | Tee-Object -FilePath "${LOG_PATH}\filevailt-import.log"
209+
210+
Write-Output "------- END Importing content ----------"
211+
212+
213+
if ($SERVICES_TO_DISABLE)
214+
{
215+
Write-Output "------- Enable Services ----------"
216+
$SERVICES_TO_DISABLE | ForEach-Object {
217+
Write-Output "Stopping service: $_"
218+
doSlingPost -Method Post -Referer $ADDRESS -UserAgent "curl" -Body $BODY_SERVICE_TO_DISABLE_ENABLE -Url "${ADDRESS}$_" -BasicAuthCreds ${AEM_USER}:${AEM_PASSWORD} -Timeout $TIMEOUT
219+
}
220+
}
221+
222+
Write-Output "------- Revert META-INF ----------"
223+
git checkout HEAD src/main/content/META-INF/
224+
git clean -fx src/main/content/META-INF
225+
Write-Output "------- Revert META-INF ----------"

0 commit comments

Comments
 (0)