-
Notifications
You must be signed in to change notification settings - Fork 23
TASK: Modernize archived URL persistence with hashed lookup path and DAL2 support #1880
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
Draft
Copilot
wants to merge
5
commits into
dev
Choose a base branch
from
copilot/modernize-archived-urls
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
38823ed
Initial plan
Copilot ee42f56
feat: modernize archived URL storage and DAL2 lookup
Copilot 9a36d7b
refactor: simplify archived URL lookup per PR feedback
Copilot 40ebe97
test: correct archived URL case-variance assertion
Copilot fab0075
fix: recreate URL search proc and align archived URL hash conversion
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,45 @@ | ||
| // Copyright (c) by DNN Community | ||
| // | ||
| // DNN Community licenses this file to you under the MIT license. | ||
| // | ||
| // See the LICENSE file in the project root for more information. | ||
| // | ||
| // 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. | ||
|
|
||
| namespace DotNetNuke.Modules.ActiveForums.Controllers | ||
| { | ||
| using System.Linq; | ||
|
|
||
| internal class ArchivedUrlController : RepositoryControllerBase<DotNetNuke.Modules.ActiveForums.Entities.ArchivedURLInfo> | ||
| { | ||
| internal DotNetNuke.Modules.ActiveForums.Entities.ArchivedURLInfo FindByURL(int portalId, string url) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(url)) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var normalizedUrl = url.ToLowerInvariant(); | ||
|
|
||
| return this.Find("WHERE PortalId = @0 AND URL_Hash = CONVERT(binary(16), HASHBYTES('MD5', @1))", portalId, normalizedUrl) | ||
| .FirstOrDefault(a => IsUrlMatch(a?.Url, normalizedUrl)); | ||
| } | ||
|
|
||
| internal static bool IsUrlMatch(string archivedUrl, string normalizedUrl) | ||
| { | ||
| return !string.IsNullOrWhiteSpace(archivedUrl) && archivedUrl.ToLowerInvariant() == normalizedUrl; | ||
| } | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,69 @@ | ||
| // Copyright (c) by DNN Community | ||
| // | ||
| // DNN Community licenses this file to you under the MIT license. | ||
| // | ||
| // See the LICENSE file in the project root for more information. | ||
| // | ||
| // 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. | ||
|
|
||
| namespace DotNetNuke.Modules.ActiveForums.Entities | ||
| { | ||
| using DotNetNuke.ComponentModel.DataAnnotations; | ||
|
|
||
| /// <summary> | ||
| /// Represents an archived forum URL entry. | ||
| /// </summary> | ||
| [TableName("activeforums_ArchivedURLs")] | ||
| [PrimaryKey("Id", AutoIncrement = true)] | ||
| public class ArchivedURLInfo | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the archived URL identifier. | ||
| /// </summary> | ||
| public int Id { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the archived URL value. | ||
| /// </summary> | ||
| [ColumnName("URL")] | ||
| public string Url { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the portal identifier. | ||
| /// </summary> | ||
| public int PortalId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the forum identifier. | ||
| /// </summary> | ||
| public int ForumId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the topic identifier. | ||
| /// </summary> | ||
| public int TopicId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the forum group identifier. | ||
| /// </summary> | ||
| public int ForumGroupId { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the MD5 hash for normalized URL lookups. | ||
| /// </summary> | ||
| [ColumnName("URL_Hash")] | ||
| public byte[] UrlHash { get; set; } | ||
| } | ||
| } |
This file contains hidden or 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,109 @@ | ||
| SET NOCOUNT ON | ||
| GO | ||
|
|
||
| /* issue 1877 - begin - modernize archived URLs */ | ||
|
|
||
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_URL]') AND type in (N'U')) | ||
| AND NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_ArchivedURLs]') AND type in (N'U')) | ||
| BEGIN | ||
| EXEC sp_rename '{databaseOwner}{objectQualifier}activeforums_URL', 'activeforums_ArchivedURLs' | ||
| END | ||
| GO | ||
|
|
||
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_ArchivedURLs]') AND type in (N'U')) | ||
| AND NOT EXISTS (SELECT * FROM sys.columns WHERE [name] = N'URL_Hash' AND [object_id] = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_ArchivedURLs]')) | ||
| BEGIN | ||
| ALTER TABLE {databaseOwner}[{objectQualifier}activeforums_ArchivedURLs] | ||
| ADD URL_Hash AS CONVERT(binary(16), HASHBYTES('MD5', LOWER(LTRIM(RTRIM([URL]))))) PERSISTED | ||
| END | ||
| GO | ||
|
|
||
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_ArchivedURLs]') AND type in (N'U')) | ||
| AND NOT EXISTS (SELECT * FROM sys.indexes WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_ArchivedURLs]') AND name = N'IX_{objectQualifier}activeforums_ArchivedURLs_URL_Hash') | ||
| BEGIN | ||
| CREATE NONCLUSTERED INDEX IX_{objectQualifier}activeforums_ArchivedURLs_URL_Hash | ||
| ON {databaseOwner}[{objectQualifier}activeforums_ArchivedURLs] (URL_Hash) | ||
| END | ||
| GO | ||
|
|
||
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_URL_Archive]') AND type in (N'P', N'PC')) | ||
| DROP PROCEDURE {databaseOwner}[{objectQualifier}activeforums_URL_Archive] | ||
| GO | ||
|
|
||
| CREATE PROCEDURE {databaseOwner}[{objectQualifier}activeforums_URL_Archive] | ||
| @PortalId int, | ||
| @ForumGroupId int, | ||
| @ForumId int, | ||
| @TopicId int, | ||
| @URL nvarchar(1000) | ||
| AS | ||
| DECLARE @NormalizedUrl nvarchar(1000) | ||
| DECLARE @UrlHash binary(16) | ||
|
|
||
| SET @NormalizedUrl = LOWER(LTRIM(RTRIM(@URL))) | ||
| SET @UrlHash = CONVERT(binary(16), HASHBYTES('MD5', @NormalizedUrl)) | ||
|
|
||
| IF NOT EXISTS | ||
| ( | ||
| SELECT 1 | ||
| FROM {databaseOwner}[{objectQualifier}activeforums_ArchivedURLs] | ||
| WHERE PortalID = @PortalId | ||
| AND URL_Hash = @UrlHash | ||
| AND LTRIM(RTRIM(LOWER([URL]))) = @NormalizedUrl | ||
| ) | ||
| BEGIN | ||
| INSERT INTO {databaseOwner}[{objectQualifier}activeforums_ArchivedURLs] (PortalId, ForumGroupId, ForumId, TopicId, URL) | ||
| VALUES (@PortalId, @ForumGroupId, @ForumId, @TopicId, @URL) | ||
| END | ||
| GO | ||
|
|
||
| IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_FindByURL]') AND type in (N'P', N'PC')) | ||
| DROP PROCEDURE {databaseOwner}[{objectQualifier}activeforums_FindByURL] | ||
| GO | ||
|
|
||
| CREATE PROCEDURE {databaseOwner}[{objectQualifier}activeforums_FindByURL] | ||
| @PortalId int, | ||
| @URL nvarchar(1000) | ||
| AS | ||
| DECLARE @NormalizedUrl nvarchar(1000) | ||
| DECLARE @NormalizedUrlNoSlash nvarchar(1000) | ||
| DECLARE @UrlHash binary(16) | ||
| DECLARE @UrlHashNoSlash binary(16) | ||
|
|
||
| SET @NormalizedUrl = LOWER(LTRIM(RTRIM(@URL))) | ||
| SET @NormalizedUrlNoSlash = CASE WHEN LEFT(@NormalizedUrl, 1) = '/' THEN STUFF(@NormalizedUrl, 1, 1, '') ELSE @NormalizedUrl END | ||
| SET @UrlHash = CONVERT(binary(16), HASHBYTES('MD5', @NormalizedUrl)) | ||
| SET @UrlHashNoSlash = CONVERT(binary(16), HASHBYTES('MD5', @NormalizedUrlNoSlash)) | ||
|
|
||
| SELECT ForumId, TopicId | ||
| FROM {databaseOwner}[{objectQualifier}activeforums_ArchivedURLs] | ||
| WHERE PortalId = @PortalId | ||
| AND (URL_Hash = @UrlHash OR URL_Hash = @UrlHashNoSlash) | ||
| AND | ||
| ( | ||
| LTRIM(RTRIM(LOWER([URL]))) = @NormalizedUrl | ||
| OR '/' + LTRIM(RTRIM(LOWER([URL]))) = @NormalizedUrl | ||
| OR LTRIM(RTRIM(LOWER([URL]))) = @NormalizedUrlNoSlash | ||
| OR '/' + LTRIM(RTRIM(LOWER([URL]))) = @NormalizedUrlNoSlash | ||
| ) | ||
| GO | ||
|
|
||
| DECLARE @urlSearchDefinition nvarchar(max) | ||
|
johnhenley marked this conversation as resolved.
Outdated
|
||
| SELECT @urlSearchDefinition = [definition] | ||
| FROM sys.sql_modules | ||
| WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}activeforums_URL_Search]') | ||
|
|
||
| IF @urlSearchDefinition IS NOT NULL | ||
| AND @urlSearchDefinition LIKE '%activeforums_URL%' | ||
| BEGIN | ||
| SET @urlSearchDefinition = REPLACE(@urlSearchDefinition, 'CREATE PROCEDURE', 'ALTER PROCEDURE') | ||
| SET @urlSearchDefinition = REPLACE(@urlSearchDefinition, 'create procedure', 'alter procedure') | ||
| SET @urlSearchDefinition = REPLACE(@urlSearchDefinition, '{objectQualifier}activeforums_URL', '{objectQualifier}activeforums_ArchivedURLs') | ||
| EXEC sp_executesql @urlSearchDefinition | ||
| END | ||
| GO | ||
|
|
||
| /* issue 1877 - end - modernize archived URLs */ | ||
|
|
||
| /* --------------------- */ | ||
|
|
||
This file contains hidden or 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
56 changes: 56 additions & 0 deletions
56
Dnn.CommunityForumsTests/Controllers/ArchivedUrlControllerTests.cs
This file contains hidden or 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,56 @@ | ||
| // Copyright (c) by DNN Community | ||
| // | ||
| // DNN Community licenses this file to you under the MIT license. | ||
| // | ||
| // See the LICENSE file in the project root for more information. | ||
| // | ||
| // 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. | ||
|
|
||
| namespace DotNetNuke.Modules.ActiveForumsTests.Controllers | ||
| { | ||
| using NUnit.Framework; | ||
|
|
||
| [TestFixture] | ||
| public class ArchivedUrlControllerTests | ||
| { | ||
| [Test] | ||
| public void IsUrlMatch_ReturnsTrue_WhenArchivedUrlCaseOnlyDiffers() | ||
| { | ||
| // Arrange | ||
| const string archivedUrl = "Forums/Topic-One/"; | ||
| const string normalizedUrl = "forums/topic-one/"; | ||
|
|
||
| // Act | ||
| var result = DotNetNuke.Modules.ActiveForums.Controllers.ArchivedUrlController.IsUrlMatch(archivedUrl, normalizedUrl); | ||
|
|
||
| // Assert | ||
| Assert.That(result, Is.True); | ||
| } | ||
|
|
||
| [Test] | ||
| public void IsUrlMatch_ReturnsFalse_WhenUrlsDoNotMatch() | ||
| { | ||
| // Arrange | ||
| const string archivedUrl = "forums/topic-one/"; | ||
| const string normalizedUrl = "forums/topic-two/"; | ||
|
|
||
| // Act | ||
| var result = DotNetNuke.Modules.ActiveForums.Controllers.ArchivedUrlController.IsUrlMatch(archivedUrl, normalizedUrl); | ||
|
|
||
| // Assert | ||
| Assert.That(result, Is.False); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.