* Refactor RemoveItem()

0.6.0-stable
Justin Clarke Casey 2008-05-03 23:23:46 +00:00
parent 688940e810
commit 56827894e9
4 changed files with 72 additions and 29 deletions

View File

@ -35,7 +35,8 @@ using log4net;
namespace OpenSim.Framework.Communications.Cache
{
//internal delegate void DeleteItemDelegate(
internal delegate void DeleteItemDelegate(LLUUID itemID);
internal delegate void CreateFolderDelegate(string folderName, LLUUID folderID, ushort folderType, LLUUID parentID);
internal delegate void MoveFolderDelegate(LLUUID folderID, LLUUID parentID);
internal delegate void PurgeFolderDelegate(LLUUID folderID);
@ -306,7 +307,10 @@ namespace OpenSim.Framework.Communications.Cache
}
/// <summary>
/// Create a folder in this agent's inventory
/// Create a folder in this agent's inventory.
///
/// If the inventory service has not yet delievered the inventory
/// for this user then the request will be queued.
/// </summary>
/// <param name="parentID"></param>
/// <returns></returns>
@ -399,10 +403,14 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary>
/// Handle a client request to update the inventory folder
///
/// If the inventory service has not yet delievered the inventory
/// for this user then the request will be queued.
///
/// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE
/// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing,
/// and needs to be changed.
/// </summary>
///
/// <param name="folderID"></param>
/// <param name="type"></param>
/// <param name="name"></param>
@ -437,7 +445,11 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary>
/// Handle an inventory folder move request from the client.
///
/// If the inventory service has not yet delievered the inventory
/// for this user then the request will be queued.
/// </summary>
///
/// <param name="folderID"></param>
/// <param name="parentID"></param>
public bool MoveFolder(LLUUID folderID, LLUUID parentID)
@ -470,7 +482,11 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary>
/// This method will delete all the items and folders in the given folder.
///
/// If the inventory service has not yet delievered the inventory
/// for this user then the request will be queued.
/// </summary>
///
/// <param name="folderID"></param>
public bool PurgeFolder(LLUUID folderID)
{
@ -540,23 +556,46 @@ namespace OpenSim.Framework.Communications.Cache
/// <summary>
/// Delete an item from the user's inventory
///
/// If the inventory service has not yet delievered the inventory
/// for this user then the request will be queued.
/// </summary>
/// <param name="userID"></param>
/// <param name="item"></param>
/// <returns></returns>
public bool DeleteItem(InventoryItemBase item)
/// <param name="itemID"></param>
/// <returns>
/// true on a successful delete or a if the request is queued.
/// Returns false on an immediate failure
/// </returns>
public bool DeleteItem(LLUUID itemID)
{
bool result = false;
if (HasInventory)
{
result = RootFolder.DeleteItem(item.ID);
if (result)
// XXX For historical reasons (grid comms), we need to retrieve the whole item in order to delete, even though
// really only the item id is required.
InventoryItemBase item = RootFolder.FindItem(itemID);
if (null == item)
{
m_commsManager.InventoryService.DeleteItem(item);
}
m_log.WarnFormat("[AGENT INVENTORY]: Tried to delete item {0} which does not exist", itemID);
return false;
}
return result;
if (RootFolder.DeleteItem(item.ID))
{
return m_commsManager.InventoryService.DeleteItem(item);
}
}
else
{
AddRequest(
new InventoryRequest(
Delegate.CreateDelegate(typeof(DeleteItemDelegate), this, "DeleteItem"),
new object[] { itemID }));
return true;
}
return false;
}
}

View File

@ -163,6 +163,7 @@ namespace OpenSim.Framework.Communications.Cache
}
}
}
return found;
}

View File

@ -62,7 +62,7 @@ namespace OpenSim.Grid.InventoryServer
m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID);
// uncomment me to simulate an overloaded inventory server
//Thread.Sleep(18000);
Thread.Sleep(18000);
InventoryCollection invCollection = new InventoryCollection();

View File

@ -467,6 +467,14 @@ namespace OpenSim.Region.Environment.Scenes
return asset;
}
/// <summary>
/// Move an item within the agent's inventory.
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="folderID"></param>
/// <param name="itemID"></param>
/// <param name="length"></param>
/// <param name="newName"></param>
public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length,
string newName)
{
@ -474,6 +482,7 @@ namespace OpenSim.Region.Environment.Scenes
"[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId);
CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId);
if (userInfo == null)
{
m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
@ -491,7 +500,8 @@ namespace OpenSim.Region.Environment.Scenes
item.Name = newName;
}
item.Folder = folderID;
userInfo.DeleteItem(item);
userInfo.DeleteItem(item.ID);
// TODO: preserve current permissions?
AddInventoryItem(remoteClient, item);
@ -616,6 +626,11 @@ namespace OpenSim.Region.Environment.Scenes
}
}
/// <summary>
/// Remove an inventory item for the client's inventory
/// </summary>
/// <param name="remoteClient"></param>
/// <param name="itemID"></param>
private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID)
{
CachedUserInfo userInfo
@ -623,26 +638,14 @@ namespace OpenSim.Region.Environment.Scenes
if (userInfo == null)
{
m_log.ErrorFormat(
"[AGENT INVENTORY]: Failed to find user {0} {1} to remove inventory item {2}",
m_log.WarnFormat(
"[AGENT INVENTORY]: Failed to find user {0} {1} to delete inventory item {2}",
remoteClient.Name, remoteClient.AgentId, itemID);
return;
}
// is going through the root folder really the best way?
// this triggers a tree walk to find and remove the item. 8-(
// since this only happens in Trash (in theory) shouldn't we grab
// the trash folder directly instead of RootFolder?
if (userInfo.RootFolder != null)
{
InventoryItemBase item = userInfo.RootFolder.FindItem(itemID);
if (item != null)
{
userInfo.DeleteItem(item);
}
}
userInfo.DeleteItem(itemID);
}
/// <summary>
@ -658,7 +661,7 @@ namespace OpenSim.Region.Environment.Scenes
if (userInfo == null)
{
m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
m_log.Warn("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString());
return;
}