Skip to content

Commit

Permalink
#923 : Added layout support.
Browse files Browse the repository at this point in the history
  • Loading branch information
michaellwest committed Aug 8, 2017
1 parent 64d5f43 commit b2eea03
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 26 deletions.
Expand Up @@ -27,7 +27,7 @@ SharedFields:
)
if($selectedItem.ItemPath.StartsWith("/sitecore/content")) {
$parameters += @{ Name = "IncludeLinkedItems"; Title = "Include Linked Items"; Hint = "Choose one or more options below to include items linked. This relies on the Link Database to determine references."; Options = $linkedItemOptions; OptionTooltips = $linkedItemOptionTooltips; Editor = "checkbox" }
$parameters += @{ Name = "IncludeLinkedItems"; Title = "Include Linked Items"; Hint = "Choose one or more options below to include items linked. This relies on the Link Database to determine references."; Options = $linkedItemOptions; OptionTooltips = $linkedItemOptionTooltips; Editor = "checkbox" }
}
$result = Read-Variable @defaultProps -Parameters $parameters -Description "Set installation options for this package source."
Expand Down
Expand Up @@ -21,6 +21,7 @@ SharedFields:
$selectedItem = Get-Item -Path .
$path = $item.ProviderPath
$examplePackageName = "$($timestamp).$($selectedItem.Name)"
$includeLinkedItems = 0
$parameters = @(
@{ Name = "packageName"; Title="Package Name"; Placeholder = $examplePackageName; Tab="Package Metadata"},
Expand All @@ -30,11 +31,13 @@ SharedFields:
@{ Name = "Readme"; Title="Readme"; Lines=10; Tab="Package Metadata"},
@{ Name = "AsXml"; Title="Download Package as XML"; Value=[bool]$False; Editor="bool"; Tab="Package Metadata" },
@{ Name = "IncludeItems"; Title="Items to include in package"; Value="RootAndDescendants"; Options=$rootOptions; OptionTooltips = $rootOptionTooltips; Tooltip = "Hover over each option to view a short description."; Hint = "The package will dynamically include the items based on your selection below. <br /><br />Root : '$($selectedItem.ProviderPath)'"; Editor="combo"; Tab="Installation Options" },
@{ Name = "Mode"; Title="Installation Options"; Value = "Overwrite"; Options = $installOptions; OptionTooltips = $installOptionsTooltips; Tooltip = "Hover over each option to view a short description."; Hint = "How should the installer behave if the package contains items that already exist?"; Editor="combo"; Tab="Installation Options"},
@{ Name = "IncludeLinkedItems"; Value = 0; Title = "Include Linked Items"; Hint = "Choose one or more options below to include items linked. This relies on the Link Database to determine references."; Options = $linkedItemOptions; OptionTooltips = $linkedItemOptionTooltips; Editor = "checkbox"; Tab = "Linked Options"; }
@{ Name = "Mode"; Title="Installation Options"; Value = "Overwrite"; Options = $installOptions; OptionTooltips = $installOptionsTooltips; Tooltip = "Hover over each option to view a short description."; Hint = "How should the installer behave if the package contains items that already exist?"; Editor="combo"; Tab="Installation Options"}
)
if($selectedItem.ItemPath.StartsWith("/sitecore/content")) {
$parameters += @{ Name = "IncludeLinkedItems"; Title = "Include Linked Items"; Hint = "Choose one or more options below to include items linked. This relies on the Link Database to determine references."; Options = $linkedItemOptions; OptionTooltips = $linkedItemOptionTooltips; Editor = "checkbox" }
}
$props = @{} + $defaultProps
$props["Title"] = "Download Tree as Package"
$props["Description"] = "This Tool allows you to download the item tree as a package quickly."
Expand Down
Expand Up @@ -41,21 +41,24 @@ SharedFields:
{
None = 1,
Media = 2,
Templates = 4,
Workflows = 8
Layouts = 4,
Templates = 8,
Workflows = 16
}
"@
$linkedItemOptions = [ordered]@{
"Include Media" = 2
"Include Templates" = 4
"Include Workflows" = 8
"Include Layouts" = 4
"Include Templates" = 8
"Include Workflows" = 16
}
$linkedItemOptionTooltips = [ordered]@{
"2" = "Include all associated content found in the media library."
"4" = "Include all associated custom templates."
"8" = "Include all associated workflows."
"4" = "Include all associated layouts and renderings."
"8" = "Include all associated custom templates."
"16" = "Include all associated workflows."
}
$rootOptions = [ordered]@{
Expand Down Expand Up @@ -91,34 +94,63 @@ SharedFields:
"Askuser" = "Prompts the user to make a decision."
}
function Test-LinkedOption {
param(
[item]$Item,
[LinkedItemOptions]$LinkedOptions
)
Write-Host "Entering Test-LinkedOption for $($item.ProviderPath)" -ForegroundColor Gray
$isItemAllowed = $true
if($item.Paths.FullPath.ToLower().Contains("/sitecore/media library/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Media)) {
$isItemAllowed = $false
} elseif($item.Paths.FullPath.ToLower().Contains("/sitecore/layout/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Layouts)) {
$isItemAllowed = $false
} elseif($item.Paths.FullPath.ToLower().Contains("/sitecore/templates/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Templates)) {
$isItemAllowed = $false
} elseif($item.Paths.FullPath.ToLower().Contains("/sitecore/system/workflows/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Workflows)) {
$isItemAllowed = $false
}
$isItemAllowed
}
function AddItems {
param(
[item]$Item,
[Sitecore.Install.Items.ExplicitItemSource]$Items
)
Write-Host "Entering AddItems for $($item.ProviderPath)" -ForegroundColor Gray
if($item -and !$itemsAddedToPackage.Contains($item.ID)) {
Write-Host "[A] $($item.ProviderPath)" -ForegroundColor Green
$itemsAddedToPackage.Add($item.ID) | Out-Null
if($items) {
$items.Entries.Add((New-Object Sitecore.Install.Items.ItemReference $item.Uri, $false).ToString())
}
} else {
Write-Host "[S] $($item.ProviderPath)" -ForegroundColor Yellow
}
}
function ProcessItemWithLinks {
param(
[item]$Item,
[Sitecore.Install.Items.ExplicitItemSource]$Items
[Sitecore.Install.Items.ExplicitItemSource]$Items,
[LinkedItemOptions]$LinkedOptions
)
Write-Host "Entering ProcessItemWithLinks for $($item.ProviderPath)" -ForegroundColor Gray
AddItems -Item $item -Items $items
Write-Host "Processing links for $($item.ProviderPath)"
$links = $item.Links.GetAllLinks($true)
foreach($link in $links) {
$linkItem = $link.GetTargetItem()
if($linkItem) {
if($linkItem -and (Test-LinkedOption -Item $linkItem -LinkedOptions $linkedOptions)) {
ProcessItem -Item $linkItem -Items $items -SkipLinks
} else {
Write-Host "[S] $($linkItem.ProviderPath) linked item skipped." -ForegroundColor Yellow
}
}
}
Expand Down Expand Up @@ -155,6 +187,8 @@ SharedFields:
[Sitecore.Install.Items.ExplicitItemSource]$Items
)
Write-Host "Entering ProcessTemplateItem for $($item.ProviderPath)" -ForegroundColor Gray
$templateItem = New-Object Sitecore.Data.Items.TemplateItem $item
$isSystemItem = IsSystemTemplateItem -Item $item
Expand All @@ -164,7 +198,7 @@ SharedFields:
ProcessFieldTemplateItem -Item $item -Items $items
$standardValues = $templateItem.StandardValues
if($standardValues) {
ProcessItem -Item $standardValues -Items $items
ProcessItem -Item $standardValues -Items $items -SkipLinks
}
}
Expand Down Expand Up @@ -197,28 +231,24 @@ SharedFields:
[switch]$SkipLinks
)
Write-Host "Entering ProcessItem for $($item.ProviderPath)" -ForegroundColor Gray
if(!$item) { return }
if(!$SkipLinks) {
if(!$itemsProcessedWithLinks.Contains($item.ID)) {
$itemsProcessedWithLinks.Add($item.ID) | Out-Null
if($LinkedOptions) {
if($item.Paths.FullPath.ToLower().Contains("/sitecore/media library/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Media)) {
Write-Host "[S] $($item.ProviderPath)" -ForegroundColor Yellow
return
} elseif($item.Paths.FullPath.ToLower().Contains("/sitecore/templates/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Templates)) {
Write-Host "[S] $($item.ProviderPath)" -ForegroundColor Yellow
return
} elseif($item.Paths.FullPath.ToLower().Contains("/sitecore/system/workflows/") -and !$LinkedOptions.HasFlag([LinkedItemOptions]::Workflows)) {
if(!(Test-LinkedOption -Item $item -LinkedOptions $linkedOptions)) {
Write-Host "[S] $($item.ProviderPath)" -ForegroundColor Yellow
return
}
}
ProcessItemWithLinks -Item $item -Items $items
ProcessItemWithLinks -Item $item -Items $items -LinkedOptions $linkedOptions
} else {
Write-Host "[S] $($item.ProviderPath)" -ForegroundColor Yellow
Write-Host "[S] $($item.ProviderPath) links already processed." -ForegroundColor Yellow
}
} else {
if(!$itemsProcessed.Contains($item.ID)) {
Expand All @@ -243,10 +273,8 @@ SharedFields:
ProcessWorkflowItem -Item $item.Parent.Parent.Parent.Parent -Items $items
}
}
} elseif ($item.Paths.FullPath.ToLower().Contains("/sitecore/content/")) {
AddItems -Item $item -Items $items
} else {
Write-Host "[S] $($item.ProviderPath) skipped." -ForegroundColor Yellow
AddItems -Item $item -Items $items
}
} else {
Write-Host "[S] $($item.ProviderPath) already processed." -ForegroundColor Yellow
Expand All @@ -261,6 +289,8 @@ SharedFields:
[LinkedItemOptions]$LinkedOptions
)
Write-Host "Entering ProcessItemWithDescendants for $($item.ProviderPath)" -ForegroundColor Gray
Write-Host "Processing item $($item.ProviderPath)"
ProcessItem -Item $Item -Items $Items -LinkedOptions $LinkedOptions
Expand All @@ -285,7 +315,7 @@ SharedFields:
$source = New-ItemSource -Item $Item -Name "$path" -InstallMode $InstallMode -MergeMode $MergeMode
Write-Host "Processing item $($item.ProviderPath)"
ProcessItem -Item $Item -SkipLinks
ProcessItem -Item $Item -LinkedOptions $LinkedOptions
if($LinkedOptions) {
$sourceDescendants = New-ExplicitItemSource -Item $Item -Name "$path children" -InstallMode $InstallMode -MergeMode $MergeMode
ProcessItemWithDescendants -Item $Item -Items $sourceDescendants -LinkedOptions $LinkedOptions
Expand Down

0 comments on commit b2eea03

Please sign in to comment.