mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-23 21:32:14 +08:00
[Fixes #5733] Update default Layout state settings
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using Orchard.ContentManagement.MetaData;
|
||||
using Orchard.Core.Contents.Extensions;
|
||||
using Orchard.Data;
|
||||
using Orchard.Data.Migration;
|
||||
|
||||
namespace Orchard.DynamicForms {
|
||||
public class Migrations : DataMigrationImpl {
|
||||
private readonly byte[] _oldLayoutHash = new byte[] { 0x91, 0x10, 0x3b, 0x97, 0xce, 0x1e, 0x1e, 0xc7, 0x7a, 0x41, 0xf7, 0x82, 0xe8, 0x58, 0x85, 0x91 };
|
||||
|
||||
private const string DefaultFormLayoutData =
|
||||
@"{
|
||||
""elements"": [
|
||||
@@ -59,7 +64,52 @@ namespace Orchard.DynamicForms {
|
||||
.WithSetting("LayoutTypePartSettings.DefaultLayoutData", DefaultFormLayoutData))
|
||||
.WithSetting("Stereotype", "Widget")
|
||||
.DisplayedAs("Form Widget"));
|
||||
return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
public int UpdateFrom1() {
|
||||
// if the default layout data was unchanged, fix it with the new default
|
||||
|
||||
var formLayoutPart = ContentDefinitionManager
|
||||
.GetTypeDefinition("Form")
|
||||
.Parts
|
||||
.FirstOrDefault(x => x.PartDefinition.Name == "LayoutPart");
|
||||
|
||||
if (formLayoutPart != null &&
|
||||
formLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"] != null) {
|
||||
var layout = formLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"];
|
||||
|
||||
if(GetMD5(layout) == _oldLayoutHash) {
|
||||
ContentDefinitionManager.AlterTypeDefinition("Form", type => type
|
||||
.WithPart("LayoutPart", p => p
|
||||
.WithSetting("LayoutTypePartSettings.DefaultLayoutData", DefaultFormLayoutData))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
var formWidgetLayoutPart = ContentDefinitionManager
|
||||
.GetTypeDefinition("FormWidget")
|
||||
.Parts
|
||||
.FirstOrDefault(x => x.PartDefinition.Name == "LayoutPart");
|
||||
|
||||
if (formWidgetLayoutPart != null &&
|
||||
formWidgetLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"] != null) {
|
||||
var layout = formWidgetLayoutPart.Settings["LayoutTypePartSettings.DefaultLayoutData"];
|
||||
|
||||
if (GetMD5(layout) == _oldLayoutHash) {
|
||||
ContentDefinitionManager.AlterTypeDefinition("FormWidget", type => type
|
||||
.WithPart("LayoutPart", p => p
|
||||
.WithSetting("LayoutTypePartSettings.DefaultLayoutData", DefaultFormLayoutData))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
private byte[] GetMD5(string text) {
|
||||
byte[] encodedText = System.Text.Encoding.UTF8.GetBytes(text);
|
||||
return ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(encodedText);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user