diff options
author | Kevin Houlihan | 2011-09-12 23:08:16 +0100 |
---|---|---|
committer | Justin Clark-Casey (justincc) | 2011-09-16 18:50:25 +0100 |
commit | 1458fab82c4dab9901d81419e6b515f47ea7320f (patch) | |
tree | 674a9ff24d27da1f5d47d77def4c92206983f376 /OpenSim/Data/MySQL/MySQLEstateData.cs | |
parent | Pass any region scope through to the CreateUser() method (diff) | |
download | opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.zip opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.gz opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.bz2 opensim-SC-1458fab82c4dab9901d81419e6b515f47ea7320f.tar.xz |
Reattaching a region was failing if the estate name had not changed (issue 5035).
Using the RemoteAdmin API to close then recreate a region would fail if the estate name had not changed. If the estate name /was/ changed then the existing estate would be renamed rather than a new one being created. The problem really arose from a lack of distinction in the data storage layer between creating new estates and loading existing ones.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Data/MySQL/MySQLEstateData.cs | 123 |
1 files changed, 79 insertions, 44 deletions
diff --git a/OpenSim/Data/MySQL/MySQLEstateData.cs b/OpenSim/Data/MySQL/MySQLEstateData.cs index 9dcf5e2..3d647ca 100644 --- a/OpenSim/Data/MySQL/MySQLEstateData.cs +++ b/OpenSim/Data/MySQL/MySQLEstateData.cs | |||
@@ -149,6 +149,22 @@ namespace OpenSim.Data.MySQL | |||
149 | } | 149 | } |
150 | } | 150 | } |
151 | 151 | ||
152 | public EstateSettings CreateNewEstate() | ||
153 | { | ||
154 | EstateSettings es = new EstateSettings(); | ||
155 | es.OnSave += StoreEstateSettings; | ||
156 | |||
157 | DoCreate(es); | ||
158 | |||
159 | LoadBanList(es); | ||
160 | |||
161 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); | ||
162 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
163 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
164 | |||
165 | return es; | ||
166 | } | ||
167 | |||
152 | private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create) | 168 | private EstateSettings DoLoad(MySqlCommand cmd, UUID regionID, bool create) |
153 | { | 169 | { |
154 | EstateSettings es = new EstateSettings(); | 170 | EstateSettings es = new EstateSettings(); |
@@ -188,63 +204,65 @@ namespace OpenSim.Data.MySQL | |||
188 | 204 | ||
189 | if (!found && create) | 205 | if (!found && create) |
190 | { | 206 | { |
191 | // Migration case | 207 | DoCreate(es); |
192 | List<string> names = new List<string>(FieldList); | 208 | LinkRegion(regionID, (int)es.EstateID); |
209 | } | ||
210 | } | ||
193 | 211 | ||
194 | names.Remove("EstateID"); | 212 | LoadBanList(es); |
195 | 213 | ||
196 | string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; | 214 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); |
215 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
216 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
217 | return es; | ||
218 | } | ||
197 | 219 | ||
198 | using (MySqlCommand cmd2 = dbcon.CreateCommand()) | 220 | private void DoCreate(EstateSettings es) |
199 | { | 221 | { |
200 | cmd2.CommandText = sql; | 222 | // Migration case |
201 | cmd2.Parameters.Clear(); | 223 | List<string> names = new List<string>(FieldList); |
202 | 224 | ||
203 | foreach (string name in FieldList) | 225 | names.Remove("EstateID"); |
204 | { | ||
205 | if (m_FieldMap[name].GetValue(es) is bool) | ||
206 | { | ||
207 | if ((bool)m_FieldMap[name].GetValue(es)) | ||
208 | cmd2.Parameters.AddWithValue("?" + name, "1"); | ||
209 | else | ||
210 | cmd2.Parameters.AddWithValue("?" + name, "0"); | ||
211 | } | ||
212 | else | ||
213 | { | ||
214 | cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); | ||
215 | } | ||
216 | } | ||
217 | 226 | ||
218 | cmd2.ExecuteNonQuery(); | 227 | string sql = "insert into estate_settings (" + String.Join(",", names.ToArray()) + ") values ( ?" + String.Join(", ?", names.ToArray()) + ")"; |
219 | 228 | ||
220 | cmd2.CommandText = "select LAST_INSERT_ID() as id"; | 229 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
221 | cmd2.Parameters.Clear(); | 230 | { |
231 | dbcon.Open(); | ||
232 | using (MySqlCommand cmd2 = dbcon.CreateCommand()) | ||
233 | { | ||
234 | cmd2.CommandText = sql; | ||
235 | cmd2.Parameters.Clear(); | ||
222 | 236 | ||
223 | using (IDataReader r = cmd2.ExecuteReader()) | 237 | foreach (string name in FieldList) |
238 | { | ||
239 | if (m_FieldMap[name].GetValue(es) is bool) | ||
240 | { | ||
241 | if ((bool)m_FieldMap[name].GetValue(es)) | ||
242 | cmd2.Parameters.AddWithValue("?" + name, "1"); | ||
243 | else | ||
244 | cmd2.Parameters.AddWithValue("?" + name, "0"); | ||
245 | } | ||
246 | else | ||
224 | { | 247 | { |
225 | r.Read(); | 248 | cmd2.Parameters.AddWithValue("?" + name, m_FieldMap[name].GetValue(es).ToString()); |
226 | es.EstateID = Convert.ToUInt32(r["id"]); | ||
227 | } | 249 | } |
250 | } | ||
228 | 251 | ||
229 | cmd2.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; | 252 | cmd2.ExecuteNonQuery(); |
230 | cmd2.Parameters.AddWithValue("?RegionID", regionID.ToString()); | ||
231 | cmd2.Parameters.AddWithValue("?EstateID", es.EstateID.ToString()); | ||
232 | 253 | ||
233 | // This will throw on dupe key | 254 | cmd2.CommandText = "select LAST_INSERT_ID() as id"; |
234 | try { cmd2.ExecuteNonQuery(); } | 255 | cmd2.Parameters.Clear(); |
235 | catch (Exception) { } | ||
236 | 256 | ||
237 | es.Save(); | 257 | using (IDataReader r = cmd2.ExecuteReader()) |
258 | { | ||
259 | r.Read(); | ||
260 | es.EstateID = Convert.ToUInt32(r["id"]); | ||
238 | } | 261 | } |
262 | |||
263 | es.Save(); | ||
239 | } | 264 | } |
240 | } | 265 | } |
241 | |||
242 | LoadBanList(es); | ||
243 | |||
244 | es.EstateManagers = LoadUUIDList(es.EstateID, "estate_managers"); | ||
245 | es.EstateAccess = LoadUUIDList(es.EstateID, "estate_users"); | ||
246 | es.EstateGroups = LoadUUIDList(es.EstateID, "estate_groups"); | ||
247 | return es; | ||
248 | } | 266 | } |
249 | 267 | ||
250 | public void StoreEstateSettings(EstateSettings es) | 268 | public void StoreEstateSettings(EstateSettings es) |
@@ -477,7 +495,6 @@ namespace OpenSim.Data.MySQL | |||
477 | } | 495 | } |
478 | } | 496 | } |
479 | 497 | ||
480 | |||
481 | dbcon.Close(); | 498 | dbcon.Close(); |
482 | } | 499 | } |
483 | 500 | ||
@@ -507,7 +524,6 @@ namespace OpenSim.Data.MySQL | |||
507 | } | 524 | } |
508 | } | 525 | } |
509 | 526 | ||
510 | |||
511 | dbcon.Close(); | 527 | dbcon.Close(); |
512 | } | 528 | } |
513 | 529 | ||
@@ -519,16 +535,34 @@ namespace OpenSim.Data.MySQL | |||
519 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) | 535 | using (MySqlConnection dbcon = new MySqlConnection(m_connectionString)) |
520 | { | 536 | { |
521 | dbcon.Open(); | 537 | dbcon.Open(); |
538 | MySqlTransaction transaction = dbcon.BeginTransaction(); | ||
522 | 539 | ||
523 | try | 540 | try |
524 | { | 541 | { |
542 | // Delete any existing association of this region with an estate. | ||
543 | using (MySqlCommand cmd = dbcon.CreateCommand()) | ||
544 | { | ||
545 | cmd.Transaction = transaction; | ||
546 | cmd.CommandText = "delete from estate_map where RegionID = ?RegionID"; | ||
547 | cmd.Parameters.AddWithValue("?RegionID", regionID); | ||
548 | |||
549 | cmd.ExecuteNonQuery(); | ||
550 | } | ||
551 | |||
525 | using (MySqlCommand cmd = dbcon.CreateCommand()) | 552 | using (MySqlCommand cmd = dbcon.CreateCommand()) |
526 | { | 553 | { |
554 | cmd.Transaction = transaction; | ||
527 | cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; | 555 | cmd.CommandText = "insert into estate_map values (?RegionID, ?EstateID)"; |
528 | cmd.Parameters.AddWithValue("?RegionID", regionID); | 556 | cmd.Parameters.AddWithValue("?RegionID", regionID); |
529 | cmd.Parameters.AddWithValue("?EstateID", estateID); | 557 | cmd.Parameters.AddWithValue("?EstateID", estateID); |
530 | 558 | ||
531 | int ret = cmd.ExecuteNonQuery(); | 559 | int ret = cmd.ExecuteNonQuery(); |
560 | |||
561 | if (ret != 0) | ||
562 | transaction.Commit(); | ||
563 | else | ||
564 | transaction.Rollback(); | ||
565 | |||
532 | dbcon.Close(); | 566 | dbcon.Close(); |
533 | 567 | ||
534 | return (ret != 0); | 568 | return (ret != 0); |
@@ -537,6 +571,7 @@ namespace OpenSim.Data.MySQL | |||
537 | catch (MySqlException ex) | 571 | catch (MySqlException ex) |
538 | { | 572 | { |
539 | m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); | 573 | m_log.Error("[REGION DB]: LinkRegion failed: " + ex.Message); |
574 | transaction.Rollback(); | ||
540 | } | 575 | } |
541 | 576 | ||
542 | dbcon.Close(); | 577 | dbcon.Close(); |