-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrates "Stop all sites" report (#238)
- Loading branch information
1 parent
37dae88
commit 39e3fde
Showing
10 changed files
with
159 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
KenticoInspector.Actions/SiteStatusSummary/Metadata/en-US.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
KenticoInspector.Actions/SiteStatusSummary/Models/Results/CmsSite.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
KenticoInspector.Actions/SiteStatusSummary/Models/Terms.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
KenticoInspector.Actions/SiteStatusSummary/Scripts/GetSiteSummary.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
1 change: 1 addition & 0 deletions
1
KenticoInspector.Actions/SiteStatusSummary/Scripts/StopSite.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
UPDATE CMS_Site SET SiteStatus = 'STOPPED' WHERE SiteID = @SiteID |