Skip to content

Commit

Permalink
migrates "Stop all sites" report (#238)
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Aug 9, 2023
1 parent 37dae88 commit 39e3fde
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 5 deletions.
10 changes: 5 additions & 5 deletions KenticoInspector.Actions/GlobalAdminSummary/Action.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ public Action(IDatabaseService databaseService, IModuleMetadataService moduleMet

public override ActionResults Execute(Options options)
{
if (options.UserId < 0)
{
return GetInvalidOptionsResult();
}

// No user provided, list users
if (options.UserId == 0)
{
return GetListingResult();
}

if (options.UserId < 0)
{
return GetInvalidOptionsResult();
}

// Reset provided user
databaseService.ExecuteSqlFromFileGeneric(Scripts.ResetAndEnableUser, new { UserID = options.UserId });
var result = GetListingResult();
Expand Down
9 changes: 9 additions & 0 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@
<None Update="GlobalAdminSummary\Scripts\ResetAndEnableUser.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SiteStatusSummary\Metadata\en-US.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SiteStatusSummary\Scripts\StopSite.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="SiteStatusSummary\Scripts\GetSiteSummary.sql">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
79 changes: 79 additions & 0 deletions KenticoInspector.Actions/SiteStatusSummary/Action.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using KenticoInspector.Actions.SiteStatusSummary.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;

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

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

public override IList<string> Tags => new List<string> {
ActionTags.Site,
ActionTags.Reset
};

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

public override ActionResults Execute(Options options)
{
// No site provided, list sites
if (options.SiteId == 0)
{
return GetListingResult();
}

if (options.SiteId < 0)
{
return GetInvalidOptionsResult();
}

// Stop provided site
databaseService.ExecuteSqlFromFileGeneric(Scripts.StopSite, new { SiteID = options.SiteId });
var result = GetListingResult();
result.Summary = Metadata.Terms.SiteStopped.With(new
{
siteId = options.SiteId
});

return result;
}

public override ActionResults GetInvalidOptionsResult()
{
return new ActionResults {
Status = ResultsStatus.Error,
Summary = Metadata.Terms.InvalidOptions
};
}

private ActionResults GetListingResult()
{
var sites = databaseService.ExecuteSqlFromFile<CmsSite>(Scripts.GetSiteSummary);
var data = new TableResult<CmsSite>()
{
Name = Metadata.Terms.TableTitle,
Rows = sites
};

return new ActionResults
{
Type = ResultsType.Table,
Status = ResultsStatus.Information,
Summary = Metadata.Terms.ListSummary,
Data = data
};
}
}
}
12 changes: 12 additions & 0 deletions KenticoInspector.Actions/SiteStatusSummary/Metadata/en-US.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
details:
name: Site Status Summary
shortDescription: Review and stop running sites.
longDescription: |
Displays all sites registered in the instance and their configuration, and allows you to stop running sites.
Run the action without options to view the site summary. To stop a site, re-run the action with the site ID below.
terms:
tableTitle: Sites
invalidOptions: The site ID must be an integer greater than zero.
listSummary: Set the site ID you wish to stop and re-run
siteStopped: Site ID <siteId> was stopped
7 changes: 7 additions & 0 deletions KenticoInspector.Actions/SiteStatusSummary/Models/Options.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace KenticoInspector.Actions.SiteStatusSummary.Models
{
public class Options
{
public int SiteId { get; set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace KenticoInspector.Actions.SiteStatusSummary.Models
{
public class CmsSite
{
public int ID { get; internal set; }

public string DisplayName { get; internal set; }

public string Description { get; internal set; }

public string AdministrationDomain { get; internal set; }

public string PresentationUrl { get; internal set; }

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

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

public Term TableTitle { get; internal set; }

public Term ListSummary { get; internal set; }

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

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

public static string StopSite => $"{BaseDirectory}/{nameof(StopSite)}.sql";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SELECT SiteID AS 'ID', SiteDisplayName AS 'DisplayName', SiteDescription AS 'Description', SiteDomainName AS 'AdministrationDomain', SitePresentationUrl AS 'PresentationUrl',
CASE WHEN SiteStatus = 'RUNNING' THEN 'true' ELSE 'false' END AS 'IsRunning'
FROM CMS_Site
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE CMS_Site SET SiteStatus = 'STOPPED' WHERE SiteID = @SiteID

0 comments on commit 39e3fde

Please sign in to comment.