Refactoring nodeSorter to utilize the changes made to the legacy/new api refactor.

Making a few of the public properties on CMSNode virtual, so we can override them in the Document and Media classes, which allow us to use the new api for saving changes to these properties instead of having them saved directly to the database.
This commit is contained in:
Morten Christensen
2012-12-28 13:40:35 -01:00
parent 8338102944
commit 3ae5aa7195
4 changed files with 148 additions and 13 deletions

View File

@@ -88,14 +88,16 @@ namespace umbraco.presentation.webservices
{
if (tmp[i] != "" && tmp[i].Trim() != "")
{
new cms.businesslogic.CMSNode(int.Parse(tmp[i])).sortOrder = i;
if (isContent)
{
var document = new Document(int.Parse(tmp[i]));
var published = document.Published;
document.sortOrder = i;
document.Save();
// refresh the xml for the sorting to work
if (document.Published)
if (published)
{
document.Publish(BusinessLogic.User.GetCurrent());
document.refreshXmlSortOrder();
library.UpdateDocumentCache(int.Parse(tmp[i]));
}
@@ -103,7 +105,13 @@ namespace umbraco.presentation.webservices
// to update the sortorder of the media node in the XML, re-save the node....
else if (isMedia)
{
new cms.businesslogic.media.Media(int.Parse(tmp[i])).Save();
var media = new cms.businesslogic.media.Media(int.Parse(tmp[i]));
media.sortOrder = i;
media.Save();
}
else
{
new cms.businesslogic.CMSNode(int.Parse(tmp[i])).sortOrder = i;
}
}
}
@@ -123,9 +131,6 @@ namespace umbraco.presentation.webservices
library.RefreshContent();
}
//TODO: Properly refactor this, we're just clearing the cache so the new sortorder will also be visible in the backoffice
InMemoryCacheProvider.Current.Clear();
// fire actionhandler, check for content
if ((helper.Request("app") == "content" | helper.Request("app") == "") && ParentId > 0)
global::umbraco.BusinessLogic.Actions.Action.RunActionHandlers(new Document(ParentId), ActionSort.Instance);

View File

@@ -680,7 +680,7 @@ order by level,sortOrder";
/// Determines if the node is in the recycle bin.
/// This is only relavent for node types that support a recyle bin (such as Document/Media)
/// </summary>
public bool IsTrashed
public virtual bool IsTrashed
{
get
{
@@ -704,7 +704,7 @@ order by level,sortOrder";
/// Gets or sets the sort order.
/// </summary>
/// <value>The sort order.</value>
public int sortOrder
public virtual int sortOrder
{
get { return _sortOrder; }
set
@@ -718,7 +718,7 @@ order by level,sortOrder";
/// Gets or sets the create date time.
/// </summary>
/// <value>The create date time.</value>
public DateTime CreateDateTime
public virtual DateTime CreateDateTime
{
get { return _createDate; }
set
@@ -752,7 +752,7 @@ order by level,sortOrder";
/// <summary>
/// Get the newParent id of the node
/// </summary>
public int ParentId
public virtual int ParentId
{
get { return _parentid; }
}
@@ -780,7 +780,7 @@ order by level,sortOrder";
/// that indicates the path from the topmost node to the given node
/// </summary>
/// <value>The path.</value>
public string Path
public virtual string Path
{
get { return _path; }
set
@@ -795,7 +795,7 @@ order by level,sortOrder";
/// tree structure the given node is
/// </summary>
/// <value>The level.</value>
public int Level
public virtual int Level
{
get { return _level; }
set

View File

@@ -203,6 +203,71 @@ namespace umbraco.cms.businesslogic.media
#endregion
#region Public Properties
public override int sortOrder
{
get
{
return _media == null ? base.sortOrder : _media.SortOrder;
}
set
{
if (_media == null)
{
base.sortOrder = value;
}
else
{
_media.SortOrder = value;
}
}
}
public override int Level
{
get
{
return _media == null ? base.Level : _media.Level;
}
set
{
if (_media == null)
{
base.Level = value;
}
else
{
_media.Level = value;
}
}
}
public override int ParentId
{
get
{
return _media == null ? base.ParentId : _media.ParentId;
}
}
public override string Path
{
get
{
return _media == null ? base.Path : _media.Path;
}
set
{
if (_media == null)
{
base.Path = value;
}
else
{
_media.Path = value;
}
}
}
/// <summary>
/// Retrieve a list of all medias underneath the current
/// </summary>

View File

@@ -524,6 +524,71 @@ namespace umbraco.cms.businesslogic.web
#region Public Properties
public override int sortOrder
{
get
{
return Content == null ? base.sortOrder : Content.SortOrder;
}
set
{
if (Content == null)
{
base.sortOrder = value;
}
else
{
Content.SortOrder = value;
}
}
}
public override int Level
{
get
{
return Content == null ? base.Level : Content.Level;
}
set
{
if (Content == null)
{
base.Level = value;
}
else
{
Content.Level = value;
}
}
}
public override int ParentId
{
get
{
return Content == null ? base.ParentId : Content.ParentId;
}
}
public override string Path
{
get
{
return Content == null ? base.Path : Content.Path;
}
set
{
if (Content == null)
{
base.Path = value;
}
else
{
Content.Path = value;
}
}
}
/// <summary>
/// Gets a value indicating whether the document was constructed for the optimized mode
/// </summary>