| 5 |
using System.Reflection; |
using System.Reflection; |
| 6 |
using OpenSim.Data; |
using OpenSim.Data; |
| 7 |
using log4net; |
using log4net; |
| 8 |
|
using ModularRex.RexFramework; |
| 9 |
|
using OpenMetaverse; |
| 10 |
|
using ModularRex.NHibernate; |
| 11 |
|
|
| 12 |
namespace ModularRex.Tools.MigrationTool |
namespace ModularRex.Tools.MigrationTool |
| 13 |
{ |
{ |
| 16 |
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); |
| 17 |
|
|
| 18 |
protected string m_connectionString = String.Empty; |
protected string m_connectionString = String.Empty; |
| 19 |
|
protected string m_rexConnectionString = String.Empty; |
| 20 |
|
|
| 21 |
private const string addAuthbyerID = "ALTER TABLE land ADD COLUMN AuthbuyerID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000'"; |
private const string addAuthbyerID = "ALTER TABLE land ADD COLUMN AuthbuyerID varchar(36) NOT NULL default '00000000-0000-0000-0000-000000000000'"; |
| 22 |
|
|
| 23 |
public RegionMigration(string connectionString) |
public RegionMigration(string connectionString, string rexConnectionString) |
| 24 |
{ |
{ |
| 25 |
// default to something sensible |
// default to something sensible |
| 26 |
if (connectionString == "") |
if (connectionString == "") |
| 31 |
{ |
{ |
| 32 |
m_connectionString = connectionString; |
m_connectionString = connectionString; |
| 33 |
} |
} |
| 34 |
|
|
| 35 |
|
if (rexConnectionString == String.Empty) |
| 36 |
|
{ |
| 37 |
|
m_rexConnectionString = "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3"; |
| 38 |
|
} |
| 39 |
|
else |
| 40 |
|
{ |
| 41 |
|
m_rexConnectionString = rexConnectionString; |
| 42 |
|
} |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
public bool Convert() |
public bool Convert() |
| 54 |
|
|
| 55 |
int version = m.Version; |
int version = m.Version; |
| 56 |
|
|
| 57 |
if (version <= 9) |
if (version <= 14) |
| 58 |
{ |
{ |
| 59 |
if (version == 0) |
if (version == 0) |
| 60 |
{ |
{ |
| 61 |
|
//read rex tables and add to rex database |
| 62 |
|
m_log.info("[regionstore] converting rex tables to rexobjectproperties"); |
| 63 |
|
if (!convertlegacyrexdatatomodrex()) |
| 64 |
|
{ |
| 65 |
|
conn.close(); |
| 66 |
|
return false; |
| 67 |
|
} |
| 68 |
|
|
| 69 |
|
m_log.Info("[RegionStore] Update region migrations"); |
| 70 |
//Add new field to Land table |
//Add new field to Land table |
| 71 |
SqliteCommand addAuthbyerIDCmd = new SqliteCommand(addAuthbyerID, conn); |
SqliteCommand addAuthbyerIDCmd = new SqliteCommand(addAuthbyerID, conn); |
| 72 |
addAuthbyerIDCmd.ExecuteNonQuery(); |
addAuthbyerIDCmd.ExecuteNonQuery(); |
| 76 |
} |
} |
| 77 |
|
|
| 78 |
//Run migrations up to 9 |
//Run migrations up to 9 |
| 79 |
|
//Note: this run migrations only to point nine since only those files exist in application resources. |
| 80 |
m.Update(); |
m.Update(); |
| 81 |
|
|
| 82 |
//Skip over 10. Change version to 10 |
//Skip over 10. Change version to 10 |
| 83 |
//This skips adding of the ClickAction since that already exists in 0.4 database |
//This skips adding of the ClickAction since that already exists in 0.4 database |
| 84 |
m.Version = 10; |
//m.Version = 10; |
| 85 |
} |
} |
| 86 |
|
|
| 87 |
conn.Close(); |
conn.Close(); |
| 93 |
return false; |
return false; |
| 94 |
} |
} |
| 95 |
} |
} |
| 96 |
|
|
| 97 |
|
protected bool ConvertLegacyRexDataToModreX() |
| 98 |
|
{ |
| 99 |
|
NHibernateRexLegacyData legacydata = new NHibernateRexLegacyData(); |
| 100 |
|
|
| 101 |
|
//convert connnection string to NHibernate style |
| 102 |
|
//parse string like this: "URI=file:OpenSim.db,version=3" |
| 103 |
|
//and convert it to like this: "SQLiteDialect;SQLite20Driver;Data Source=RexObjects.db;Version=3" |
| 104 |
|
string arg1 = String.Empty; |
| 105 |
|
string arg2 = String.Empty; |
| 106 |
|
|
| 107 |
|
string[] components = m_connectionString.Split(','); |
| 108 |
|
if (components[0].StartsWith("URI=file:")) |
| 109 |
|
{ |
| 110 |
|
arg1 = components[0].Substring(9); |
| 111 |
|
} |
| 112 |
|
else |
| 113 |
|
{ |
| 114 |
|
m_log.ErrorFormat("[MODREXOBJECTS]: Error parseing connection string {0}", m_connectionString); |
| 115 |
|
return false; |
| 116 |
|
} |
| 117 |
|
if (components[1].StartsWith("version=")) |
| 118 |
|
{ |
| 119 |
|
arg2 = components[1].Substring(8); |
| 120 |
|
} |
| 121 |
|
else |
| 122 |
|
{ |
| 123 |
|
m_log.ErrorFormat("[MODREXOBJECTS]: Error parseing connection string {0}", m_connectionString); |
| 124 |
|
return false; |
| 125 |
|
} |
| 126 |
|
|
| 127 |
|
StringBuilder sb = new StringBuilder(); |
| 128 |
|
sb.AppendFormat("SQLiteDialect;SQLite20Driver;Data Source={0};Version={1}", arg1, arg2); |
| 129 |
|
|
| 130 |
|
legacydata.Initialise(sb.ToString()); |
| 131 |
|
if (!legacydata.Inizialized) |
| 132 |
|
{ |
| 133 |
|
m_log.Info("[MODREXOBJECTS]: Legacy database failed to initialize."); |
| 134 |
|
return false; |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
List<RexLegacyPrimData> rexprimdata = legacydata.LoadAllRexPrimData(); |
| 138 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimdata objects loaded:" + rexprimdata.Count.ToString()); |
| 139 |
|
|
| 140 |
|
List<RexLegacyPrimMaterialData> rexprimmaterialdata = legacydata.LoadAllRexPrimMaterialData(); |
| 141 |
|
m_log.Info("[MODREXOBJECTS]: Legacy rexprimmaterialdata objects loaded:" + rexprimmaterialdata.Count.ToString()); |
| 142 |
|
|
| 143 |
|
Dictionary<UUID, RexObjectProperties> rexObjects = new Dictionary<UUID, RexObjectProperties>(); |
| 144 |
|
|
| 145 |
|
foreach (RexLegacyPrimData prim in rexprimdata) |
| 146 |
|
{ |
| 147 |
|
RexObjectProperties p = new RexObjectProperties(); |
| 148 |
|
p.SetRexPrimDataFromLegacyData(prim); |
| 149 |
|
rexObjects.Add(prim.UUID, p); |
| 150 |
|
} |
| 151 |
|
|
| 152 |
|
foreach (RexLegacyPrimMaterialData primmat in rexprimmaterialdata) |
| 153 |
|
{ |
| 154 |
|
if (rexObjects.ContainsKey(primmat.UUID) && rexObjects[primmat.UUID] != null) |
| 155 |
|
{ |
| 156 |
|
rexObjects[primmat.UUID].RexMaterials.AddMaterial((uint)primmat.MaterialIndex, primmat.MaterialUUID); |
| 157 |
|
} |
| 158 |
|
else |
| 159 |
|
{ |
| 160 |
|
m_log.WarnFormat("[MODREXOBJECTS]: Could not find RexObjectData for prim {0} while adding materials. Creating", primmat.UUID); |
| 161 |
|
RexObjectProperties p = new RexObjectProperties(); |
| 162 |
|
p.ParentObjectID = primmat.UUID; |
| 163 |
|
p.RexMaterials.AddMaterial((uint)primmat.MaterialIndex, primmat.MaterialUUID); |
| 164 |
|
rexObjects.Add(primmat.UUID, p); |
| 165 |
|
} |
| 166 |
|
} |
| 167 |
|
|
| 168 |
|
//Add rex object to database |
| 169 |
|
NHibernateRexObjectData rexObjectManager = new NHibernateRexObjectData(); |
| 170 |
|
rexObjectManager.Initialise(m_rexConnectionString); |
| 171 |
|
foreach (KeyValuePair<UUID, RexObjectProperties> data in rexObjects) |
| 172 |
|
{ |
| 173 |
|
rexObjectManager.StoreObject(data.Value); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
|
return true; |
| 177 |
|
} |
| 178 |
} |
} |
| 179 |
} |
} |