Skip to content

Commit 7eca8a7

Browse files
committed
Updated install language resource files to reflect the most current migration head
1 parent 239eb0f commit 7eca8a7

7 files changed

Lines changed: 923 additions & 378 deletions

File tree

src/Libraries/SmartStore.Data/ObjectContextBase.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,6 @@ public bool HooksEnabled
138138

139139
#region IDbContext members
140140

141-
protected override void Dispose(bool disposing)
142-
{
143-
this.EventPublisher = null;
144-
base.Dispose(disposing);
145-
}
146-
147141
public virtual string CreateDatabaseScript()
148142
{
149143
return ((IObjectContextAdapter)this).ObjectContext.CreateDatabaseScript();

src/Libraries/SmartStore.Data/Setup/MigratorUtils.cs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Data.Entity.Migrations;
4+
using System.IO;
45
using System.Linq;
56
using System.Text;
67
using System.Text.RegularExpressions;
78
using System.Threading.Tasks;
9+
using SmartStore.Data.Migrations;
810

911
namespace SmartStore.Data.Setup
1012
{
@@ -101,5 +103,72 @@ private static TType CreateTypeInstance<TType>(string typeName) where TType : cl
101103
return newType as TType;
102104
}
103105

106+
107+
public static void ExecutePendingResourceMigrations(string resPath, SmartObjectContext dbContext)
108+
{
109+
Guard.ArgumentNotNull(() => dbContext);
110+
111+
string headPath = Path.Combine(resPath, "head.txt");
112+
if (!File.Exists(headPath))
113+
return;
114+
115+
string resHead = File.ReadAllText(headPath);
116+
if (!MigratorUtils.IsValidMigrationId(resHead))
117+
return;
118+
119+
var migrator = new DbMigrator(new MigrationsConfiguration());
120+
var migrations = GetPendingResourceMigrations(migrator, resHead);
121+
122+
foreach (var id in migrations)
123+
{
124+
if (IsAutomaticMigration(id))
125+
continue;
126+
127+
if (!IsValidMigrationId(id))
128+
continue;
129+
130+
// Resolve and instantiate the DbMigration instance from the assembly
131+
var migration = CreateMigrationInstanceByMigrationId(id, migrator.Configuration);
132+
133+
var provider = migration as ILocaleResourcesProvider;
134+
if (provider == null)
135+
continue;
136+
137+
var builder = new LocaleResourcesBuilder();
138+
provider.MigrateLocaleResources(builder);
139+
140+
var resEntries = builder.Build();
141+
var resMigrator = new LocaleResourcesMigrator(dbContext);
142+
resMigrator.Migrate(resEntries);
143+
}
144+
}
145+
146+
private static IEnumerable<string> GetPendingResourceMigrations(DbMigrator migrator, string resHead)
147+
{
148+
var local = migrator.GetLocalMigrations();
149+
var atHead = false;
150+
151+
if (local.Last().IsCaseInsensitiveEqual(resHead))
152+
yield break;
153+
154+
foreach (var id in local)
155+
{
156+
if (!atHead)
157+
{
158+
if (!id.IsCaseInsensitiveEqual(resHead))
159+
{
160+
continue;
161+
}
162+
else
163+
{
164+
atHead = true;
165+
continue;
166+
}
167+
}
168+
169+
yield return id;
170+
}
171+
}
172+
104173
}
105174
}

0 commit comments

Comments
 (0)