public static bool AddUrlMapping(IContent content, int rootNodeId, string url, AutoTrackingTypes type, bool isChild = false) { if (url != "#" && content.Template != null && content.Template.Id > 0) { string notes = isChild ? "An ancestor" : "This page"; switch (type) { case AutoTrackingTypes.Moved: notes += " was moved"; break; case AutoTrackingTypes.Renamed: notes += " was renamed"; break; case AutoTrackingTypes.UrlOverwritten: notes += "'s property 'umbracoUrlName' changed"; break; } url = UrlTrackerHelper.ResolveShortestUrl(url); if (UrlTrackerSettings.HasDomainOnChildNode) { var rootNode = new Node(rootNodeId); var rootUri = new Uri(rootNode.NiceUrl); var shortRootUrl = UrlTrackerHelper.ResolveShortestUrl(rootUri.AbsolutePath); if (url.StartsWith(shortRootUrl, StringComparison.OrdinalIgnoreCase)) { url = UrlTrackerHelper.ResolveShortestUrl(url.Substring(shortRootUrl.Length)); } } if (!string.IsNullOrEmpty(url)) { string query = "SELECT 1 FROM icUrlTracker WHERE RedirectNodeId = @nodeId AND OldUrl = @url"; int exists = _sqlHelper.ExecuteScalar<int>(query, _sqlHelper.CreateParameter("nodeId", content.Id), _sqlHelper.CreateStringParameter("url", url)); if (exists != 1) { LoggingHelper.LogInformation("UrlTracker Repository | Adding mapping for node id: {0} and url: {1}", new string[] { content.Id.ToString(), url }); query = "INSERT INTO icUrlTracker (RedirectRootNodeId, RedirectNodeId, OldUrl, Notes) VALUES (@rootNodeId, @nodeId, @url, @notes)"; _sqlHelper.ExecuteNonQuery(query, _sqlHelper.CreateParameter("rootNodeId", rootNodeId), _sqlHelper.CreateParameter("nodeId", content.Id), _sqlHelper.CreateStringParameter("url", url), _sqlHelper.CreateStringParameter("notes", notes)); if (content.Children().Any()) { foreach (IContent child in content.Children()) { Node node = new Node(child.Id); AddUrlMapping(child, rootNodeId, node.NiceUrl, type, true); } } return true; } } } return false; }
public static bool AddUrlMapping(Document doc, int rootNodeId, string url, AutoTrackingTypes type, bool isChild = false) { if (url != "#") { string notes = isChild ? "An ancestor" : "This page"; switch (type) { case AutoTrackingTypes.Moved: notes += " was moved"; break; case AutoTrackingTypes.Renamed: notes += " was renamed"; break; case AutoTrackingTypes.UrlOverwritten: notes += "'s property 'umbracoUrlName' changed"; break; } url = UrlTrackerHelper.ResolveShortestUrl(url); if (!string.IsNullOrEmpty(url)) { string query = "SELECT 1 FROM icUrlTracker WHERE RedirectNodeId = @nodeId AND OldUrl = @url"; int exists = _sqlHelper.ExecuteScalar <int>(query, _sqlHelper.CreateParameter("nodeId", doc.Id), _sqlHelper.CreateStringParameter("url", url)); if (exists != 1) { LoggingHelper.LogInformation("UrlTracker Repository | Adding mapping for node id: {0} and url: {1}", new string[] { doc.Id.ToString(), url }); query = "INSERT INTO icUrlTracker (RedirectRootNodeId, RedirectNodeId, OldUrl, Notes) VALUES (@rootNodeId, @nodeId, @url, @notes)"; _sqlHelper.ExecuteNonQuery(query, _sqlHelper.CreateParameter("rootNodeId", rootNodeId), _sqlHelper.CreateParameter("nodeId", doc.Id), _sqlHelper.CreateStringParameter("url", url), _sqlHelper.CreateStringParameter("notes", notes)); if (doc.HasChildren) { foreach (Document child in doc.Children) { Node node = new Node(child.Id); AddUrlMapping(child, rootNodeId, node.NiceUrl, type, true); } } return(true); } } } return(false); }
public static bool AddUrlMapping(Document doc, int rootNodeId, string url, AutoTrackingTypes type, bool isChild = false) { if (url != "#") { string notes = isChild ? "An ancestor" : "This page"; switch (type) { case AutoTrackingTypes.Moved: notes += " was moved"; break; case AutoTrackingTypes.Renamed: notes += " was renamed"; break; case AutoTrackingTypes.UrlOverwritten: notes = "'s property 'umbracoUrlName' changed"; break; } url = UrlTrackerHelper.ResolveShortestUrl(url); if (!string.IsNullOrEmpty(url)) { string query = "SELECT 1 FROM icUrlTracker WHERE RedirectNodeId = @nodeId AND OldUrl = @url"; int exists = _sqlHelper.ExecuteScalar<int>(query, _sqlHelper.CreateParameter("nodeId", doc.Id), _sqlHelper.CreateStringParameter("url", url)); if (exists != 1) { UrlTrackerLoggingHelper.LogInformation("UrlTracker Repository | Adding mapping for node id: {0} and url: {1}", new string[] { doc.Id.ToString(), url }); query = "INSERT INTO icUrlTracker (RedirectRootNodeId, RedirectNodeId, OldUrl, Notes) VALUES (@rootNodeId, @nodeId, @url, @notes)"; _sqlHelper.ExecuteNonQuery(query, _sqlHelper.CreateParameter("rootNodeId", rootNodeId), _sqlHelper.CreateParameter("nodeId", doc.Id), _sqlHelper.CreateStringParameter("url", url), _sqlHelper.CreateStringParameter("notes", notes)); if (doc.HasChildren) { foreach (Document child in doc.Children) { Node node = new Node(child.Id); AddUrlMapping(child, rootNodeId, node.NiceUrl, type, true); } } return true; } } } return false; }
public static bool AddUrlMapping(IContent content, int rootNodeId, string url, AutoTrackingTypes type, bool isChild = false) { if (url != "#" && content.Template != null && content.Template.Id > 0) { string notes = isChild ? "An ancestor" : "This page"; switch (type) { case AutoTrackingTypes.Moved: notes += " was moved"; break; case AutoTrackingTypes.Renamed: notes += " was renamed"; break; case AutoTrackingTypes.UrlOverwritten: notes += "'s property 'umbracoUrlName' changed"; break; } url = UrlTrackerHelper.ResolveShortestUrl(url); if (UrlTrackerSettings.HasDomainOnChildNode) { var rootNode = new Node(rootNodeId); var rootUri = new Uri(rootNode.NiceUrl); var shortRootUrl = UrlTrackerHelper.ResolveShortestUrl(rootUri.AbsolutePath); if (url.StartsWith(shortRootUrl, StringComparison.OrdinalIgnoreCase)) { url = UrlTrackerHelper.ResolveShortestUrl(url.Substring(shortRootUrl.Length)); } } if (!string.IsNullOrEmpty(url)) { string query = "SELECT 1 FROM icUrlTracker WHERE RedirectNodeId = @nodeId AND OldUrl = @url"; int exists = _sqlHelper.ExecuteScalar <int>(query, _sqlHelper.CreateParameter("nodeId", content.Id), _sqlHelper.CreateStringParameter("url", url)); if (exists != 1) { LoggingHelper.LogInformation("UrlTracker Repository | Adding mapping for node id: {0} and url: {1}", new string[] { content.Id.ToString(), url }); query = "INSERT INTO icUrlTracker (RedirectRootNodeId, RedirectNodeId, OldUrl, Notes) VALUES (@rootNodeId, @nodeId, @url, @notes)"; _sqlHelper.ExecuteNonQuery(query, _sqlHelper.CreateParameter("rootNodeId", rootNodeId), _sqlHelper.CreateParameter("nodeId", content.Id), _sqlHelper.CreateStringParameter("url", url), _sqlHelper.CreateStringParameter("notes", notes)); if (content.Children().Any()) { foreach (IContent child in content.Children()) { Node node = new Node(child.Id); AddUrlMapping(child, rootNodeId, node.NiceUrl, type, true); } } return(true); } } } return(false); }
public static bool AddUrlMapping(IContent content, int rootNodeId, string url, AutoTrackingTypes type, bool isChild = false) { if (url != "#" && content.Template != null && content.Template.Id > 0) { var notes = isChild ? "An ancestor" : "This page"; switch (type) { case AutoTrackingTypes.Moved: notes += " was moved"; break; case AutoTrackingTypes.Renamed: notes += " was renamed"; break; case AutoTrackingTypes.UrlOverwritten: notes += "'s property 'umbracoUrlName' changed"; break; case AutoTrackingTypes.UrlOverwrittenSEOMetadata: notes += string.Format("'s property '{0}' changed", UrlTrackerSettings.SEOMetadataPropertyName); break; } url = UrlTrackerHelper.ResolveShortestUrl(url); if (UrlTrackerSettings.HasDomainOnChildNode) { var rootNode = new Node(rootNodeId); var rootUrl = !rootNode.Url.StartsWith("/") ? rootNode.NiceUrl : string.Format("{0}{1}{2}", Uri.UriSchemeHttp, Uri.SchemeDelimiter, HttpContext.Current.Request.Url.Host) + rootNode.NiceUrl; var rootUri = new Uri(rootUrl); var shortRootUrl = UrlTrackerHelper.ResolveShortestUrl(rootUri.AbsolutePath); if (url.StartsWith(shortRootUrl, StringComparison.OrdinalIgnoreCase)) { url = UrlTrackerHelper.ResolveShortestUrl(url.Substring(shortRootUrl.Length)); } } var database = ApplicationContext.Current.DatabaseContext.Database; if (!string.IsNullOrEmpty(url)) { var query = "SELECT 1 FROM icUrlTracker WHERE RedirectNodeId = @nodeId AND OldUrl = @url"; var exists = database.ExecuteScalar <int?>(query, new object[] { new { nodeId = content.Id }, new { url = url } }); if (exists != 1) { LoggingHelper.LogInformation("UrlTracker Repository | Adding mapping for node id: {0} and url: {1}", new string[] { content.Id.ToString(), url }); database.Insert( "icUrlTracker", "Id", true, new { RedirectRootNodeId = rootNodeId, RedirectNodeId = content.Id, OldUrl = url, Notes = notes }); if (content.Children().Any()) { foreach (var child in content.Children()) { var node = new Node(child.Id); AddUrlMapping(child, rootNodeId, node.NiceUrl, type, true); } } return(true); } } } return(false); }