From 07ab4301c31b1f3613f4858dc935e1d2ce90fd34 Mon Sep 17 00:00:00 2001 From: Aaron Bickle Date: Fri, 14 Jun 2019 08:17:22 -0700 Subject: [PATCH 1/4] Adding additional fields to import scripts for - Pagination - Multi-lingual support - Request Headers (web service only) Adding several re-usable scripts Moving re-usable functions to separate folder, allowing for a place for custom functions Refactoring Item processor into a method --- .../DataSync/Content Editor/Context Menu.yml | 14 ++ .../DataSync/Development/Import Runner.yml | 236 ++++++------------ .../DataSync/Functions/Custom Functions.yml | 18 ++ .../DataSync/Functions/Module Functions.yml | 18 ++ .../Module Functions/Get-DateFromString.yml | 43 ++++ .../Module Functions/Get-DateFromUnix.yml | 45 ++++ .../Get-ExternalLinkValue.yml | 27 ++ .../Get-SitecoreBoolValue.yml | 33 +++ .../Module Functions/Get-UriContent.yml | 61 +++++ .../Invoke-ProcessSourceItems.yml | 204 +++++++++++++++ .../Module Functions/New-ItemName.yml | 55 ++++ .../Receive-FileForUpload.yml | 29 +++ .../DataSync/DataSync/Toolbox/Data Sync.yml | 14 ++ .../Toolbox/Data Sync/Data Sync - All.yml | 57 +++++ .../Toolbox/Data Sync/Data Sync - Single.yml | 53 ++++ .../Templates/PowerShell DataSync.yml | 5 +- .../Import Script/Step 1/PaginationScript.yml | 25 ++ .../Import Script/Step 2/ForceIdScript.yml | 25 ++ .../Import Script/Step 2/LanguageScript.yml | 25 ++ .../Import Web Service Script/Step 1.yml | 8 +- .../Step 1/Generate Request Headers Scrip.yml | 21 ++ 21 files changed, 848 insertions(+), 168 deletions(-) create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Content Editor/Context Menu.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Custom Functions.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromString.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromUnix.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-ExternalLinkValue.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-SitecoreBoolValue.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-UriContent.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/New-ItemName.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Receive-FileForUpload.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - All.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - Single.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 1/PaginationScript.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/ForceIdScript.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/LanguageScript.yml create mode 100644 App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/Generate Request Headers Scrip.yml diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Content Editor/Context Menu.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Content Editor/Context Menu.yml new file mode 100644 index 0000000..b7deeb8 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Content Editor/Context Menu.yml @@ -0,0 +1,14 @@ +--- +ID: "87e625d0-b074-4e07-bb30-f319bc4609d6" +Parent: "d8394784-a396-48bb-b588-2eabce3d2bff" +Template: "ab154d3d-1126-4ab4-ac21-8b86e6bd70ea" +Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Content Editor/Context Menu +DB: master +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190307T181845Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml index 8223f99..f1ad449 100644 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml @@ -13,14 +13,17 @@ SharedFields: $Watch = [System.Diagnostics.Stopwatch]::StartNew() ) + Import-Function -Name Invoke-SqlCommand Import-Function -Name New-ItemName - Import-Function -Name Invoke-SourceRequest + Import-Function -Name Get-UriContent + Import-Function -Name Invoke-ProcessSourceItems class FieldIds { static [ID]$SourcePath = "{07476EF8-B3B6-46A1-82D7-0E793E7BA658}" static [ID]$SqlScript = "{53B07925-8E6B-49E5-B58D-F8E2B0489EFE}" static [ID]$BeforeImportScript = "{2B47ED82-A477-4D3B-AE17-FC1B64D54440}" static [ID]$ImportTemplate = "{66103474-141A-4CD7-BC64-3E7CF0858441}" + static [ID]$ForceIdScript = "{B0A60B70-8A87-4526-ABF4-62A721961217}" static [ID]$ItemName = "{FAC6C69F-07F1-4801-9CB8-2DCB77AFC71D}" static [ID]$ItemDisplayName = "{6D7F51CA-56E5-4E30-8735-CDF77BEABEDE}" static [ID]$FieldMapping = "{C1561963-9C44-444B-9002-732147905DA2}" @@ -30,7 +33,9 @@ SharedFields: static [ID]$DestinationPath = "{CFBA481F-6001-4C0F-A1FC-2FB0CE049F9C}" static [ID]$ItemParentExpression = "{35DE0F36-FC21-4F02-BC7F-9B3D2BCAA6EC}" static [ID]$AfterImportScript = "{5721604B-75FF-46A7-984D-6A6F8E8BF4AB}" - static [ID]$PaginationScript = "{E7D5151C-808C-4DB2-A0AE-EBCB662C15C7}" + static [ID]$NextPageScript = "{F23573B3-33F2-4448-B213-93B8607A9612}" + static [ID]$LanguageScript = "{EDD8DCB0-7EB3-48A6-9CB6-369DE0CFE6B2}" + static [ID]$GenerateHeadersScript = "{3E3448F8-5D08-45D9-BC45-73040EA1711C}" } class TemplateIds { @@ -68,7 +73,8 @@ SharedFields: foreach($importFieldMapping in $importFieldMappings) { $split = $importFieldMapping -split "=" if($split -and $split.Length -le 2) { - $importFieldMappingsLookup[$split[0]] = $split[1] + $fieldName = $split[0].Replace("_", " ") + $importFieldMappingsLookup[$fieldName] = $split[1] } } @@ -80,181 +86,89 @@ SharedFields: Write-Host "$($timestamp) Selecting import script $($importScriptItem.TemplateId)" $sourceItems = @() $loadFromSource = $true - if($lastImportScriptId -ne $importScriptItem.ID -and $lastSourcePath -and $lastSourcePath -eq $sourcePath) { - if($lastImport) { - Write-Host "$($timestamp) Reusing last items loaded from source" - $sourceItems = $lastImport - $loadFromSource = $false - } + #if($lastSourcePath -and $lastSourcePath -eq $sourcePath) { + # if($lastImport) { + # Write-Host "$($timestamp) Reusing last items loaded from source" + # $sourceItems = $lastImport + # $loadFromSource = $false + # } + #} + + $statTracker = @{ + "Import items processed" = 0 + "New items created" = 0 + "Existing items skipped" = 0 + "Existing items updated" = 0 + "Execution time in seconds" = 0 } - $beforeImportScript = $importScriptItem.Fields[[FieldIds]::BeforeImportScript].Value - $paginationScript = $importScriptItem.Fields[[FieldIds]::PaginationScript].Value if($loadFromSource) { - Write-Host "$($timestamp) Loading items from source" - Write-Host "$($timestamp) Source $($sourcePath)" - $lastResult = Invoke-SourceRequest -ImportItem $importScriptItem -SourcePath $sourcePath - - if($lastResult) { - $sourceItems += $lastResult - } - - if($lastResult -and ![string]::IsNullOrEmpty($paginationScript)) { - - while($true) { - Write-Progress -Activity "Running pagination script" -Status $status - $pagedSourcePath = Invoke-Expression -Command $paginationScript - if([string]::IsNullOrEmpty($pagedSourcePath)) { break } - Write-Host "$($timestamp) Pagination source $($pagedSourcePath)" - $lastResult = Invoke-SourceRequest -ImportItem $importScriptItem -SourcePath $pagedSourcePath - if($lastResult) { - $sourceItems += $lastResult + switch($importScriptItem.TemplateId) { + ([TemplateIds]::ImportFlatFileScript) { + # Flat File + $extension = [System.IO.Path]::GetExtension($sourcePath) + if([string]::IsNullOrEmpty($extension)) { exit } + if($extension -eq ".csv") { + $sourceItems = Import-Csv -Path $sourcePath + } elseif ($extension -eq ".xml") { + $sourceItems = [xml](Get-Content -Path $sourcePath -Raw) + } elseif ($extension -eq ".json") { + $sourceItems = (Get-Content -Path $sourcePath -Raw) | ConvertFrom-Json } else { - break + $sourceItems = Get-Content -Path $sourcePath -Raw } + + $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker } - } - - if($sourceItems -and $sourceItems -isnot [array]) { - $sourceItemsTemp = $sourceItems - $sourceItems = [System.Collections.ArrayList]@() - $sourceItems.Add($sourceItemsTemp) > $null - } - - if(![string]::IsNullOrEmpty($beforeImportScript)) { - Write-Progress -Activity "Running pre import script" -Status $status - Invoke-Expression -Command $beforeImportScript - } - - $lastImportScriptId = $importScriptItem.ID - $lastSourcePath = $sourcePath - $lastImport = $sourceItems - } else { - if(![string]::IsNullOrEmpty($beforeImportScript)) { - Write-Progress -Activity "Running pre import script" -Status $status - Invoke-Expression -Command $beforeImportScript - } - } - - if($sourceItems -isnot [array]) { - $sourceItemsTemp = $sourceItems - $sourceItems = [System.Collections.ArrayList]@() - $sourceItems.Add($sourceItemsTemp) > $null - } - - Write-Progress -Activity "Configuring import settings" -Status $status - $itemSyncFieldName = $importScriptItem.Fields[[FieldIds]::ItemSyncField].Value - $checkSyncField = $false - $skipExisting = [Sitecore.MainUtil]::GetBool($importScriptItem.Fields[[FieldIds]::SkipExisting].Value, $false) - if(![string]::IsNullOrEmpty($itemSyncFieldName)) { - $checkSyncField = $true - } - - $destinationItemId = $importScriptItem.Fields[[FieldIds]::DestinationPath].Value - $destinationRoot = Get-Item -Path "master:" -ID $destinationItemId - $syncFieldLookup = @{} - if($checkSyncField) { - $existingItems = $destinationRoot.Axes.GetDescendants() | Where-Object { $_.TemplateId -eq $importTemplateId } | Initialize-Item - foreach($existingItem in $existingItems) { - $existingItemSyncFieldValue = $existingItem.Fields[$itemSyncFieldName].Value - if(!$existingItemSyncFieldValue) { - $member = Get-Member -InputObject $existingItem -Name $itemSyncFieldName - if($member) { - $existingItemSyncFieldValue = $existingItem.($member.Name) - } + ([TemplateIds]::ImportSqlScript) { + # Sql Script + $query = $importScriptItem.Fields[[FieldIds]::SqlScript].Value + $sourceItems = Invoke-SqlCommand -Query $query -Connection $sourcePath + + $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker } - if([string]::IsNullOrEmpty($existingItemSyncFieldValue)) { continue } - $syncFieldLookup[$existingItemSyncFieldValue] = $existingItem - } - } + ([TemplateIds]::ImportWebServiceScript) { + # Web service + if (![Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)) { + [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 + } - $destinationItems = [System.Collections.ArrayList]@() - $count = 0 - $countTotal = $sourceItems.Count - $skippedItemsCount = 0 - $newItemsCount = 0 - $existingItemsUpdatedCount = 0 - $parentPathExpression = $importScriptItem.Fields[[FieldIds]::ItemParentExpression].Value - foreach($sourceItem in $sourceItems) { - $count++ - Write-Host "$($timestamp) Processing source item $($count) of $($countTotal)" - $itemName = Invoke-Expression -Command $importScriptItem.Fields[[FieldIds]::ItemName].Value - Write-Progress -Activity "Creating or updating destination items" -Status $status -PercentComplete ($count / $countTotal * 100) -CurrentOperation "$($itemName)" - $destinationItem = $null - if($checkSyncField -and $importFieldMappingsLookup.ContainsKey($itemSyncFieldName)) { - $lookupValue = Invoke-Expression -Command $importFieldMappingsLookup[$itemSyncFieldName] - if($lookupValue -and $syncFieldLookup.ContainsKey($lookupValue)) { - if($skipExisting) { - Write-Host "- [S] Item found by matching field $($itemSyncFieldName)" - $skippedItemsCount++ - continue + $generateHeadersScript = $importScriptItem.Fields[[FieldIds]::GenerateHeadersScript].Value + if (![string]::IsNullOrEmpty($generateHeadersScript)) { + $PSDefaultParameterValues = Invoke-Expression -Command $generateHeadersScript + } + + while (![string]::IsNullOrEmpty($sourcePath)) { + $sourceItems = Get-UriContent -sourcePath $sourcePath + + $nextPageSourcePath = ""; + + Write-Progress -Activity "Running next page script" -Status $status + $nextPageScript = $importScriptItem.Fields[[FieldIds]::NextPageScript].Value + if(![string]::IsNullOrEmpty($nextPageScript)) { + $nextPageSourcePath = Invoke-Expression -Command $nextPageScript + } + + $sourcePath = $nextPageSourcePath + + $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker } - $destinationItem = $syncFieldLookup[$lookupValue] } - } - - $path = "$($destinationRoot.ProviderPath)\$($itemName)" - if(![string]::IsNullOrEmpty($parentPathExpression)) { - $parentPath = Invoke-Expression -Command $parentPathExpression - $parentPath = "$($destinationRoot.ProviderPath)\$($parentPath.Trim('\','/'))" - $path = "$($parentPath)\$($itemName)" - $parentItem = Get-Item -Path $parentPath - } else { - $parentItem = $destinationRoot - } - - if((Test-Path -Path $path)) { - Write-Host "- [!] Item exists at path $($path)" - $destinationItem = Get-Item -Path $path - } - if(!$destinationItem) { - Write-Host "- [A] $($path)" - $newItemsCount++ - $destinationItem = New-Item -Parent $parentItem -Name $itemName -ItemType $importTemplateId - } else { - Write-Host "- [S] Item with the same name exists" - $existingItemsUpdatedCount++ - } - - $displayName = $importScriptItem.Fields[[FieldIds]::ItemDisplayName].Value - if(![string]::IsNullOrEmpty($displayName)) { - $displayName = Invoke-Expression -Command $displayName - } - $destinationItem.Editing.BeginEdit() - if(![string]::IsNullOrEmpty($displayName)) { - $destinationItem[[Sitecore.FieldIDs]::DisplayName] = $displayName - } - foreach($fieldName in $importFieldMappingsLookup.Keys) { - if($destinationItem.Fields[$fieldName]) { - $destinationItem.Fields[$fieldName].Value = Invoke-Expression -Command $importFieldMappingsLookup[$fieldName] - } else { - Write-Host " - [S] $($fieldName) does not exist on the item" + default { + Write-Host "Unable to complete because the import script is unrecognized." -ForegroundColor White -BackgroundColor Red + exit } } - if(![string]::IsNullOrEmpty($importScriptItem.Fields[[FieldIds]::ForEachItemScript].Value)) { - Invoke-Expression -Command $importScriptItem.Fields[[FieldIds]::ForEachItemScript].Value - } - - $destinationItem.Editing.EndEdit() > $null - $destinationItems.Add($destinationItem) > $null - } - - Write-Progress -Activity "Running post import script" -Status $status - $afterImportScript = $importScriptItem.Fields[[FieldIds]::AfterImportScript].Value - if(![string]::IsNullOrEmpty($afterImportScript)) { - Invoke-Expression -Command $afterImportScript + $lastSourcePath = $sourcePath + $lastImport = $sourceItems } Write-Host "$($timestamp) $($importScriptItem.Name) completed" -ForegroundColor Green $time = $watch.ElapsedMilliseconds / 1000 - [PSCustomObject]@{ - "Import items processed" = $sourceItems.Count - "New items created" = $newItemsCount - "Existing items skipped" = $skippedItemsCount - "Existing items updated" = $existingItemsUpdatedCount - "Execution time in seconds" = $time - } | Format-List + + $statTracker["Execution time in seconds"] = $time > $null + $statTracker | Format-List Write-Progress -Activity "Completed importing data for $($importScriptItem.Name)" -Completed -Status "Import Complete" diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Custom Functions.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Custom Functions.yml new file mode 100644 index 0000000..f968b31 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Custom Functions.yml @@ -0,0 +1,18 @@ +--- +ID: "3950ab30-fdf8-4149-9c2e-59c43ca9ad6f" +Parent: "d3c93968-b343-4fa5-be29-0b7138359988" +Template: "ab154d3d-1126-4ab4-ac21-8b86e6bd70ea" +Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Custom Functions +DB: master +SharedFields: +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 100 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190327T190416Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions.yml new file mode 100644 index 0000000..896a3a9 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions.yml @@ -0,0 +1,18 @@ +--- +ID: "015d201e-8730-48ff-b7a7-279f05d82642" +Parent: "d3c93968-b343-4fa5-be29-0b7138359988" +Template: "ab154d3d-1126-4ab4-ac21-8b86e6bd70ea" +Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions +DB: master +SharedFields: +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 0 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190327T190805Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromString.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromString.yml new file mode 100644 index 0000000..83eebc6 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromString.yml @@ -0,0 +1,43 @@ +--- +ID: "7e65cc39-38e0-42ad-aaa9-f4975fa76807" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Get-DateFromString" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Get-DateFromString { + param ( + $value, + $format + ) + + if ($value -eq $null) { return "" } + + $date = New-Object DateTime + + # Check that directory name could be parsed to DateTime + if ([DateTime]::TryParseExact($value, $format, + [System.Globalization.CultureInfo]::InvariantCulture, + [System.Globalization.DateTimeStyles]::None, + [ref]$date)) + { + $date = [DateTime]::ParseExact($value, $format, $null) + + $isoDate = [Sitecore.DateUtil]::ToIsoDate($date) + + return $isoDate + } + + return "" + } +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190327T184304Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromUnix.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromUnix.yml new file mode 100644 index 0000000..81d5018 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-DateFromUnix.yml @@ -0,0 +1,45 @@ +--- +ID: "9f131669-5c8e-4f6f-9038-59094eddf3df" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Get-DateFromUnix" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Get-DateFromUnix { + param( + $date + ) + + Write-Host $date + + if ($date -eq $null) { return "" } + + $origin = New-Object -Type DateTime -ArgumentList 1970, 1, 1, 0, 0, 0, 0 + + Write-Host $origin + + $newDate = $origin.AddSeconds($date) + + Write-Host $newDate + + $pst = [System.TimeZoneInfo]::FindSystemTimeZoneById("Pacific Standard Time") + $utcDate = [System.TimeZoneInfo]::ConvertTimeToUtc($newDate, $pst) + + $isoDate = [Sitecore.DateUtil]::ToIsoDate($utcDate) + + return $isoDate + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 50 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190326T135628Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-ExternalLinkValue.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-ExternalLinkValue.yml new file mode 100644 index 0000000..ec354c4 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-ExternalLinkValue.yml @@ -0,0 +1,27 @@ +--- +ID: "779bd7a9-bb29-4ed6-91d3-87aaad69a324" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Get-ExternalLinkValue" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Get-ExternalLinkValue { + param ( + $link + ) + + $linkValue = "" + + return $linkValue + } +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190326T194138Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-SitecoreBoolValue.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-SitecoreBoolValue.yml new file mode 100644 index 0000000..d122d9c --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-SitecoreBoolValue.yml @@ -0,0 +1,33 @@ +--- +ID: "f5524dea-e2dd-48c6-aa4e-69e7dbd46175" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Get-SitecoreBoolValue" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Get-SitecoreBoolValue { + param( + $fieldValue + ) + + if ($fieldValue -eq $true -or $fieldValue -eq 1 -or $fieldValue -eq "true") { + return "1" + } + else { + return "0" + } + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 400 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190326T135050Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-UriContent.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-UriContent.yml new file mode 100644 index 0000000..359546e --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Get-UriContent.yml @@ -0,0 +1,61 @@ +--- +ID: "2b7f00fd-6382-40ac-b27c-8289bcfe8b8d" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Get-UriContent" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Get-UriContent { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [object]$sourcePath, + [object]$body, + [string]$method + ) + + if ([string]::IsNullOrEmpty($method)) { + $method = "GET" + } + + if ($body) { + $response = Invoke-WebRequest -Uri $sourcePath -Method $method -Body $body + } + else { + $response = Invoke-WebRequest -Uri $sourcePath -Method $method + } + + $contentType = $response.Headers["Content-Type"] + + if([string]::IsNullOrEmpty($contentType)) { exit } + + $content = $response.Content + + if ($content -is [byte[]]) { + $content = [System.Text.Encoding]::UTF8.GetString($content) + } + + if($contentType -match "json") { + $sourceItems = $content | ConvertFrom-Json + } elseif($contentType -match "xml") { + $sourceItems = [xml]$content + } else { + $sourceItems = $content + } + + return $sourceItems + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 600 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190226T155811Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml new file mode 100644 index 0000000..adf558e --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml @@ -0,0 +1,204 @@ +--- +ID: "28e3fe10-a345-434c-9124-77a4d9fa717d" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Invoke-ProcessSourceItems( + $SourceItems, + $ScriptItem, + $FieldMappings, + $StatTracker + ) { + Write-Progress -Activity "Running pre import script" -Status $status + $beforeImportScript = $scriptItem.Fields[[FieldIds]::BeforeImportScript].Value + if(![string]::IsNullOrEmpty($beforeImportScript)) { + Invoke-Expression -Command $beforeImportScript + } + + if($sourceItems -isnot [array]) { + $sourceItemsTemp = $sourceItems + $sourceItems = [System.Collections.ArrayList]@() + $sourceItems.Add($sourceItemsTemp) > $null + } + + Write-Progress -Activity "Configuring import settings" -Status $status + + $itemSyncFieldName = $scriptItem.Fields[[FieldIds]::ItemSyncField].Value + $checkSyncField = $false + $skipExisting = [Sitecore.MainUtil]::GetBool($scriptItem.Fields[[FieldIds]::SkipExisting].Value, $false) + if(![string]::IsNullOrEmpty($itemSyncFieldName)) { + $checkSyncField = $true + } + + $destinationItemId = $scriptItem.Fields[[FieldIds]::DestinationPath].Value + $destinationRoot = Get-Item -Path "master:" -ID $destinationItemId + $syncFieldLookup = @{} + + if($checkSyncField) { + $existingItems = $destinationRoot.Axes.GetDescendants() | Where-Object { $_.TemplateId -eq $importTemplateId -and $($_.Language.Name) -eq $langCode } | Initialize-Item + foreach($existingItem in $existingItems) { + $existingItemSyncFieldValue = $existingItem.Fields[$itemSyncFieldName].Value + if(!$existingItemSyncFieldValue) { + $member = Get-Member -InputObject $existingItem -Name $itemSyncFieldName + if($member) { + $existingItemSyncFieldValue = $existingItem.($member.Name) + } + } + if([string]::IsNullOrEmpty($existingItemSyncFieldValue)) { continue } + $syncFieldLookup[$existingItemSyncFieldValue] = $existingItem + } + } + + $destinationItems = [System.Collections.ArrayList]@() + $count = 0 + $countTotal = $sourceItems.Count + $skippedItemsCount = 0 + $newItemsCount = 0 + $existingItemsUpdatedCount = 0 + $parentPathExpression = $scriptItem.Fields[[FieldIds]::ItemParentExpression].Value + + foreach($sourceItem in $sourceItems) { + $count++ + Write-Host "$($timestamp) Processing source item $($count) of $($countTotal)" + $itemName = Invoke-Expression -Command $scriptItem.Fields[[FieldIds]::ItemName].Value + Write-Progress -Activity "Creating or updating destination items" -Status $status -PercentComplete ($count / $countTotal * 100) -CurrentOperation "$($itemName)" + $destinationItem = $null + if($checkSyncField -and $fieldMappings.ContainsKey($itemSyncFieldName)) { + $lookupValue = Invoke-Expression -Command $fieldMappings[$itemSyncFieldName] + if($syncFieldLookup.ContainsKey($lookupValue)) { + if($skipExisting) { + Write-Host "- [S] Item found by matching field $($itemSyncFieldName)" + $skippedItemsCount++ + continue + } + $destinationItem = $syncFieldLookup[$lookupValue] + } + } + + $path = "$($destinationRoot.ProviderPath)\$($itemName)" + if(![string]::IsNullOrEmpty($parentPathExpression)) { + $parentPath = Invoke-Expression -Command $parentPathExpression + $parentPath = "$($destinationRoot.ProviderPath)\$($parentPath.Trim('\','/'))" + $path = "$($parentPath)\$($itemName)" + $parentItem = Get-Item -Path $parentPath + } else { + $parentItem = $destinationRoot + } + + $langCode = "en" + + $langCodeScript = $scriptItem.Fields[[FieldIds]::LanguageScript].Value + if (![string]::IsNullOrEmpty($langCodeScript)) { + $langCode = Invoke-Expression -Command $langCodeScript + } + + $forceId = "" + $forceIdScript = $scriptItem.Fields[[FieldIds]::ForceIdScript].Value + if (![string]::IsNullOrEmpty($forceIdScript)) { + $forceId = Invoke-Expression -Command $forceIdScript + } + + if((Test-Path -Path $path)) { + Write-Host "- [!] Item exists at path $($path)" + $destinationItem = Get-Item -Path $path + } + + if(!$destinationItem -and $langCode -eq "en") { + Write-Host "- [A] $($path)" + $newItemsCount++ + + if (![string]::IsNullOrEmpty($forceId)) { + $destinationItem = New-Item -Parent $parentItem -Name $itemName -ItemType $importTemplateId -ForceId "{$($forceId)}" + } + else { + $destinationItem = New-Item -Parent $parentItem -Name $itemName -ItemType $importTemplateId + } + } elseif (!$destinationItem) { + $lookupValue = Invoke-Expression -Command $fieldMappings[$itemSyncFieldName] + $existingEnglishItems = $destinationRoot.Axes.GetDescendants() | Where-Object { $_.TemplateId -eq $importTemplateId -and $($_.Language.Name) -eq "en" -and $_.Fields[$itemSyncFieldName].Value -eq $lookupValue } + + $existingEnglishItem = $existingEnglishItems | Select-Object -Index 0 + + if ($existingEnglishItems.count -gt 1) { + Write-Host "- [!] Multiple items for nid $($sourceItem.attributes.nid) location. Using Sitecore Item $($existingEnglishItem.ID)" + } + + if (!$existingEnglishItem) { + $newItemsCount++ + + if (![string]::IsNullOrEmpty($forceId)) { + $existingEnglishItem = New-Item -Parent $parentItem -Name $itemName -ItemType $importTemplateId -ForceId "{$($forceId)}" + } + else { + $existingEnglishItem = New-Item -Parent $parentItem -Name $itemName -ItemType $importTemplateId + } + } + + Write-Host "- [A] $($path) - Language Version: $($langCode)" + $destinationItem = Add-ItemVersion -Item $existingEnglishItem -TargetLanguage $langCode + } else { + Write-Host "- [S] Item with the same name exists" + $existingItemsUpdatedCount++ + } + + $displayName = $scriptItem.Fields[[FieldIds]::ItemDisplayName].Value + if(![string]::IsNullOrEmpty($displayName)) { + $displayName = Invoke-Expression -Command $displayName + } + + if (!$destinationItem) { + Write-Error "Destination Item was not properly created, likely due to name: '$itemName'" + return + } + + $destinationItem.Editing.BeginEdit() + if(![string]::IsNullOrEmpty($displayName)) { + $destinationItem[[Sitecore.FieldIDs]::DisplayName] = $displayName + } + foreach($fieldName in $fieldMappings.Keys) { + if($destinationItem.Fields[$fieldName]) { + $fieldValue = Invoke-Expression -Command $fieldMappings[$fieldName] + + $destinationItem.Fields[$fieldName].Value = $fieldValue + } else { + Write-Host " - [S] $($fieldName) does not exist on the item" + } + } + + if(![string]::IsNullOrEmpty($scriptItem.Fields[[FieldIds]::ForEachItemScript].Value)) { + Invoke-Expression -Command $scriptItem.Fields[[FieldIds]::ForEachItemScript].Value + } + + $destinationItem.Editing.EndEdit() > $null + $destinationItems.Add($destinationItem) > $null + } + + Write-Progress -Activity "Running post import script" -Status $status + $afterImportScript = $scriptItem.Fields[[FieldIds]::AfterImportScript].Value + if(![string]::IsNullOrEmpty($afterImportScript)) { + Invoke-Expression -Command $afterImportScript + } + + $statTracker["Import items processed"] = $statTracker["Import items processed"] + $sourceItems.Count > $null + $statTracker["New items created"] = $statTracker["New items created"] + $newItemsCount > $null + $statTracker["Existing items skipped"] = $statTracker["Existing items skipped"] + $skippedItemsCount > $null + $statTracker["Existing items updated"] = $statTracker["Existing items updated"] + $existingItemsUpdatedCount > $null + + return $statTracker + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 700 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190208T173119Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/New-ItemName.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/New-ItemName.yml new file mode 100644 index 0000000..3349192 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/New-ItemName.yml @@ -0,0 +1,55 @@ +--- +ID: "539b2434-9f59-4ae9-b726-1a423e4adf36" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/New-ItemName" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function New-ItemName { + [CmdletBinding()] + param( + [Parameter(Mandatory=$true)] + [ValidateNotNullOrEmpty()] + [string]$Name, + [string]$FallbackName = "InvalidName", + [switch]$Lowercase, + [switch]$SpaceToDash, + [switch]$SlashToDash + ) + + Write-Host "Getting name for: $Name" + + if($Lowercase) { + $name = $name.ToLower() + } + + if($SpaceToDash) { + $name = $name -replace '\s+','-' + $name = $name -replace '-{2,}','-' + } + + if ($SlashToDash) { + $name = $name -replace '\\','-' + $name = $name -replace '/','-' + } + + $name = $name.Trim() + + $newName = [Sitecore.Data.Items.ItemUtil]::ProposeValidItemName($name, $fallbackName) + + return $newName.Trim() + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 800 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190117T160255Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Receive-FileForUpload.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Receive-FileForUpload.yml new file mode 100644 index 0000000..681b1f4 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Receive-FileForUpload.yml @@ -0,0 +1,29 @@ +--- +ID: "abae703f-f465-426c-8403-49525d223e69" +Parent: "015d201e-8730-48ff-b7a7-279f05d82642" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Module Functions/Receive-FileForUpload" +DB: master +SharedFields: +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + function Receive-FileForUpload { + [CmdletBinding()] + + $tempPath = [Sitecore.Configuration.Settings]::TempFolderPath + + $requestPath = [Sitecore.MainUtil]::MapPath($tempPath) + + $filePath = Receive-File -Path $requestPath + + return $filePath + } +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190429T204757Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync.yml new file mode 100644 index 0000000..ece71b5 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync.yml @@ -0,0 +1,14 @@ +--- +ID: "41ec2178-8414-4da6-8dda-e1cc66e4c532" +Parent: "3298f7ca-0aba-4bca-8e26-f6b70760208b" +Template: "ab154d3d-1126-4ab4-ac21-8b86e6bd70ea" +Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Toolbox/Data Sync +DB: master +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190326T142301Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - All.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - All.yml new file mode 100644 index 0000000..4f25acb --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - All.yml @@ -0,0 +1,57 @@ +--- +ID: "591b50a8-2a00-4c45-be7f-1365951e1458" +Parent: "41ec2178-8414-4da6-8dda-e1cc66e4c532" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Toolbox/Data Sync/Data Sync - All" +DB: master +SharedFields: +- ID: "06d5295c-ed2f-4a54-9bf2-26228d113318" + Hint: __Icon + Value: office/32x32/escalator_up.png +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + $module = Get-SpeModule -Name DataSync + $importsRoot = Get-Item -Path "master:$($module.Path)/Imports" + $imports = $importsRoot.Children + + $options = [ordered]@{} + foreach($import in $imports) { + $options[$import.Name] = $import.ID + } + + # $props = @{ + # Parameters = @( + # @{Name="selectedImportSet"; Title="Choose an import set"; Tooltip="All imports defined within the set will be processed."; Options=$options; } + # ) + # Title = "DataSync" + # Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + # Description = "Choose a set of import scripts to process." + # ShowHints = $true + # } + # + # $result = Read-Variable @props + # if($result -ne "ok") { + # exit + # } + + $imports | ForEach-Object { + $importScripts = Get-ChildItem -Path "master:" -ID $_.ID + + $importScripts | ForEach-Object { + Write-Host "Peparing to run import $($_.Name)" -ForegroundColor Yellow + Invoke-Script -Item $_ -ArgumentList $_ + } + } + +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 200 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190116T155504Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - Single.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - Single.yml new file mode 100644 index 0000000..e8ea122 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/Data Sync/Data Sync - Single.yml @@ -0,0 +1,53 @@ +--- +ID: "d3fef36c-f4ad-4f60-83e9-f0d708e58168" +Parent: "41ec2178-8414-4da6-8dda-e1cc66e4c532" +Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" +Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Toolbox/Data Sync/Data Sync - Single" +DB: master +SharedFields: +- ID: "06d5295c-ed2f-4a54-9bf2-26228d113318" + Hint: __Icon + Value: office/32x32/escalator_up.png +- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" + Hint: Script + Value: | + $module = Get-SpeModule -Name DataSync + $importsRoot = Get-Item -Path "master:$($module.Path)/Imports" + $imports = $importsRoot.Children + + $options = [ordered]@{} + foreach($import in $imports) { + $options[$import.Name] = $import.ID + } + + $props = @{ + Parameters = @( + @{Name="selectedImportSet"; Title="Choose an import set"; Tooltip="All imports defined within the set will be processed."; Options=$options; } + ) + Title = "DataSync" + Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) + Description = "Choose a set of import scripts to process." + ShowHints = $true + } + + $result = Read-Variable @props + if($result -ne "ok") { + exit + } + + $importScripts = Get-ChildItem -Path "master:" -ID $selectedImportSet + $importScripts | ForEach-Object { + Write-Host "Peparing to run import $($_.Name)" -ForegroundColor Yellow + Invoke-Script -Item $_ -ArgumentList $_ + } +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 200 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190116T155504Z diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync.yml index 458e426..b77909a 100644 --- a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync.yml +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync.yml @@ -1,6 +1,6 @@ --- ID: "116571f4-6797-4825-b79d-fe88ca1c0e9b" -Parent: "51e35b38-38ab-4b8c-b202-40d2f03b1056" +Parent: "ff9edd61-8020-4b40-87a8-314972f2b5dc" Template: "a87a00b1-e6db-45ab-8b54-636fec3b5523" Path: /sitecore/templates/Modules/PowerShell DataSync DB: master @@ -8,6 +8,9 @@ SharedFields: - ID: "06d5295c-ed2f-4a54-9bf2-26228d113318" Hint: __Icon Value: Office/32x32/folder.png +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 200 Languages: - Language: en Versions: diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 1/PaginationScript.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 1/PaginationScript.yml new file mode 100644 index 0000000..c323a7e --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 1/PaginationScript.yml @@ -0,0 +1,25 @@ +--- +ID: "f23573b3-33f2-4448-b213-93b8607a9612" +Parent: "5ec34870-1a95-4f6b-a3dd-ed543191f306" +Template: "455a3e98-a627-4b40-8035-e683a0331ac7" +Path: /sitecore/templates/Modules/PowerShell DataSync/Import Script/Step 1/PaginationScript +DB: master +SharedFields: +- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32" + Hint: Type + Value: "Multi-Line Text" +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 150 +Languages: +- Language: en + Fields: + - ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8" + Hint: Title + Value: "Script to determine source path for next page - must return empty string to stop processor" + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190208T165838Z diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/ForceIdScript.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/ForceIdScript.yml new file mode 100644 index 0000000..1f7b8ed --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/ForceIdScript.yml @@ -0,0 +1,25 @@ +--- +ID: "b0a60b70-8a87-4526-abf4-62a721961217" +Parent: "660c300e-2415-453e-a6cb-fa8c5f010180" +Template: "455a3e98-a627-4b40-8035-e683a0331ac7" +Path: /sitecore/templates/Modules/PowerShell DataSync/Import Script/Step 2/ForceIdScript +DB: master +SharedFields: +- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32" + Hint: Type + Value: "Single-Line Text" +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 57 +Languages: +- Language: en + Fields: + - ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8" + Hint: Title + Value: "Script to calculate ItemId - if defined, will attempt use -ForceId when creating new items" + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190212T153124Z diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/LanguageScript.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/LanguageScript.yml new file mode 100644 index 0000000..8b1e5b9 --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Script/Step 2/LanguageScript.yml @@ -0,0 +1,25 @@ +--- +ID: "edd8dcb0-7eb3-48a6-9cb6-369de0cfe6b2" +Parent: "660c300e-2415-453e-a6cb-fa8c5f010180" +Template: "455a3e98-a627-4b40-8035-e683a0331ac7" +Path: /sitecore/templates/Modules/PowerShell DataSync/Import Script/Step 2/LanguageScript +DB: master +SharedFields: +- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32" + Hint: Type + Value: "Multi-Line Text" +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 500 +Languages: +- Language: en + Fields: + - ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8" + Hint: Title + Value: "Script to get language code for item - if set, will attempt to create a language version of item, instead of always creating a new item" + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190211T175118Z diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1.yml index 14b1903..ea42824 100644 --- a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1.yml +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1.yml @@ -1,13 +1,9 @@ --- -ID: "48d1b11e-a28d-48d7-a5d0-1fb81448b8d2" +ID: "41987704-d4fd-43c4-ab2c-ed9a2183a583" Parent: "286b8d8d-eead-48cb-87e2-4c4273f0a67e" Template: "e269fbb5-3750-427a-9149-7aa950b49301" Path: /sitecore/templates/Modules/PowerShell DataSync/Import Web Service Script/Step 1 DB: master -SharedFields: -- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" - Hint: __Sortorder - Value: 10 Languages: - Language: en Versions: @@ -15,7 +11,7 @@ Languages: Fields: - ID: "25bed78c-4957-4165-998a-ca1b52f67497" Hint: __Created - Value: 20190210T032716Z + Value: 20190208T165838Z - ID: "5dd74568-4d4b-44c1-b513-0af5f4cda34f" Hint: __Created by Value: | diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/Generate Request Headers Scrip.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/Generate Request Headers Scrip.yml new file mode 100644 index 0000000..56e1a8a --- /dev/null +++ b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/Generate Request Headers Scrip.yml @@ -0,0 +1,21 @@ +--- +ID: "3e3448f8-5d08-45d9-bc45-73040ea1711c" +Parent: "41987704-d4fd-43c4-ab2c-ed9a2183a583" +Template: "455a3e98-a627-4b40-8035-e683a0331ac7" +Path: /sitecore/templates/Modules/PowerShell DataSync/Import Web Service Script/Step 1/Generate Request Headers Script +DB: master +SharedFields: +- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32" + Hint: Type + Value: "Multi-Line Text" +- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" + Hint: __Sortorder + Value: 700 +Languages: +- Language: en + Versions: + - Version: 1 + Fields: + - ID: "25bed78c-4957-4165-998a-ca1b52f67497" + Hint: __Created + Value: 20190226T171153Z From 81f3577e3f6f40fd2de56c167c677c7463718a02 Mon Sep 17 00:00:00 2001 From: Aaron Bickle Date: Fri, 14 Jun 2019 08:19:45 -0700 Subject: [PATCH 2/4] Removing items that got moved to a different location. --- .../Functions/Invoke-SourceRequest.yml | 77 ------------------- .../DataSync/Functions/New-ItemName.yml | 40 ---------- .../DataSync/DataSync/Toolbox/DataSync.yml | 50 ------------ .../Step 1/PaginationScript.yml | 25 ------ 4 files changed, 192 deletions(-) delete mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Invoke-SourceRequest.yml delete mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/New-ItemName.yml delete mode 100644 App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/DataSync.yml delete mode 100644 App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/PaginationScript.yml diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Invoke-SourceRequest.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Invoke-SourceRequest.yml deleted file mode 100644 index 203945d..0000000 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Invoke-SourceRequest.yml +++ /dev/null @@ -1,77 +0,0 @@ ---- -ID: "97338054-16ac-43dc-8e9e-292e0e6aa017" -Parent: "d3c93968-b343-4fa5-be29-0b7138359988" -Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" -Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/Invoke-SourceRequest" -DB: master -SharedFields: -- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" - Hint: Script - Value: | - Import-Function -Name Invoke-SqlCommand - - function Invoke-SourceRequest { - param( - [Item]$ImportItem, - [string]$SourcePath - ) - - $sourceItems = @() - - switch($importScriptItem.TemplateId) { - ([TemplateIds]::ImportFlatFileScript) { - # Flat File - $extension = [System.IO.Path]::GetExtension($sourcePath) - if([string]::IsNullOrEmpty($extension)) { exit } - if($extension -eq ".csv") { - $sourceItems = Import-Csv -Path $sourcePath - } elseif ($extension -eq ".xml") { - $sourceItems = [xml](Get-Content -Path $sourcePath -Raw) - } elseif ($extension -eq ".json") { - $sourceItems = (Get-Content -Path $sourcePath -Raw) | ConvertFrom-Json - } else { - $sourceItems = Get-Content -Path $sourcePath -Raw - } - } - ([TemplateIds]::ImportSqlScript) { - # Sql Script - $query = $importScriptItem.Fields[[FieldIds]::SqlScript].Value - $sourceItems = Invoke-SqlCommand -Query $query -Connection $sourcePath - } - ([TemplateIds]::ImportWebServiceScript) { - # Web service - if (![Net.ServicePointManager]::SecurityProtocol.HasFlag([Net.SecurityProtocolType]::Tls12)) { - [Net.ServicePointManager]::SecurityProtocol += [Net.SecurityProtocolType]::Tls12 - } - - $response = Invoke-WebRequest -UseBasicParsing -Uri $sourcePath - $contentType = $response.Headers["Content-Type"] - if([string]::IsNullOrEmpty($contentType)) { exit } - $content = $response.Content - if($content -is [byte[]]) { - $content = [System.Text.Encoding]::UTF8.GetString($content) - } - if($contentType -match "json") { - $sourceItems = $content | ConvertFrom-Json - } elseif($contentType -match "xml") { - $sourceItems = [xml]$content - } else { - $sourceItems = $content - } - } - default { - Write-Host "Unable to complete because the import script is unrecognized." -ForegroundColor White -BackgroundColor Red - exit - } - } - - ,$sourceItems - } -Languages: -- Language: en - Versions: - - Version: 1 - Fields: - - ID: "25bed78c-4957-4165-998a-ca1b52f67497" - Hint: __Created - Value: 20190210T022528Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/New-ItemName.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/New-ItemName.yml deleted file mode 100644 index 475f101..0000000 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/New-ItemName.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -ID: "539b2434-9f59-4ae9-b726-1a423e4adf36" -Parent: "d3c93968-b343-4fa5-be29-0b7138359988" -Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" -Path: "/sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Functions/New-ItemName" -DB: master -SharedFields: -- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" - Hint: Script - Value: | - function New-ItemName { - [CmdletBinding()] - param( - [Parameter(Mandatory=$true)] - [ValidateNotNullOrEmpty()] - [string]$Name, - [string]$FallbackName = "InvalidName", - [switch]$Lowercase, - [switch]$SpaceToDash - ) - - if($Lowercase) { - $name = $name.ToLower() - } - - if($SpaceToDash) { - $name = $name -replace '\s+','-' - $name = $name -replace '-{2,}','-' - } - - [Sitecore.Data.Items.ItemUtil]::ProposeValidItemName($name, $fallbackName) - } -Languages: -- Language: en - Versions: - - Version: 1 - Fields: - - ID: "25bed78c-4957-4165-998a-ca1b52f67497" - Hint: __Created - Value: 20190117T160255Z diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/DataSync.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/DataSync.yml deleted file mode 100644 index 5df60bd..0000000 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Toolbox/DataSync.yml +++ /dev/null @@ -1,50 +0,0 @@ ---- -ID: "d3fef36c-f4ad-4f60-83e9-f0d708e58168" -Parent: "3298f7ca-0aba-4bca-8e26-f6b70760208b" -Template: "dd22f1b3-bd87-4db2-9e7d-f7a496888d43" -Path: /sitecore/system/Modules/PowerShell/Script Library/SPE/Extensions/DataSync/Toolbox/DataSync -DB: master -SharedFields: -- ID: "06d5295c-ed2f-4a54-9bf2-26228d113318" - Hint: __Icon - Value: office/32x32/escalator_up.png -- ID: "b1a94ff0-6897-47c0-9c51-aa6acb80b1f0" - Hint: Script - Value: | - $module = Get-SpeModule -Name DataSync - $importsRoot = Get-Item -Path "master:$($module.Path)/Imports" - $imports = $importsRoot.Children - - $options = [ordered]@{} - foreach($import in $imports) { - $options[$import.Name] = $import.ID - } - - $props = @{ - Parameters = @( - @{Name="selectedImportSet"; Title="Choose an import set"; Tooltip="All imports defined within the set will be processed."; Options=$options; } - ) - Title = "DataSync" - Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase) - Description = "Choose a set of import scripts to process." - ShowHints = $true - } - - $result = Read-Variable @props - if($result -ne "ok") { - exit - } - - $importScripts = Get-ChildItem -Path "master:" -ID $selectedImportSet - $importScripts | ForEach-Object { - Write-Host "Peparing to run import $($_.Name)" -ForegroundColor Yellow - Invoke-Script -Item $_ -ArgumentList $_ - } -Languages: -- Language: en - Versions: - - Version: 1 - Fields: - - ID: "25bed78c-4957-4165-998a-ca1b52f67497" - Hint: __Created - Value: 20190116T155504Z diff --git a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/PaginationScript.yml b/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/PaginationScript.yml deleted file mode 100644 index e3ef208..0000000 --- a/App_Data/Unicorn/SPE/Extensions/Templates/PowerShell DataSync/Import Web Service Script/Step 1/PaginationScript.yml +++ /dev/null @@ -1,25 +0,0 @@ ---- -ID: "e7d5151c-808c-4db2-a0ae-ebcb662c15c7" -Parent: "48d1b11e-a28d-48d7-a5d0-1fb81448b8d2" -Template: "455a3e98-a627-4b40-8035-e683a0331ac7" -Path: /sitecore/templates/Modules/PowerShell DataSync/Import Web Service Script/Step 1/PaginationScript -DB: master -SharedFields: -- ID: "ab162cc0-dc80-4abf-8871-998ee5d7ba32" - Hint: Type - Value: "Multi-Line Text" -- ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" - Hint: __Sortorder - Value: 150 -Languages: -- Language: en - Fields: - - ID: "19a69332-a23e-4e70-8d16-b2640cb24cc8" - Hint: Title - Value: Script to determine the next source path - Versions: - - Version: 1 - Fields: - - ID: "25bed78c-4957-4165-998a-ca1b52f67497" - Hint: __Created - Value: 20190210T032717Z From 5cb3b9edec46626763dd35a931e2735a622dac1b Mon Sep 17 00:00:00 2001 From: Aaron Bickle Date: Tue, 18 Jun 2019 15:03:44 -0700 Subject: [PATCH 3/4] Fixing multi-lingual import processor. --- .../Functions/Module Functions/Invoke-ProcessSourceItems.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml index adf558e..b82c2ef 100644 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml @@ -105,7 +105,7 @@ SharedFields: if((Test-Path -Path $path)) { Write-Host "- [!] Item exists at path $($path)" - $destinationItem = Get-Item -Path $path + $destinationItem = Get-Item -Path $path -Language $langCode } if(!$destinationItem -and $langCode -eq "en") { @@ -122,9 +122,8 @@ SharedFields: $lookupValue = Invoke-Expression -Command $fieldMappings[$itemSyncFieldName] $existingEnglishItems = $destinationRoot.Axes.GetDescendants() | Where-Object { $_.TemplateId -eq $importTemplateId -and $($_.Language.Name) -eq "en" -and $_.Fields[$itemSyncFieldName].Value -eq $lookupValue } - $existingEnglishItem = $existingEnglishItems | Select-Object -Index 0 - if ($existingEnglishItems.count -gt 1) { + $existingEnglishItem = $existingEnglishItems | Select-Object -Index 0 Write-Host "- [!] Multiple items for nid $($sourceItem.attributes.nid) location. Using Sitecore Item $($existingEnglishItem.ID)" } From 2e2bb2e0cc4bfdf4de1f36a8bf7880f80a899973 Mon Sep 17 00:00:00 2001 From: Aaron Bickle Date: Tue, 18 Jun 2019 15:41:33 -0700 Subject: [PATCH 4/4] Fixing stat tracker --- .../DataSync/DataSync/Development/Import Runner.yml | 8 ++++---- .../Module Functions/Invoke-ProcessSourceItems.yml | 12 +++++------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml index f1ad449..b4d5471 100644 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Development/Import Runner.yml @@ -118,14 +118,14 @@ SharedFields: $sourceItems = Get-Content -Path $sourcePath -Raw } - $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker + Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker ([ref]$statTracker) } ([TemplateIds]::ImportSqlScript) { # Sql Script $query = $importScriptItem.Fields[[FieldIds]::SqlScript].Value $sourceItems = Invoke-SqlCommand -Query $query -Connection $sourcePath - $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker + Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker ([ref]$statTracker) } ([TemplateIds]::ImportWebServiceScript) { # Web service @@ -151,7 +151,7 @@ SharedFields: $sourcePath = $nextPageSourcePath - $statTracker = Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker $statTracker + Invoke-ProcessSourceItems -SourceItems $sourceItems -ScriptItem $importScriptItem -FieldMappings $importFieldMappingsLookup -StatTracker ([ref]$statTracker) } } default { @@ -167,7 +167,7 @@ SharedFields: Write-Host "$($timestamp) $($importScriptItem.Name) completed" -ForegroundColor Green $time = $watch.ElapsedMilliseconds / 1000 - $statTracker["Execution time in seconds"] = $time > $null + $statTracker["Execution time in seconds"] = $time $statTracker | Format-List Write-Progress -Activity "Completed importing data for $($importScriptItem.Name)" -Completed -Status "Import Complete" diff --git a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml index b82c2ef..5f84cd8 100644 --- a/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml +++ b/App_Data/Unicorn/SPE/Extensions/DataSync/DataSync/Functions/Module Functions/Invoke-ProcessSourceItems.yml @@ -12,7 +12,7 @@ SharedFields: $SourceItems, $ScriptItem, $FieldMappings, - $StatTracker + [ref]$StatTracker ) { Write-Progress -Activity "Running pre import script" -Status $status $beforeImportScript = $scriptItem.Fields[[FieldIds]::BeforeImportScript].Value @@ -183,12 +183,10 @@ SharedFields: Invoke-Expression -Command $afterImportScript } - $statTracker["Import items processed"] = $statTracker["Import items processed"] + $sourceItems.Count > $null - $statTracker["New items created"] = $statTracker["New items created"] + $newItemsCount > $null - $statTracker["Existing items skipped"] = $statTracker["Existing items skipped"] + $skippedItemsCount > $null - $statTracker["Existing items updated"] = $statTracker["Existing items updated"] + $existingItemsUpdatedCount > $null - - return $statTracker + $statTracker.Value["Import items processed"] = $statTracker.Value["Import items processed"] + $sourceItems.Count + $statTracker.Value["New items created"] = $statTracker.Value["New items created"] + $newItemsCount + $statTracker.Value["Existing items skipped"] = $statTracker.Value["Existing items skipped"] + $skippedItemsCount + $statTracker.Value["Existing items updated"] = $statTracker.Value["Existing items updated"] + $existingItemsUpdatedCount } - ID: "ba3f86a2-4a1c-4d78-b63d-91c2779c1b5e" Hint: __Sortorder