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

[Set-DbaAgentAlert] - Added ShouldProcess to the Rename to fix #8137 #8138

Merged

Conversation

MikeyBronowski
Copy link
Contributor

Type of Change

  • Bug fix (non-breaking change, fixes Set-DbaAgentAlert - renames an alert even with Whatif #8137 )
  • New feature (non-breaking change, adds functionality, fixes # )
  • Breaking change (effects multiple commands or functionality, fixes # )
  • Ran manual Pester test and has passed (.\tests\manual.pester.ps1)
  • Adding code coverage to existing functionality
  • Pester test is included
  • If new file reference added for test, has is been added to github.com/dataplat/appveyor-lab ?
  • Unit test is included
  • Documentation
  • Build system

Purpose

Approach

Commands to test

Screenshots

Learning

Write-Message -Message "Setting alert name to $NewName" -Level Verbose
$currentAlert.Rename($NewName)
if ($Pscmdlet.ShouldProcess($server, "Setting alert name to $NewName for $a")) {
$JobSchedule.Rename($NewName)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$JobSchedule?


# Change the alert
$currentAlert.Alter()
} catch {
Stop-Function -Message "Something went wrong changing the alert" -ErrorRecord $_ -Target $instance -Continue
}
Get-DbaAgentAlert -SqlInstance $server | Where-Object Name -eq $currentAlert.name
Get-DbaAgentAlert -SqlInstance $server | Where-Object Name -EQ $currentAlert.name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if not the correct case, we use -eq with Where-Object for better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, don't follow - do you want me to change here something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. I caught it in the other command, but this was changed by the formatted and I missed it to change it back to -eq

@@ -132,7 +132,7 @@ function Set-DbaAgentAlert {
#region alert options
# Settings the options for the alert
if ($NewName) {
if ($Pscmdlet.ShouldProcess($server, "Setting alert name to $NewName for $Alert")) {
if ($Pscmdlet.ShouldProcess($server, "Setting alert name to $NewName for $a")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why have you changed that? $a is only the last alert from the foreach loop. Shouldn't it be $currentAlert?

@@ -149,9 +150,9 @@ function Set-DbaAgentAlert {
#endregion alert options

# Execute
if ($PSCmdlet.ShouldProcess($SqlInstance, "Changing the alert $a")) {
if ($PSCmdlet.ShouldProcess($SqlInstance, "Committing changes for alert $a")) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like in line 135, this should not be $a but $currentAlert.

try {
Write-Message -Message "Changing the alert" -Level Verbose
Write-Message -Message "Committing changes for alert $a" -Level Verbose
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this line, as ShouldProcess also has verbose output. (But if you still like to have the line: Like in line 135, this should not be $a but $currentAlert.)

@potatoqualitee
Copy link
Member

I will hold off until this is approved ✅

@potatoqualitee
Copy link
Member

I take that back, we can fix those small issues in another PR, this is an important fix! thank you both 🙇🏼

@potatoqualitee potatoqualitee merged commit 613ea84 into dataplat:development Feb 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set-DbaAgentAlert - renames an alert even with Whatif
3 participants