From 0907d5d69e10ba5be79a6d03366ce3cfa59c0bec Mon Sep 17 00:00:00 2001 From: Melanie Date: Mon, 4 Jan 2010 20:52:44 +0000 Subject: [PATCH] Finish conversion if XInventoryService --- OpenSim/Data/IXInventoryData.cs | 4 +- OpenSim/Data/MySQL/MySQLXInventoryData.cs | 55 ++++++++++++++++-- .../InventoryService/XInventoryService.cs | 58 +++++++++++++++---- 3 files changed, 98 insertions(+), 19 deletions(-) diff --git a/OpenSim/Data/IXInventoryData.cs b/OpenSim/Data/IXInventoryData.cs index 88174d9e91..cd9273ef2f 100644 --- a/OpenSim/Data/IXInventoryData.cs +++ b/OpenSim/Data/IXInventoryData.cs @@ -77,6 +77,8 @@ namespace OpenSim.Data bool DeleteFolders(string field, string val); bool DeleteItems(string field, string val); - bool MoveItem(string principalID, string id, string newParent); + bool MoveItem(string id, string newParent); + XInventoryItem[] GetActiveGestures(UUID principalID); + int GetAssetPermissions(UUID principalID, UUID assetID); } } diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs index dd3e6ea540..0eebc9c7fd 100644 --- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs +++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs @@ -85,9 +85,19 @@ namespace OpenSim.Data.MySQL return m_Items.Delete(field, val); } - public bool MoveItem(string principalID, string id, string newParent) + public bool MoveItem(string id, string newParent) { - return m_Items.MoveItem(principalID, id, newParent); + return m_Items.MoveItem(id, newParent); + } + + public XInventoryItem[] GetActiveGestures(UUID principalID) + { + return m_Items.GetActiveGestures(principalID); + } + + public int GetAssetPermissions(UUID principalID, UUID assetID) + { + return m_Items.GetAssetPermissions(principalID, assetID); } } @@ -98,16 +108,49 @@ namespace OpenSim.Data.MySQL { } - public bool MoveItem(string principalID, string id, string newParent) + public bool MoveItem(string id, string newParent) { MySqlCommand cmd = new MySqlCommand(); - cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where agentID = ?AgentID and folderID = ?FolderID"); + cmd.CommandText = String.Format("update {0} set parentFolderID = ?ParentFolderID where inventoryID = ?InventoryID", m_Realm); cmd.Parameters.AddWithValue("?ParentFolderID", newParent); - cmd.Parameters.AddWithValue("?FolderID", id); - cmd.Parameters.AddWithValue("?AgentID", principalID); + cmd.Parameters.AddWithValue("?InventoryID", id); return ExecuteNonQuery(cmd) == 0 ? false : true; } + + public XInventoryItem[] GetActiveGestures(UUID principalID) + { + MySqlCommand cmd = new MySqlCommand(); + cmd.CommandText = String.Format("select * from inventoryitems where avatarId = ?uuid and assetType = ?type and flags = 1", m_Realm); + + cmd.Parameters.AddWithValue("?uuid", principalID.ToString()); + cmd.Parameters.AddWithValue("?type", (int)AssetType.Gesture); + + return DoQuery(cmd); + } + + public int GetAssetPermissions(UUID principalID, UUID assetID) + { + MySqlCommand cmd = new MySqlCommand(); + + cmd.CommandText = String.Format("select bit_or(inventoryCurrentPermissions) as inventoryCurrentPermissions from inventoryitems where avatarID = ?PrincipalID and assetID = ?AssetID group by assetID", m_Realm); + cmd.Parameters.AddWithValue("?PrincipalID", principalID.ToString()); + cmd.Parameters.AddWithValue("?AssetID", assetID.ToString()); + + IDataReader reader = ExecuteReader(cmd); + + int perms = 0; + + if (reader.Read()) + { + perms = Convert.ToInt32(reader["inventoryCurrentPermissions"]); + } + + reader.Close(); + CloseReaderCommand(cmd); + + return perms; + } } } diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs index 1e7f206eb9..2c79c777f8 100644 --- a/OpenSim/Services/InventoryService/XInventoryService.cs +++ b/OpenSim/Services/InventoryService/XInventoryService.cs @@ -183,7 +183,10 @@ namespace OpenSim.Services.InventoryService List folders = new List(); foreach (XInventoryFolder x in allFolders) + { + m_log.DebugFormat("[INVENTORY]: Adding folder {0} to skeleton", x.folderName); folders.Add(ConvertToOpenSim(x)); + } return folders; } @@ -214,35 +217,48 @@ namespace OpenSim.Services.InventoryService public InventoryCollection GetFolderContent(UUID principalID, UUID folderID) { + // This method doesn't receive a valud principal id from the + // connector. So we disregard the principal and look + // by ID. + // + m_log.DebugFormat("[INVENTORY]: Fetch contents for folder {0}", folderID.ToString()); InventoryCollection inventory = new InventoryCollection(); inventory.UserID = principalID; inventory.Folders = new List(); inventory.Items = new List(); XInventoryFolder[] folders = m_Database.GetFolders( - new string[] { "agentID", "parentFolderID"}, - new string[] { principalID.ToString(), UUID.Zero.ToString() }); + new string[] { "parentFolderID"}, + new string[] { folderID.ToString() }); foreach (XInventoryFolder x in folders) + { + m_log.DebugFormat("[INVENTORY]: Adding folder {0} to response", x.folderName); inventory.Folders.Add(ConvertToOpenSim(x)); + } XInventoryItem[] items = m_Database.GetItems( - new string[] { "avatarID", "parentFolderID"}, - new string[] { principalID.ToString(), UUID.Zero.ToString() }); + new string[] { "parentFolderID"}, + new string[] { folderID.ToString() }); foreach (XInventoryItem i in items) + { + m_log.DebugFormat("[INVENTORY]: Adding item {0} to response", i.inventoryName); inventory.Items.Add(ConvertToOpenSim(i)); + } return inventory; } public List GetFolderItems(UUID principalID, UUID folderID) { + // Since we probably don't get a valid principal here, either ... + // List invItems = new List(); XInventoryItem[] items = m_Database.GetItems( - new string[] { "avatarID", "parentFolderID"}, - new string[] { principalID.ToString(), UUID.Zero.ToString() }); + new string[] { "parentFolderID"}, + new string[] { UUID.Zero.ToString() }); foreach (XInventoryItem i in items) invItems.Add(ConvertToOpenSim(i)); @@ -279,6 +295,8 @@ namespace OpenSim.Services.InventoryService // public bool DeleteFolders(UUID principalID, List folderIDs) { + // Ignore principal ID, it's bogus at connector level + // foreach (UUID id in folderIDs) { InventoryFolderBase f = new InventoryFolderBase(); @@ -297,7 +315,10 @@ namespace OpenSim.Services.InventoryService new string[] { folder.ID.ToString() }); foreach (XInventoryFolder x in subFolders) + { PurgeFolder(ConvertToOpenSim(x)); + m_Database.DeleteFolders("folderID", x.folderID.ToString()); + } m_Database.DeleteItems("parentFolderID", folder.ID.ToString()); @@ -316,10 +337,11 @@ namespace OpenSim.Services.InventoryService public bool MoveItems(UUID principalID, List items) { + // Principal is b0rked. *sigh* + // foreach (InventoryItemBase i in items) { - m_Database.MoveItem(principalID.ToString(), i.ID.ToString(), - i.Folder.ToString()); + m_Database.MoveItem(i.ID.ToString(), i.Folder.ToString()); } return true; @@ -327,6 +349,8 @@ namespace OpenSim.Services.InventoryService public bool DeleteItems(UUID principalID, List itemIDs) { + // Just use the ID... *facepalms* + // foreach (UUID id in itemIDs) m_Database.DeleteItems("inventoryID", id.ToString()); @@ -357,14 +381,24 @@ namespace OpenSim.Services.InventoryService return ConvertToOpenSim(folders[0]); } - public List GetActiveGestures(UUID userId) + public List GetActiveGestures(UUID principalID) { - return null; + XInventoryItem[] items = m_Database.GetActiveGestures(principalID); + + if (items.Length == 0) + return null; + + List ret = new List(); + + foreach (XInventoryItem x in items) + ret.Add(ConvertToOpenSim(x)); + + return ret; } - public int GetAssetPermissions(UUID userID, UUID assetID) + public int GetAssetPermissions(UUID principalID, UUID assetID) { - return 0; + return m_Database.GetAssetPermissions(principalID, assetID); } // CM never needed those. Left unimplemented.