Skip to content

Commit 76ab09b

Browse files
committed
Fixes remaining tests
1 parent d6f4736 commit 76ab09b

File tree

6 files changed

+69
-22
lines changed

6 files changed

+69
-22
lines changed

src/Umbraco.Tests/UmbracoExamine/IndexTest.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,15 @@ public void Index_Reindex_Content()
142142
{
143143
var s = (IndexSearcher)_searcher.GetSearcher();
144144

145+
146+
145147
//first delete all 'Content' (not media). This is done by directly manipulating the index with the Lucene API, not examine!
146-
var r = IndexReader.Open(s.GetIndexReader().Directory(), false);
148+
147149
var contentTerm = new Term(LuceneIndexer.IndexTypeFieldName, IndexTypes.Content);
148-
var delCount = r.DeleteDocuments(contentTerm);
149-
r.Commit();
150-
r.Close();
150+
var writer = _indexer.GetIndexWriter();
151+
writer.DeleteDocuments(contentTerm);
152+
writer.Commit();
153+
151154

152155
//make sure the content is gone. This is done with lucene APIs, not examine!
153156
var collector = new AllHitsCollector(false, true);

src/Umbraco.Web/PublishedCache/XmlPublishedCache/PublishedMediaCache.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,24 @@ private BaseSearchProvider GetSearchProviderSafe()
145145
var eMgr = GetExamineManagerSafe();
146146
if (eMgr != null)
147147
{
148-
try
149-
{
150-
//by default use the InternalSearcher
151-
return eMgr.SearchProviderCollection["InternalSearcher"];
152-
}
153-
catch (FileNotFoundException)
154-
{
155-
//Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco
156-
//See this thread: http://examine.cdodeplex.com/discussions/264341
157-
//Catch the exception here for the time being, and just fallback to GetMedia
158-
//TODO: Need to fix examine in LB scenarios!
159-
}
148+
try
149+
{
150+
//by default use the InternalSearcher
151+
return eMgr.SearchProviderCollection["InternalSearcher"];
152+
}
153+
catch (FileNotFoundException)
154+
{
155+
//Currently examine is throwing FileNotFound exceptions when we have a loadbalanced filestore and a node is published in umbraco
156+
//See this thread: http://examine.cdodeplex.com/discussions/264341
157+
//Catch the exception here for the time being, and just fallback to GetMedia
158+
//TODO: Need to fix examine in LB scenarios!
159+
}
160+
catch (NullReferenceException)
161+
{
162+
//This will occur when the search provider cannot be initialized. In newer examine versions the initialization is lazy and therefore
163+
// the manager will return the singleton without throwing initialization errors, however if examine isn't configured correctly a null
164+
// reference error will occur because the examine settings are null.
165+
}
160166
}
161167
return null;
162168
}

src/UmbracoExamine/BaseUmbracoIndexer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,9 @@ protected override IndexWriter CreateIndexWriter()
202202
//if temp local storage is configured use that, otherwise return the default
203203
if (_localTempStorageHelper.LuceneDirectory != null)
204204
{
205-
return new IndexWriter(GetLuceneDirectory(), IndexingAnalyzer,
206-
DeletePolicyTracker.Current.GetPolicy(IndexSetName),
205+
var directory = GetLuceneDirectory();
206+
return new IndexWriter(directory, IndexingAnalyzer,
207+
DeletePolicyTracker.Current.GetPolicy(directory),
207208
IndexWriter.MaxFieldLength.UNLIMITED);
208209
}
209210

src/UmbracoExamine/DeletePolicyTracker.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ public static DeletePolicyTracker Current
1414
get { return Instance; }
1515
}
1616

17-
public IndexDeletionPolicy GetPolicy(string indexSetName)
17+
public IndexDeletionPolicy GetPolicy(Lucene.Net.Store.Directory directory)
1818
{
19-
var resolved = _directories.GetOrAdd(indexSetName, s => new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()));
19+
var resolved = _directories.GetOrAdd(directory.GetLockID(), s => new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy()));
2020
return resolved;
2121
}
2222
}

