Skip to content

Commit aceadc1

Browse files
committed
Fixed formatting and comment warnings/errors
1 parent 9a80328 commit aceadc1

File tree

2 files changed

+97
-92
lines changed

2 files changed

+97
-92
lines changed

src/Umbraco.Infrastructure/Migrations/Upgrade/V_15_0_0/ConvertBlockEditorPropertiesBase.cs

Lines changed: 96 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ protected override void Migrate()
6868
}
6969

7070
using UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();
71-
var languagesById = _languageService.GetAllAsync().GetAwaiter().GetResult().ToDictionary(language => language.Id);
71+
var languagesById = _languageService.GetAllAsync().GetAwaiter().GetResult()
72+
.ToDictionary(language => language.Id);
7273
IContentType[] allContentTypes = _contentTypeService.GetAll().ToArray();
7374
var allPropertyTypesByEditor = allContentTypes
7475
.SelectMany(ct => ct.PropertyTypes)
@@ -83,14 +84,17 @@ protected override void Migrate()
8384
continue;
8485
}
8586

86-
_logger.LogInformation("Migration starting for all properties of type: {propertyEditorAlias}", propertyEditorAlias);
87+
_logger.LogInformation("Migration starting for all properties of type: {propertyEditorAlias}",
88+
propertyEditorAlias);
8789
if (Handle(propertyTypes, languagesById))
8890
{
89-
_logger.LogInformation("Migration succeeded for all properties of type: {propertyEditorAlias}", propertyEditorAlias);
91+
_logger.LogInformation("Migration succeeded for all properties of type: {propertyEditorAlias}",
92+
propertyEditorAlias);
9093
}
9194
else
9295
{
93-
_logger.LogError("Migration failed for one or more properties of type: {propertyEditorAlias}", propertyEditorAlias);
96+
_logger.LogError("Migration failed for one or more properties of type: {propertyEditorAlias}",
97+
propertyEditorAlias);
9498
}
9599
}
96100
}
@@ -111,7 +115,7 @@ private bool Handle(IPropertyType[] propertyTypes, IDictionary<int, ILanguage> l
111115
{
112116
_logger.LogInformation(
113117
"- starting property type {propertyTypeIndex}/{propertyTypeCount} : {propertyTypeName} (id: {propertyTypeId}, alias: {propertyTypeAlias})...",
114-
propertyTypeIndex+1,
118+
propertyTypeIndex + 1,
115119
propertyTypeCount,
116120
propertyType.Name, propertyType.Id, propertyType.Alias);
117121
IDataType dataType = _dataTypeService.GetAsync(propertyType.DataTypeKey).GetAwaiter().GetResult()
@@ -146,116 +150,116 @@ private bool Handle(IPropertyType[] propertyTypes, IDictionary<int, ILanguage> l
146150

147151
Parallel.ForEachAsync(updateBatch, async (update, token) =>
148152
{
149-
//Foreach here, but we need to suppress the flow before each task, but not the actuall await of the task
153+
//Foreach here, but we need to suppress the flow before each task, but not the actual await of the task
150154
Task task;
151155
using (ExecutionContext.SuppressFlow())
152156
{
153157
task = Task.Run(() =>
154158
{
155-
using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
156-
scope.Complete();
157-
using UmbracoContextReference umbracoContextReference =
158-
_umbracoContextFactory.EnsureUmbracoContext();
159+
using ICoreScope scope = _coreScopeProvider.CreateCoreScope();
160+
scope.Complete();
161+
using UmbracoContextReference umbracoContextReference =
162+
_umbracoContextFactory.EnsureUmbracoContext();
159163

160-
progress++;
161-
if (progress % 100 == 0)
162-
{
163-
_logger.LogInformation(" - finíshed {progress} of {total} properties", progress,
164-
updateBatch.Count);
165-
}
164+
progress++;
165+
if (progress % 100 == 0)
166+
{
167+
_logger.LogInformation(" - finíshed {progress} of {total} properties", progress,
168+
updateBatch.Count);
169+
}
166170

167-
PropertyDataDto propertyDataDto = update.Poco;
171+
PropertyDataDto propertyDataDto = update.Poco;
168172

169-
// NOTE: some old property data DTOs can have variance defined, even if the property type no longer varies
170-
var culture = propertyType.VariesByCulture()
171-
&& propertyDataDto.LanguageId.HasValue
172-
&& languagesById.TryGetValue(propertyDataDto.LanguageId.Value,
173-
out ILanguage? language)
174-
? language.IsoCode
175-
: null;
173+
// NOTE: some old property data DTOs can have variance defined, even if the property type no longer varies
174+
var culture = propertyType.VariesByCulture()
175+
&& propertyDataDto.LanguageId.HasValue
176+
&& languagesById.TryGetValue(propertyDataDto.LanguageId.Value,
177+
out ILanguage? language)
178+
? language.IsoCode
179+
: null;
176180

177-
if (culture is null && propertyType.VariesByCulture())
178-
{
179-
// if we end up here, the property DTO is bound to a language that no longer exists. this is an error scenario,
180-
// and we can't really handle it in any other way than logging; in all likelihood this is an old property version,
181-
// and it won't cause any runtime issues
182-
_logger.LogWarning(
183-
" - property data with id: {propertyDataId} references a language that does not exist - language id: {languageId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
184-
propertyDataDto.Id,
185-
propertyDataDto.LanguageId,
186-
propertyType.Name,
187-
propertyType.Id,
188-
propertyType.Alias);
189-
return;
190-
}
181+
if (culture is null && propertyType.VariesByCulture())
182+
{
183+
// if we end up here, the property DTO is bound to a language that no longer exists. this is an error scenario,
184+
// and we can't really handle it in any other way than logging; in all likelihood this is an old property version,
185+
// and it won't cause any runtime issues
186+
_logger.LogWarning(
187+
" - property data with id: {propertyDataId} references a language that does not exist - language id: {languageId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
188+
propertyDataDto.Id,
189+
propertyDataDto.LanguageId,
190+
propertyType.Name,
191+
propertyType.Id,
192+
propertyType.Alias);
193+
return;
194+
}
191195

192-
var segment = propertyType.VariesBySegment() ? propertyDataDto.Segment : null;
193-
var property = new Property(propertyType);
194-
property.SetValue(propertyDataDto.Value, culture, segment);
195-
var toEditorValue = valueEditor.ToEditor(property, culture, segment);
196-
switch (toEditorValue)
197-
{
198-
case null:
199-
_logger.LogWarning(
200-
" - value editor yielded a null value for property data with id: {propertyDataId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
201-
propertyDataDto.Id,
202-
propertyType.Name,
203-
propertyType.Id,
204-
propertyType.Alias);
205-
updatesToSkip.Add(update);
206-
return;
207-
208-
case string str when str.IsNullOrWhiteSpace():
209-
// indicates either an empty block editor or corrupt block editor data - we can't do anything about either here
210-
updatesToSkip.Add(update);
211-
return;
212-
213-
default:
214-
switch (DetermineEditorValueHandling(toEditorValue))
196+
var segment = propertyType.VariesBySegment() ? propertyDataDto.Segment : null;
197+
var property = new Property(propertyType);
198+
property.SetValue(propertyDataDto.Value, culture, segment);
199+
var toEditorValue = valueEditor.ToEditor(property, culture, segment);
200+
switch (toEditorValue)
215201
{
216-
case EditorValueHandling.IgnoreConversion:
217-
// nothing to convert, continue
218-
updatesToSkip.Add(update);
219-
return;
220-
case EditorValueHandling.ProceedConversion:
221-
// continue the conversion
222-
break;
223-
case EditorValueHandling.HandleAsError:
224-
_logger.LogError(
225-
" - value editor did not yield a valid ToEditor value for property data with id: {propertyDataId} - the value type was {valueType} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
202+
case null:
203+
_logger.LogWarning(
204+
" - value editor yielded a null value for property data with id: {propertyDataId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
226205
propertyDataDto.Id,
227-
toEditorValue.GetType(),
228206
propertyType.Name,
229207
propertyType.Id,
230208
propertyType.Alias);
231209
updatesToSkip.Add(update);
232210
return;
211+
212+
case string str when str.IsNullOrWhiteSpace():
213+
// indicates either an empty block editor or corrupt block editor data - we can't do anything about either here
214+
updatesToSkip.Add(update);
215+
return;
216+
233217
default:
234-
throw new ArgumentOutOfRangeException();
235-
}
218+
switch (DetermineEditorValueHandling(toEditorValue))
219+
{
220+
case EditorValueHandling.IgnoreConversion:
221+
// nothing to convert, continue
222+
updatesToSkip.Add(update);
223+
return;
224+
case EditorValueHandling.ProceedConversion:
225+
// continue the conversion
226+
break;
227+
case EditorValueHandling.HandleAsError:
228+
_logger.LogError(
229+
" - value editor did not yield a valid ToEditor value for property data with id: {propertyDataId} - the value type was {valueType} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
230+
propertyDataDto.Id,
231+
toEditorValue.GetType(),
232+
propertyType.Name,
233+
propertyType.Id,
234+
propertyType.Alias);
235+
updatesToSkip.Add(update);
236+
return;
237+
default:
238+
throw new ArgumentOutOfRangeException();
239+
}
236240

237-
break;
238-
}
241+
break;
242+
}
239243

240-
toEditorValue = UpdateEditorValue(toEditorValue);
244+
toEditorValue = UpdateEditorValue(toEditorValue);
241245

242-
var editorValue = _jsonSerializer.Serialize(toEditorValue);
243-
var dbValue = valueEditor.FromEditor(new ContentPropertyData(editorValue, null), null);
244-
if (dbValue is not string stringValue || stringValue.DetectIsJson() is false)
245-
{
246-
_logger.LogError(
247-
" - value editor did not yield a valid JSON string as FromEditor value property data with id: {propertyDataId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
248-
propertyDataDto.Id,
249-
propertyType.Name,
250-
propertyType.Id,
251-
propertyType.Alias);
252-
updatesToSkip.Add(update);
253-
return;
254-
}
246+
var editorValue = _jsonSerializer.Serialize(toEditorValue);
247+
var dbValue = valueEditor.FromEditor(new ContentPropertyData(editorValue, null), null);
248+
if (dbValue is not string stringValue || stringValue.DetectIsJson() is false)
249+
{
250+
_logger.LogError(
251+
" - value editor did not yield a valid JSON string as FromEditor value property data with id: {propertyDataId} (property type: {propertyTypeName}, id: {propertyTypeId}, alias: {propertyTypeAlias})",
252+
propertyDataDto.Id,
253+
propertyType.Name,
254+
propertyType.Id,
255+
propertyType.Alias);
256+
updatesToSkip.Add(update);
257+
return;
258+
}
255259

256-
stringValue = UpdateDatabaseValue(stringValue);
260+
stringValue = UpdateDatabaseValue(stringValue);
257261

258-
propertyDataDto.TextValue = stringValue;
262+
propertyDataDto.TextValue = stringValue;
259263
}, token);
260264
}
261265

src/Umbraco.Infrastructure/PropertyEditors/BlockValuePropertyIndexValueFactoryBase.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ protected override IEnumerable<IndexValue> HandleResume(
173173
/// Gets a resume as string of all the content in this nested type.
174174
/// </summary>
175175
/// <param name="indexedContent">All the indexed content for this property.</param>
176+
/// <param name="culture">The culture to get the resume for.</param>
176177
/// <returns>the string with all relevant content from </returns>
177178
private static string GetResumeFromAllContent(List<IndexValue> indexedContent, string? culture)
178179
{

0 commit comments

Comments
 (0)