From 16dd94b9560d186a922b717d08c24f654f6e21aa Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Thu, 15 Nov 2012 03:39:17 +0000 Subject: [PATCH] Improve inventory folder version updating for mssql database plugin. I am not in a position to test this so the updates have been done blind. If it needs any fixing will probably require patches. --- OpenSim/Data/MSSQL/MSSQLXInventoryData.cs | 116 +++++++++++++++++++--- 1 file changed, 102 insertions(+), 14 deletions(-) diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs index 7ab0ebbe7b..97970af325 100644 --- a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs +++ b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs @@ -131,6 +131,12 @@ namespace OpenSim.Data.MSSQL public bool MoveItem(string id, string newParent) { + XInventoryItem[] retrievedItems = Get(new string[] { "inventoryID" }, new string[] { id }); + if (retrievedItems.Length == 0) + return false; + + UUID oldParent = retrievedItems[0].parentFolderID; + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) @@ -141,9 +147,16 @@ namespace OpenSim.Data.MSSQL cmd.Parameters.Add(m_database.CreateParameter("@InventoryID", id)); cmd.Connection = conn; conn.Open(); - return cmd.ExecuteNonQuery() == 0 ? false : true; + + if (cmd.ExecuteNonQuery() == 0) + return false; } } + + IncrementFolderVersion(oldParent); + IncrementFolderVersion(newParent); + + return true; } public XInventoryItem[] GetActiveGestures(UUID principalID) @@ -196,26 +209,43 @@ namespace OpenSim.Data.MSSQL if (!base.Store(item)) return false; - string sql = "update inventoryfolders set version=version+1 where folderID = @folderID"; + IncrementFolderVersion(item.parentFolderID); + + return true; + } + + private bool IncrementFolderVersion(UUID folderID) + { + return IncrementFolderVersion(folderID.ToString()); + } + + private bool IncrementFolderVersion(string folderID) + { +// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); +// Util.PrintCallStack(); + + string sql = "update inventoryfolders set version=version+1 where folderID = ?folderID"; + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) { using (SqlCommand cmd = new SqlCommand(sql, conn)) { conn.Open(); - cmd.Parameters.AddWithValue("@folderID", item.parentFolderID.ToString()); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception) - { - return false; - } - } + cmd.Parameters.AddWithValue("@folderID", folderID); - return true; + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { + return false; + } + } } + + return true; } } @@ -228,6 +258,13 @@ namespace OpenSim.Data.MSSQL public bool MoveFolder(string id, string newParentFolderID) { + XInventoryFolder[] folders = Get(new string[] { "folderID" }, new string[] { id }); + + if (folders.Length == 0) + return false; + + UUID oldParentFolderUUID = folders[0].parentFolderID; + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) { using (SqlCommand cmd = new SqlCommand()) @@ -238,9 +275,60 @@ namespace OpenSim.Data.MSSQL cmd.Parameters.Add(m_database.CreateParameter("@folderID", id)); cmd.Connection = conn; conn.Open(); - return cmd.ExecuteNonQuery() == 0 ? false : true; + + if (cmd.ExecuteNonQuery() == 0) + return false; } } + + IncrementFolderVersion(oldParentFolderUUID); + IncrementFolderVersion(newParentFolderID); + + return true; + } + + public override bool Store(XInventoryFolder folder) + { + if (!base.Store(folder)) + return false; + + IncrementFolderVersion(folder.parentFolderID); + + return true; + } + + private bool IncrementFolderVersion(UUID folderID) + { + return IncrementFolderVersion(folderID.ToString()); + } + + private bool IncrementFolderVersion(string folderID) + { +// m_log.DebugFormat("[MYSQL ITEM HANDLER]: Incrementing version on folder {0}", folderID); +// Util.PrintCallStack(); + + string sql = "update inventoryfolders set version=version+1 where folderID = ?folderID"; + + using (SqlConnection conn = new SqlConnection(m_ConnectionString)) + { + using (SqlCommand cmd = new SqlCommand(sql, conn)) + { + conn.Open(); + + cmd.Parameters.AddWithValue("@folderID", folderID); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception) + { + return false; + } + } + } + + return true; } } } \ No newline at end of file