U4-1080 - updateDate value for media item pulled from it's xml fragment (as only verison in db for media is the created version)
This commit is contained in:
@@ -3,10 +3,10 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Umbraco.Core.IO;
|
||||
using umbraco.BasePages;
|
||||
using umbraco.cms.businesslogic;
|
||||
using umbraco.cms.businesslogic.datatype.controls;
|
||||
@@ -16,8 +16,8 @@ using umbraco.cms.businesslogic.propertytype;
|
||||
using umbraco.cms.businesslogic.web;
|
||||
using umbraco.interfaces;
|
||||
using umbraco.uicontrols;
|
||||
using Umbraco.Core.IO;
|
||||
using Content = umbraco.cms.businesslogic.Content;
|
||||
using System.Linq;
|
||||
using SystemDirectories = umbraco.IO.SystemDirectories;
|
||||
|
||||
namespace umbraco.controls
|
||||
|
||||
@@ -19,6 +19,10 @@ namespace umbraco.cms.presentation
|
||||
/// </summary>
|
||||
public partial class editMedia : BasePages.UmbracoEnsuredPage
|
||||
{
|
||||
private uicontrols.Pane mediaPropertyPane = new uicontrols.Pane();
|
||||
private LiteralControl updateDateLiteral = new LiteralControl();
|
||||
|
||||
|
||||
public editMedia()
|
||||
{
|
||||
CurrentApp = BusinessLogic.DefaultApps.media.ToString();
|
||||
@@ -29,7 +33,51 @@ namespace umbraco.cms.presentation
|
||||
controls.ContentControl tmp;
|
||||
|
||||
//protected System.Web.UI.WebControls.Literal SyncPath;
|
||||
|
||||
|
||||
override protected void OnInit(EventArgs e)
|
||||
{
|
||||
//
|
||||
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
|
||||
//
|
||||
InitializeComponent();
|
||||
base.OnInit(e);
|
||||
|
||||
_media = new cms.businesslogic.media.Media(int.Parse(Request.QueryString["id"]));
|
||||
|
||||
// Save media on first load
|
||||
bool exists = SqlHelper.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId",
|
||||
SqlHelper.CreateParameter("@nodeId", _media.Id)) > 0;
|
||||
if (!exists)
|
||||
_media.XmlGenerate(new XmlDocument());
|
||||
|
||||
|
||||
tmp = new controls.ContentControl(_media, controls.ContentControl.publishModes.NoPublish, "TabView1");
|
||||
tmp.Width = Unit.Pixel(666);
|
||||
tmp.Height = Unit.Pixel(666);
|
||||
plc.Controls.Add(tmp);
|
||||
|
||||
tmp.Save += new System.EventHandler(Save);
|
||||
|
||||
updateDateLiteral.ID = "updateDate";
|
||||
updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString();
|
||||
|
||||
mediaPropertyPane.addProperty(ui.Text("content", "updateDate", base.getUser()), updateDateLiteral);
|
||||
|
||||
// TODO: move the LinkToMediaItem property here - that way it's updated after save, rather than relying on a reload
|
||||
|
||||
// add the property pane to the page rendering
|
||||
tmp.tpProp.Controls.AddAt(1, mediaPropertyPane);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected void Page_Load(object sender, System.EventArgs e)
|
||||
{
|
||||
//if (!IsPostBack)
|
||||
@@ -64,44 +112,11 @@ namespace umbraco.cms.presentation
|
||||
}
|
||||
}
|
||||
_media.Save();
|
||||
|
||||
this.updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString();
|
||||
|
||||
_media.XmlGenerate(new XmlDocument());
|
||||
ClientTools.SyncTree(_media.Path, true);
|
||||
}
|
||||
|
||||
#region Web Form Designer generated code
|
||||
override protected void OnInit(EventArgs e)
|
||||
{
|
||||
//
|
||||
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
|
||||
//
|
||||
InitializeComponent();
|
||||
base.OnInit(e);
|
||||
|
||||
_media = new cms.businesslogic.media.Media(int.Parse(Request.QueryString["id"]));
|
||||
|
||||
// Save media on first load
|
||||
bool exists = SqlHelper.ExecuteScalar<int>("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId",
|
||||
SqlHelper.CreateParameter("@nodeId", _media.Id)) > 0;
|
||||
if (!exists)
|
||||
_media.XmlGenerate(new XmlDocument());
|
||||
|
||||
|
||||
tmp = new controls.ContentControl(_media,controls.ContentControl.publishModes.NoPublish, "TabView1");
|
||||
tmp.Width = Unit.Pixel(666);
|
||||
tmp.Height = Unit.Pixel(666);
|
||||
plc.Controls.Add(tmp);
|
||||
|
||||
tmp.Save += new System.EventHandler(Save);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,15 +160,32 @@ namespace umbraco.cms.businesslogic
|
||||
{
|
||||
if (!_versionDateInitialized)
|
||||
{
|
||||
object o = SqlHelper.ExecuteScalar<object>(
|
||||
"select VersionDate from cmsContentVersion where versionId = '" + this.Version.ToString() + "'");
|
||||
if (o == null)
|
||||
// A Media item only contains a single version (which relates to it's creation) so get this value from the media xml fragment instead
|
||||
if (this is media.Media)
|
||||
{
|
||||
_versionDate = DateTime.Now;
|
||||
// get the xml fragment from cmsXmlContent
|
||||
string xmlFragment = SqlHelper.ExecuteScalar<string>(@"SELECT [xml] FROM cmsContentXml WHERE nodeId = " + this.Id);
|
||||
if (!string.IsNullOrWhiteSpace(xmlFragment))
|
||||
{
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
xmlDocument.LoadXml(xmlFragment);
|
||||
|
||||
_versionDateInitialized = DateTime.TryParse(xmlDocument.SelectSingleNode("//*[1]").Attributes["updateDate"].Value, out _versionDate);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if (!_versionDateInitialized)
|
||||
{
|
||||
_versionDateInitialized = DateTime.TryParse(o.ToString(), out _versionDate);
|
||||
object o = SqlHelper.ExecuteScalar<object>(
|
||||
"select VersionDate from cmsContentVersion where versionId = '" + this.Version.ToString() + "'");
|
||||
if (o == null)
|
||||
{
|
||||
_versionDate = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
_versionDateInitialized = DateTime.TryParse(o.ToString(), out _versionDate);
|
||||
}
|
||||
}
|
||||
}
|
||||
return _versionDate;
|
||||
|
||||
Reference in New Issue
Block a user