src/UmbracoExamine/UmbracoExamineSearcher.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,10 @@ protected internal override string[] GetSearchFields()
170170

171171
protected override IndexReader OpenNewReader()
172172
{
173+
var directory = GetLuceneDirectory();
173174
return IndexReader.Open(
174-
GetLuceneDirectory(),
175-
DeletePolicyTracker.Current.GetPolicy(IndexSetName),
175+
directory,
176+
DeletePolicyTracker.Current.GetPolicy(directory),
176177
true);
177178
}
178179

src/umbraco.businesslogic/ui.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class ui
3838
[Obsolete("Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext")]
3939
public static string Culture(User u)
4040
{
41+
if (ApplicationContext.Current == null) return string.Empty;
42+
4143
var found = UserExtensions.GetUserCulture(u.Language, ApplicationContext.Current.Services.TextService);
4244
return found == null ? string.Empty : found.Name;
4345
}
@@ -46,6 +48,8 @@ public static string Culture(User u)
4648
[Obsolete("Get the current culture/language from the currently logged in IUser, the IUser object is available on most Umbraco base classes and on the UmbracoContext")]
4749
internal static string Culture(IUser u)
4850
{
51+
if (ApplicationContext.Current == null) return string.Empty;
52+
4953
var found = u.GetUserCulture(ApplicationContext.Current.Services.TextService);
5054
return found == null ? string.Empty : found.Name;
5155
}
@@ -94,11 +98,15 @@ private static string GetLanguage(string userLanguage)
9498
/// <returns></returns>
9599
public static string Text(string Key, User u)
96100
{
101+
if (ApplicationContext.Current == null) return "[" + Key + "]";
102+
97103
return ApplicationContext.Current.Services.TextService.Localize(Key, GetCultureFromUserLanguage(GetLanguage(u)));
98104
}
99105

100106
internal static string Text(string key, IUser u)
101107
{
108+
if (ApplicationContext.Current == null) return "[" + key + "]";
109+
102110
return ApplicationContext.Current.Services.TextService.Localize(key, GetCultureFromUserLanguage(GetLanguage(u)));
103111
}
104112

@@ -109,6 +117,8 @@ internal static string Text(string key, IUser u)
109117
/// <returns></returns>
110118
public static string Text(string Key)
111119
{
120+
if (ApplicationContext.Current == null) return "[" + Key + "]";
121+
112122
return ApplicationContext.Current.Services.TextService.Localize(Key, GetCultureFromUserLanguage(GetLanguage()));
113123
}
114124

@@ -121,13 +131,17 @@ public static string Text(string Key)
121131
/// <returns></returns>
122132
public static string Text(string Area, string Key, User u)
123133
{
134+
if (ApplicationContext.Current == null) return "[" + Key + "]";
135+
124136
return ApplicationContext.Current.Services.TextService.Localize(
125137
string.Format("{0}/{1}", Area, Key),
126138
GetCultureFromUserLanguage(GetLanguage(u)));
127139
}
128140

