Skip to content

Commit

Permalink
add StagingServerSummary (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Aug 10, 2023
1 parent 4e0e3ae commit 8f1da23
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 15 deletions.
8 changes: 5 additions & 3 deletions KenticoInspector.Actions/GlobalAdminSummary/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace KenticoInspector.Actions.GlobalAdminSummary
{
public class Action : AbstractAction<Terms,Options>
public class Action : AbstractAction<Terms, Options>
{
private readonly IDatabaseService databaseService;

Expand All @@ -31,7 +31,9 @@ public override ActionResults Execute(Options options)
{
databaseService.ExecuteSqlFromFileGeneric(Scripts.ResetAndEnableUser, new { UserID = options.UserId });
var result = ExecuteListing();
result.Summary = Metadata.Terms.UserReset.With(new {
result.Status = ResultsStatus.Good;
result.Summary = Metadata.Terms.UserReset.With(new
{
userId = options.UserId
});

Expand Down Expand Up @@ -78,4 +80,4 @@ public override bool ValidateOptions(Options options)
return options.UserId > 0 && administratorUsers.Any(u => u.UserID == options.UserId);
}
}
}
}
9 changes: 9 additions & 0 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
<None Update="SiteStatusSummary\Scripts\GetSiteSummary.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StagingServerSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StagingServerSummary\Scripts\GetStagingServerSummary.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="StagingServerSummary\Scripts\DisableServer.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="WebFarmServerSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
5 changes: 3 additions & 2 deletions KenticoInspector.Actions/SiteStatusSummary/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace KenticoInspector.Actions.SiteStatusSummary
{
public class Action : AbstractAction<Terms,Options>
public class Action : AbstractAction<Terms, Options>
{
private readonly IDatabaseService databaseService;

Expand All @@ -31,6 +31,7 @@ public override ActionResults Execute(Options options)
{
databaseService.ExecuteSqlFromFileGeneric(Scripts.StopSite, new { SiteID = options.SiteId });
var result = ExecuteListing();
result.Status = ResultsStatus.Good;
result.Summary = Metadata.Terms.SiteStopped.With(new
{
siteId = options.SiteId
Expand Down Expand Up @@ -79,4 +80,4 @@ public override bool ValidateOptions(Options options)
return options.SiteId > 0 && sites.Any(s => s.ID == options.SiteId);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
{
public class CmsSite
{
public int ID { get; internal set; }
public int ID { get; set; }

public string DisplayName { get; internal set; }
public string DisplayName { get; set; }

public string Description { get; internal set; }
public string Description { get; set; }

public string AdministrationDomain { get; internal set; }
public string AdministrationDomain { get; set; }

public string PresentationUrl { get; internal set; }
public string PresentationUrl { get; set; }

public bool Running { get; internal set; }
public bool Running { get; set; }
}
}
85 changes: 85 additions & 0 deletions KenticoInspector.Actions/StagingServerSummary/Action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using KenticoInspector.Actions.StagingServerSummary.Models;
using KenticoInspector.Core;
using KenticoInspector.Core.Constants;
using KenticoInspector.Core.Helpers;
using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;

using System;
using System.Collections.Generic;
using System.Linq;

namespace KenticoInspector.Actions.StagingServerSummary
{
public class Action : AbstractAction<Terms, Options>
{
private readonly IDatabaseService databaseService;

public override IList<Version> CompatibleVersions => VersionHelper.GetVersionList("12", "13");

public override IList<string> Tags => new List<string> {
ModuleTags.Configuration,
ModuleTags.Staging
};

public Action(IDatabaseService databaseService, IModuleMetadataService moduleMetadataService) : base(moduleMetadataService)
{
this.databaseService = databaseService;
}

public override ActionResults Execute(Options options)
{
databaseService.ExecuteSqlFromFileGeneric(Scripts.DisableServer, new { ServerID = options.ServerId });
var result = ExecuteListing();
result.Status = ResultsStatus.Good;
result.Summary = Metadata.Terms.ServerDisabled.With(new
{
serverId = options.ServerId
});

return result;
}

public override ActionResults ExecutePartial(Options options)
{
// All options are required for this action
throw new NotImplementedException();
}

public override ActionResults ExecuteListing()
{
var servers = databaseService.ExecuteSqlFromFile<StagingServer>(Scripts.GetStagingServerSummary);
var data = new TableResult<StagingServer>()
{
Name = Metadata.Terms.TableTitle,
Rows = servers
};

return new ActionResults
{
Type = ResultsType.Table,
Status = ResultsStatus.Information,
Summary = Metadata.Terms.ListSummary,
Data = data
};
}

public override ActionResults GetInvalidOptionsResult()
{
var result = ExecuteListing();
result.Status = ResultsStatus.Error;
result.Summary = Metadata.Terms.InvalidOptions;

return result;
}

public override bool ValidateOptions(Options options)
{
var servers = databaseService.ExecuteSqlFromFile<StagingServer>(Scripts.GetStagingServerSummary);

return options.ServerId > 0 &&
servers.Any(s => s.ID == options.ServerId) &&
servers.FirstOrDefault(s => s.ID == options.ServerId).Enabled;
}
}
}
12 changes: 12 additions & 0 deletions KenticoInspector.Actions/StagingServerSummary/Metadata/en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
details:
name: Content Staging Server Summary
shortDescription: Review and disable staging servers.
longDescription: |
Displays all staging servers, and allows you to disable them.
Run the action without options to view the staging servers. To disable a server, re-run the action with the server ID below. Servers disabled by this action have the *.disabled* prefix applied to their name, so you can identify which servers were disabled by this action and which were disabled manually.
terms:
tableTitle: Content staging servers
invalidOptions: Invalid server ID provided. Ensure that the server ID is listed in the results below, and the server is enabled.
listSummary: Set the server ID you wish to disable and re-run
serverDisabled: Server ID <serverId> was disabled
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace KenticoInspector.Actions.StagingServerSummary.Models
{
public class Options
{
public int? ServerId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
namespace KenticoInspector.Actions.StagingServerSummary.Models
{
public class StagingServer
{
public int ID { get; set; }

public string Name { get; set; }

public string Site { get; set; }

public string Url { get; set; }

public bool Enabled { get; set; }
}
}
15 changes: 15 additions & 0 deletions KenticoInspector.Actions/StagingServerSummary/Models/Terms.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using KenticoInspector.Core.Models;

namespace KenticoInspector.Actions.StagingServerSummary.Models
{
public class Terms
{
public Term InvalidOptions { get; internal set; }

public Term TableTitle { get; internal set; }

public Term ListSummary { get; internal set; }

public Term ServerDisabled { get; internal set; }
}
}
11 changes: 11 additions & 0 deletions KenticoInspector.Actions/StagingServerSummary/Scripts.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace KenticoInspector.Actions.StagingServerSummary
{
public static class Scripts
{
public static string BaseDirectory => $"{nameof(StagingServerSummary)}/Scripts";

public static string GetStagingServerSummary => $"{BaseDirectory}/{nameof(GetStagingServerSummary)}.sql";

public static string DisableServer => $"{BaseDirectory}/{nameof(DisableServer)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
UPDATE Staging_Server SET ServerDisplayName = ServerDisplayName + N'.disabled', ServerEnabled = 0
WHERE ServerID = @ServerID
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT C.ServerID AS 'ID', C.ServerDisplayName AS 'Name', C.ServerEnabled AS 'Enabled', C.ServerURL AS 'Url', S.SiteDisplayName AS 'Site'
FROM Staging_Server AS C
JOIN CMS_Site AS S ON S.SiteID = C.ServerSiteID
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
longDescription: |
Displays all web farm servers, and allows you to disable them.
Run the action without options to view the web farm server. To disable a server, re-run the action with the server ID below. Servers disabled by this action have the *.disabled* prefix applied to their name, so you can identify which servers were disabled by this action and which were disabled manually.
Run the action without options to view the web farm servers. To disable a server, re-run the action with the server ID below. Servers disabled by this action have the *.disabled* prefix applied to their name, so you can identify which servers were disabled by this action and which were disabled manually.
terms:
tableTitle: Web farm servers
invalidOptions: Invalid server ID provided. Ensure that the server ID is listed in the results below, and the server is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
{
public class WebFarmServer
{
public int ID { get; internal set; }
public int ID { get; set; }

public string Name { get; internal set; }
public string Name { get; set; }

public bool Enabled { get; internal set; }
public bool Enabled { get; set; }
}
}
1 change: 1 addition & 0 deletions KenticoInspector.Core/Constants/ModuleTags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public static class ModuleTags
public const string User = "User";
public const string Site = "Site";
public const string WebFarms = "Web farms";
public const string Staging = "Content staging";
}
}

0 comments on commit 8f1da23

Please sign in to comment.