diff --git a/src/Umbraco.Core/Media/Result.cs b/src/Umbraco.Core/Media/Result.cs index fc1ea08f32..89e311e2d6 100644 --- a/src/Umbraco.Core/Media/Result.cs +++ b/src/Umbraco.Core/Media/Result.cs @@ -1,5 +1,7 @@ namespace Umbraco.Core.Media { + + //NOTE: Could definitely have done with a better name public class Result { public Status Status { get; set; } diff --git a/src/Umbraco.Core/Media/Status.cs b/src/Umbraco.Core/Media/Status.cs index a66ff34b9e..c0f448156e 100644 --- a/src/Umbraco.Core/Media/Status.cs +++ b/src/Umbraco.Core/Media/Status.cs @@ -1,5 +1,7 @@ namespace Umbraco.Core.Media { + + //NOTE: Could definitely have done with a better name public enum Status { NotSupported, diff --git a/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs b/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs index c60174ec9e..14c8640fc9 100644 --- a/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs +++ b/src/Umbraco.Core/Models/Editors/ContentPropertyData.cs @@ -23,10 +23,8 @@ namespace Umbraco.Core.Models.Editors AdditionalData = new ReadOnlyDictionary(additionalData); } - //TODO: Change this to an object so we can post JSON or json converted clr types if we want! - /// - /// The string value submitted for the property + /// The value submitted for the property /// public object Value { get; private set; } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 1e102c9c6c..7b5de2e441 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -923,6 +923,7 @@ + diff --git a/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs b/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs index 41cbaaf452..bc09186a45 100644 --- a/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/DataTypeModelMapper.cs @@ -45,6 +45,7 @@ namespace Umbraco.Web.Models.Mapping config.CreateMap() .ConstructUsing(save => new DataTypeDefinition(-1, save.SelectedEditor) {CreateDate = DateTime.Now}) + .ForMember(definition => definition.Path, expression => expression.Ignore()) .ForMember(definition => definition.ControlId, expression => expression.MapFrom(save => save.SelectedEditor)) .ForMember(definition => definition.ParentId, expression => expression.MapFrom(save => -1)) .ForMember(definition => definition.DatabaseType, expression => expression.ResolveUsing()); diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs index b4033d5871..182da1880f 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadPropertyEditor.cs @@ -1,10 +1,13 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Xml; +using Newtonsoft.Json.Linq; using Umbraco.Core; using Umbraco.Core.Configuration; using Umbraco.Core.IO; +using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; @@ -43,6 +46,10 @@ namespace Umbraco.Web.PropertyEditors }; } + protected override PreValueEditor CreatePreValueEditor() + { + return new FileUploadPreValueEditor(); + } static void MediaServiceCreating(IMediaService sender, Core.Events.NewEventArgs e) { @@ -125,5 +132,56 @@ namespace Umbraco.Web.PropertyEditors } } + /// + /// A custom pre-val editor to ensure that the data is stored how the legacy data was stored in + /// + internal class FileUploadPreValueEditor : ValueListPreValueEditor + { + /// + /// Format the persisted value to work with our multi-val editor. + /// + /// + /// + /// + public override IDictionary FormatDataForEditor(IDictionary defaultPreVals, PreValueCollection persistedPreVals) + { + var result = new Dictionary(); + + //the pre-values just take up one field with a semi-colon delimiter so we'll just parse + var dictionary = persistedPreVals.FormatAsDictionary(); + if (dictionary.Any()) + { + //there should only be one val + var delimited = dictionary.First().Value.Value.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries); + for (var index = 0; index < delimited.Length; index++) + { + result.Add(index.ToInvariantString(), delimited[index]); + } + } + + //the items list will be a dictionary of it's id -> value we need to use the id for persistence for backwards compatibility + return new Dictionary { { "items", result } }; + } + + /// + /// Take the posted values and convert them to a semi-colon separated list so that its backwards compatible + /// + /// + /// + /// + public override IDictionary FormatDataForPersistence(IDictionary editorValue, PreValueCollection currentValue) + { + var result = base.FormatDataForPersistence(editorValue, currentValue); + + //this should just be a dictionary of values, we want to re-format this so that it is just one value in the dictionary that is + // semi-colon delimited + var values = result.Select(item => item.Value).ToList(); + + result.Clear(); + result.Add("thumbs", string.Join(";", values)); + return result; + } + } + } } \ No newline at end of file diff --git a/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs b/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs index bb0f3432f6..ad839acbcc 100644 --- a/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs +++ b/src/Umbraco.Web/PropertyEditors/FileUploadValueEditor.cs @@ -5,6 +5,7 @@ using System.IO; using System.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Umbraco.Core.Configuration; using Umbraco.Core.IO; using Umbraco.Core.Logging; using Umbraco.Core.Media; @@ -94,7 +95,7 @@ namespace Umbraco.Web.PropertyEditors var name = IOHelper.SafeFileName(file.FileName.Substring(file.FileName.LastIndexOf(IOHelper.DirSepChar) + 1, file.FileName.Length - file.FileName.LastIndexOf(IOHelper.DirSepChar) - 1).ToLower()); - var subfolder = UmbracoSettings.UploadAllowDirectories + var subfolder = LegacyUmbracoSettings.UploadAllowDirectories ? currentPersistedFile.Replace(fs.GetUrl("/"), "").Split('/')[0] : currentPersistedFile.Substring(currentPersistedFile.LastIndexOf("/", StringComparison.Ordinal) + 1).Split('-')[0]; @@ -103,7 +104,7 @@ namespace Umbraco.Web.PropertyEditors ? subfolderId.ToString(CultureInfo.InvariantCulture) : MediaSubfolderCounter.Current.Increment().ToString(CultureInfo.InvariantCulture); - var fileName = UmbracoSettings.UploadAllowDirectories + var fileName = LegacyUmbracoSettings.UploadAllowDirectories ? Path.Combine(numberedFolder, name) : numberedFolder + "-" + name;