Remove code duplicated from PR #7957
This commit is contained in:
@@ -197,7 +197,6 @@ namespace Umbraco.Core.Migrations.Upgrade
|
||||
|
||||
// to 8.7.0...
|
||||
To<StackedContentToBlockList>("{DFA35FA2-BFBB-433F-84E5-BD75940CDDF6}");
|
||||
To<ColorPickerPreValues>("{711AC937-B11C-47AC-8D4A-5B8868A3C2C6}");
|
||||
To<ConvertToElements>("{DA434576-3DEF-46D7-942A-CE34D7F7FB8A}");
|
||||
//FINAL
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0
|
||||
{
|
||||
public class ColorPickerPreValues : MigrationBase
|
||||
{
|
||||
private static readonly Regex OldPreValuesPattern1 = new Regex("\\s*{(\\s*\"[0-9]+\"\\s*:\\s*\"[0-9a-fA-F]+\"\\s*,)*\\s*\"useLabel\"\\s*:\\s*\"[01]\"\\s*}\\s*", RegexOptions.Compiled);
|
||||
private static readonly Regex OldPreValuesPattern2 = new Regex("\\s*{(\\s*\"[0-9]+\"\\s*:\\s*{\\s*\"value\"\\s*:\\s*\"[0-9a-fA-F]+\"\\s*(,\\s*\"label\"\\s*:\\s*\"[^\"]*\"\\s*)?(,\\s*\"sortOrder\"\\s*:\\s*[0-9]+\\s*)?}\\s*,)*\\s*\"useLabel\"\\s*:\\s*\"[01]\"\\s*}\\s*", RegexOptions.Compiled);
|
||||
|
||||
public ColorPickerPreValues(IMigrationContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public override void Migrate()
|
||||
{
|
||||
var sql = Sql()
|
||||
.Select<DataTypeDto>()
|
||||
.From<DataTypeDto>()
|
||||
.Where<DataTypeDto>(d => d.EditorAlias == Constants.PropertyEditors.Aliases.ColorPicker);
|
||||
|
||||
var dtos = Database.Fetch<DataTypeDto>(sql);
|
||||
|
||||
foreach (var dto in dtos)
|
||||
{
|
||||
if (dto.Configuration.IsNullOrWhiteSpace()) continue;
|
||||
|
||||
if (OldPreValuesPattern1.IsMatch(dto.Configuration)) ConvertPreValues(dto, ConvertStyle1);
|
||||
else if (OldPreValuesPattern2.IsMatch(dto.Configuration)) ConvertPreValues(dto, ConvertStyle2);
|
||||
else continue;
|
||||
|
||||
Database.Update(dto);
|
||||
}
|
||||
}
|
||||
|
||||
private void ConvertPreValues(DataTypeDto dto, Func<int, JToken, ItemValue> converter)
|
||||
{
|
||||
var obj = JObject.Parse(dto.Configuration);
|
||||
var config = new ColorPickerConfiguration();
|
||||
var id = 0;
|
||||
|
||||
foreach (var prop in obj.Properties())
|
||||
{
|
||||
if (prop.Name.ToLowerInvariant() == "uselabel")
|
||||
{
|
||||
config.UseLabel = prop.Value.ToString() == "1";
|
||||
}
|
||||
else
|
||||
{
|
||||
id++;
|
||||
config.Items.Add(new ValueListConfiguration.ValueListItem
|
||||
{
|
||||
Id = id,
|
||||
Value = JsonConvert.SerializeObject(converter(id, prop.Value))
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
dto.Configuration = JsonConvert.SerializeObject(config);
|
||||
}
|
||||
|
||||
private ItemValue ConvertStyle1(int index, JToken token)
|
||||
{
|
||||
var value = token.ToString();
|
||||
return new ItemValue
|
||||
{
|
||||
Color = value,
|
||||
Label = value,
|
||||
SortOrder = index
|
||||
};
|
||||
}
|
||||
|
||||
private ItemValue ConvertStyle2(int index, JToken token)
|
||||
{
|
||||
var obj = (JObject)token;
|
||||
var value = obj["value"].ToString();
|
||||
var label = obj["label"]?.ToString();
|
||||
var order = obj["sortOrder"]?.ToString();
|
||||
|
||||
return new ItemValue
|
||||
{
|
||||
Color = value,
|
||||
Label = label.IsNullOrWhiteSpace() ? value : label,
|
||||
SortOrder = int.TryParse(order, out var o) ? o : index
|
||||
};
|
||||
}
|
||||
|
||||
private class ItemValue
|
||||
{
|
||||
[JsonProperty("value")]
|
||||
public string Color { get; set; }
|
||||
|
||||
[JsonProperty("label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
[JsonProperty("sortOrder")]
|
||||
public int SortOrder { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
|
||||
@@ -24,7 +21,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0
|
||||
docTypes.ForEach(d => docTypeMap[d.Alias] = d.NodeId);
|
||||
|
||||
// Find all Nested Content or Block List data types
|
||||
var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.NestedContent, Constants.PropertyEditors.Aliases.BlockList);
|
||||
var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.BlockList);
|
||||
|
||||
// Find all document types listed in each
|
||||
var elementTypeIds = dataTypes.SelectMany(d => GetDocTypeIds(d.Configuration, docTypeMap)).ToList();
|
||||
@@ -63,12 +60,7 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0
|
||||
if (configuration.IsNullOrWhiteSpace() || configuration[0] != '{') return Enumerable.Empty<int>();
|
||||
|
||||
var obj = JObject.Parse(configuration);
|
||||
if (obj["contentTypes"] is JArray ncArr)
|
||||
{
|
||||
var arr = ncArr.ToObject<ContentType[]>();
|
||||
return arr.Select(i => idMap.TryGetValue(i.Alias, out var id) ? id : 0).Where(i => i != 0);
|
||||
}
|
||||
else if (obj["blocks"] is JArray blArr)
|
||||
if (obj["blocks"] is JArray blArr)
|
||||
{
|
||||
var arr = blArr.ToObject<BlockConfiguration[]>();
|
||||
return arr.Select(i => idMap.TryGetValue(i.Alias, out var id) ? id : 0).Where(i => i != 0);
|
||||
@@ -77,12 +69,6 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_7_0
|
||||
return Enumerable.Empty<int>();
|
||||
}
|
||||
|
||||
public class ContentType
|
||||
{
|
||||
[JsonProperty("ncAlias")]
|
||||
public string Alias { get; set; }
|
||||
}
|
||||
|
||||
public class BlockConfiguration
|
||||
{
|
||||
[JsonProperty("contentTypeAlias")]
|
||||
|
||||
@@ -131,7 +131,6 @@
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\ContentTypeDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyDataDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyTypeDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_7_0\ColorPickerPreValues.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_7_0\ConvertToElements.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_7_0\StackedContentToBlockList.cs" />
|
||||
<Compile Include="Models\Blocks\IBlockEditorDataHelper.cs" />
|
||||
|
||||
Reference in New Issue
Block a user