Skip to content

Commit

Permalink
Merge pull request #15 from UpendoVentures/tasks/themes-used
Browse files Browse the repository at this point in the history
Adds a themes-used command
  • Loading branch information
WillStrohl committed Feb 18, 2022
2 parents d2f71bb + 0570114 commit 9b929d3
Show file tree
Hide file tree
Showing 13 changed files with 402 additions and 7 deletions.
40 changes: 40 additions & 0 deletions Modules/UpendoPrompt/App_LocalResources/Global.resx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,31 @@
<data name="PromptPopupMode.Text" xml:space="preserve">
<value>Allows you to enable/disable the popup editing feature on the current website or all sites in this installation. </value>
</data>
<data name="PromptThemeseUsed.Text" xml:space="preserve">
<value>This command allows you to see all of the themes that currently are used by one or more pages, modules, and other settings.</value>
</data>
<data name="Prompt_DebugInfo_ResultHtml.Text" xml:space="preserve">
<value>&lt;div&gt;
&lt;p&gt;Helps you see and know where debugging might already be turned on. This is helpful when you're not sure or have multiple people working on a site.&lt;/p&gt;
&lt;h4&gt;Toggle whether the site is in debug mode, or running normally&lt;/h4&gt;
&lt;code class="block"&gt;debug-info&lt;/code&gt;
&lt;p&gt;This command does not have any options.&lt;/p&gt;
&lt;p&gt;If you find that one or more areas have debug turned on, you should use the command below to disable debug mode. You may need to run it twice.&lt;/p&gt;
&lt;code class="block"&gt;debug-mode&lt;/code&gt;
&lt;/div&gt;</value>
</data>
<data name="Prompt_DebugMode_ResultHtml.Text" xml:space="preserve">
<value>&lt;div&gt;
&lt;p&gt;When you need more information to help diagnose and resolve an error, this command can help you get more verbose and detailed information.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;WARNING!&lt;/strong&gt; When used, this command will RESTART your website. Page loads for the next few moments after running this command will be slower.&lt;/p&gt;
&lt;h4&gt;Using debug-mode&lt;/h4&gt;
&lt;code class="block"&gt;debug-mode&lt;/code&gt;
&lt;p&gt;This command does not have any options.&lt;/p&gt;
&lt;p&gt;When you run this command, debug mode is toggled in the superuser settings, web.config, and the DotNetNuke.log4net.config files.&lt;/p&gt;
&lt;p&gt;If you're unsure if you need to run this command, first try running the command below.&lt;/p&gt;
&lt;code class="block"&gt;debug-info&lt;/code&gt;
&lt;/div&gt;</value>
</data>
<data name="Prompt_ModeInvalid.Text" xml:space="preserve">
<value>The mode can only be 'enable' or 'disable'. The default is 'disable'.</value>
</data>
Expand All @@ -186,6 +211,21 @@
<data name="Prompt_ScopeInvalid.Text" xml:space="preserve">
<value>The scope can only be 'all' or 'current'. Omitting it will default to 'current'.</value>
</data>
<data name="Prompt_ThemesUsed_ResultHtml.Text" xml:space="preserve">
<value>&lt;div&gt;
&lt;p&gt;Ideally, this list should be as short as possible on most websites.&lt;/p&gt;
&lt;p&gt;View all of the theme settings used on the entire DNN instance&lt;/p&gt;
&lt;h4&gt;Using themes-used&lt;/h4&gt;
&lt;code class="block"&gt;themes-used&lt;/code&gt;
&lt;p&gt;A listing of all of the themes that have been specified in the superuser settings, site settings, pages, and modules will be listed.&lt;/p&gt;
&lt;/div&gt;</value>
</data>
<data name="RecordsNone.Text" xml:space="preserve">
<value>No matches were found for your query.</value>
</data>
<data name="RecordsSome.Text" xml:space="preserve">
<value>Maches were found for your query.</value>
</data>
<data name="ScopeAll.Text" xml:space="preserve">
<value>all sites</value>
</data>
Expand Down
111 changes: 111 additions & 0 deletions Modules/UpendoPrompt/Commands/ThemesUsed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#region License

// Distributed under the MIT License
// ============================================================
// Copyright (c) Upendo Ventures, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#endregion

using System;
using System.Linq;
using Dnn.PersonaBar.Library.Helper;
using Dnn.PersonaBar.Library.Prompt;
using Dnn.PersonaBar.Library.Prompt.Attributes;
using Dnn.PersonaBar.Library.Prompt.Models;
using DotNetNuke.Application;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Controllers;
using DotNetNuke.Entities.Host;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Profile;
using DotNetNuke.Entities.Users;
using DotNetNuke.Instrumentation;
using Upendo.Modules.UpendoPrompt.Components;
using Upendo.Modules.UpendoPrompt.Data;
using Upendo.Modules.UpendoPrompt.Entities;
using Constants = Upendo.Modules.UpendoPrompt.Components.Constants;

namespace Upendo.Modules.UpendoPrompt.Commands
{
[ConsoleCommand("themes-used", Constants.PromptCategory, "PromptThemeseUsed")]
public class ThemesUsed : PromptBase, IConsoleCommand
{
private static readonly ILog Logger = LoggerSource.Instance.GetLogger(typeof(ThemesUsed));

#region Implementation

public override void Init(string[] args, PortalSettings portalSettings, UserInfo userInfo, int activeTabId)
{
// do nothing
}

public override ConsoleResultModel Run()
{
try
{
var dbAccess = new DataAccess();
var themesUsed = dbAccess.GetThemesUsed();
var recordCount = themesUsed.Count();

var output = string.Empty;

if (recordCount > 0)
{
output = LocalizeString(Constants.LocalizationKeys.RECORDS_SOME);
}
else
{
output = LocalizeString(Constants.LocalizationKeys.RECORDS_NONE);
}

return new ConsoleResultModel
{
Records = recordCount,
Data = themesUsed,
IsError = false,
Output = output
};
}
catch (Exception e)
{
LogError(e);
return new ConsoleErrorResultModel(string.Concat(Constants.OutputPrefix, this.LocalizeString(Constants.LocalizationKeys.ErrorOccurred)));
}
}

#endregion

#region Helpers

protected override void LogError(Exception ex)
{
if (ex != null)
{
Logger.Error(ex.Message, ex);
if (ex.InnerException != null)
{
Logger.Error(ex.InnerException.Message, ex.InnerException);
}
}
}
#endregion
}
}
8 changes: 8 additions & 0 deletions Modules/UpendoPrompt/Components/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ public static class LocalizationKeys

public const string ENABLED = "Enabled";
public const string DISABLED = "Disabled";

public const string RECORDS_NONE = "RecordsNone";
public const string RECORDS_SOME = "RecordsSome";
}

public static class Procedures
{
public const string ThemesUsed = "uvm_Prompt_GetThemesUsed";
}
}
}
49 changes: 49 additions & 0 deletions Modules/UpendoPrompt/Data/DataAccess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#region License

// Distributed under the MIT License
// ============================================================
// Copyright (c) Upendo Ventures, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#endregion

using System.Collections.Generic;
using System.Data;
using System.Linq;
using DotNetNuke.Data;
using Upendo.Modules.UpendoPrompt.Components;
using Upendo.Modules.UpendoPrompt.Entities;

namespace Upendo.Modules.UpendoPrompt.Data
{
public class DataAccess
{
public IEnumerable<ThemeItem> GetThemesUsed()
{
IList<ThemeItem> themesUsed;

using (IDataContext db = DataContext.Instance())
{
themesUsed = db.ExecuteQuery<ThemeItem>(CommandType.StoredProcedure, Constants.Procedures.ThemesUsed).ToList();
}

return themesUsed;
}
}
}
36 changes: 36 additions & 0 deletions Modules/UpendoPrompt/Entities/Interfaces/IThemeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#region License

// Distributed under the MIT License
// ============================================================
// Copyright (c) Upendo Ventures, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#endregion

namespace Upendo.Modules.UpendoPrompt.Entities.Interfaces
{
public interface IThemeItem
{
string Source { get; set; }
string ThemePath { get; set; }
int PortalId { get; set; }
int TabId { get; set; }
int ModuleId { get; set; }
}
}
40 changes: 40 additions & 0 deletions Modules/UpendoPrompt/Entities/ThemeItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#region License

// Distributed under the MIT License
// ============================================================
// Copyright (c) Upendo Ventures, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the "Software"), to deal in the Software without restriction,
// including without limitation the rights to use, copy, modify, merge, publish, distribute,
// sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#endregion

