From baddfa08f379e2bfd799a14ecc2f2eb5b9404a16 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Tue, 6 Nov 2012 22:39:54 +0000 Subject: [PATCH] Increment version number of a folder when an object it contains is deleted. Not doing this was allowing the viewer inventory cache to become out of sync if an item was directly deleted. --- OpenSim/Data/MySQL/MySQLXInventoryData.cs | 28 ++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs index caf18a4780..189ee5e64d 100644 --- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs @@ -123,11 +123,24 @@ namespace OpenSim.Data.MySQL { } + public override bool Delete(string field, string val) + { + XInventoryItem[] retrievedItems = Get(new string[] { field }, new string[] { val }); + if (retrievedItems.Length == 0) + return false; + + if (!base.Delete(field, val)) + return false; + + IncrementFolderVersion(retrievedItems[0].parentFolderID); + + return true; + } + public bool MoveItem(string id, string newParent) { using (MySqlCommand cmd = new MySqlCommand()) { - cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm); cmd.Parameters.AddWithValue("?ParentFolderID", newParent); cmd.Parameters.AddWithValue("?InventoryID", id); @@ -184,6 +197,13 @@ namespace OpenSim.Data.MySQL if (!base.Store(item)) return false; + IncrementFolderVersion(item.parentFolderID); + + return true; + } + + private bool IncrementFolderVersion(UUID folderID) + { using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) { dbcon.Open(); @@ -193,7 +213,7 @@ namespace OpenSim.Data.MySQL cmd.Connection = dbcon; cmd.CommandText = String.Format("update inventoryfolders set version=version+1 where folderID = ?folderID"); - cmd.Parameters.AddWithValue("?folderID", item.parentFolderID.ToString()); + cmd.Parameters.AddWithValue("?folderID", folderID.ToString()); try { @@ -205,9 +225,11 @@ namespace OpenSim.Data.MySQL } cmd.Dispose(); } + dbcon.Close(); } + return true; } } -} +} \ No newline at end of file