Skip to content

Commit e1c41c3

Browse files
committed
Ensure better updating of translation count
1 parent af8f8da commit e1c41c3

3 files changed

Lines changed: 49 additions & 34 deletions

File tree

Server/Core/Repositories/LocaleRepository.cs

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,50 @@
22
using DotNetNuke.Framework;
33
using Connect.LanguagePackManager.Core.Models.Locales;
44
using System.Collections.Generic;
5+
using Connect.LanguagePackManager.Core.Data;
56

67
namespace Connect.LanguagePackManager.Core.Repositories
78
{
8-
public partial class LocaleRepository : ServiceLocator<ILocaleRepository, LocaleRepository>, ILocaleRepository
9+
public partial class LocaleRepository : ServiceLocator<ILocaleRepository, LocaleRepository>, ILocaleRepository
10+
{
11+
public Locale GetOrCreateLocale(string code)
912
{
10-
public Locale GetOrCreateLocale(string code)
13+
using (var context = DataContext.Instance())
14+
{
15+
var res = context.ExecuteSingleOrDefault<Locale>(System.Data.CommandType.Text, @"SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0;", code);
16+
if (res == null)
1117
{
12-
using (var context = DataContext.Instance())
13-
{
14-
if (code.IndexOf("-") > 0)
15-
{
16-
var genericCode = code.Substring(0, code.IndexOf("-"));
17-
var genericLocale = this.GetOrCreateLocale(genericCode);
18-
context.Execute(System.Data.CommandType.Text, @"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0)
18+
if (code.IndexOf("-") > 0)
19+
{
20+
var genericCode = code.Substring(0, code.IndexOf("-"));
21+
var genericLocale = this.GetOrCreateLocale(genericCode);
22+
context.Execute(System.Data.CommandType.Text, @"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0)
1923
INSERT INTO {databaseOwner}{objectQualifier}Connect_LPM_Locales (Code, GenericLocaleId) VALUES (@0, @1);", code, genericLocale.LocaleId);
20-
}
21-
else
22-
{
23-
context.Execute(System.Data.CommandType.Text, @"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0)
24+
}
25+
else
26+
{
27+
context.Execute(System.Data.CommandType.Text, @"IF NOT EXISTS (SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0)
2428
INSERT INTO {databaseOwner}{objectQualifier}Connect_LPM_Locales (Code) VALUES (@0);", code);
25-
}
26-
return context.ExecuteSingleOrDefault<Locale>(System.Data.CommandType.Text, @"SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0;", code);
27-
}
29+
}
30+
res = context.ExecuteSingleOrDefault<Locale>(System.Data.CommandType.Text, @"SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0;", code);
31+
Sprocs.RefreshLocaleTextCount(res.LocaleId);
2832
}
29-
public IEnumerable<Locale> GetLocaleChain(string code)
30-
{
31-
using (var context = DataContext.Instance())
32-
{
33-
return context.ExecuteQuery<Locale>(System.Data.CommandType.Text, @"SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0 OR Code=LEFT(@0,2) ORDER BY LEN(Code)", code);
34-
}
35-
}
36-
33+
return res;
34+
}
3735
}
38-
public partial interface ILocaleRepository
36+
public IEnumerable<Locale> GetLocaleChain(string code)
3937
{
40-
Locale GetOrCreateLocale(string code);
41-
IEnumerable<Locale> GetLocaleChain(string code);
38+
using (var context = DataContext.Instance())
39+
{
40+
return context.ExecuteQuery<Locale>(System.Data.CommandType.Text, @"SELECT * FROM {databaseOwner}{objectQualifier}Connect_LPM_Locales WHERE Code=@0 OR Code=LEFT(@0,2) ORDER BY LEN(Code)", code);
41+
}
4242
}
43+
44+
}
45+
public partial interface ILocaleRepository
46+
{
47+
Locale GetOrCreateLocale(string code);
48+
IEnumerable<Locale> GetLocaleChain(string code);
49+
}
4350
}
4451

Server/Core/Services/Packages/LanguagePackManifest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,15 @@ public LanguagePackManifest(UnzipResult unzipResult, int moduleId)
4141

4242
public void Process(bool generic, int userId)
4343
{
44+
var handledLocaleIds = new List<int>();
4445
foreach (var p in this.Components)
4546
{
4647
var locale = generic ? p.Locale.Substring(0, 2) : p.Locale;
4748
var localeId = LocaleRepository.Instance.GetOrCreateLocale(locale).LocaleId;
49+
if (!handledLocaleIds.Contains(localeId))
50+
{
51+
handledLocaleIds.Add(localeId);
52+
}
4853
var dbResFiles = ResourceFileRepository.Instance.GetResourceFilesByPackage(p.Package.PackageId);
4954
foreach (var rf in p.ResourceFiles)
5055
{
@@ -63,6 +68,16 @@ public void Process(bool generic, int userId)
6368
}
6469
}
6570
}
71+
foreach (var loc in LocaleRepository.Instance.GetLocales())
72+
{
73+
foreach (var localeId in handledLocaleIds)
74+
{
75+
if (loc.LocaleId == localeId || loc.GenericLocaleId == localeId)
76+
{
77+
Sprocs.RefreshLocaleTextCount(loc.LocaleId);
78+
}
79+
}
80+
}
6681
}
6782

6883
private void LoadPackV5FromUploadedZipFile(UnzipResult unzipResult)

Server/LanguagePackManager/Api/PacksController.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,6 @@ public HttpResponseMessage TextStats(int id, string locale)
6060
var nrTexts = PackageVersionLocaleTextCountRepository.Instance.GetPackageVersionLocaleTextCounts(loc.LocaleId)
6161
.Where(t => t.PackageId == id)
6262
.ToList();
63-
if (nrTexts.Count == 0)
64-
{
65-
Core.Data.Sprocs.RefreshLocaleTextCount(loc.LocaleId);
66-
nrTexts = PackageVersionLocaleTextCountRepository.Instance.GetPackageVersionLocaleTextCounts(loc.LocaleId)
67-
.Where(t => t.PackageId == id)
68-
.ToList();
69-
}
7063
return Request.CreateResponse(HttpStatusCode.OK, nrTexts);
7164
}
7265
}

0 commit comments

Comments
 (0)