Fixing: U4-6942 During upgrade MUST make sure that the new Property Type GUIDs are consistent ... just needs some testing now;

This commit is contained in:
Shannon
2015-08-11 15:56:48 +02:00
parent cfb84cae44
commit 9e6a2d8a7c
2 changed files with 31 additions and 1 deletions

View File

@@ -30,9 +30,26 @@ namespace Umbraco.Core.Persistence.Migrations.Upgrades.TargetVersionSevenThreeZe
.NonClustered()
.WithOptions()
.Unique();
//now we need to fill in the data so that it is consistent, we can't have it generating random GUIDs for
// the already existing data, see: http://issues.umbraco.org/issue/U4-6942
foreach (var data in Context.Database.Query<dynamic>(@"
SELECT cmsPropertyType.id ptId, cmsPropertyType.Alias ptAlias, cmsContentType.alias ctAlias
FROM cmsPropertyType
INNER JOIN cmsContentType
ON cmsPropertyType.contentTypeId = cmsContentType.nodeId"))
{
//create a guid from the concatenation of the property type alias + the doc type alias
string concatAlias = data.ptAlias + data.ctAlias;
var ptGuid = concatAlias.ToGuid();
//set the Unique Id to the one we've generated
Update.Table("cmsPropertyType").Set(new {uniqueID = ptGuid}).Where(new {id = data.ptId });
}
}
}
public override void Down()

View File

@@ -1409,5 +1409,18 @@ namespace Umbraco.Core
{
return string.IsNullOrEmpty(text) ? text : InvalidXmlChars.Replace(text, "");
}
/// <summary>
/// Converts a string to a Guid - WARNING, depending on the string, this may not be unique
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
internal static Guid ToGuid(this string text)
{
var md5 = MD5.Create();
byte[] myStringBytes = Encoding.ASCII.GetBytes(text);
byte[] hash = md5.ComputeHash(myStringBytes);
return new Guid(hash);
}
}
}