From d2d43255aa0f2ca58387b6ee6162045bfa896593 Mon Sep 17 00:00:00 2001
From: Shannon
Date: Thu, 28 Sep 2017 02:38:53 +1000
Subject: [PATCH] U4-5222 Rollback Feature fails to update the UI to show the
rolled back content - requires refresh
---
.../lib/umbraco/LegacyUmbClientMgr.js | 28 +++++++++---
.../Application/UmbracoClientManager.js | 4 +-
.../umbraco/dialogs/rollBack.aspx.cs | 36 ++++++---------
.../BasePages/ClientTools.cs | 45 ++++++++++++-------
src/umbraco.cms/businesslogic/Content.cs | 7 ++-
5 files changed, 70 insertions(+), 50 deletions(-)
diff --git a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js
index 06d6c11c71..db02a1de4a 100644
--- a/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js
+++ b/src/Umbraco.Web.UI.Client/lib/umbraco/LegacyUmbClientMgr.js
@@ -361,11 +361,29 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
rootScope : function(){
return getRootScope();
},
-
- reloadLocation: function() {
- var injector = getRootInjector();
- var $route = injector.get("$route");
- $route.reload();
+
+ /**
+ This will reload the content frame based on it's current route, if pathToMatch is specified it will only reload it if the current
+ location matches the path
+ */
+ reloadLocation: function(pathToMatch) {
+
+ var injector = getRootInjector();
+ var doChange = true;
+ if (pathToMatch) {
+ var $location = injector.get("$location");
+ var path = $location.path();
+ if (path != pathToMatch) {
+ doChange = false;
+ }
+ }
+
+ if (doChange) {
+ var $route = injector.get("$route");
+ $route.reload();
+ var $rootScope = injector.get("$rootScope");
+ $rootScope.$apply();
+ }
},
closeModalWindow: function(rVal) {
diff --git a/src/Umbraco.Web.UI/umbraco_client/Application/UmbracoClientManager.js b/src/Umbraco.Web.UI/umbraco_client/Application/UmbracoClientManager.js
index 88f385eac3..ec76e8f8f6 100644
--- a/src/Umbraco.Web.UI/umbraco_client/Application/UmbracoClientManager.js
+++ b/src/Umbraco.Web.UI/umbraco_client/Application/UmbracoClientManager.js
@@ -172,9 +172,9 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
},
- reloadLocation: function () {
+ reloadLocation: function (pathToMatch) {
if (this.mainWindow().UmbClientMgr) {
- this.mainWindow().UmbClientMgr.reloadLocation();
+ this.mainWindow().UmbClientMgr.reloadLocation(pathToMatch);
}
},
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/rollBack.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/rollBack.aspx.cs
index 34ff19907e..b28e40163b 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/rollBack.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/dialogs/rollBack.aspx.cs
@@ -3,6 +3,7 @@ using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
+using System.Linq;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
@@ -117,36 +118,23 @@ namespace umbraco.presentation.dialogs
if (!IsPostBack) {
allVersions.Items.Add(new ListItem(ui.Text("rollback", "selectVersion")+ "...", ""));
- foreach (DocumentVersionList dl in currentDoc.GetVersions()) {
+
+ foreach (DocumentVersionList dl in currentDoc.GetVersions())
+ {
+ //we don't need to show the current version
+ if (dl.Version == currentDoc.Version)
+ continue;
+
allVersions.Items.Add(new ListItem(dl.Text + " (" + ui.Text("content", "createDate") + ": " + dl.Date.ToShortDateString() + " " + dl.Date.ToShortTimeString() + ")", dl.Version.ToString()));
}
Button1.Text = ui.Text("actions", "rollback");
}
}
-
- #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);
- }
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
-
- }
- #endregion
-
+
protected void doRollback_Click(object sender, System.EventArgs e)
{
- if (allVersions.SelectedValue.Trim() != "") {
+ if (allVersions.SelectedValue.Trim() != "")
+ {
Document d = new Document(int.Parse(helper.Request("nodeId")));
d.RollBack(new Guid(allVersions.SelectedValue), base.getUser());
@@ -159,6 +147,8 @@ namespace umbraco.presentation.dialogs
feedBackMsg.Text = ui.Text("rollback", "documentRolledBack", vars, new global::umbraco.BusinessLogic.User(0)) + "
" + ui.Text("closeThisWindow") + "";
diffPanel.Visible = false;
pl_buttons.Visible = false;
+
+ ClientTools.ReloadLocationIfMatched(string.Format("/content/content/edit/{0}", d.Id));
}
}
}
diff --git a/src/umbraco.businesslogic/BasePages/ClientTools.cs b/src/umbraco.businesslogic/BasePages/ClientTools.cs
index 47c7890fc8..4b27e888ab 100644
--- a/src/umbraco.businesslogic/BasePages/ClientTools.cs
+++ b/src/umbraco.businesslogic/BasePages/ClientTools.cs
@@ -52,7 +52,8 @@ namespace umbraco.BasePages
public static string ReloadContentFrameUrlIfPathLoaded(string url) {
return string.Format(ClientMgrScript + ".reloadContentFrameUrlIfPathLoaded('{0}');", url);
}
- public static string ReloadLocation { get { return string.Format(ClientMgrScript + ".reloadLocation();"); } }
+ public static string ReloadLocation { get { return ClientMgrScript + ".reloadLocation();"; } }
+ public static string ReloadLocationIfMatched { get { return ClientMgrScript + ".reloadLocation('{0}');"; } }
public static string ChildNodeCreated = GetMainTree + ".childNodeCreated();";
public static string SyncTree { get { return GetMainTree + ".syncTree('{0}', {1});"; } }
public static string ClearTreeCache { get { return GetMainTree + ".clearTreeCache();"; } }
@@ -277,21 +278,33 @@ namespace umbraco.BasePages
RegisterClientScript(string.Format(Scripts.ReloadActionNode, (!reselect).ToString().ToLower(), (!reloadChildren).ToString().ToLower()));
return this;
}
-
- ///
- /// When the application searches for a node, it searches for nodes in specific tree types.
- /// If SyncTree is used, it will sync the tree nodes with the active tree type, therefore if
- /// a developer wants to sync a specific tree, they can call this method to set the type to sync.
- ///
- ///
- /// Each branch of a particular tree should theoretically be the same type, however, developers can
- /// override the type of each branch in their BaseTree's but this is not standard practice. If there
- /// are multiple types of branches in one tree, then only those branches that have the Active tree type
- /// will be searched for syncing.
- ///
- ///
- ///
- public ClientTools SetActiveTreeType(string treeType)
+
+ public ClientTools ReloadLocationIfMatched(string routePath)
+ {
+ RegisterClientScript(string.Format(Scripts.ReloadLocationIfMatched, routePath));
+ return this;
+ }
+
+ public ClientTools ReloadLocation()
+ {
+ RegisterClientScript(Scripts.ReloadLocation);
+ return this;
+ }
+
+ ///
+ /// When the application searches for a node, it searches for nodes in specific tree types.
+ /// If SyncTree is used, it will sync the tree nodes with the active tree type, therefore if
+ /// a developer wants to sync a specific tree, they can call this method to set the type to sync.
+ ///
+ ///
+ /// Each branch of a particular tree should theoretically be the same type, however, developers can
+ /// override the type of each branch in their BaseTree's but this is not standard practice. If there
+ /// are multiple types of branches in one tree, then only those branches that have the Active tree type
+ /// will be searched for syncing.
+ ///
+ ///
+ ///
+ public ClientTools SetActiveTreeType(string treeType)
{
RegisterClientScript(string.Format(Scripts.SetActiveTreeType, treeType));
return this;
diff --git a/src/umbraco.cms/businesslogic/Content.cs b/src/umbraco.cms/businesslogic/Content.cs
index b64e4cf678..b0ad710f2c 100644
--- a/src/umbraco.cms/businesslogic/Content.cs
+++ b/src/umbraco.cms/businesslogic/Content.cs
@@ -276,13 +276,12 @@ namespace umbraco.cms.businesslogic
{
if (_version == Guid.Empty)
{
- string sql = "Select versionId from cmsContentVersion where contentID = " + this.Id +
- " order by id desc ";
-
+ var sql = string.Format("SELECT versionId FROM cmsDocument where nodeid={0} AND newest = 1 ORDER BY updateDate desc", this.Id);
+
using (var sqlHelper = Application.SqlHelper)
using (IRecordsReader dr = sqlHelper.ExecuteReader(sql))
{
- if (!dr.Read())
+ if (dr.Read() == false)
_version = Guid.Empty;
else
_version = dr.GetGuid("versionId");