From 79844154fb4d95736fb2e527dca2ccbd7aed5e02 Mon Sep 17 00:00:00 2001 From: Claus Date: Thu, 18 May 2017 11:30:11 +0200 Subject: [PATCH] U4-9919 Updated media files are deleted --- src/Umbraco.Core/IO/MediaFileSystem.cs | 2 +- .../fileupload/fileupload.controller.js | 14 +++++++------- src/Umbraco.Web/Editors/ContentControllerBase.cs | 2 +- .../WebApi/Binders/ContentItemBinder.cs | 3 +-- src/Umbraco.Web/WebApi/Binders/MediaItemBinder.cs | 9 ++++----- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index c57cf94cef..fc6490e8cd 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -159,7 +159,7 @@ namespace Umbraco.Core.IO // ReSharper disable once AssignNullToNotNullAttribute var filepath = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories - ? Path.Combine(folder, filename) + ? Path.Combine(folder, filename).Replace('\\', '/') : folder + "-" + filename; return filepath; diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js index df21541f09..3c8170e54b 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/fileupload/fileupload.controller.js @@ -138,15 +138,15 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag //cannot just check for !newVal because it might be an empty string which we //want to look for. if (newVal !== null && newVal !== undefined && newVal !== oldVal) { - //now we need to check if we need to re-initialize our structure which is kind of tricky - // since we only want to do that if the server has changed the value, not if this controller - // has changed the value. There's only 2 scenarios where we change the value internall so - // we know what those values can be, if they are not either of them, then we'll re-initialize. - - if (newVal.clearFiles !== true && newVal !== $scope.originalValue && !newVal.selectedFiles) { + // here we need to check if the value change needs to trigger an update in the UI. + // if the value is only changed in the controller and not in the server values, we do not + // want to trigger an update yet. + // we can however no longer rely on checking values in the controller vs. values from the server + // to determine whether to update or not, since you could potentially be uploading a file with + // the exact same name - in that case we need to reinitialize to show the newly uploaded file. + if (newVal.clearFiles !== true && !newVal.selectedFiles) { initialize($scope.rebuildInput.index + 1); } - } }); }; diff --git a/src/Umbraco.Web/Editors/ContentControllerBase.cs b/src/Umbraco.Web/Editors/ContentControllerBase.cs index 6b8d570e5f..f67ce13950 100644 --- a/src/Umbraco.Web/Editors/ContentControllerBase.cs +++ b/src/Umbraco.Web/Editors/ContentControllerBase.cs @@ -57,7 +57,7 @@ namespace Umbraco.Web.Editors where TPersisted : IContentBase { //Don't update the name if it is empty - if (!contentItem.Name.IsNullOrWhiteSpace()) + if (contentItem.Name.IsNullOrWhiteSpace() == false) { contentItem.PersistedContent.Name = contentItem.Name; } diff --git a/src/Umbraco.Web/WebApi/Binders/ContentItemBinder.cs b/src/Umbraco.Web/WebApi/Binders/ContentItemBinder.cs index 5afc7cee19..a19123f35e 100644 --- a/src/Umbraco.Web/WebApi/Binders/ContentItemBinder.cs +++ b/src/Umbraco.Web/WebApi/Binders/ContentItemBinder.cs @@ -3,7 +3,6 @@ using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Models.Mapping; namespace Umbraco.Web.WebApi.Binders { @@ -33,7 +32,7 @@ namespace Umbraco.Web.WebApi.Binders var contentType = ApplicationContext.Services.ContentTypeService.GetContentType(model.ContentTypeAlias); if (contentType == null) { - throw new InvalidOperationException("No content type found wth alias " + model.ContentTypeAlias); + throw new InvalidOperationException("No content type found with alias " + model.ContentTypeAlias); } return new Content(model.Name, model.ParentId, contentType); } diff --git a/src/Umbraco.Web/WebApi/Binders/MediaItemBinder.cs b/src/Umbraco.Web/WebApi/Binders/MediaItemBinder.cs index 726994d43e..0196c5c6f6 100644 --- a/src/Umbraco.Web/WebApi/Binders/MediaItemBinder.cs +++ b/src/Umbraco.Web/WebApi/Binders/MediaItemBinder.cs @@ -3,7 +3,6 @@ using AutoMapper; using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Web.Models.ContentEditing; -using Umbraco.Web.Models.Mapping; namespace Umbraco.Web.WebApi.Binders { @@ -29,12 +28,12 @@ namespace Umbraco.Web.WebApi.Binders protected override IMedia CreateNew(MediaItemSave model) { - var contentType = ApplicationContext.Services.ContentTypeService.GetMediaType(model.ContentTypeAlias); - if (contentType == null) + var mediaType = ApplicationContext.Services.ContentTypeService.GetMediaType(model.ContentTypeAlias); + if (mediaType == null) { - throw new InvalidOperationException("No content type found wth alias " + model.ContentTypeAlias); + throw new InvalidOperationException("No media type found with alias " + model.ContentTypeAlias); } - return new Core.Models.Media(model.Name, model.ParentId, contentType); + return new Core.Models.Media(model.Name, model.ParentId, mediaType); } protected override ContentItemDto MapFromPersisted(MediaItemSave model)