Merge pull request #3019 from ed-parry/v8hackathon-remove-pageid-references

Replaced references of PageID with the UmbracoContext calls. [v8hackathon]
This commit is contained in:
Sebastiaan Janssen
2018-09-25 21:45:06 +02:00
committed by GitHub
10 changed files with 12 additions and 151 deletions

View File

@@ -40,21 +40,6 @@ namespace Umbraco.Tests.PublishedContent
Assert.IsFalse(result);
}
[Test]
public void ConfigureRequest_Adds_HttpContext_Items_When_Published_Content_Assigned()
{
var umbracoContext = GetUmbracoContext("/test");
var publishedRouter = CreatePublishedRouter();
var request = publishedRouter.CreateRequest(umbracoContext);
var content = GetPublishedContentMock();
request.PublishedContent = content.Object;
request.Culture = new CultureInfo("en-AU");
publishedRouter.ConfigureRequest(request);
Assert.AreEqual(1, umbracoContext.HttpContext.Items["pageID"]);
Assert.AreEqual(request.UmbracoPage.Elements.Count, ((Hashtable) umbracoContext.HttpContext.Items["pageElements"]).Count);
}
[Test]
public void ConfigureRequest_Sets_UmbracoPage_When_Published_Content_Assigned()
{

View File

@@ -135,7 +135,6 @@ namespace Umbraco.Web.Editors
var legacyPage = new global::umbraco.page(doc, _variationContextAccessor);
UmbracoContext.HttpContext.Items["pageID"] = doc.Id;
UmbracoContext.HttpContext.Items["pageElements"] = legacyPage.Elements;
UmbracoContext.HttpContext.Items[global::Umbraco.Core.Constants.Conventions.Url.AltTemplate] = null;

View File

@@ -211,7 +211,6 @@ namespace Umbraco.Web.Routing
frequest.UmbracoPage = new page(frequest);
// used by many legacy objects
frequest.UmbracoContext.HttpContext.Items["pageID"] = frequest.PublishedContent.Id;
frequest.UmbracoContext.HttpContext.Items["pageElements"] = frequest.UmbracoPage.Elements;
return true;
@@ -257,8 +256,7 @@ namespace Umbraco.Web.Routing
// handlers like default.aspx will want it and most macros currently need it
request.UmbracoPage = new page(request);
// these two are used by many legacy objects
request.UmbracoContext.HttpContext.Items["pageID"] = request.PublishedContent.Id;
// this is used by many legacy objects
request.UmbracoContext.HttpContext.Items["pageElements"] = request.UmbracoPage.Elements;
}

View File

@@ -202,7 +202,6 @@ namespace Umbraco.Web.Templates
// handlers like default.aspx will want it and most macros currently need it
request.UmbracoPage = new page(request);
//now, set the new ones for this page execution
_umbracoContext.HttpContext.Items["pageID"] = request.PublishedContent.Id;
_umbracoContext.HttpContext.Items["pageElements"] = request.UmbracoPage.Elements;
_umbracoContext.HttpContext.Items[Core.Constants.Conventions.Url.AltTemplate] = null;
_umbracoContext.PublishedRequest = request;
@@ -214,8 +213,8 @@ namespace Umbraco.Web.Templates
private void SaveExistingItems()
{
//Many objects require that these legacy items are in the http context items... before we render this template we need to first
//save the values in them so that we can re-set them after we render so the rest of the execution works as per normal.
_oldPageId = _umbracoContext.HttpContext.Items["pageID"];
//save the values in them so that we can re-set them after we render so the rest of the execution works as per normal
_oldPageId = _umbracoContext.PageId;
_oldPageElements = _umbracoContext.HttpContext.Items["pageElements"];
_oldPublishedRequest = _umbracoContext.PublishedRequest;
_oldAltTemplate = _umbracoContext.HttpContext.Items[Umbraco.Core.Constants.Conventions.Url.AltTemplate];
@@ -227,7 +226,6 @@ namespace Umbraco.Web.Templates
private void RestoreItems()
{
_umbracoContext.PublishedRequest = _oldPublishedRequest;
_umbracoContext.HttpContext.Items["pageID"] = _oldPageId;
_umbracoContext.HttpContext.Items["pageElements"] = _oldPageElements;
_umbracoContext.HttpContext.Items[Umbraco.Core.Constants.Conventions.Url.AltTemplate] = _oldAltTemplate;
}

View File

@@ -1409,9 +1409,6 @@
<DependentUpon>nodeSorter.asmx</DependentUpon>
<SubType>Component</SubType>
</Compile>
<Compile Include="umbraco.presentation\umbraco\Web\UI\ContentPage.cs">
<SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="UmbracoApplication.cs" />
<Compile Include="UmbracoContext.cs" />
<Compile Include="UmbracoModule.cs" />

View File

@@ -253,17 +253,15 @@ namespace Umbraco.Web
/// </summary>
public int? PageId
{
// TODO - this is dirty old legacy tricks, we should clean it up at some point
// also, what is a "custom page" and when should this be either null, or different
// from PublishedContentRequest.PublishedContent.Id ??
// SD: Have found out it can be different when rendering macro contents in the back office, but really youshould just be able
// to pass a page id to the macro renderer instead but due to all the legacy bits that's real difficult.
get
{
try
{
//TODO: this should be done with a wrapper: http://issues.umbraco.org/issue/U4-61
return int.Parse(HttpContext.Items["pageID"].ToString());
// This was changed but the comments used to refer to
// macros in the backoffice not working with this Id
// it's probably not a problem any more though. Old comment:
// https://github.com/umbraco/Umbraco-CMS/blob/7a615133ff9de84ee667fb7794169af65e2b4d7a/src/Umbraco.Web/UmbracoContext.cs#L256
return Current.PublishedRequest.PublishedContent.Id;
}
catch
{

View File

@@ -3,18 +3,13 @@ using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Xml;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Editors;
using Umbraco.Web.Routing;
using Umbraco.Core.Configuration;
using Umbraco.Core.PropertyEditors;
using Umbraco.Web;
using Umbraco.Web.Composing;
namespace umbraco
@@ -146,55 +141,7 @@ namespace umbraco
_elements.Add("path", path);
_elements.Add("splitpath", _splitpath);
}
void populatePageData(XmlNode node)
{
string s;
DateTime dt;
Guid guid;
int i;
if (int.TryParse(attrValue(node, "id"), out i))
_elements["pageID"] = this._pageId = i;
if ((s = attrValue(node, "nodeName")) != null)
_elements["pageName"] = this._pageName = s;
if (int.TryParse(attrValue(node, "parentId"), out i))
_elements["parentId"] = this._parentId = i;
if (int.TryParse(attrValue(node, "nodeType"), out i))
_elements["nodeType"] = this._nodeType = i;
if ((s = attrValue(node, "nodeTypeAlias")) != null)
_elements["nodeTypeAlias"] = this._nodeTypeAlias = s;
if ((s = attrValue(node, "writerName")) != null)
_elements["writerName"] = this._writerName = s;
if ((s = attrValue(node, "creatorName")) != null)
_elements["creatorName"] = this._creatorName = s;
if (DateTime.TryParse(attrValue(node, "createDate"), out dt))
_elements["createDate"] = this._createDate = dt;
if (DateTime.TryParse(attrValue(node, "updateDate"), out dt))
_elements["updateDate"] = this._updateDate = dt;
if (Guid.TryParse(attrValue(node, "pageVersion"), out guid))
_elements["pageVersion"] = this._pageVersion = guid;
if ((s = attrValue(node, "path")) != null)
{
_elements["path"] = this._path = s;
_elements["splitpath"] = this._splitpath = _path.Split(',');
}
}
string attrValue(XmlNode node, string attributeName)
{
var attr = node.Attributes.GetNamedItem(attributeName);
var value = attr != null ? attr.Value : null;
return value;
}
/// <summary>
/// Puts the properties of the node into the elements table
/// </summary>
@@ -217,42 +164,6 @@ namespace umbraco
}
}
}
void populateElementData(XmlNode node)
{
string xpath = "./* [not(@isDoc)]";
foreach (XmlNode data in node.SelectNodes(xpath))
{
// ignore empty elements
if (data.ChildNodes.Count == 0)
continue;
string alias = data.Name;
string value = data.FirstChild.Value;
// moved to PublishedContentRequest + UmbracoModule
//if (alias == "umbracoRedirect")
//{
// int i;
// if (int.TryParse(value, out i))
// HttpContext.Current.Response.Redirect(library.NiceUrl(int.Parse(data.FirstChild.Value)), true);
//}
if (_elements.ContainsKey(alias))
{
Current.Logger.Debug<page>(
string.Format("Aliases must be unique, an element with alias \"{0}\" has already been loaded!", alias));
}
else
{
_elements[alias] = value;
Current.Logger.Debug<page>(
string.Format("Load element \"{0}\"", alias));
}
}
}
#endregion
#region Public properties

View File

@@ -1,25 +0,0 @@
using System;
namespace umbraco.presentation.Web.UI
{
/// <summary>
/// Summary description for ContentPage.
/// </summary>
public class ContentPage : System.Web.UI.Page
{
private int _id = 0;
public int UmbracoNodeId
{
set
{
_id = value;
System.Web.HttpContext.Current.Items["pageID"] = _id;
}
get {return _id;}
}
public ContentPage()
{
}
}
}

View File

@@ -203,9 +203,9 @@ namespace umbraco.presentation.templateControls
return nodeIdInt;
}
}
else if (PageElements["pageID"] != null)
else if (UmbracoContext.Current.PageId != null)
{
return int.Parse(PageElements["pageID"].ToString());
return UmbracoContext.Current.PageId.Value;
}
return null;
}

View File

@@ -132,7 +132,7 @@ namespace umbraco.presentation.templateControls
// set pageId to int.MinValue if no pageID was found,
// e.g. if the macro was rendered on a custom (non-Umbraco) page
var pageId = Context.Items["pageID"] == null ? int.MinValue : int.Parse(Context.Items["pageID"].ToString());
var pageId = UmbracoContext.Current.PageId == null ? int.MinValue : UmbracoContext.Current.PageId.Value;
if ((string.IsNullOrEmpty(Language) == false && Text != "") || string.IsNullOrEmpty(FileLocation) == false) {
var tempMacro = new MacroModel();