Skip to content

Commit e716f30

Browse files
committed
Minor improvement to the locked item report.
1 parent fa730e2 commit e716f30

File tree

1 file changed

+27
-22
lines changed
  • unicorn/SPE/Scripts/SPE/SPE/Tools/Security Management/Reports/Security Audit

1 file changed

+27
-22
lines changed

unicorn/SPE/Scripts/SPE/SPE/Tools/Security Management/Reports/Security Audit/Locked Items.yml

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,18 @@ SharedFields:
1414
<#
1515
.SYNOPSIS
1616
Lists all the items locked by the specified user.
17-
1817
.NOTES
1918
Adam Najmanowicz, Michael West
2019
#>
21-
2220
Import-Function -Name Invoke-SqlCommand
23-
2421
filter Where-LockedOnDate {
2522
param(
2623
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
2724
[Sitecore.Data.Items.Item]$Item,
28-
2925
[datetime]$Date=([datetime]::Today),
3026
[switch]$IsBefore,
31-
3227
[int]$MaxDays
3328
)
34-
3529
$convertedDate = [Sitecore.DateUtil]::ToServerTime(([Sitecore.Data.Fields.LockField]($item.Fields[[Sitecore.FieldIDs]::Lock])).Date)
3630
$isWithinDate = $false
3731
if($IsBefore.IsPresent) {
@@ -43,7 +37,6 @@ SharedFields:
4337
$isWithinDate = $true
4438
}
4539
}
46-
4740
if($isWithinDate) {
4841
if($MaxDays -lt [int]::MaxValue) {
4942
if([math]::Abs(($convertedDate - $Date).Days) -le $MaxDays) {
@@ -54,13 +47,25 @@ SharedFields:
5447
}
5548
}
5649
}
57-
50+
filter Where-InactiveGreaterThan {
51+
param(
52+
[Parameter(Mandatory=$true,ValueFromPipeline=$true)]
53+
[Sitecore.Data.Items.Item]$Item,
54+
[int]$MinDays
55+
)
56+
if($MinDays -gt 0) {
57+
if([math]::Round(([datetime]::UtcNow - $item.__Updated).TotalDays) -ge $MinDays) {
58+
$item
59+
}
60+
} else {
61+
$item
62+
}
63+
}
5864
$item = Get-Item -Path "master:\content\"
59-
6065
$user = ""
61-
6266
$periodOptions = [ordered]@{Before=1;After=2;}
6367
$maxDaysOptions = [ordered]@{"-- Skip --"=[int]::MaxValue;30=30;90=90;120=120;365=365;}
68+
$minInactiveDaysOptions = [ordered]@{"-- Skip --"=0;14=14;30=30;60=60;90=90;120=120;365=365;}
6469
$dialogProps = @{
6570
Title = "Items Locked"
6671
Description = "Lists all the items locked by the specified user."
@@ -88,41 +93,43 @@ SharedFields:
8893
},
8994
@{
9095
Name = "selectedMaxDays"
91-
Title = "Max Days"
96+
Title = "Maximum Days Locked"
9297
Value = [int]::MaxValue
9398
Options = $maxDaysOptions
94-
Tooltip = "Pick the maximum number of days to include starting with the specified date"
99+
Tooltip = "Pick the maximum number of days to include starting with the specified date."
100+
Editor = "combo"
101+
},
102+
@{
103+
Name = "selectedMinimumInactiveDays"
104+
Title = "Minimum Inactive Days"
105+
Value = [int]::MaxValue
106+
Options = $minInactiveDaysOptions
107+
Tooltip = "Pick the minimum number of inactive days to include starting with the specified date."
95108
Editor = "combo"
96109
}
97110
)
98111
Icon = [regex]::Replace($PSScript.Appearance.Icon, "Office", "OfficeWhite", [System.Text.RegularExpressions.RegexOptions]::IgnoreCase)
99112
ShowHints = $true
100113
}
101-
102114
$result = Read-Variable @dialogProps
103-
104115
if($result -ne "ok") {
105116
Close-Window
106117
Exit
107118
}
108-
109119
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
110-
111120
$query = @"
112121
SELECT [ItemId], [Value], [Language], [Version]
113122
FROM [dbo].[VersionedFields]
114123
WHERE [FieldId] = '$([Sitecore.FieldIDs]::Lock.ToString())'
115124
AND [Value] <> '' AND [Value] <> '<r />'
116125
"@
117-
118126
if($user) {
119127
$query += " AND [Value] LIKE '<r owner=`"$($user)`"%'"
120128
}
121-
122129
$records = Invoke-SqlCommand -Connection $connection -Query $query
123130
$items = $records | ForEach-Object { Get-Item -Path "master:" -ID $_.ItemId -Language $_.Language -Version $_.Version } |
124-
Where-LockedOnDate -Date $selectedDate -IsBefore:($selectedPeriod -eq 1) -MaxDays $selectedMaxDays
125-
131+
Where-LockedOnDate -Date $selectedDate -IsBefore:($selectedPeriod -eq 1) -MaxDays $selectedMaxDays |
132+
Where-InactiveGreaterThan -MinDays $selectedMinimumInactiveDays
126133
if($items.Count -eq 0) {
127134
Show-Alert "There are no items items locked by the specified user."
128135
} else {
@@ -137,7 +144,6 @@ SharedFields:
137144
param(
138145
[datetime]$Date
139146
)
140-
141147
if($Date -ge [datetime]::MinValue) {
142148
$Date
143149
}
@@ -157,7 +163,6 @@ SharedFields:
157163
@{Label="Created by"; Expression={$_."__Created by"} },
158164
@{Label="Owner"; Expression={ $_.__Owner} }
159165
}
160-
161166
Close-Window
162167
Languages:
163168
- Language: da

0 commit comments

Comments
 (0)