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.bulletsim
parent
6dcc87b1ad
commit
bdd7849094
|
@ -74,9 +74,38 @@ namespace OpenSim.Data
|
|||
bool StoreFolder(XInventoryFolder folder);
|
||||
bool StoreItem(XInventoryItem item);
|
||||
|
||||
/// <summary>
|
||||
/// Delete folders where field == val
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="val"></param>
|
||||
/// <returns>true if the delete was successful, false if it was not</returns>
|
||||
bool DeleteFolders(string field, string val);
|
||||
|
||||
/// <summary>
|
||||
/// Delete folders where field1 == val1, field2 == val2...
|
||||
/// </summary>
|
||||
/// <param name="fields"></param>
|
||||
/// <param name="vals"></param>
|
||||
/// <returns>true if the delete was successful, false if it was not</returns>
|
||||
bool DeleteFolders(string[] fields, string[] vals);
|
||||
|
||||
/// <summary>
|
||||
/// Delete items where field == val
|
||||
/// </summary>
|
||||
/// <param name="field"></param>
|
||||
/// <param name="val"></param>
|
||||
/// <returns>true if the delete was successful, false if it was not</returns>
|
||||
bool DeleteItems(string field, string val);
|
||||
|
||||
/// <summary>
|
||||
/// Delete items where field1 == val1, field2 == val2...
|
||||
/// </summary>
|
||||
/// <param name="fields"></param>
|
||||
/// <param name="vals"></param>
|
||||
/// <returns>true if the delete was successful, false if it was not</returns>
|
||||
bool DeleteItems(string[] fields, string[] vals);
|
||||
|
||||
bool MoveItem(string id, string newParent);
|
||||
XInventoryItem[] GetActiveGestures(UUID principalID);
|
||||
int GetAssetPermissions(UUID principalID, UUID assetID);
|
||||
|
|
|
@ -335,24 +335,35 @@ namespace OpenSim.Data.MSSQL
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool Delete(string field, string val)
|
||||
public virtual bool Delete(string field, string key)
|
||||
{
|
||||
return Delete(new string[] { field }, new string[] { key });
|
||||
}
|
||||
|
||||
public virtual bool Delete(string[] fields, string[] keys)
|
||||
{
|
||||
if (fields.Length != keys.Length)
|
||||
return false;
|
||||
|
||||
List<string> terms = new List<string>();
|
||||
|
||||
using (SqlConnection conn = new SqlConnection(m_ConnectionString))
|
||||
using (SqlCommand cmd = new SqlCommand())
|
||||
{
|
||||
string deleteCommand = String.Format("DELETE FROM {0} WHERE [{1}] = @{1}", m_Realm, field);
|
||||
cmd.CommandText = deleteCommand;
|
||||
|
||||
cmd.Parameters.Add(m_database.CreateParameter(field, val));
|
||||
cmd.Connection = conn;
|
||||
conn.Open();
|
||||
|
||||
if (cmd.ExecuteNonQuery() > 0)
|
||||
for (int i = 0; i < fields.Length; i++)
|
||||
{
|
||||
//m_log.Warn("[MSSQLGenericTable]: " + deleteCommand);
|
||||
return true;
|
||||
cmd.Parameters.Add(m_database.CreateParameter(fields[i], keys[i]));
|
||||
terms.Add("[" + fields[i] + "] = @" + fields[i]);
|
||||
}
|
||||
return false;
|
||||
|
||||
string where = String.Join(" AND ", terms.ToArray());
|
||||
|
||||
string query = String.Format("DELETE * FROM {0} WHERE {1}", m_Realm, where);
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandText = query;
|
||||
conn.Open();
|
||||
return cmd.ExecuteNonQuery() > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,11 +79,21 @@ namespace OpenSim.Data.MSSQL
|
|||
return m_Folders.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteFolders(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Folders.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string field, string val)
|
||||
{
|
||||
return m_Items.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Items.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool MoveItem(string id, string newParent)
|
||||
{
|
||||
return m_Items.MoveItem(id, newParent);
|
||||
|
|
|
@ -264,18 +264,33 @@ namespace OpenSim.Data.MySQL
|
|||
}
|
||||
}
|
||||
|
||||
public virtual bool Delete(string field, string val)
|
||||
public virtual bool Delete(string field, string key)
|
||||
{
|
||||
return Delete(new string[] { field }, new string[] { key });
|
||||
}
|
||||
|
||||
public virtual bool Delete(string[] fields, string[] keys)
|
||||
{
|
||||
if (fields.Length != keys.Length)
|
||||
return false;
|
||||
|
||||
List<string> terms = new List<string>();
|
||||
|
||||
using (MySqlCommand cmd = new MySqlCommand())
|
||||
{
|
||||
for (int i = 0 ; i < fields.Length ; i++)
|
||||
{
|
||||
cmd.Parameters.AddWithValue(fields[i], keys[i]);
|
||||
terms.Add("`" + fields[i] + "` = ?" + fields[i]);
|
||||
}
|
||||
|
||||
cmd.CommandText = String.Format("delete from {0} where `{1}` = ?{1}", m_Realm, field);
|
||||
cmd.Parameters.AddWithValue(field, val);
|
||||
string where = String.Join(" and ", terms.ToArray());
|
||||
|
||||
if (ExecuteNonQuery(cmd) > 0)
|
||||
return true;
|
||||
string query = String.Format("delete from {0} where {1}", m_Realm, where);
|
||||
|
||||
return false;
|
||||
cmd.CommandText = query;
|
||||
|
||||
return ExecuteNonQuery(cmd) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -85,11 +85,21 @@ namespace OpenSim.Data.MySQL
|
|||
return m_Folders.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteFolders(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Folders.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string field, string val)
|
||||
{
|
||||
return m_Items.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Items.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool MoveItem(string id, string newParent)
|
||||
{
|
||||
return m_Items.MoveItem(id, newParent);
|
||||
|
|
|
@ -258,17 +258,33 @@ namespace OpenSim.Data.SQLite
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool Delete(string field, string val)
|
||||
public virtual bool Delete(string field, string key)
|
||||
{
|
||||
return Delete(new string[] { field }, new string[] { key });
|
||||
}
|
||||
|
||||
public bool Delete(string[] fields, string[] keys)
|
||||
{
|
||||
if (fields.Length != keys.Length)
|
||||
return false;
|
||||
|
||||
List<string> terms = new List<string>();
|
||||
|
||||
SqliteCommand cmd = new SqliteCommand();
|
||||
|
||||
cmd.CommandText = String.Format("delete from {0} where `{1}` = :{1}", m_Realm, field);
|
||||
cmd.Parameters.Add(new SqliteParameter(field, val));
|
||||
for (int i = 0 ; i < fields.Length ; i++)
|
||||
{
|
||||
cmd.Parameters.Add(new SqliteParameter(":" + fields[i], keys[i]));
|
||||
terms.Add("`" + fields[i] + "` = :" + fields[i]);
|
||||
}
|
||||
|
||||
if (ExecuteNonQuery(cmd, m_Connection) > 0)
|
||||
return true;
|
||||
string where = String.Join(" and ", terms.ToArray());
|
||||
|
||||
return false;
|
||||
string query = String.Format("delete * from {0} where {1}", m_Realm, where);
|
||||
|
||||
cmd.CommandText = query;
|
||||
|
||||
return ExecuteNonQuery(cmd, m_Connection) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,11 +91,21 @@ namespace OpenSim.Data.SQLite
|
|||
return m_Folders.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteFolders(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Folders.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string field, string val)
|
||||
{
|
||||
return m_Items.Delete(field, val);
|
||||
}
|
||||
|
||||
public bool DeleteItems(string[] fields, string[] vals)
|
||||
{
|
||||
return m_Items.Delete(fields, vals);
|
||||
}
|
||||
|
||||
public bool MoveItem(string id, string newParent)
|
||||
{
|
||||
return m_Items.MoveItem(id, newParent);
|
||||
|
|
|
@ -393,6 +393,10 @@ namespace OpenSim.Services.InventoryService
|
|||
|
||||
public virtual bool UpdateItem(InventoryItemBase item)
|
||||
{
|
||||
if (!m_AllowDelete)
|
||||
if (item.AssetType == (sbyte)AssetType.Link || item.AssetType == (sbyte)AssetType.LinkFolder)
|
||||
return false;
|
||||
|
||||
return m_Database.StoreItem(ConvertFromOpenSim(item));
|
||||
}
|
||||
|
||||
|
@ -411,12 +415,30 @@ namespace OpenSim.Services.InventoryService
|
|||
public virtual bool DeleteItems(UUID principalID, List<UUID> itemIDs)
|
||||
{
|
||||
if (!m_AllowDelete)
|
||||
return false;
|
||||
|
||||
// Just use the ID... *facepalms*
|
||||
//
|
||||
foreach (UUID id in itemIDs)
|
||||
m_Database.DeleteItems("inventoryID", id.ToString());
|
||||
{
|
||||
// We must still allow links and links to folders to be deleted, otherwise they will build up
|
||||
// in the player's inventory until they can no longer log in. Deletions of links due to code bugs or
|
||||
// similar is inconvenient but on a par with accidental movement of items. The original item is never
|
||||
// touched.
|
||||
foreach (UUID id in itemIDs)
|
||||
{
|
||||
if (!m_Database.DeleteItems(
|
||||
new string[] { "inventoryID", "assetType" },
|
||||
new string[] { id.ToString(), ((sbyte)AssetType.Link).ToString() }));
|
||||
{
|
||||
m_Database.DeleteItems(
|
||||
new string[] { "inventoryID", "assetType" },
|
||||
new string[] { id.ToString(), ((sbyte)AssetType.LinkFolder).ToString() });
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Just use the ID... *facepalms*
|
||||
//
|
||||
foreach (UUID id in itemIDs)
|
||||
m_Database.DeleteItems("inventoryID", id.ToString());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue