Created
September 24, 2019 17:40
-
-
Save jamiehowarth0/2e94c7cb0747cd9854cbb0987322d5f6 to your computer and use it in GitHub Desktop.
Potential fix for nvarchar/ntext Umbraco bug for Teacommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FixNvarcharContentInstallTask : AUmbracoDbInstallTask | |
| { | |
| public override void Install() | |
| { | |
| // Get all property types using the datatype | |
| var datatype = ApplicationContext.Current.Services.DataTypeService.GetDataTypeDefinitionByPropertyEditorAlias( | |
| "TeaCommerce.VariantEditor").FirstOrDefault(); | |
| var allContentTypes = ApplicationContext.Current.Services.ContentTypeService.GetAllContentTypes(); | |
| var hasVariantPicker = allContentTypes.Where(ct => ct.PropertyTypes.Any(prop => prop.DataTypeDefinitionId == datatype.Id)); | |
| var propIds = hasVariantPicker.SelectMany(ct => ct.PropertyTypes) | |
| .Where(pt => pt.DataTypeDefinitionId == datatype.Id) | |
| .Select(pt => pt.Id); | |
| using (var db = ApplicationContext.Current.DatabaseContext.Database) | |
| { | |
| using (var ctx = db.GetTransaction()) | |
| { | |
| var query = "UPDATE cmsPropertyData SET dataNtext = dataNvarchar, dataNvarchar = NULL WHERE propertytypeid IN (@0)"; | |
| var queryParam = string.Join(",", propIds); | |
| db.Execute(new Sql(query, queryParam)); | |
| ctx.Complete(); | |
| } | |
| } | |
| } | |
| public override void Uninstall() | |
| { | |
| // Do nothing | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment