Skip to content

Commit

Permalink
Merge pull request #1331 from jensotto/fix-spsearchserviceapp-dbname
Browse files Browse the repository at this point in the history
SPSearchServiceApp: Fixed issue with hardcoded database name and space
  • Loading branch information
ykuijs committed Aug 25, 2021
2 parents 59601b6 + 18b6def commit 106cade
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- SPFarm
- Added parameter SkipRegisterAsDistributedCacheHost
- SPSearchServiceApp
- Fixed an issue if the analytics database where not provisioned with a
hardcoded name
- Fixed an issue if search databases had names containing one or more spaces
- SPWebAppAuthentication
- Updated the description for the new zone setting parameters
- SPWebAppClientCallableSettings
Expand Down
1 change: 1 addition & 0 deletions Modules/SharePointDsc/DscResource.Tests
Submodule DscResource.Tests added at bc9a07
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,15 @@ function Get-TargetResource
-User $farmAccount) -eq $false

Write-Verbose -Message "Checking Analytics reporting Database"
$analyticsDB = "$($adminDB)_AnalyticsReportingStore"
if ($farmAccountPermissionsNeedCorrecting -eq $false)
foreach ($database in $serviceApp.AnalyticsReportingDatabases)
{
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false
$analyticsDB = $database.Name
if ($farmAccountPermissionsNeedCorrecting -eq $false)
{
$farmAccountPermissionsNeedCorrecting = (Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false
}
}

Write-Verbose -Message "Checking Crawl Database(s)"
Expand Down Expand Up @@ -539,14 +542,17 @@ function Set-TargetResource
}

Write-Verbose -Message "Checking and correcting Analytics reporting Database"
$analyticsDB = "$($adminDB)_AnalyticsReportingStore"
if ((Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false)
foreach ($database in $serviceApp.AnalyticsReportingDatabases)
{
Set-UserAsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount
$analyticsDB = $database.Name
if ((Confirm-UserIsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount) -eq $false)
{
Set-UserAsDBOwner -SQLServer $dbServer `
-Database $analyticsDB `
-User $farmAccount
}
}

Write-Verbose -Message "Checking and correcting Crawl Database(s)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function Confirm-UserIsDBOwner
$command.Connection = $connection

$command.CommandText = @"
USE $Database
USE [$Database]
SELECT DP1.name AS DatabaseRoleName,
isnull (DP2.name, 'No members') AS DatabaseUserName
Expand Down Expand Up @@ -116,7 +116,7 @@ function Set-UserAsDBOwner
$command.Connection = $connection

$command.CommandText = @"
USE $Database
USE [$Database]
DECLARE @NewUserName sysname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,18 +306,22 @@ try

Mock -CommandName Get-SPServiceApplication -MockWith {
$spServiceApp = [PSCustomObject]@{
TypeName = "Search Service Application"
DisplayName = $testParams.Name
Name = $testParams.Name
ApplicationPool = @{ Name = $testParams.ApplicationPool }
Database = @{
TypeName = "Search Service Application"
DisplayName = $testParams.Name
Name = $testParams.Name
ApplicationPool = @{ Name = $testParams.ApplicationPool }
Database = @{
Name = $testParams.DatabaseName
NormalizedDataSource = 'SQL01'
}
SearchAdminDatabase = @{
SearchAdminDatabase = @{
Name = $testParams.DatabaseName
NormalizedDataSource = 'SQL01'
}
AnalyticsReportingDatabases = @{
Name = $testParams.DatabaseName + '_AnalyticsReportingStore'
NormalizedDataSource = 'SQL01'
}
}
$spServiceApp = $spServiceApp | Add-Member -MemberType ScriptMethod -Name GetType -Value {
return @{ FullName = $getTypeFullName }
Expand Down

0 comments on commit 106cade

Please sign in to comment.