-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path03-Cache_classes.ps1
105 lines (91 loc) · 3.35 KB
/
03-Cache_classes.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
Using module .\OneRoster.psm1
Param(
[String]$WorkFolder = ".\gclass-OneRoster\"
)
Get-Module -Name GClass | Remove-Module; Import-Module .\GClass.psm1
$TLOG = ((".\Logs\" + (Get-Date -Format u) +"-Cache.log").Replace(" ", "-")).Replace(":", "-")
Start-Transcript -path $TLOG
$ErrorActionPreference = "Stop"
#$ErrorActionPreference = "Inquire"
Function Find_classes()
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[String]$WorkFolder
)
If ((Show-PSGSuiteConfig | Select-Object -ExpandProperty ConfigName) -ne "TEACHERS")
{
Write-Host -Object "Switching to TEACHERS"
Switch-PSGSuiteConfig -ConfigName TEACHERS
}
#Clear-_GSCourse -Domain $(Show-PSGSuiteConfig).Domain
#Clear-_GSCourseAlias -Domain $(Show-PSGSuiteConfig).Domain
#Write-Host -Object "Getting fresh Class data"
#Read-ORclasses -FolderPath $WorkFolder -LoadXML $true | Select-Object -ExpandProperty sourcedId | New-ClassAlias | Get-_GSCourse -SkipCache $true | Out-Null
#Write-Host -Object "Done getting Class data"
Read-OROrgs -FolderPath $WorkFolder | ForEach-Object -Process {
#Imports
Write-Host -Object "Importing classes For: $($_.name)"
$classes_I = @()
$classes_I += Read-ORclasses -FolderPath $WorkFolder -Org $_ -LoadXML $true #| Where-Object -Property status -NE ([OR_StatusType]::inactive)
If ($classes_I.Count -gt 0)
{
Write-Host -Object "Caching classes datas: $($classes_I.Count)"
$classes_I.sourcedId | New-ClassAlias
}
Else
{
Write-Host -Object "No classes to cache"
}
} | Get-_GSCourse -SkipCache $true
}
Function Link_classes()
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[String]$WorkFolder
)
If ((Show-PSGSuiteConfig | Select-Object -ExpandProperty ConfigName) -ne "TEACHERS")
{
Write-Host -Object "Switching to TEACHERS"
Switch-PSGSuiteConfig -ConfigName TEACHERS
}
#Clear-_GSCourse -Domain $(Show-PSGSuiteConfig).Domain
#Clear-_GSCourseAlias -Domain $(Show-PSGSuiteConfig).Domain
#Write-Host -Object "Getting fresh Class data"
#Read-ORclasses -FolderPath $WorkFolder -LoadXML $true | Select-Object -ExpandProperty sourcedId | New-ClassAlias | Get-_GSCourse -SkipCache $true | Out-Null
#Write-Host -Object "Done getting Class data"
Read-OROrgs -FolderPath $WorkFolder | ForEach-Object -Process {
#Imports
Write-Host -Object "Importing classes For: $($_.name)"
$classes_I = @()
$classes_I += Read-ORclasses -FolderPath $WorkFolder -Org $_ -LoadXML $true #| Where-Object -Property status -NE ([OR_StatusType]::inactive)
If ($classes_I.Count -gt 0)
{
Write-Host -Object "Caching classes links: $($classes_I.Count)"
$classes_I.sourcedId
}
Else
{
Write-Host -Object "No classes to cache"
}
} | Update-ClassLink -SkipCache $false -Domain $(Show-PSGSuiteConfig).Domain
}
Function Export-classes
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true)]
[String]$WorkFolder
)
$r = Find_classes -WorkFolder $WorkFolder
$r = Link_classes -WorkFolder $WorkFolder
#Export-ClassLink -InputObject $r
#Return $r
}
$r = Export-classes -WorkFolder $WorkFolder