Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forbedringer av Install.ps1 og UpgradeAllExistingSitesToLatest.ps1 skriptene #1508

Merged
merged 12 commits into from
Apr 24, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Sjekk ut [release notes](./releasenotes/1.9.0.md) for høydepunkter og mer detal
- Rettet et problem med visning av 'valuta' felt-verdier i redigeringspaneler for prosjektstatus og prosjektinformasjon [#1503](https://github.com/Puzzlepart/prosjektportalen365/issues/1503)
- Rettet et problem hvor visnings-id ikke la seg i URL feltet ved innlastning eller bytting av visninger i Porteføljeoversikt [#1355](https://github.com/Puzzlepart/prosjektportalen365/issues/1355)
- Rettet et problem hvor visnings-id ikke la seg i URL feltet ved opprettelse av nye visninger, samt oppdatering av visningen (Porteføljeoversikter og andre aggregerte oversikter) [#1441](https://github.com/Puzzlepart/prosjektportalen365/issues/1441)
- Rettet og forbedret skript for å oppgradere eksisterende prosjektområder [#1471](https://github.com/Puzzlepart/prosjektportalen365/issues/1471) [#1475](https://github.com/Puzzlepart/prosjektportalen365/issues/1475) [#1487](https://github.com/Puzzlepart/prosjektportalen365/issues/1487)

### Forbedringer

Expand Down
13 changes: 8 additions & 5 deletions Install/Install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -561,10 +561,15 @@ if ($Upgrade.IsPresent) {
else {
Write-Host "[SUCCESS] Installation completed in $($sw.Elapsed)" -ForegroundColor Green
}
Write-Host "[INFO] Consider running .\Install\Scripts\UpgradeAllSitesToLatest.ps1 to upgrade all sites to the latest version of Prosjektportalen 365."
Write-Host "[INFO] This is required after upgrading between minor versions, e.g. from 1.8.x to 1.9.x."
#endregion

## Turning off PnP trace logging
Set-PnPTraceLog -Off

#region Log installation and send pingback to Azure Function
Write-Host "[INFO] Logged installation entry"
Write-Host "[INFO] Logging installation entry"
$InstallEndTime = (Get-Date -Format o)

$InstallEntry = @{
Expand All @@ -590,7 +595,7 @@ $InstallationEntry = Add-PnPListItem -List "Installasjonslogg" -Values $InstallE

## Attempting to attach the log file to installation entry
if ($null -ne $InstallationEntry) {
Add-PnPListItemAttachment -List "Installasjonslogg" -Identity $InstallationEntry.Id -Path $LogFilePath -ErrorAction SilentlyContinue >$null 2>&1
$AttachmentOutput = Add-PnPListItemAttachment -List "Installasjonslogg" -Identity $InstallationEntry.Id -Path $LogFilePath -ErrorAction SilentlyContinue
}

Disconnect-PnPOnline
Expand All @@ -603,8 +608,6 @@ try {
catch {}
#endregion

## Turning off PnP trace logging
Set-PnPTraceLog -Off

## Clearing cached access tokens
$global:__InteractiveCachedAccessTokens = $null

11 changes: 10 additions & 1 deletion Install/Scripts/PostInstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ foreach ($tmpl in $TemplatesMap.GetEnumerator()) {
}

Write-Host "[SUCCESS] Post-install action: Ensured default project templates" -ForegroundColor Green
Write-Host "[INFO] Post-install action: Adding list content to template setup"
Write-Host "[INFO] Post-install action: Adding default list content to template setup"

$TemplateSetupMap = @{
"Bygg" = "Byggprosjekt";
Expand All @@ -54,6 +54,10 @@ $ListContentMap = @{
$ListContent = Get-PnPListItem -List Listeinnhold
$TemplateOptions = Get-PnPListItem -List Maloppsett


$DefaultExists = $TemplateOptions | Where-Object { $_["IsDefaultTemplate"] -eq $True }


$Standard = $TemplateOptions | Where-Object { $_["Title"] -eq $TemplateSetupMap["Standard"] }
if ($Standard) {
$StandardPlanner = $ListContent | Where-Object { $_["Title"] -eq $ListContentMap["PlannerStandard"] }
Expand All @@ -63,6 +67,9 @@ if ($Standard) {
$StandardItems += [Microsoft.SharePoint.Client.FieldLookupValue]@{"LookupId" = $StandardPlanner.Id }
$StandardItems += [Microsoft.SharePoint.Client.FieldLookupValue]@{"LookupId" = $StandardPhaseChecklist.Id }

if ($null -eq $DefaultExists) {
$Standard["IsDefaultTemplate"] = $True
}
$Standard["ListContentConfigLookup"] = $StandardItems
$Standard.SystemUpdate()
$Standard.Context.ExecuteQuery()
Expand Down Expand Up @@ -102,3 +109,5 @@ if ($Anlegg) {
else {
Write-Host "[WARNING] Failed to find Anleggsprosjekt template. Please check the Maloppsett list." -ForegroundColor Yellow
}

Write-Host "[SUCCESS] Post-install action: Added default list content to template setup" -ForegroundColor Green
65 changes: 57 additions & 8 deletions Install/Scripts/UpgradeAllSitesToLatest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ $global:__InstalledVersion = $null
$global:__PreviousVersion = $null
$global:__PnPConnection = $null
$global:__CurrentChannelConfig = $null
$InstallStartTime = (Get-Date -Format o)

$ScriptDir = (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent)

Expand Down Expand Up @@ -57,6 +58,11 @@ function Connect-SharePoint {

function UpgradeSite($Url) {
Connect-SharePoint -Url $Url
$ProjectPropertiesList = Get-PnPList -Identity "Prosjektegenskaper" -ErrorAction SilentlyContinue
if ($null -eq $ProjectPropertiesList) {
Write-Host "`t`tNo Prosjektegenskaper list found - this site is not a qualified Prosjektportalen site. Skipping upgrade of site $Url" -ForegroundColor Yellow
return
}
Get-ChildItem $ScriptDir/UpgradeAllSitesToLatest -Filter *.ps1 | ForEach-Object {
. $_.FullName
}
Expand All @@ -65,12 +71,14 @@ function UpgradeSite($Url) {
Write-Host "This script will update all existing sites in a Prosjektportalen installation. This requires you to have the SharePoint admin role"

Set-PnPTraceLog -Off
Start-Transcript -Path "$PSScriptRoot/UpgradeSites_Log-$((Get-Date).ToString('yyyy-MM-dd-HH-mm')).txt"
$LogFilePath = "$PSScriptRoot/UpgradeSites_Log-$((Get-Date).ToString('yyyy-MM-dd-HH-mm')).txt"
Start-Transcript -Path $LogFilePath

Connect-SharePoint -Url $Url
$InstallLogEntries = Get-PnPListItem -List "Installasjonslogg" -Query "<View><Query><OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy></Query></View>"
$global:__InstalledVersion = ($InstallLogEntries | Select-Object -First 1).FieldValues["InstallVersion"]
$global:__PreviousVersion = ($InstallLogEntries | Select-Object -Skip 1 -First 1).FieldValues["InstallVersion"]
$NativeLogEntries = $InstallLogEntries | Where-Object {$_.FieldValues.Title -match "PP365+[\s]+[0-9]+[.][0-9]+[.][0-9]+[.][a-zA-Z0-9]+"}
$global:__InstalledVersion = ($NativeLogEntries | Select-Object -First 1).FieldValues["InstallVersion"]
$global:__PreviousVersion = ($NativeLogEntries | Select-Object -Skip 1 -First 1).FieldValues["InstallVersion"]

[System.Uri]$Uri = $Url
$AdminSiteUrl = (@($Uri.Scheme, "://", $Uri.Authority) -join "").Replace(".sharepoint.com", "-admin.sharepoint.com")
Expand All @@ -85,7 +93,7 @@ $UserName = $Context.Web.CurrentUser.LoginName

Write-Host "Retrieving all sites of the Project Portal hub..."
$ProjectsHub = Get-PnPTenantSite -Identity $Url
$ProjectsInHub = Get-PnPTenantSite | Where-Object { $_.HubSiteId -eq $ProjectsHub.HubSiteId -and $_.Url -ne $ProjectsHub.Url } | ForEach-Object { return $_.Url }
$ProjectsInHub = Get-PnPTenantSite -Template "GROUP#0" | Where-Object { $_.HubSiteId -eq $ProjectsHub.HubSiteId -and $_.Url -ne $ProjectsHub.Url } | ForEach-Object { return $_.Url }

Write-Host "The following sites were found to be part of the Project Portal hub:"
$ProjectsInHub | ForEach-Object { Write-Host "`t$_" }
Expand All @@ -98,15 +106,21 @@ if (-not $CI_MODE) {
while ("y", "n" -notcontains $YesOrNo)
}

if ($YesOrNo -eq "y" -or $CI_MODE) {
$ProjectsInHub | ForEach-Object {
if ($YesOrNo -eq "y" -or $CI_MODE) {
$ProjectsInHub | ForEach-Object -Begin {$ProgressCount = 0} {
[Int16]$PercentComplete = (++$ProgressCount)*100/$ProjectsInHub.Count
Write-Progress -Activity "Granting access to all sites in the hub" -Status "$PercentComplete% Complete" -PercentComplete $PercentComplete -CurrentOperation "Processing site $_"

Write-Host "`tGranting access to $_"
Set-PnPTenantSite -Url $_ -Owners $UserName
}
}

Write-Host "Upgrading existing sites from version $global:__PreviousVersion to $global:__InstalledVersion)..."
$ProjectsInHub | ForEach-Object {
$ProjectsInHub | ForEach-Object -Begin {$ProgressCount = 0} {
[Int16]$PercentComplete = (++$ProgressCount)*100/$ProjectsInHub.Count
Write-Progress -Activity "Upgrading all sites in hub" -Status "$PercentComplete% Complete" -PercentComplete $PercentComplete -CurrentOperation "Processing site $_"

Write-Host "`tUpgrading site $_"
UpgradeSite -Url $_
Write-Host "`t`tDone processing $_" -ForegroundColor Green
Expand All @@ -121,13 +135,48 @@ if (-not $CI_MODE) {
}

if ($YesOrNo -eq "y" -or $CI_MODE) {
$ProjectsInHub | ForEach-Object {
$ProjectsInHub | ForEach-Object -Begin {$ProgressCount = 0} {
[Int16]$PercentComplete = (++$ProgressCount)*100/$ProjectsInHub.Count
Write-Progress -Activity "Removing admin access" -Status "$PercentComplete% Complete" -PercentComplete $PercentComplete -CurrentOperation "Processing site $_"

Write-Host "`tRemoving access to $_"
Connect-SharePoint -Url $_
Remove-PnPSiteCollectionAdmin -Owners $UserName
}
}

Write-Progress -Activity "Upgrading all sites in hub" -Status "Completed" -PercentComplete 100 -Completed
Write-Host "Upgrade of all project sites is complete" -ForegroundColor Green

Stop-Transcript

Connect-SharePoint -Url $Url

$InstallEntry = @{
Title = "PP365 UpgradeAllSitesToLatest.ps1"
InstallStartTime = $InstallStartTime;
InstallEndTime = (Get-Date -Format o);
InstallVersion = $global:__InstalledVersion;
InstallCommand = $MyInvocation.Line.Substring(2);
}

if ($null -ne $UserName) {
$InstallEntry.InstallUser = $UserName
}
if (-not [string]::IsNullOrEmpty($CI)) {
$InstallEntry.InstallCommand = "GitHub CI";
}
if ($Channel -ne "main") {
$InstallEntry.InstallChannel = $global:__CurrentChannelConfig.Channel
}

## Logging installation to SharePoint list
$InstallationEntry = Add-PnPListItem -List "Installasjonslogg" -Values $InstallEntry -ErrorAction SilentlyContinue

## Attempting to attach the log file to installation entry
if ($null -ne $InstallationEntry) {
$AttachmentOutput = Add-PnPListItemAttachment -List "Installasjonslogg" -Identity $InstallationEntry.Id -Path $LogFilePath -ErrorAction SilentlyContinue
}


$global:__PnPConnection = $null
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ if ($global:__PreviousVersion -lt $TargetVersion) {
foreach ($Page in $Pages) {
$PageName = "$($Page.Name).aspx"
$DeprecatedComponent = Get-PnPPageComponent -Page $PageName -ErrorAction SilentlyContinue | Where-Object { $_.WebPartId -eq $Page.ControlId } | Select-Object -First 1
if ($null -ne $DeprecatedComponent) {
if ($null -ne $DeprecatedComponent -and $DeprecatedComponent.WebPartId -ne "6c0e484d-f6da-40d4-81fc-ec1389ef29a8") {
Write-Host "`t`tReplacing deprecated component $($Page.ControlId) for $($PageName)"
$JsonControlData = Get-Content "$BaseDir/JsonControlData_$($Page.Name).json" -Raw -Encoding UTF8
$Title = $JsonControlData | ConvertFrom-Json | Select-Object -ExpandProperty title

Remove-PnPPageComponent -Page $PageName -InstanceId $DeprecatedComponent.InstanceId -Force -ErrorAction SilentlyContinue
Invoke-PnPSiteTemplate -Path "$BaseDir/Template_ProjectAggregationWebPart.xml" -Parameters @{"JsonControlData" = $JsonControlData; "PageName" = $PageName; "Title" = $Title }
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if ($global:__PreviousVersion -lt $TargetVersion) {
if ($null -ne $ResourceAllocation) {
$ResourceLoadSiteColumn = Get-PnPField -Identity "GtResourceLoad"
$ResourceLoadListColumn = Get-PnPField -Identity "GtResourceLoad" -List $ResourceAllocation
if ($null -ne $ResourceLoadSiteColumn) {
if ($ResourceLoadSiteColumn.Id.Guid -ne $ResourceLoadListColumn.Id.Guid) {
Write-Host "`t`tReplacing GtResourceLoad field"
$PreviousValues = Get-PnPListItem -List $ResourceAllocation -Fields "ID", "GtResourceLoad" | ForEach-Object {
@{Id = $_.Id; GtResourceLoad = $_.FieldValues["GtResourceLoad"] }
Expand All @@ -18,13 +18,13 @@ if ($global:__PreviousVersion -lt $TargetVersion) {
$ResourceAllocationContentType = Get-PnPContentType -Identity "Ressursallokering" -List "Ressursallokering" -ErrorAction SilentlyContinue
if ($null -ne $ResourceAllocationContentType) {
Write-Host "`t`t`tRemoving old field"
Remove-PnPField -Identity $ResourceLoadListColumn -List $ResourceAllocation -Force >$null 2>&1
$ResourceOperation = Remove-PnPField -Identity $ResourceLoadListColumn -List $ResourceAllocation -Force


Write-Host "`t`t`tAdding the site field"
$FieldLink = New-Object Microsoft.SharePoint.Client.FieldLinkCreationInformation
$FieldLink.Field = $ResourceLoadSiteColumn
$ResourceAllocationContentType.FieldLinks.Add($FieldLink) >$null 2>&1
$ResourceOperation = $ResourceAllocationContentType.FieldLinks.Add($FieldLink)
$ResourceAllocationContentType.Update($false)
$ResourceAllocationContentType.Context.ExecuteQuery()

Expand All @@ -46,7 +46,7 @@ if ($global:__PreviousVersion -lt $TargetVersion) {
# Assuming that noone had more than 200% previously
$ResourceLoad = ($ResourceLoad / 100) # Convert to percentage if it wasn't previously
}
Set-PnPListItem -List $ResourceAllocation -Identity $_.Id -Values @{"GtResourceLoad" = $ResourceLoad } -UpdateType SystemUpdate >$null 2>&1
$ResourceOperation = Set-PnPListItem -List $ResourceAllocation -Identity $_.Id -Values @{"GtResourceLoad" = $ResourceLoad } -UpdateType SystemUpdate
}
}

Expand Down
2 changes: 1 addition & 1 deletion Templates/Portfolio/Objects/Lists/Maloppsett.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<pnp:DataValue FieldName="GtProjectStatusContentType">0x010022252E35737A413FB56A1BA53862F6D5</pnp:DataValue>
<pnp:DataValue FieldName="GtProjectColumns">Kolonner for Prosjektportalen (Prosjekt)</pnp:DataValue>
<pnp:DataValue FieldName="GtProjectCustomColumns">Egendefinerte kolonner for Prosjektportalen</pnp:DataValue>
<pnp:DataValue FieldName="IsDefaultTemplate">True</pnp:DataValue>
<pnp:DataValue FieldName="IsDefaultTemplate">False</pnp:DataValue>
<pnp:DataValue FieldName="IsDefaultExtensionsLocked">False</pnp:DataValue>
<pnp:DataValue FieldName="IsDefaultListContentLocked">False</pnp:DataValue>
<pnp:DataValue FieldName="GtDescription">Dette er standardmalen for prosjekt som følger med Prosjektportalen 365.</pnp:DataValue>
Expand Down