diff --git a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs index ccacaa8893..ddc4289718 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/UmbracoPlan.cs @@ -128,7 +128,7 @@ namespace Umbraco.Core.Migrations.Upgrade To("{38C809D5-6C34-426B-9BEA-EFD39162595C}"); To("{6017F044-8E70-4E10-B2A3-336949692ADD}"); To("98339BEF-E4B2-48A8-B9D1-D173DC842BBE"); - To("{940FD19A-00A8-4D5C-B8FF-939143585726}"); + To("{940FD19A-00A8-4D5C-B8FF-939143585726}"); //FINAL diff --git a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonPropertyEditorsMigration.cs b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonAndCheckboxPropertyEditorsMigration.cs similarity index 56% rename from src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonPropertyEditorsMigration.cs rename to src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonAndCheckboxPropertyEditorsMigration.cs index 2c4e601a9e..ec60a22ecd 100644 --- a/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonPropertyEditorsMigration.cs +++ b/src/Umbraco.Core/Migrations/Upgrade/V_8_0_0/RadioButtonAndCheckboxPropertyEditorsMigration.cs @@ -1,81 +1,98 @@ using System; using System.Collections.Generic; using System.Linq; -using Umbraco.Core.Cache; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Dtos; using Umbraco.Core.PropertyEditors; -using Umbraco.Core.Sync; -using Umbraco.Web.Cache; namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 { - public class RadioButtonPropertyEditorsMigration : MigrationBase + public class RadioButtonAndCheckboxPropertyEditorsMigration : MigrationBase { - public RadioButtonPropertyEditorsMigration(IMigrationContext context) + public RadioButtonAndCheckboxPropertyEditorsMigration(IMigrationContext context) : base(context) { } public override void Migrate() { - //need to convert the old drop down data types to use the new one - var dataTypes = Database.Fetch(Sql() - .Select() - .From() - .Where(x => x.EditorAlias == "Umbraco.RadioButtonList")); + MigrateRadioButtons(); + MigrateCheckBoxes(); + } + + private void MigrateCheckBoxes() + { + //fixme: complete this + + var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.CheckBoxList); + + + } + + private void MigrateRadioButtons() + { + var dataTypes = GetDataTypes(Constants.PropertyEditors.Aliases.RadioButtonList); var refreshCache = false; foreach (var dataType in dataTypes) { ValueListConfiguration config; - if (!dataType.Configuration.IsNullOrWhiteSpace()) + if (dataType.Configuration.IsNullOrWhiteSpace()) + continue; + + // parse configuration, and update everything accordingly + try { - // parse configuration, and update everything accordingly - try - { - config = (ValueListConfiguration) new ValueListConfigurationEditor().FromDatabase( - dataType.Configuration); - } - catch (Exception ex) - { - Logger.Error( - ex, - "Invalid drop down configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared", - dataType.Configuration); - - continue; - } - - // get property data dtos - var propertyDataDtos = Database.Fetch(Sql() - .Select() - .From() - .InnerJoin() - .On((pt, pd) => pt.Id == pd.PropertyTypeId) - .InnerJoin() - .On((dt, pt) => dt.NodeId == pt.DataTypeId) - .Where(x => x.DataTypeId == dataType.NodeId)); - - // update dtos - var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config)); - - // persist changes - foreach (var propertyDataDto in updatedDtos) Database.Update(propertyDataDto); - - UpdateDataType(dataType); - refreshCache = true; + config = (ValueListConfiguration)new ValueListConfigurationEditor().FromDatabase( + dataType.Configuration); } + catch (Exception ex) + { + Logger.Error( + ex, + "Invalid radio button configuration detected: \"{Configuration}\", cannot convert editor, values will be cleared", + dataType.Configuration); + + continue; + } + + // get property data dtos + var propertyDataDtos = Database.Fetch(Sql() + .Select() + .From() + .InnerJoin() + .On((pt, pd) => pt.Id == pd.PropertyTypeId) + .InnerJoin() + .On((dt, pt) => dt.NodeId == pt.DataTypeId) + .Where(x => x.DataTypeId == dataType.NodeId)); + + // update dtos + var updatedDtos = propertyDataDtos.Where(x => UpdatePropertyDataDto(x, config)); + + // persist changes + foreach (var propertyDataDto in updatedDtos) Database.Update(propertyDataDto); + + UpdateDataType(dataType); + refreshCache = true; } if (refreshCache) { //FIXME: trigger cache rebuild. Currently the data in the database tables is wrong. } + } + private List GetDataTypes(string editorAlias) + { + //need to convert the old drop down data types to use the new one + var dataTypes = Database.Fetch(Sql() + .Select() + .From() + .Where(x => x.EditorAlias == editorAlias)); + return dataTypes; } private void UpdateDataType(DataTypeDto dataType) @@ -123,7 +140,8 @@ namespace Umbraco.Core.Migrations.Upgrade.V_8_0_0 if (!canConvert) return false; - propData.VarcharValue = string.Join(",", values); + //The radio button only supports selecting a single value, so if there are multiple for some insane reason we can only use the first + propData.VarcharValue = values.Count > 0 ? values[0] : string.Empty; propData.TextValue = null; propData.IntegerValue = null; return true; diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 4358fdbd42..d43aedc2d0 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -52,9 +52,6 @@ - - ..\Umbraco.Tests\bin\Debug\Umbraco.Web.dll - @@ -389,7 +386,7 @@ - + diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js index 9ef1b69aad..8897c59cef 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.controller.js @@ -42,7 +42,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro return f.checked; }), function(m) { - return m.key; + return m.value; }); //get all of the same values between the arrays var same = _.intersection($scope.model.value, selectedVals); @@ -54,7 +54,7 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro $scope.selectedItems = []; for (var i = 0; i < configItems.length; i++) { - var isChecked = _.contains($scope.model.value, configItems[i].id); + var isChecked = _.contains($scope.model.value, configItems[i].value); $scope.selectedItems.push({ checked: isChecked, key: configItems[i].id, @@ -66,13 +66,13 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.CheckboxListContro function changed(item) { var index = _.findIndex($scope.model.value, function (v) { - return v === item.key; + return v === item.value; }); if (item.checked) { //if it doesn't exist in the model, then add it if (index < 0) { - $scope.model.value.push(item.key); + $scope.model.value.push(item.value); } } else { diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html index 29760e3f5b..6e9150d07c 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/checkboxlist/checkboxlist.html @@ -4,7 +4,7 @@