aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim
diff options
context:
space:
mode:
authorJustin Clark-Casey (justincc)2011-05-17 21:49:38 +0100
committerJustin Clark-Casey (justincc)2011-05-27 01:36:33 +0100
commit3738aff608cfd7ea0cce9e89c496d9be5fbd39f0 (patch)
tree5f72dbd5158a4051df3d9a6f26092696254b2ec9 /OpenSim
parentdon't throw a null reference if an inventory link target doesn't exist when w... (diff)
downloadopensim-SC_OLD-3738aff608cfd7ea0cce9e89c496d9be5fbd39f0.zip
opensim-SC_OLD-3738aff608cfd7ea0cce9e89c496d9be5fbd39f0.tar.gz
opensim-SC_OLD-3738aff608cfd7ea0cce9e89c496d9be5fbd39f0.tar.bz2
opensim-SC_OLD-3738aff608cfd7ea0cce9e89c496d9be5fbd39f0.tar.xz
Allow item links to be deleted even when other deletes and purges are disabled.
If these links are not deleted, then they will build up in the player's inventory until they can no longer log in. Accidental deletion of links due to bugs or other causes is potentially inconvenient but on a par with items being accidentally moved. When a link is deleted, the target of the link is never touched. This is a general solution that accounts for the use of links anywhere in the user's inventory.
Diffstat (limited to 'OpenSim')
-rw-r--r--OpenSim/Data/IXInventoryData.cs29
-rw-r--r--OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs35
-rw-r--r--OpenSim/Data/MSSQL/MSSQLXInventoryData.cs10
-rw-r--r--OpenSim/Data/MySQL/MySQLGenericTableHandler.cs27
-rw-r--r--OpenSim/Data/MySQL/MySQLXInventoryData.cs10
-rw-r--r--OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs28
-rw-r--r--OpenSim/Data/SQLite/SQLiteXInventoryData.cs10
-rw-r--r--OpenSim/Services/InventoryService/XInventoryService.cs30
8 files changed, 149 insertions, 30 deletions
diff --git a/OpenSim/Data/IXInventoryData.cs b/OpenSim/Data/IXInventoryData.cs
index d85a7ef..85a5c08 100644
--- a/OpenSim/Data/IXInventoryData.cs
+++ b/OpenSim/Data/IXInventoryData.cs
@@ -74,9 +74,38 @@ namespace OpenSim.Data
74 bool StoreFolder(XInventoryFolder folder); 74 bool StoreFolder(XInventoryFolder folder);
75 bool StoreItem(XInventoryItem item); 75 bool StoreItem(XInventoryItem item);
76 76
77 /// <summary>
78 /// Delete folders where field == val
79 /// </summary>
80 /// <param name="field"></param>
81 /// <param name="val"></param>
82 /// <returns>true if the delete was successful, false if it was not</returns>
77 bool DeleteFolders(string field, string val); 83 bool DeleteFolders(string field, string val);
84
85 /// <summary>
86 /// Delete folders where field1 == val1, field2 == val2...
87 /// </summary>
88 /// <param name="fields"></param>
89 /// <param name="vals"></param>
90 /// <returns>true if the delete was successful, false if it was not</returns>
91 bool DeleteFolders(string[] fields, string[] vals);
92
93 /// <summary>
94 /// Delete items where field == val
95 /// </summary>
96 /// <param name="field"></param>
97 /// <param name="val"></param>
98 /// <returns>true if the delete was successful, false if it was not</returns>
78 bool DeleteItems(string field, string val); 99 bool DeleteItems(string field, string val);
79 100
101 /// <summary>
102 /// Delete items where field1 == val1, field2 == val2...
103 /// </summary>
104 /// <param name="fields"></param>
105 /// <param name="vals"></param>
106 /// <returns>true if the delete was successful, false if it was not</returns>
107 bool DeleteItems(string[] fields, string[] vals);
108
80 bool MoveItem(string id, string newParent); 109 bool MoveItem(string id, string newParent);
81 XInventoryItem[] GetActiveGestures(UUID principalID); 110 XInventoryItem[] GetActiveGestures(UUID principalID);
82 int GetAssetPermissions(UUID principalID, UUID assetID); 111 int GetAssetPermissions(UUID principalID, UUID assetID);
diff --git a/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs b/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs
index f5492b3..317afac 100644
--- a/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs
+++ b/OpenSim/Data/MSSQL/MSSQLGenericTableHandler.cs
@@ -335,24 +335,35 @@ namespace OpenSim.Data.MSSQL
335 } 335 }
336 } 336 }
337 337
338 public virtual bool Delete(string field, string val) 338 public virtual bool Delete(string field, string key)
339 { 339 {
340 return Delete(new string[] { field }, new string[] { key });
341 }
342
343 public virtual bool Delete(string[] fields, string[] keys)
344 {
345 if (fields.Length != keys.Length)
346 return false;
347
348 List<string> terms = new List<string>();
349
340 using (SqlConnection conn = new SqlConnection(m_ConnectionString)) 350 using (SqlConnection conn = new SqlConnection(m_ConnectionString))
341 using (SqlCommand cmd = new SqlCommand()) 351 using (SqlCommand cmd = new SqlCommand())
342 { 352 {
343 string deleteCommand = String.Format("DELETE FROM {0} WHERE [{1}] = @{1}", m_Realm, field); 353 for (int i = 0; i < fields.Length; i++)
344 cmd.CommandText = deleteCommand;
345
346 cmd.Parameters.Add(m_database.CreateParameter(field, val));
347 cmd.Connection = conn;
348 conn.Open();
349
350 if (cmd.ExecuteNonQuery() > 0)
351 { 354 {
352 //m_log.Warn("[MSSQLGenericTable]: " + deleteCommand); 355 cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i]));
353 return true; 356 terms.Add("[" + fields[i] + "] = @" + fields[i]);
354 } 357 }
355 return false; 358
359 string where = String.Join(" AND ", terms.ToArray());
360
361 string query = String.Format("DELETE * FROM {0} WHERE {1}", m_Realm, where);
362
363 cmd.Connection = conn;
364 cmd.CommandText = query;
365 conn.Open();
366 return cmd.ExecuteNonQuery() > 0;
356 } 367 }
357 } 368 }
358 } 369 }
diff --git a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
index 5bc4fe4..01689a4 100644
--- a/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
+++ b/OpenSim/Data/MSSQL/MSSQLXInventoryData.cs
@@ -79,11 +79,21 @@ namespace OpenSim.Data.MSSQL
79 return m_Folders.Delete(field, val); 79 return m_Folders.Delete(field, val);
80 } 80 }
81 81
82 public bool DeleteFolders(string[] fields, string[] vals)
83 {
84 return m_Folders.Delete(fields, vals);
85 }
86
82 public bool DeleteItems(string field, string val) 87 public bool DeleteItems(string field, string val)
83 { 88 {
84 return m_Items.Delete(field, val); 89 return m_Items.Delete(field, val);
85 } 90 }
86 91
92 public bool DeleteItems(string[] fields, string[] vals)
93 {
94 return m_Items.Delete(fields, vals);
95 }
96
87 public bool MoveItem(string id, string newParent) 97 public bool MoveItem(string id, string newParent)
88 { 98 {
89 return m_Items.MoveItem(id, newParent); 99 return m_Items.MoveItem(id, newParent);
diff --git a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
index 50b6dbe..b5f8e64 100644
--- a/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
+++ b/OpenSim/Data/MySQL/MySQLGenericTableHandler.cs
@@ -264,18 +264,33 @@ namespace OpenSim.Data.MySQL
264 } 264 }
265 } 265 }
266 266
267 public virtual bool Delete(string field, string val) 267 public virtual bool Delete(string field, string key)
268 { 268 {
269 return Delete(new string[] { field }, new string[] { key });
270 }
271
272 public virtual bool Delete(string[] fields, string[] keys)
273 {
274 if (fields.Length != keys.Length)
275 return false;
276
277 List<string> terms = new List<string>();
278
269 using (MySqlCommand cmd = new MySqlCommand()) 279 using (MySqlCommand cmd = new MySqlCommand())
270 { 280 {
281 for (int i = 0 ; i < fields.Length ; i++)
282 {
283 cmd.Parameters.AddWithValue(fields[i], keys[i]);
284 terms.Add("`" + fields[i] + "` = ?" + fields[i]);
285 }
271 286
272 cmd.CommandText = String.Format("delete from {0} where `{1}` = ?{1}", m_Realm, field); 287 string where = String.Join(" and ", terms.ToArray());
273 cmd.Parameters.AddWithValue(field, val);
274 288
275 if (ExecuteNonQuery(cmd) > 0) 289 string query = String.Format("delete from {0} where {1}", m_Realm, where);
276 return true;
277 290
278 return false; 291 cmd.CommandText = query;
292
293 return ExecuteNonQuery(cmd) > 0;
279 } 294 }
280 } 295 }
281 } 296 }
diff --git a/OpenSim/Data/MySQL/MySQLXInventoryData.cs b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
index 287c4dd..e69f107 100644
--- a/OpenSim/Data/MySQL/MySQLXInventoryData.cs
+++ b/OpenSim/Data/MySQL/MySQLXInventoryData.cs
@@ -85,11 +85,21 @@ namespace OpenSim.Data.MySQL
85 return m_Folders.Delete(field, val); 85 return m_Folders.Delete(field, val);
86 } 86 }
87 87
88 public bool DeleteFolders(string[] fields, string[] vals)
89 {
90 return m_Folders.Delete(fields, vals);
91 }
92
88 public bool DeleteItems(string field, string val) 93 public bool DeleteItems(string field, string val)
89 { 94 {
90 return m_Items.Delete(field, val); 95 return m_Items.Delete(field, val);
91 } 96 }
92 97
98 public bool DeleteItems(string[] fields, string[] vals)
99 {
100 return m_Items.Delete(fields, vals);
101 }
102
93 public bool MoveItem(string id, string newParent) 103 public bool MoveItem(string id, string newParent)
94 { 104 {
95 return m_Items.MoveItem(id, newParent); 105 return m_Items.MoveItem(id, newParent);
diff --git a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
index 0d7b001..3fb2d3f 100644
--- a/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
+++ b/OpenSim/Data/SQLite/SQLiteGenericTableHandler.cs
@@ -258,17 +258,33 @@ namespace OpenSim.Data.SQLite
258 return false; 258 return false;
259 } 259 }
260 260
261 public bool Delete(string field, string val) 261 public virtual bool Delete(string field, string key)
262 { 262 {
263 return Delete(new string[] { field }, new string[] { key });
264 }
265
266 public bool Delete(string[] fields, string[] keys)
267 {
268 if (fields.Length != keys.Length)
269 return false;
270
271 List<string> terms = new List<string>();
272
263 SqliteCommand cmd = new SqliteCommand(); 273 SqliteCommand cmd = new SqliteCommand();
264 274
265 cmd.CommandText = String.Format("delete from {0} where `{1}` = :{1}", m_Realm, field); 275 for (int i = 0 ; i < fields.Length ; i++)
266 cmd.Parameters.Add(new SqliteParameter(field, val)); 276 {
277 cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i]));
278 terms.Add("`" + fields[i] + "` = :" + fields[i]);
279 }
280
281 string where = String.Join(" and ", terms.ToArray());
267 282
268 if (ExecuteNonQuery(cmd, m_Connection) > 0) 283 string query = String.Format("delete * from {0} where {1}", m_Realm, where);
269 return true;
270 284
271 return false; 285 cmd.CommandText = query;
286
287 return ExecuteNonQuery(cmd, m_Connection) > 0;
272 } 288 }
273 } 289 }
274} 290}
diff --git a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
index ccbd86e..02edc30 100644
--- a/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
+++ b/OpenSim/Data/SQLite/SQLiteXInventoryData.cs
@@ -91,11 +91,21 @@ namespace OpenSim.Data.SQLite
91 return m_Folders.Delete(field, val); 91 return m_Folders.Delete(field, val);
92 } 92 }
93 93
94 public bool DeleteFolders(string[] fields, string[] vals)
95 {
96 return m_Folders.Delete(fields, vals);
97 }
98
94 public bool DeleteItems(string field, string val) 99 public bool DeleteItems(string field, string val)
95 { 100 {
96 return m_Items.Delete(field, val); 101 return m_Items.Delete(field, val);
97 } 102 }
98 103
104 public bool DeleteItems(string[] fields, string[] vals)
105 {
106 return m_Items.Delete(fields, vals);
107 }
108
99 public bool MoveItem(string id, string newParent) 109 public bool MoveItem(string id, string newParent)
100 { 110 {
101 return m_Items.MoveItem(id, newParent); 111 return m_Items.MoveItem(id, newParent);
diff --git a/OpenSim/Services/InventoryService/XInventoryService.cs b/OpenSim/Services/InventoryService/XInventoryService.cs
index 0af35c8..a094a02 100644
--- a/OpenSim/Services/InventoryService/XInventoryService.cs
+++ b/OpenSim/Services/InventoryService/XInventoryService.cs
@@ -411,12 +411,30 @@ namespace OpenSim.Services.InventoryService
411 public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs) 411 public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
412 { 412 {
413 if (!m_AllowDelete) 413 if (!m_AllowDelete)
414 return false; 414 {
415 415 // We must still allow links and links to folders to be deleted, otherwise they will build up
416 // Just use the ID... *facepalms* 416 // in the player's inventory until they can no longer log in. Deletions of links due to code bugs or
417 // 417 // similar is inconvenient but on a par with accidental movement of items. The original item is never
418 foreach (UUID id in itemIDs) 418 // touched.
419 m_Database.DeleteItems("inventoryID", id.ToString()); 419 foreach (UUID id in itemIDs)
420 {
421 if (!m_Database.DeleteItems(
422 new string[] { "inventoryID", "assetType" },
423 new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }));
424 {
425 m_Database.DeleteItems(
426 new string[] { "inventoryID", "assetType" },
427 new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
428 }
429 }
430 }
431 else
432 {
433 // Just use the ID... *facepalms*
434 //
435 foreach (UUID id in itemIDs)
436 m_Database.DeleteItems("inventoryID", id.ToString());
437 }
420 438
421 return true; 439 return true;
422 } 440 }