diff options
author | Justin Clarke Casey | 2008-05-03 23:23:46 +0000 |
---|---|---|
committer | Justin Clarke Casey | 2008-05-03 23:23:46 +0000 |
commit | 56827894e9fca8d15b84a1f897b24e88c8ab9c29 (patch) | |
tree | dfbd1fc9609a9835e5565bdf6ef89d685d92f9f5 | |
parent | * Refactor: Renaming item and folder tree search methods to have Find*() pref... (diff) | |
download | opensim-SC_OLD-56827894e9fca8d15b84a1f897b24e88c8ab9c29.zip opensim-SC_OLD-56827894e9fca8d15b84a1f897b24e88c8ab9c29.tar.gz opensim-SC_OLD-56827894e9fca8d15b84a1f897b24e88c8ab9c29.tar.bz2 opensim-SC_OLD-56827894e9fca8d15b84a1f897b24e88c8ab9c29.tar.xz |
* Refactor RemoveItem()
4 files changed, 72 insertions, 29 deletions
diff --git a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs index 6a7b6b7..84e42a3 100644 --- a/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs +++ b/OpenSim/Framework/Communications/Cache/CachedUserInfo.cs | |||
@@ -35,7 +35,8 @@ using log4net; | |||
35 | 35 | ||
36 | namespace OpenSim.Framework.Communications.Cache | 36 | namespace OpenSim.Framework.Communications.Cache |
37 | { | 37 | { |
38 | //internal delegate void DeleteItemDelegate( | 38 | internal delegate void DeleteItemDelegate(LLUUID itemID); |
39 | |||
39 | internal delegate void CreateFolderDelegate(string folderName, LLUUID folderID, ushort folderType, LLUUID parentID); | 40 | internal delegate void CreateFolderDelegate(string folderName, LLUUID folderID, ushort folderType, LLUUID parentID); |
40 | internal delegate void MoveFolderDelegate(LLUUID folderID, LLUUID parentID); | 41 | internal delegate void MoveFolderDelegate(LLUUID folderID, LLUUID parentID); |
41 | internal delegate void PurgeFolderDelegate(LLUUID folderID); | 42 | internal delegate void PurgeFolderDelegate(LLUUID folderID); |
@@ -306,7 +307,10 @@ namespace OpenSim.Framework.Communications.Cache | |||
306 | } | 307 | } |
307 | 308 | ||
308 | /// <summary> | 309 | /// <summary> |
309 | /// Create a folder in this agent's inventory | 310 | /// Create a folder in this agent's inventory. |
311 | /// | ||
312 | /// If the inventory service has not yet delievered the inventory | ||
313 | /// for this user then the request will be queued. | ||
310 | /// </summary> | 314 | /// </summary> |
311 | /// <param name="parentID"></param> | 315 | /// <param name="parentID"></param> |
312 | /// <returns></returns> | 316 | /// <returns></returns> |
@@ -399,10 +403,14 @@ namespace OpenSim.Framework.Communications.Cache | |||
399 | /// <summary> | 403 | /// <summary> |
400 | /// Handle a client request to update the inventory folder | 404 | /// Handle a client request to update the inventory folder |
401 | /// | 405 | /// |
406 | /// If the inventory service has not yet delievered the inventory | ||
407 | /// for this user then the request will be queued. | ||
408 | /// | ||
402 | /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE | 409 | /// FIXME: We call add new inventory folder because in the data layer, we happen to use an SQL REPLACE |
403 | /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing, | 410 | /// so this will work to rename an existing folder. Needless to say, to rely on this is very confusing, |
404 | /// and needs to be changed. | 411 | /// and needs to be changed. |
405 | /// </summary> | 412 | /// </summary> |
413 | /// | ||
406 | /// <param name="folderID"></param> | 414 | /// <param name="folderID"></param> |
407 | /// <param name="type"></param> | 415 | /// <param name="type"></param> |
408 | /// <param name="name"></param> | 416 | /// <param name="name"></param> |
@@ -437,7 +445,11 @@ namespace OpenSim.Framework.Communications.Cache | |||
437 | 445 | ||
438 | /// <summary> | 446 | /// <summary> |
439 | /// Handle an inventory folder move request from the client. | 447 | /// Handle an inventory folder move request from the client. |
448 | /// | ||
449 | /// If the inventory service has not yet delievered the inventory | ||
450 | /// for this user then the request will be queued. | ||
440 | /// </summary> | 451 | /// </summary> |
452 | /// | ||
441 | /// <param name="folderID"></param> | 453 | /// <param name="folderID"></param> |
442 | /// <param name="parentID"></param> | 454 | /// <param name="parentID"></param> |
443 | public bool MoveFolder(LLUUID folderID, LLUUID parentID) | 455 | public bool MoveFolder(LLUUID folderID, LLUUID parentID) |
@@ -470,7 +482,11 @@ namespace OpenSim.Framework.Communications.Cache | |||
470 | 482 | ||
471 | /// <summary> | 483 | /// <summary> |
472 | /// This method will delete all the items and folders in the given folder. | 484 | /// This method will delete all the items and folders in the given folder. |
485 | /// | ||
486 | /// If the inventory service has not yet delievered the inventory | ||
487 | /// for this user then the request will be queued. | ||
473 | /// </summary> | 488 | /// </summary> |
489 | /// | ||
474 | /// <param name="folderID"></param> | 490 | /// <param name="folderID"></param> |
475 | public bool PurgeFolder(LLUUID folderID) | 491 | public bool PurgeFolder(LLUUID folderID) |
476 | { | 492 | { |
@@ -540,23 +556,46 @@ namespace OpenSim.Framework.Communications.Cache | |||
540 | 556 | ||
541 | /// <summary> | 557 | /// <summary> |
542 | /// Delete an item from the user's inventory | 558 | /// Delete an item from the user's inventory |
559 | /// | ||
560 | /// If the inventory service has not yet delievered the inventory | ||
561 | /// for this user then the request will be queued. | ||
543 | /// </summary> | 562 | /// </summary> |
544 | /// <param name="userID"></param> | 563 | /// <param name="itemID"></param> |
545 | /// <param name="item"></param> | 564 | /// <returns> |
546 | /// <returns></returns> | 565 | /// true on a successful delete or a if the request is queued. |
547 | public bool DeleteItem(InventoryItemBase item) | 566 | /// Returns false on an immediate failure |
567 | /// </returns> | ||
568 | public bool DeleteItem(LLUUID itemID) | ||
548 | { | 569 | { |
549 | bool result = false; | ||
550 | if (HasInventory) | 570 | if (HasInventory) |
551 | { | 571 | { |
552 | result = RootFolder.DeleteItem(item.ID); | 572 | // XXX For historical reasons (grid comms), we need to retrieve the whole item in order to delete, even though |
553 | if (result) | 573 | // really only the item id is required. |
574 | InventoryItemBase item = RootFolder.FindItem(itemID); | ||
575 | |||
576 | if (null == item) | ||
554 | { | 577 | { |
555 | m_commsManager.InventoryService.DeleteItem(item); | 578 | m_log.WarnFormat("[AGENT INVENTORY]: Tried to delete item {0} which does not exist", itemID); |
579 | |||
580 | return false; | ||
581 | } | ||
582 | |||
583 | if (RootFolder.DeleteItem(item.ID)) | ||
584 | { | ||
585 | return m_commsManager.InventoryService.DeleteItem(item); | ||
556 | } | 586 | } |
557 | } | 587 | } |
588 | else | ||
589 | { | ||
590 | AddRequest( | ||
591 | new InventoryRequest( | ||
592 | Delegate.CreateDelegate(typeof(DeleteItemDelegate), this, "DeleteItem"), | ||
593 | new object[] { itemID })); | ||
594 | |||
595 | return true; | ||
596 | } | ||
558 | 597 | ||
559 | return result; | 598 | return false; |
560 | } | 599 | } |
561 | } | 600 | } |
562 | 601 | ||
diff --git a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs index 39296eb..af05af3 100644 --- a/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs +++ b/OpenSim/Framework/Communications/Cache/InventoryFolderImpl.cs | |||
@@ -163,6 +163,7 @@ namespace OpenSim.Framework.Communications.Cache | |||
163 | } | 163 | } |
164 | } | 164 | } |
165 | } | 165 | } |
166 | |||
166 | return found; | 167 | return found; |
167 | } | 168 | } |
168 | 169 | ||
diff --git a/OpenSim/Grid/InventoryServer/GridInventoryService.cs b/OpenSim/Grid/InventoryServer/GridInventoryService.cs index 4864185..5c1902f 100644 --- a/OpenSim/Grid/InventoryServer/GridInventoryService.cs +++ b/OpenSim/Grid/InventoryServer/GridInventoryService.cs | |||
@@ -62,7 +62,7 @@ namespace OpenSim.Grid.InventoryServer | |||
62 | m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID); | 62 | m_log.InfoFormat("[GRID AGENT INVENTORY]: Processing request for inventory of {0}", userID); |
63 | 63 | ||
64 | // uncomment me to simulate an overloaded inventory server | 64 | // uncomment me to simulate an overloaded inventory server |
65 | //Thread.Sleep(18000); | 65 | Thread.Sleep(18000); |
66 | 66 | ||
67 | InventoryCollection invCollection = new InventoryCollection(); | 67 | InventoryCollection invCollection = new InventoryCollection(); |
68 | 68 | ||
diff --git a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs index 7cce216..490457d 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.Inventory.cs | |||
@@ -467,6 +467,14 @@ namespace OpenSim.Region.Environment.Scenes | |||
467 | return asset; | 467 | return asset; |
468 | } | 468 | } |
469 | 469 | ||
470 | /// <summary> | ||
471 | /// Move an item within the agent's inventory. | ||
472 | /// </summary> | ||
473 | /// <param name="remoteClient"></param> | ||
474 | /// <param name="folderID"></param> | ||
475 | /// <param name="itemID"></param> | ||
476 | /// <param name="length"></param> | ||
477 | /// <param name="newName"></param> | ||
470 | public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length, | 478 | public void MoveInventoryItem(IClientAPI remoteClient, LLUUID folderID, LLUUID itemID, int length, |
471 | string newName) | 479 | string newName) |
472 | { | 480 | { |
@@ -474,6 +482,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
474 | "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId); | 482 | "[AGENT INVENTORY]: Moving item {0} to {1} for {2}", itemID, folderID, remoteClient.AgentId); |
475 | 483 | ||
476 | CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); | 484 | CachedUserInfo userInfo = CommsManager.UserProfileCacheService.GetUserDetails(remoteClient.AgentId); |
485 | |||
477 | if (userInfo == null) | 486 | if (userInfo == null) |
478 | { | 487 | { |
479 | m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString()); | 488 | m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString()); |
@@ -491,7 +500,8 @@ namespace OpenSim.Region.Environment.Scenes | |||
491 | item.Name = newName; | 500 | item.Name = newName; |
492 | } | 501 | } |
493 | item.Folder = folderID; | 502 | item.Folder = folderID; |
494 | userInfo.DeleteItem(item); | 503 | |
504 | userInfo.DeleteItem(item.ID); | ||
495 | 505 | ||
496 | // TODO: preserve current permissions? | 506 | // TODO: preserve current permissions? |
497 | AddInventoryItem(remoteClient, item); | 507 | AddInventoryItem(remoteClient, item); |
@@ -616,6 +626,11 @@ namespace OpenSim.Region.Environment.Scenes | |||
616 | } | 626 | } |
617 | } | 627 | } |
618 | 628 | ||
629 | /// <summary> | ||
630 | /// Remove an inventory item for the client's inventory | ||
631 | /// </summary> | ||
632 | /// <param name="remoteClient"></param> | ||
633 | /// <param name="itemID"></param> | ||
619 | private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID) | 634 | private void RemoveInventoryItem(IClientAPI remoteClient, LLUUID itemID) |
620 | { | 635 | { |
621 | CachedUserInfo userInfo | 636 | CachedUserInfo userInfo |
@@ -623,26 +638,14 @@ namespace OpenSim.Region.Environment.Scenes | |||
623 | 638 | ||
624 | if (userInfo == null) | 639 | if (userInfo == null) |
625 | { | 640 | { |
626 | m_log.ErrorFormat( | 641 | m_log.WarnFormat( |
627 | "[AGENT INVENTORY]: Failed to find user {0} {1} to remove inventory item {2}", | 642 | "[AGENT INVENTORY]: Failed to find user {0} {1} to delete inventory item {2}", |
628 | remoteClient.Name, remoteClient.AgentId, itemID); | 643 | remoteClient.Name, remoteClient.AgentId, itemID); |
629 | 644 | ||
630 | return; | 645 | return; |
631 | } | 646 | } |
632 | 647 | ||
633 | // is going through the root folder really the best way? | 648 | userInfo.DeleteItem(itemID); |
634 | // this triggers a tree walk to find and remove the item. 8-( | ||
635 | // since this only happens in Trash (in theory) shouldn't we grab | ||
636 | // the trash folder directly instead of RootFolder? | ||
637 | if (userInfo.RootFolder != null) | ||
638 | { | ||
639 | InventoryItemBase item = userInfo.RootFolder.FindItem(itemID); | ||
640 | |||
641 | if (item != null) | ||
642 | { | ||
643 | userInfo.DeleteItem(item); | ||
644 | } | ||
645 | } | ||
646 | } | 649 | } |
647 | 650 | ||
648 | /// <summary> | 651 | /// <summary> |
@@ -658,7 +661,7 @@ namespace OpenSim.Region.Environment.Scenes | |||
658 | 661 | ||
659 | if (userInfo == null) | 662 | if (userInfo == null) |
660 | { | 663 | { |
661 | m_log.Error("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString()); | 664 | m_log.Warn("[AGENT INVENTORY]: Failed to find user " + remoteClient.AgentId.ToString()); |
662 | return; | 665 | return; |
663 | } | 666 | } |
664 | 667 | ||