diff --git a/src/Umbraco.Core/Persistence/Repositories/RedirectUrlRepository.cs b/src/Umbraco.Core/Persistence/Repositories/RedirectUrlRepository.cs index 16e0c44da2..ec6e57b7b3 100644 --- a/src/Umbraco.Core/Persistence/Repositories/RedirectUrlRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/RedirectUrlRepository.cs @@ -185,7 +185,7 @@ JOIN umbracoNode ON umbracoRedirectUrl.contentKey=umbracoNode.uniqueID"); public IEnumerable GetAllUrls(int rootContentId, long pageIndex, int pageSize, out long total) { var sql = GetBaseQuery(false) - .Where("[umbracoNode].[path] LIKE @path", new { path = "%," + rootContentId + ",%" }) + .Where(string.Format("{0}.{1} LIKE @path", SqlSyntax.GetQuotedTableName("umbracoNode"), SqlSyntax.GetQuotedColumnName("path")), new { path = "%," + rootContentId + ",%" }) .OrderByDescending(x => x.CreateDateUtc, SqlSyntax); var result = Database.Page(pageIndex + 1, pageSize, sql); total = Convert.ToInt32(result.TotalItems); @@ -197,7 +197,7 @@ JOIN umbracoNode ON umbracoRedirectUrl.contentKey=umbracoNode.uniqueID"); public IEnumerable SearchUrls(string searchTerm, long pageIndex, int pageSize, out long total) { var sql = GetBaseQuery(false) - .Where("[umbracoRedirectUrl].[Url] LIKE @url", new { url = "%" + searchTerm.Trim().ToLowerInvariant() + "%" }) + .Where(string.Format("{0}.{1} LIKE @url", SqlSyntax.GetQuotedTableName("umbracoRedirectUrl"), SqlSyntax.GetQuotedColumnName("Url")), new { url = "%" + searchTerm.Trim().ToLowerInvariant() + "%" }) .OrderByDescending(x => x.CreateDateUtc, SqlSyntax); var result = Database.Page(pageIndex + 1, pageSize, sql); total = Convert.ToInt32(result.TotalItems); diff --git a/src/Umbraco.Core/Services/RedirectUrlService.cs b/src/Umbraco.Core/Services/RedirectUrlService.cs index d71a38b8e9..d4c7614aa4 100644 --- a/src/Umbraco.Core/Services/RedirectUrlService.cs +++ b/src/Umbraco.Core/Services/RedirectUrlService.cs @@ -75,7 +75,6 @@ namespace Umbraco.Core.Services using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow)) { var rule = repo.GetMostRecentUrl(url); - uow.Commit(); return rule; } } @@ -86,7 +85,6 @@ namespace Umbraco.Core.Services using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow)) { var rules = repo.GetContentUrls(contentKey); - uow.Commit(); return rules; } } @@ -97,7 +95,6 @@ namespace Umbraco.Core.Services using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow)) { var rules = repo.GetAllUrls(pageIndex, pageSize, out total); - uow.Commit(); return rules; } } @@ -108,7 +105,6 @@ namespace Umbraco.Core.Services using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow)) { var rules = repo.GetAllUrls(rootContentId, pageIndex, pageSize, out total); - uow.Commit(); return rules; } } @@ -118,7 +114,6 @@ namespace Umbraco.Core.Services using (var repo = RepositoryFactory.CreateRedirectUrlRepository(uow)) { var rules = repo.SearchUrls(searchTerm, pageIndex, pageSize, out total); - uow.Commit(); return rules; } } diff --git a/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs b/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs index 604dea8cc5..a147d859e0 100644 --- a/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs +++ b/src/Umbraco.Web/Redirects/RedirectUrlManagementController.cs @@ -26,7 +26,6 @@ namespace Umbraco.Web.Redirects searchResult.SearchResults = redirects; searchResult.TotalCount = resultCount; searchResult.CurrentPage = page; - //hmm how many results 'could there be ? searchResult.PageCount = ((int)resultCount + pageSize - 1) / pageSize; searchResult.HasSearchResults = resultCount > 0; @@ -40,52 +39,42 @@ namespace Umbraco.Web.Redirects { var publishedUrl = "#"; if (id > 0) - { publishedUrl = Umbraco.Url(id); - } return new HttpResponseMessage { Content = new StringContent(publishedUrl, Encoding.UTF8, "text/html") }; } [HttpPost] - public HttpResponseMessage DeleteRedirectUrl(int id) + public IHttpActionResult DeleteRedirectUrl(int id) { - var redirectUrlService = Services.RedirectUrlService; - // has the redirect already been deleted ? - //var redirectUrl = redirectUrlService.GetById(redirectUrl.Id); - //if (redirectUrl== null) - //{ - // return new HttpResponseMessage(System.Net.HttpStatusCode.NotFound); - //} redirectUrlService.Delete(id); - return new HttpResponseMessage(System.Net.HttpStatusCode.OK); + return Ok(); } [HttpPost] - public HttpResponseMessage ToggleUrlTracker(bool disable) + public IHttpActionResult ToggleUrlTracker(bool disable) { var configFilePath = HttpContext.Current.Server.MapPath("~/config/umbracoSettings.config"); - if (File.Exists(configFilePath)) - { - var umbracoConfig = new XmlDocument { PreserveWhitespace = true }; - umbracoConfig.Load(configFilePath); + var action = disable ? "disable" : "enable"; - var webRoutingElement = umbracoConfig.SelectSingleNode("//web.routing") as XmlElement; - if (webRoutingElement != null) - { - // note: this adds the attribute if it does not exist - webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant()); - umbracoConfig.Save(configFilePath); - } + if (File.Exists(configFilePath) == false) + return BadRequest(string.Format("Couldn't {0} URL Tracker, the umbracoSettings.config file does not exist.", action)); + var umbracoConfig = new XmlDocument { PreserveWhitespace = true }; + umbracoConfig.Load(configFilePath); - return new HttpResponseMessage(System.Net.HttpStatusCode.OK); - } + var webRoutingElement = umbracoConfig.SelectSingleNode("//web.routing") as XmlElement; + if (webRoutingElement == null) + return BadRequest(string.Format("Couldn't {0} URL Tracker, the web.routing element was not found in umbracoSettings.config.", action)); - return new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest); + // note: this adds the attribute if it does not exist + webRoutingElement.SetAttribute("disableRedirectUrlTracking", disable.ToString().ToLowerInvariant()); + umbracoConfig.Save(configFilePath); + + return Ok(string.Format("URL tracker is now {0}d", action)); } } } \ No newline at end of file