129141
public static string Text(string area, string key, IUser u)
130142
{
143+
if (ApplicationContext.Current == null) return "[" + key + "]";
144+
131145
return ApplicationContext.Current.Services.TextService.Localize(
132146
string.Format("{0}/{1}", area, key),
133147
GetCultureFromUserLanguage(GetLanguage(u)));
@@ -141,6 +155,8 @@ public static string Text(string area, string key, IUser u)
141155
/// <returns></returns>
142156
public static string Text(string Area, string Key)
143157
{
158+
if (ApplicationContext.Current == null) return "[" + Key + "]";
159+
144160
return ApplicationContext.Current.Services.TextService.Localize(
145161
string.Format("{0}/{1}", Area, Key),
146162
GetCultureFromUserLanguage(GetLanguage()));
@@ -156,6 +172,8 @@ public static string Text(string Area, string Key)
156172
/// <returns></returns>
157173
public static string Text(string Area, string Key, string[] Variables, User u)
158174
{
175+
if (ApplicationContext.Current == null) return "[" + Key + "]";
176+
159177
return ApplicationContext.Current.Services.TextService.Localize(
160178
string.Format("{0}/{1}", Area, Key),
161179
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -164,6 +182,8 @@ public static string Text(string Area, string Key, string[] Variables, User u)
164182

165183
internal static string Text(string area, string key, string[] variables)
166184
{
185+
if (ApplicationContext.Current == null) return "[" + key + "]";
186+
167187
return ApplicationContext.Current.Services.TextService.Localize(
168188
string.Format("{0}/{1}", area, key),
169189
GetCultureFromUserLanguage(GetLanguage()),
@@ -172,6 +192,8 @@ internal static string Text(string area, string key, string[] variables)
172192

173193
internal static string Text(string area, string key, string[] variables, IUser u)
174194
{
195+
if (ApplicationContext.Current == null) return "[" + key + "]";
196+
175197
return ApplicationContext.Current.Services.TextService.Localize(
176198
string.Format("{0}/{1}", area, key),
177199
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -188,6 +210,8 @@ internal static string Text(string area, string key, string[] variables, IUser u
188210
/// <returns></returns>
189211
public static string Text(string Area, string Key, string Variable, User u)
190212
{
213+
if (ApplicationContext.Current == null) return "[" + Key + "]";
214+
191215
return ApplicationContext.Current.Services.TextService.Localize(
192216
string.Format("{0}/{1}", Area, Key),
193217
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -196,6 +220,8 @@ public static string Text(string Area, string Key, string Variable, User u)
196220

197221
internal static string Text(string area, string key, string variable)
198222
{
223+
if (ApplicationContext.Current == null) return "[" + key + "]";
224+
199225
return ApplicationContext.Current.Services.TextService.Localize(
200226
string.Format("{0}/{1}", area, key),
201227
GetCultureFromUserLanguage(GetLanguage()),
@@ -204,6 +230,8 @@ internal static string Text(string area, string key, string variable)
204230

205231
internal static string Text(string area, string key, string variable, IUser u)
206232
{
233+
if (ApplicationContext.Current == null) return "[" + key + "]";
234+
207235
return ApplicationContext.Current.Services.TextService.Localize(
208236
string.Format("{0}/{1}", area, key),
209237
GetCultureFromUserLanguage(GetLanguage(u)),
@@ -228,6 +256,8 @@ public static string GetText(string key)
228256
/// <returns></returns>
229257
public static string GetText(string area, string key)
230258
{
259+
if (ApplicationContext.Current == null) return "[" + key + "]";
260+
231261
return ApplicationContext.Current.Services.TextService.Localize(
232262
string.Format("{0}/{1}", area, key),
233263
GetCultureFromUserLanguage(GetLanguage()));
@@ -242,6 +272,8 @@ public static string GetText(string area, string key)
242272
/// <returns></returns>
243273
public static string GetText(string area, string key, string[] variables)
244274
{
275+
if (ApplicationContext.Current == null) return "[" + key + "]";
276+
245277
return ApplicationContext.Current.Services.TextService.Localize(
246278
string.Format("{0}/{1}", area, key),
247279
GetCultureFromUserLanguage(GetLanguage()),
@@ -257,6 +289,8 @@ public static string GetText(string area, string key, string[] variables)
257289
/// <returns></returns>
258290
public static string GetText(string area, string key, string variable)
259291
{
292+
if (ApplicationContext.Current == null) return "[" + key + "]";
293+
260294
return ApplicationContext.Current.Services.TextService.Localize(
261295
string.Format("{0}/{1}", area, key),
262296
GetCultureFromUserLanguage(GetLanguage()),
@@ -274,6 +308,8 @@ public static string GetText(string area, string key, string variable)
274308
/// <remarks>This is the underlying call for all Text/GetText method calls</remarks>
275309
public static string GetText(string area, string key, string[] variables, string language)
276310
{
311+
if (ApplicationContext.Current == null) return "[" + key + "]";
312+
277313
return ApplicationContext.Current.Services.TextService.Localize(
278314
string.Format("{0}/{1}", area, key),
279315
GetCultureFromUserLanguage(GetLanguage()),

0 commit comments

Comments
 (0)