-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.ps1
722 lines (655 loc) · 27.7 KB
/
main.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
Import-Function Get-CurrentSxaVersion
Import-Function Get-TenantItem
Class ValidationStep {
[String]$Title
[String]$Description
[System.Object]$Script
[System.Object]$Version
[ID[]]$Dependency
[ValidationResult]$ValidationResult
}
enum Result {
OK;
Error;
Warning
}
class ValidationResult {
[Result]$Result
[System.String]$Message
}
function Test-ValidVersion {
param (
[ValidationStep]$Step
)
$current = Get-CurrentSxaVersion
$from = $Step.Version.From
$to = $Step.Version.To
$from -le $current -and ($to -eq "*" -or $to -ge $current)
}
function Test-Dependency {
param (
[ValidationStep]$Step,
[Sitecore.Data.Fields.MultilistField]$SitesModulesField,
[Sitecore.Data.Fields.MultilistField]$TenantModulesField
)
$unresolved = $Step.Dependency | ? { $_ -ne $null } | ? {
$SitesModulesField.Contains($_) -eq $false -and $TenantModulesField.Contains($_) -eq $false
}
if ($unresolved.Count -eq 0) {
$true
}
else {
Write-Host "Skipping step: $($Step.Title) due to lack of required dependencies" -ForegroundColor Gray
$false
}
}
function Test-BrokenLink {
param (
[Sitecore.Data.Items.Item]$Item,
[Sitecore.Data.ID]$FieldID
)
[ValidationResult]$result = New-Object ValidationResult
$result.Result = [Result]::OK
[Sitecore.Data.Fields.ReferenceField]$field = $Item.Fields[$FieldID]
if ($field.Value -ne $null -and $field.TargetItem -eq $null) {
$result.Message = "Could not find an item with id: $($field.Value)"
$result.Result = [Result]::Error
}
return $result
}
function New-ResultObject {
param ()
[ValidationResult]$result = New-Object ValidationResult
$result.Result = [Result]::OK
$result.Message = ""
$result
}
$steps =
@{
Title = "SXA Best practices - limit the number of renderings on a page";
Description = "Checks whether there are pages with more than 30 renderings";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[ValidationResult]$result = New-ResultObject
function Get-PresentationDetails($Item) {
Write-Verbose "Cmdlet Get-PresentationDetails - Process"
$layoutFieldValue = $Item.Fields[[Sitecore.FieldIDs]::LayoutField].Value
$finalLayoutFieldValue = $Item.Fields[[Sitecore.FieldIDs]::FinalLayoutField].Value
[Sitecore.Data.Fields.XmlDeltas]::ApplyDelta($layoutFieldValue, $finalLayoutFieldValue)
}
function Test-ExceededRenderingsLimit($pageItem) {
$presentation = Get-PresentationDetails $pageItem
$definition = [Sitecore.Layouts.LayoutDefinition]::Parse($presentation)
$d = $definition.Devices | ? {
$_.Renderings.Count -gt 30
}
$d.Count -gt 0
}
$pages = $SiteItem.Axes.GetDescendants() | `
? { [Sitecore.Data.Managers.TemplateManager]::GetTemplate($_).InheritsFrom([Sitecore.XA.Foundation.Multisite.Templates+Page]::ID) } | `
? { Test-ExceededRenderingsLimit $_ }
if ($pages.Count -gt 0) {
$result.Result = [Result]::Warning
$result.Message = "Do not use too many renderings on a page; we recommend absolutely no more than 30. Having too many editable renderings on a single page can slow down the Experience Editor</br><b>Affected pages:</b>"
$pages | % {
$id = $_.ID
$name = $_.Name
$result.Message += ", <a onclick=`"javascript:return window.top.scForm.postEvent(this,event,'item:load(id=$id)')`" href=`"#`" style='color: red;'>$name</a>"
}
}
return $result
}
},
@{
Title = "SXA Best practices - media under virtual media folder";
Description = "Checks whether there are media items stored directly under virtual media folder";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SiteMediaItem
[ValidationResult]$result = New-ResultObject
$mediaVirtualFolder = Get-SiteMediaItem $SiteItem
$mediaItems = $mediaVirtualFolder.Children | ? {
[Sitecore.Data.Managers.TemplateManager]::GetTemplate($_).InheritsFrom([Sitecore.TemplateIDs]::UnversionedFile) -or [Sitecore.Data.Managers.TemplateManager]::GetTemplate($_).InheritsFrom([Sitecore.TemplateIDs]::VersionedFile)
}
if ($mediaItems.Count -gt 0) {
$result.Result = [Result]::Error
$result.Message = "Do not store media items under <b>Virtual Media Folder</b>"
}
return $result
}
},
@{
Title = "Field 'SiteMediaLibrary'";
Description = "Checks whether 'SiteMediaLibrary' field contains proper reference to a site specific media library item";
Version = @{
From = 1400;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Multisite.Templates+Site+Fields]::SiteMediaLibrary
$temp = Test-BrokenLink $SiteItem $id
if ($temp.Result -eq [Result]::Error) {
return $temp
}
[ValidationResult]$result = New-ResultObject
return $result
}
},
@{
Title = "Field 'ThemesFolder'";
Description = "Checks whether 'ThemesFolder' field contains proper reference to a site specific themes folder item";
Version = @{
From = 1400;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Multisite.Templates+Site+Fields]::ThemesFolder
$temp = Test-BrokenLink $SiteItem $id
if ($temp.Result -eq [Result]::Error) {
return $temp
}
[ValidationResult]$result = New-ResultObject
return $result
}
},
@{
Title = "Field 'AdditionalChildren'";
Description = "Checks whether 'AdditionalChildren' field contains proper reference to a tenant shared media library folder and there are no broken links";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SiteMediaItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Multisite.Templates+Media+Fields]::AdditionalChildren
$siteMediaItem = Get-SiteMediaItem $SiteItem
[Sitecore.Data.Fields.MultilistField]$field = $siteMediaItem.Fields[$id]
$items = $field.GetItems()
if ($items.Count -ne $field.TargetIDs.Count) {
$result.Result = [Result]::Error
$missingIDs = $field.TargetIDs | ? { $items.ID.Contains($_) -eq $false }
$result.Message = "Could not find items with id: $($missingIDs -join ',')"
return $result
}
return $result
}
},
@{
Title = "Field 'Styles Optimizing Enabled'";
Description = "Checks 'Styles Optimizing Enabled' field to determine if styles optimization is disabled";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-PageDesignsItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Theming.Templates+_Optimizable+Fields]::StylesOptimisingEnabled
[Sitecore.Data.Items.Item]$pageDesignItem = Get-PageDesignsItem $SiteItem
$fieldValue = $pageDesignItem.Fields[$id].Value
$state = [Sitecore.MainUtil]::GetTristate($fieldValue, [Sitecore.Tristate]::Undefined)
if ($state -eq [Sitecore.Tristate]::False) {
$result.Result = [Result]::Warning
$result.Message = "Styles optimization for yor site is explicitly disabled. This may cause performance problems. </br>You should enable assests optimization on production"
return $result
}
return $result
}
},
@{
Title = "Field 'Scripts Optimizing Enabled'";
Description = "Checks 'Scripts Optimizing Enabled' field to determine if scripts optimization is disabled";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-PageDesignsItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Theming.Templates+_Optimizable+Fields]::ScriptsOptimisingEnabled
[Sitecore.Data.Items.Item]$pageDesignItem = Get-PageDesignsItem $SiteItem
$fieldValue = $pageDesignItem.Fields[$id].Value
$state = [Sitecore.MainUtil]::GetTristate($fieldValue, [Sitecore.Tristate]::Undefined)
if ($state -eq [Sitecore.Tristate]::False) {
$result.Result = [Result]::Warning
$result.Message = "Scripts optimization for yor site is explicitly disabled. This may cause performance problems. </br>You should enable assests optimization on production"
return $result
}
return $result
}
},
@{
Title = "Theme for Default device";
Description = "Checks whether any theme is assigned to a default device";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$defaultDeviceID = "{FE5D7FDF-89C0-4D99-9AA3-B5FBD009C9F3}"
$deviceItem = Get-Item master: -ID $defaultDeviceID
$theme = [Sitecore.XA.Foundation.Theming.ThemingContext]::new().GetThemeItem($siteItem, $deviceItem)
if ($theme -eq $null) {
$result.Result = [Result]::Error
$result.Message = "There is no theme assigned to the Default device"
return $result
}
return $result
}
},
@{
Title = "Theme and Compatible Themes field consistency";
Description = "Checks whether themes used in Theme-to-Device mapping are compatible with current site";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-PageDesignsItem
Import-Function Get-SettingsItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$themesMappingFieldID = [Sitecore.XA.Foundation.Theming.Templates+SiteTheme+Fields]::Theme
[Sitecore.Data.ID]$compatibleThemesFieldIdD = [Sitecore.XA.Foundation.Theming.Templates+_Compatiblethemes+Fields]::Themes
[Sitecore.Data.Items.Item]$pageDesignItem = Get-PageDesignsItem $SiteItem
[Sitecore.Data.Items.Item]$settingsItem = Get-SettingsItem $SiteItem
[Sitecore.XA.Foundation.SitecoreExtensions.CustomFields.MappingField]$themesMappingFields = $pageDesignItem.Fields[$themesMappingFieldID]
[Sitecore.Data.Fields.MultilistField]$compatibleThemesField = $settingsItem.Fields[$compatibleThemesFieldIdD]
$incorrectDeviceMapping = $themesMappingFields.Keys | % { $_.ToString() } | ? {
$key = $_
$theme = $themesMappingFields.Lookup($key)
$compatibleThemesField.Items.Contains($theme.ID.ToString()) -eq $false
}
if ($incorrectDeviceMapping.Count -gt 0) {
$result.Result = [Result]::Error
$result.Message = "Some themes used for mapping are not compatible with current site. Please check themes mapping for following devices: $($incorrectDeviceMapping -join ',')"
return $result
}
return $result
}
},
@{
Title = "Site definitions conflicts";
Description = "Checks whether current site definitions have any conflicts with other sites";
Version = @{
From = 1500;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SettingsItem
Import-Function Get-SxaSiteDefinitions
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.Items.Item]$settingsItem = Get-SettingsItem $SiteItem
$siteDefinitions = $settingsItem.Axes.GetDescendants() | ? { $_.TemplateID -eq "{EDA823FC-BC7E-4EF6-B498-CD09EC6FDAEF}" } | Wrap-Item | % { $_."SiteName" }
$sites = Get-SxaSiteDefinitions | ? { $siteDefinitions.Contains($_.Name) } | ? { $_.State -eq "Conflict" }
if ($sites.Count -gt 0) {
$result.Result = [Result]::Error
$result.Message = $sites[0].Conflict
return $result
}
return $result
}
},
@{
Title = "Error Handling - 404";
Description = "Checks whether current site has 404 page configured";
Version = @{
From = 1000;
To = "*";
};
Dependency = @("{8F9355F1-F6AC-49A1-8465-0B905E3E8CAF}");
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SettingsItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$id = [Sitecore.XA.Feature.ErrorHandling.Templates+_ErrorHandling+Fields]::Error404Page
[Sitecore.Data.Items.Item]$settingsItem = Get-SettingsItem $SiteItem
[Sitecore.Data.Fields.InternalLinkField]$field = $settingsItem.Fields[$id]
if ($field.TargetItem -eq $null) {
$result.Result = [Result]::Warning
$result.Message = "Error page for 404 code (Page Not Found) is not configured"
return $result
}
return $result
}
},
@{
Title = "Site name";
Description = "Validates site name. Site names cannot contain control characters, spaces (' ') semicolons, or commas";
Version = @{
From = 1000;
To = "*";
};
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SettingsItem
Import-Function Get-SxaSiteDefinitions
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.Items.Item]$settingsItem = Get-SettingsItem $SiteItem
$siteDefinitions = $settingsItem.Axes.GetDescendants() | ? { $_.TemplateID -eq "{EDA823FC-BC7E-4EF6-B498-CD09EC6FDAEF}" } | Wrap-Item
$current = Get-CurrentSxaVersion
if ($current -ge 1500) {
$siteNames = $siteDefinitions | % { $_."SiteName" }
}
else {
$siteNames = $siteDefinitions | % { $_.Name }
}
[string[]]$invaludNames = $siteNames | ? {
[regex]::Match($_, "^[a-zA-z0-9]*$").Success -eq $false
}
if ($invaludNames.Count -gt 0) {
$result.Result = [Result]::Error
$invaludNames = $invaludNames | % { "'<b>$($_)</b>'" }
$result.Message = "There are site definition items with incorrect site names: $($invaludNames -join ', ')"
return $result
}
return $result
}
},
@{
Title = "Error Handling - 500";
Description = "Checks whether current site has 500 page configured";
Version = @{
From = 1000;
To = "*";
};
Dependency = @("{8F9355F1-F6AC-49A1-8465-0B905E3E8CAF}");
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
Import-Function Get-SettingsItem
[ValidationResult]$result = New-ResultObject
[Sitecore.Data.ID]$id = [Sitecore.XA.Feature.ErrorHandling.Templates+_ErrorHandling+Fields]::Error500Page
[Sitecore.Data.Items.Item]$settingsItem = Get-SettingsItem $SiteItem
[Sitecore.Data.Fields.InternalLinkField]$field = $settingsItem.Fields[$id]
if ($field.TargetItem -eq $null) {
$result.Result = [Result]::Warning
$result.Message = "Error page for 500 code (Server Error Page) is not configured"
return $result
}
$sitesWithoutStaticHTML = $settingsItem.Axes.GetDescendants() | `
? { $_.TemplateID -eq "{EDA823FC-BC7E-4EF6-B498-CD09EC6FDAEF}" } | Wrap-Item | `
% { $_."SiteName" } | `
? { (Test-Path ([Sitecore.IO.FileUtil]::MapPath("/ErrorPages/$($_).html"))) -eq $false }
if ($sitesWithoutStaticHTML.Count -gt 0) {
$result.Result = [Result]::Error
$result.Message = "There are sites without static HTML error page: $($sitesWithoutStaticHTML -join ', ')"
return $result
}
return $result
}
},
@{
Title = "Maps Provider key";
Description = "If there is any use of Maps rendering, it checks whether maps provider key has been configured";
Version = @{
From = 1000;
To = "*";
};
Dependency = @("{4EE33975-DB00-455E-9F9C-2CB78C892C79}");
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[ValidationResult]$result = New-ResultObject
$mapsRenderingID = "{4DD74227-4504-4102-A802-76241F372B9E}"
$rendering = $SiteItem.Database.GetItem($mapsRenderingID)
$siteLongID = $SiteItem.Paths.LongID
$mapsRenderingUsages = [Sitecore.Globals]::LinkDatabase.GetItemReferrers($rendering, $false) | `
? { ($_.SourceFieldID -eq [Sitecore.FieldIDs]::LayoutField) -or ($_.SourceFieldID -eq [Sitecore.FieldIDs]::FinalLayoutField) } | `
? { $_.TargetDatabaseName -eq $rendering.Database.Name } | `
% { $rendering.Database.GetItem($_.SourceItemID) } | `
? { $_ -ne $null } | `
? { $_.Paths.LongID.StartsWith($siteLongID) }
$instance = [Sitecore.DependencyInjection.ServiceLocator]::ServiceProvider
$mapsProvider = $instance.GetType().GetMethod('GetService').Invoke($instance, [Sitecore.XA.Foundation.Geospatial.Services.IMapsProvider])
$key = $mapsProvider.GetMapsKey($SiteItem)
if ([string]::IsNullOrWhiteSpace($key) -eq $true) {
if ($mapsRenderingUsages.Count -gt 0) {
$result.Result = [Result]::Error
$result.Message = "Found $($mapsRenderingUsages.Count) useages of <b>Maps</b> rendering in selected site but <b>Maps Provider key</b> is empty."
$mapsRenderingUsages | % { Write-Log "[SXA.HealthCheck][Maps Provider key] $($_.Paths.Path)" }
}
else {
$result.Result = [Result]::Warning
$result.Message = "<b>Maps Provider key</b> is empty. If you are not going to use <b>Maps</b> rendering that's fine."
}
return $result
}
return $result
}
},
@{
Title = "SXA Best practices - unused data sources";
Description = "Checks whether there are unused data sources present in your site";
Version = @{
From = 1800;
To = "*";
};
Dependency = @("{4EE33975-DB00-455E-9F9C-2CB78C892C79}");
Script = {
param(
[Sitecore.Data.Items.Item]$SiteItem
)
[ValidationResult]$result = New-ResultObject
Import-Function CleanDataFolder
function Get-RelativeDatasourcePath {
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, Position = 0 )]
[Item]$Item
)
process {
Import-Function Get-PresentationDetails
Write-Verbose "Cmdlet Get-RelativeDatasourcePath - Process"
$presentation = Get-PresentationDetails $item
$definition = [Sitecore.Layouts.LayoutDefinition]::Parse($presentation)
$definition.Devices | % {
$_.Renderings | ? { $_.Datasource -ne $null } | ? {
$_.Datasource.StartsWith([Sitecore.XA.Foundation.LocalDatasources.Constants]::LocalPrefix) -or $_.Datasource.StartsWith([Sitecore.XA.Foundation.LocalDatasources.Constants]::PageRelativePrefix)
} | % {
$_.Datasource.Replace([Sitecore.XA.Foundation.LocalDatasources.Constants]::LocalPrefix, "").Replace([Sitecore.XA.Foundation.LocalDatasources.Constants]::PageRelativePrefix, "")
}
}
}
}
$item = $SiteItem.Axes.GetDescendants() | ? { $_.TemplateID -eq "{1C82E550-EBCD-4E5D-8ABD-D50D0809541E}" } | Wrap-Item
$unusedDatasources = $item | % {
$item = $_.Parent
$dataFolder = $_
[Item[]]$dataSources = Get-NestedDatasource $dataFolder
$dataSourcesPaths = Get-RelativeDatasourcePath $item
$dataSourcesIds = Get-DataSourcesIdsFromLayout $item
foreach ($datasource in $dataSources) {
$usedAsPageRelative = IsDataSourceUsedAsPageRelative $datasource $dataSourcesPaths
$usedAsGlobal = IsDataSourceUsedAsGlobal $datasource
$usedAsGlobalOnCurrentPage = IsDataSourceUsedAsGlobalOnCurrentPage $datasource $dataSourcesIds
if ($usedAsPageRelative -or $usedAsGlobal -or $usedAsGlobalOnCurrentPage) {
}
else {
Write-Log "[SXA.HealthCheck][Unused data sources] Following data source is probably unused and could be recycled: $($datasource.Paths.Path)"
$datasource
}
}
}
if ($unusedDatasources.Count -gt 0) {
$result.Result = [Result]::Warning
$result.Message = "Found unused datasources ($($unusedDatasources.Count)). Open <b>SPE</b> log file to learn more"
}
return $result
}
},
@{
Title = "SXA Best practices - custom items under SXA nodes";
Description = "Checks whether there are additional or modified files under SXA nodes";
Version = @{
From = 1000;
To = "*";
};
Script = {
$excludedItems = @("{B0979E0D-16D4-46CC-9D7A-88895FEA2165}" , "{F78EC6BE-D9BA-4595-B740-E801ACDB0459}")
$excludedTemplates = @("{B43AB8D5-E123-42DD-8042-DE869CC98C4F}")
$rootsWildcard = @("/sitecore/templates/",
"/sitecore/system/Settings",
"/sitecore/layout/Renderings",
"/sitecore/layout/Placeholder",
"/sitecore/layout/Layouts",
"/sitecore/media library",
"/sitecore/templates/Branches")
$rootsPaths = @("/sitecore/system/Modules/PowerShell/Script Library/SXA",
"/sitecore/system/Modules/PowerShell/Script Library/JSS SXA",
"/sitecore/media library/Themes/Wireframe#-#deprecated",
"/sitecore/media library/Themes/Wireframe",
"/sitecore/media library/Base Themes/Analytics",
"/sitecore/media library/Base Themes/Bing Maps JS Connector",
"/sitecore/media library/Base Themes/Google Maps JS Connector",
"/sitecore/media library/Base Themes/Grid Theme",
"/sitecore/media library/Base Themes/Json",
"/sitecore/media library/Base Themes/Main Theme",
"/sitecore/media library/Base Themes/Maps",
"/sitecore/media library/Base Themes/Meta Partial Design Theme",
"/sitecore/media library/Base Themes/SearchTheme",
"/sitecore/media library/Base Themes/StickyNotes",
"/sitecore/media library/Base Themes/Variants",
"/sitecore/media library/Base Themes/XA API",
"/sitecore/media library/Base Themes/Core Libraries",
"/sitecore/media library/Base Themes/Editing Theme",
"/sitecore/media library/Base Themes/Horizon Editing Theme",
"/sitecore/media library/Base Themes/Editing Components",
"/sitecore/media library/Base Themes/Composite Theme",
"/sitecore/media library/Base Themes/Resolve Conflicts",
"/sitecore/media library/Base Themes/Components Theme"
)
function Get-UpdatedItems {
param (
[string]$root,
[string]$updated,
[Switch]$Wildcard
)
if ($Wildcard) {
$query = "fast:$root/*/Experience Accelerator//*[@__Updated != '$updated%']"
}
else {
$query = "fast:$root//*[@__Updated != '$updated%']"
}
Get-Item -Path master: -Query $query
}
function Test-NotExcludedTemplate {
param (
[Sitecore.Data.Items.Item]$Item
)
!$excludedTemplates.Contains($Item.TemplateID.ToString())
}
function Test-NotExcludedItem {
param (
[Sitecore.Data.Items.Item]$Item
)
!$excludedItems.Contains($Item.ID.ToString())
}
function Get-UpdatedDate {
$initialItem = Get-Item -Path '/sitecore/system/Settings/Foundation/Experience Accelerator/Upgrade/Initial'
$initialItem."__Updated".ToString("yyyyMMdd")
}
function Get-ModifiedSXAItems {
$updated = Get-UpdatedDate
$rootsWildcard | % { Get-UpdatedItems $_ $updated -Wildcard } | ? { Test-NotExcludedItem $_ } | ? { Test-NotExcludedTemplate $_ }
$rootsPaths | % { Get-UpdatedItems $_ $updated } | ? { Test-NotExcludedTemplate $_ }
}
[ValidationResult]$result = New-ResultObject
$items = Get-ModifiedSXAItems
if ($items.length -ne 0) {
$result.Result = [Result]::Error
$result.Message = "Found custom/modified items under SXA nodes ($($items.Count)). Open <b>SPE</b> log file to learn more"
$items | % {
Write-Log "[SXA.HealthCheck][Custom items under SXA nodes] The following item was probably updated/added after package installation $($_.Paths.Path)"
}
}
else {
$result.Result = [Result]::OK
}
$result
}
}
$siteItem = Get-Item .
[Sitecore.Data.ID]$siteTemplateID = [Sitecore.XA.Foundation.Multisite.Templates+Site]::ID
if ([Sitecore.Data.Managers.TemplateManager]::GetTemplate($siteItem).InheritsFrom($siteTemplateID) -eq $false) {
Show-Alert "Please select a SXA site`n`nCurrent item: '$($siteItem.Paths.Path)'`nis not a SXA site item"
return
}
$TenantItem = Get-TenantItem $SiteItem
[Sitecore.Data.ID]$id = [Sitecore.XA.Foundation.Scaffolding.Templates+_Modules+Fields]::Modules
[Sitecore.Data.Fields.MultilistField]$sitesModulesField = $SiteItem.Fields[$id]
[Sitecore.Data.Fields.MultilistField]$tenantModulesField = $TenantItem.Fields[$id]
Write-Host "Validating site: $($siteItem.Paths.Path)" -ForegroundColor Cyan
# Icon mapping
$modeMapping = @{}
$modeMapping[[Result]::Warning] = "\Images\warning.png"
$modeMapping[[Result]::Error] = "\Images\error.png"
$modeMapping[[Result]::OK] = "\Images\check.png"
$steps | `
? { Test-ValidVersion $_ } | `
? { Test-Dependency $_ $sitesModulesField $tenantModulesField } | `
% {
[ValidationStep]$step = $_
Write-Host "`nValidation step: $($step.Title)" -ForegroundColor Cyan
[ValidationResult]$result = Invoke-Command -Script $step.Script -Args $siteItem
$step.ValidationResult = $result
if ($result.Result -eq [Result]::Error) {
Write-Host $result.Message -ForegroundColor Red
}
if ($result.Result -eq [Result]::Warning) {
Write-Host $result.Message -ForegroundColor Yellow
}
if ($result.Result -eq [Result]::OK) {
Write-Host $result.Message -ForegroundColor Green
}
$step
} | Show-ListView `
-PageSize 25 `
-Property `
@{Label = "Title"; Expression = { $_.Title } },
@{Label = "Icon"; Expression = { $modeMapping[$_.ValidationResult.Result] } },
@{Label = "Description"; Expression = { $_.Description } },
@{Label = "Message"; Expression = { $_.ValidationResult.Message } }