using System;
using Upendo.Modules.UpendoPrompt.Entities.Interfaces;

namespace Upendo.Modules.UpendoPrompt.Entities
{
[Serializable]
public class ThemeItem : IThemeItem
{
public string Source { get; set; }
public string ThemePath { get; set; }
public int PortalId { get; set; }
public int TabId { get; set; }
public int ModuleId { get; set; }
}
}
4 changes: 2 additions & 2 deletions Modules/UpendoPrompt/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("01.02.00")]
[assembly: AssemblyFileVersion("01.02.00")]
[assembly: AssemblyVersion("01.03.00")]
[assembly: AssemblyFileVersion("01.03.00")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*

INSTALL/UPGRADE SQL PROVIDER SCRIPT

Prompt Extension Suite for DNN by Upendo Ventures, LLC

*/

IF EXISTS (SELECT * FROM sys.objects WHERE type = N'P' AND OBJECT_ID = OBJECT_ID(N'{databaseOwner}[{objectQualifier}uvm_Prompt_GetThemesUsed]'))
DROP PROCEDURE {databaseOwner}[{objectQualifier}uvm_Prompt_GetThemesUsed];
GO

CREATE PROCEDURE [uvm_Prompt_GetThemesUsed]
AS
BEGIN
CREATE TABLE #ThemesUsed (
[Source] NVARCHAR(50) NOT NULL,
[ThemePath] NVARCHAR (200) NOT NULL,
[PortalId] INT,
[TabId] INT,
[ModuleId] INT
);

INSERT INTO #ThemesUsed ([Source], [ThemePath], [PortalId], [TabId], [ModuleId])
SELECT N'HostSettings' AS [Source],hs.[SettingValue] AS [ThemePath],-1 AS [PortalId],-1 AS [TabId],-1 AS [ModuleId]
FROM {databaseOwner}[{objectQualifier}HostSettings] hs
WHERE hs.[SettingName] LIKE N'%Container' OR hs.[SettingName] LIKE N'%Skin'
ORDER BY hs.[SettingValue];

INSERT INTO #ThemesUsed ([Source], [ThemePath], [PortalId], [TabId], [ModuleId])
SELECT N'PortalSettings' AS [Source],ps.[SettingValue] AS [ThemePath],ps.[PortalID],-1 AS [TabId],-1 AS [ModuleId]
FROM {databaseOwner}[{objectQualifier}PortalSettings] ps
WHERE ps.[SettingName] LIKE N'%Container' OR ps.[SettingName] LIKE N'%Skin'
ORDER BY ps.[SettingValue];

INSERT INTO #ThemesUsed ([Source], [ThemePath], [PortalId], [TabId], [ModuleId])
SELECT N'Page' AS [Source],t.[SkinSrc] AS [ThemePath],t.[PortalID],t.[TabID],-1 AS [ModuleId]
FROM {databaseOwner}[{objectQualifier}Tabs] t
WHERE NOT t.[SkinSrc] IS NULL
ORDER BY t.[SkinSrc];

INSERT INTO #ThemesUsed ([Source], [ThemePath], [PortalId], [TabId], [ModuleId])
SELECT N'Page' AS [Source],t.[ContainerSrc] AS [ThemePath],t.[PortalID],t.[TabID],-1 AS [ModuleId]
FROM {databaseOwner}[{objectQualifier}Tabs] t
WHERE NOT t.[ContainerSrc] IS NULL
ORDER BY t.[ContainerSrc];

INSERT INTO #ThemesUsed ([Source], [ThemePath], [PortalId], [TabId], [ModuleId])
SELECT N'Module' AS [Source],tm.[ContainerSrc] AS [ThemePath],-1 AS [PortalId],tm.[TabID],tm.[ModuleID]
FROM {databaseOwner}[{objectQualifier}TabModules] tm
WHERE NOT tm.[ContainerSrc] IS NULL
ORDER BY tm.[ContainerSrc];

SELECT tu.[Source], tu.[ThemePath], tu.[PortalId], tu.[TabId], tu.[ModuleId]
FROM #ThemesUsed tu
ORDER BY tu.[Source], tu.[ThemePath], tu.[PortalId], tu.[TabId], tu.[ModuleId];

DROP TABLE #ThemesUsed;
END
GO

/*

END OF FILE

*/
Loading

0 comments on commit 9b929d3

Please sign in to comment.