Skip to content
This repository has been archived by the owner on Jun 16, 2022. It is now read-only.

Commit

Permalink
Convert 410 to 301 (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Chenery committed Sep 26, 2017
1 parent 1f99e0f commit 872f1ef
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("3.13.*")]
[assembly: AssemblyVersion("3.14.*")]
[assembly: AssemblyInformationalVersion("3.14.0-beta")]

// SQL
[assembly: WebResource("InfoCaster.Umbraco.UrlTracker.SQL.MicrosoftSqlServer.create-table-1.sql", "text/plain")]
Expand Down
6 changes: 6 additions & 0 deletions Repositories/UrlTrackerRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,12 @@ public static void UpdateUrlTrackerEntry(UrlTrackerModel urlTrackerModel)
if (urlTrackerModel.ForceRedirect)
ReloadForcedRedirectsCache();
}

public static void Convert410To301(int nodeId)
{
string query = "UPDATE icUrlTracker SET RedirectHttpCode = 301 WHERE RedirectHttpCode = 410 AND RedirectNodeId = @redirectNodeId";
_sqlHelper.ExecuteNonQuery(query, _sqlHelper.CreateParameter("redirectNodeId", nodeId));
}
#endregion

#region Support
Expand Down
2 changes: 1 addition & 1 deletion UrlTracker.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down
5 changes: 4 additions & 1 deletion UrlTracker.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
<summary>The Url Tracker is used to manage URLs within Umbraco</summary>
<description>The Url Tracker is used to manage URLs within umbraco. It automatically tracks URL changes, for instance when a node is renamed, and makes sure the old URL will redirect to the new location. This is great for SEO and great for people visiting your website via this old URL. Search engines will update the indexed URL and people won't visit the old, broken URL.
You can also create your own redirects, based on a simple URL or using a Regex pattern. You can redirect to an existing node or a manually entered URL. This is great for migrating existing indexed URLs to your new website!</description>
<releaseNotes>[Bugfix] Switched to Umbraco's EndRequest event to prevent MetaData Reader error</releaseNotes>
<releaseNotes>
[Bugfix] Only subscribe to each event once
[Bugfix] Convert 410 entries to 301 when a node is republished
</releaseNotes>
<tags>urltracker umbraco</tags>
</metadata>
<files>
Expand Down
13 changes: 11 additions & 2 deletions UrlTrackerApplicationEventHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica

ContentService.Moving += ContentService_Moving;
ContentService.Publishing += ContentService_Publishing;
ContentService.Published += ContentService_Published;
ContentService.Deleting += ContentService_Deleting;
content.BeforeClearDocumentCache += content_BeforeClearDocumentCache;
Domain.AfterDelete += Domain_AfterDelete;
Expand All @@ -54,7 +55,7 @@ protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplica
}
}

void ContentService_Deleting(IContentService sender, DeleteEventArgs<IContent> e)
void ContentService_Deleting(IContentService sender, DeleteEventArgs<IContent> e)
{
foreach (IContent content in e.DeletedEntities)
{
Expand Down Expand Up @@ -136,7 +137,15 @@ void ContentService_Publishing(IPublishingStrategy sender, PublishEventArgs<ICon
}
}

void ContentService_Moving(IContentService sender, MoveEventArgs<IContent> e)
void ContentService_Published(IPublishingStrategy sender, PublishEventArgs<IContent> e)
{
foreach(IContent content in e.PublishedEntities)
{
UrlTrackerRepository.Convert410To301(content.Id);
}
}

void ContentService_Moving(IContentService sender, MoveEventArgs<IContent> e)
{
IContent content = e.Entity;
#if !DEBUG
Expand Down

0 comments on commit 872f1ef

Please sign in to comment.