diff --git a/src/Umbraco.Core/Services/IMediaService.cs b/src/Umbraco.Core/Services/IMediaService.cs index 8759d9d790..31c2e74fd4 100644 --- a/src/Umbraco.Core/Services/IMediaService.cs +++ b/src/Umbraco.Core/Services/IMediaService.cs @@ -10,51 +10,6 @@ using Umbraco.Core.Persistence.Querying; namespace Umbraco.Core.Services { - /// - /// A temporary interface until we are in v8, this is used to return a different result for the same method and this interface gets implemented - /// explicitly. These methods will replace the normal ones in IContentService in v8 and this will be removed. - /// - public interface IMediaServiceOperations - { - //TODO: Remove this class in v8 - - //TODO: There's probably more that needs to be added like the EmptyRecycleBin, etc... - - /// - /// Deletes an object by moving it to the Recycle Bin - /// - /// The to delete - /// Id of the User deleting the Media - Attempt MoveToRecycleBin(IMedia media, int userId = 0); - - /// - /// Permanently deletes an object - /// - /// - /// Please note that this method will completely remove the Media from the database, - /// but current not from the file system. - /// - /// The to delete - /// Id of the User deleting the Media - Attempt Delete(IMedia media, int userId = 0); - - /// - /// Saves a single object - /// - /// The to save - /// Id of the User saving the Media - /// Optional boolean indicating whether or not to raise events. - Attempt Save(IMedia media, int userId = 0, bool raiseEvents = true); - - /// - /// Saves a collection of objects - /// - /// Collection of to save - /// Id of the User saving the Media - /// Optional boolean indicating whether or not to raise events. - Attempt Save(IEnumerable medias, int userId = 0, bool raiseEvents = true); - } - /// /// Defines the Media Service, which is an easy access to operations involving /// @@ -238,6 +193,13 @@ namespace Umbraco.Core.Services /// Id of the User moving the Media void Move(IMedia media, int parentId, int userId = 0); + /// + /// Deletes an object by moving it to the Recycle Bin + /// + /// The to delete + /// Id of the User deleting the Media + Attempt MoveToRecycleBin(IMedia media, int userId = 0); + /// /// Empties the Recycle Bin by deleting all that resides in the bin /// @@ -259,6 +221,33 @@ namespace Umbraco.Core.Services /// Optional Id of the user issueing the delete operation void DeleteMediaOfTypes(IEnumerable mediaTypeIds, int userId = 0); + /// + /// Permanently deletes an object + /// + /// + /// Please note that this method will completely remove the Media from the database, + /// but current not from the file system. + /// + /// The to delete + /// Id of the User deleting the Media + Attempt Delete(IMedia media, int userId = 0); + + /// + /// Saves a single object + /// + /// The to save + /// Id of the User saving the Media + /// Optional boolean indicating whether or not to raise events. + Attempt Save(IMedia media, int userId = 0, bool raiseEvents = true); + + /// + /// Saves a collection of objects + /// + /// Collection of to save + /// Id of the User saving the Media + /// Optional boolean indicating whether or not to raise events. + Attempt Save(IEnumerable medias, int userId = 0, bool raiseEvents = true); + /// /// Gets an object by its 'UniqueId' /// diff --git a/src/Umbraco.Core/Services/Implement/MediaService.cs b/src/Umbraco.Core/Services/Implement/MediaService.cs index f1c70b92ad..cca7eb8fb7 100644 --- a/src/Umbraco.Core/Services/Implement/MediaService.cs +++ b/src/Umbraco.Core/Services/Implement/MediaService.cs @@ -19,7 +19,7 @@ namespace Umbraco.Core.Services.Implement /// /// Represents the Media Service, which is an easy access to operations involving /// - public class MediaService : ScopeRepositoryService, IMediaService, IMediaServiceOperations + public class MediaService : ScopeRepositoryService, IMediaService { private readonly IMediaRepository _mediaRepository; private readonly IMediaTypeRepository _mediaTypeRepository; @@ -743,14 +743,13 @@ namespace Umbraco.Core.Services.Implement #region Save - /// /// Saves a single object /// /// The to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. - Attempt IMediaServiceOperations.Save(IMedia media, int userId, bool raiseEvents) + public Attempt Save(IMedia media, int userId = 0, bool raiseEvents = true) { var evtMsgs = EventMessagesFactory.Get(); @@ -797,18 +796,7 @@ namespace Umbraco.Core.Services.Implement /// Collection of to save /// Id of the User saving the Media /// Optional boolean indicating whether or not to raise events. - public void Save(IEnumerable medias, int userId = 0, bool raiseEvents = true) - { - ((IMediaServiceOperations) this).Save(medias, userId, raiseEvents); - } - - /// - /// Saves a collection of objects - /// - /// Collection of to save - /// Id of the User saving the Media - /// Optional boolean indicating whether or not to raise events. - Attempt IMediaServiceOperations.Save(IEnumerable medias, int userId, bool raiseEvents) + public Attempt Save(IEnumerable medias, int userId = 0, bool raiseEvents = true) { var evtMsgs = EventMessagesFactory.Get(); var mediasA = medias.ToArray(); @@ -855,7 +843,7 @@ namespace Umbraco.Core.Services.Implement /// /// The to delete /// Id of the User deleting the Media - Attempt IMediaServiceOperations.Delete(IMedia media, int userId) + public Attempt Delete(IMedia media, int userId = 0) { var evtMsgs = EventMessagesFactory.Get(); @@ -1010,7 +998,7 @@ namespace Umbraco.Core.Services.Implement /// /// The to delete /// Id of the User deleting the Media - Attempt IMediaServiceOperations.MoveToRecycleBin(IMedia media, int userId) + public Attempt MoveToRecycleBin(IMedia media, int userId = 0) { var evtMsgs = EventMessagesFactory.Get(); var moves = new List>(); @@ -1056,7 +1044,7 @@ namespace Umbraco.Core.Services.Implement // if moving to the recycle bin then use the proper method if (parentId == Constants.System.RecycleBinMedia) { - ((IMediaServiceOperations)this).MoveToRecycleBin(media, userId); + MoveToRecycleBin(media, userId); return; } diff --git a/src/Umbraco.Core/Services/ServiceWithResultExtensions.cs b/src/Umbraco.Core/Services/ServiceWithResultExtensions.cs deleted file mode 100644 index f64a10540f..0000000000 --- a/src/Umbraco.Core/Services/ServiceWithResultExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace Umbraco.Core.Services -{ - /// - /// These are used currently to return the temporary 'operation' interfaces for services - /// which are used to return a status from operational methods so we can determine if things are - /// cancelled, etc... - /// - /// These will be obsoleted in v8 since all real services methods will be changed to have the correct result. - /// - public static class ServiceWithResultExtensions - { - public static IMediaServiceOperations WithResult(this IMediaService mediaService) - { - return (IMediaServiceOperations)mediaService; - } - } -} diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index 6bd78044f8..728e507c05 100644 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1424,7 +1424,6 @@ - diff --git a/src/Umbraco.Tests/Services/MediaServiceTests.cs b/src/Umbraco.Tests/Services/MediaServiceTests.cs index 1329438c7b..02e8e3673e 100644 --- a/src/Umbraco.Tests/Services/MediaServiceTests.cs +++ b/src/Umbraco.Tests/Services/MediaServiceTests.cs @@ -34,9 +34,9 @@ namespace Umbraco.Tests.Services for (int i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType1, -1); - ((IMediaServiceOperations)(mediaService)).Save(m1); + mediaService.Save(m1); var m2 = MockedMedia.CreateMediaImage(mediaType2, -1); - ((IMediaServiceOperations)(mediaService)).Save(m2); + mediaService.Save(m2); } long total; @@ -74,7 +74,7 @@ namespace Umbraco.Tests.Services var media = mediaService.GetById(mediaItems.Item1.Id); // Act - ((IMediaServiceOperations)mediaService).MoveToRecycleBin(media); + mediaService.MoveToRecycleBin(media); // Assert Assert.That(media.ParentId, Is.EqualTo(-21)); @@ -110,7 +110,7 @@ namespace Umbraco.Tests.Services var media = mediaService.CreateMedia(string.Empty, -1, "video"); // Act & Assert - Assert.Throws(() => ((IMediaServiceOperations)(mediaService)).Save(media)); + Assert.Throws(() => mediaService.Save(media)); } [Test] @@ -121,7 +121,7 @@ namespace Umbraco.Tests.Services ServiceContext.MediaTypeService.Save(mediaType); var media = mediaService.CreateMedia("Test", -1, "video"); - ((IMediaServiceOperations)(mediaService)).Save(media); + mediaService.Save(media); using (var scope = ScopeProvider.CreateScope()) { @@ -137,7 +137,7 @@ namespace Umbraco.Tests.Services ServiceContext.MediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImage(mediaType, -1); - ((IMediaServiceOperations)(mediaService)).Save(media); + mediaService.Save(media); var mediaPath = "/media/test-image.png"; var resolvedMedia = mediaService.GetMediaByPath(mediaPath); @@ -154,7 +154,7 @@ namespace Umbraco.Tests.Services ServiceContext.MediaTypeService.Save(mediaType); var media = MockedMedia.CreateMediaImageWithCrop(mediaType, -1); - ((IMediaServiceOperations)(mediaService)).Save(media); + mediaService.Save(media); var mediaPath = "/media/test-image.png"; var resolvedMedia = mediaService.GetMediaByPath(mediaPath); @@ -171,7 +171,7 @@ namespace Umbraco.Tests.Services for (int i = 0; i < 10; i++) { var c1 = MockedMedia.CreateMediaImage(mediaType, -1); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(c1); + ServiceContext.MediaService.Save(c1); } var service = ServiceContext.MediaService; @@ -194,17 +194,17 @@ namespace Umbraco.Tests.Services for (int i = 0; i < 9; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, -1); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(m1); + ServiceContext.MediaService.Save(m1); } var mediaTypeForFolder = MockedContentTypes.CreateImageMediaType("Folder2"); ServiceContext.MediaTypeService.Save(mediaTypeForFolder); var mediaFolder = MockedMedia.CreateMediaFolder(mediaTypeForFolder, -1); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(mediaFolder); + ServiceContext.MediaService.Save(mediaFolder); for (int i = 0; i < 10; i++) { var m1 = MockedMedia.CreateMediaImage(mediaType, mediaFolder.Id); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(m1); + ServiceContext.MediaService.Save(m1); } var service = ServiceContext.MediaService; @@ -232,26 +232,26 @@ namespace Umbraco.Tests.Services //Create and Save folder-Media -> 1050 var folderMediaType = ServiceContext.MediaTypeService.Get(1031); var folder = MockedMedia.CreateMediaFolder(folderMediaType, -1); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(folder); + ServiceContext.MediaService.Save(folder); //Create and Save folder-Media -> 1051 var folder2 = MockedMedia.CreateMediaFolder(folderMediaType, -1); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(folder2); + ServiceContext.MediaService.Save(folder2); //Create and Save image-Media -> 1052 var imageMediaType = ServiceContext.MediaTypeService.Get(1032); var image = (Media)MockedMedia.CreateMediaImage(imageMediaType, 1050); - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(image); + ServiceContext.MediaService.Save(image); //Create and Save folder-Media that is trashed -> 1053 var folderTrashed = (Media)MockedMedia.CreateMediaFolder(folderMediaType, -21); folderTrashed.Trashed = true; - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(folderTrashed); + ServiceContext.MediaService.Save(folderTrashed); //Create and Save image-Media child of folderTrashed -> 1054 var imageTrashed = (Media)MockedMedia.CreateMediaImage(imageMediaType, folderTrashed.Id); imageTrashed.Trashed = true; - ((IMediaServiceOperations)(ServiceContext.MediaService)).Save(imageTrashed); + ServiceContext.MediaService.Save(imageTrashed); return new Tuple(folder, folder2, image, folderTrashed, imageTrashed); diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 2401798ce2..3fde20df28 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -376,7 +376,7 @@ namespace Umbraco.Web.Editors //if the current item is in the recycle bin if (foundMedia.Trashed == false) { - var moveResult = Services.MediaService.WithResult().MoveToRecycleBin(foundMedia, (int)Security.CurrentUser.Id); + var moveResult = Services.MediaService.MoveToRecycleBin(foundMedia, (int)Security.CurrentUser.Id); if (moveResult == false) { //returning an object of INotificationModel will ensure that any pending @@ -386,7 +386,7 @@ namespace Umbraco.Web.Editors } else { - var deleteResult = Services.MediaService.WithResult().Delete(foundMedia, (int)Security.CurrentUser.Id); + var deleteResult = Services.MediaService.Delete(foundMedia, (int)Security.CurrentUser.Id); if (deleteResult == false) { //returning an object of INotificationModel will ensure that any pending @@ -464,7 +464,7 @@ namespace Umbraco.Web.Editors } //save the item - var saveStatus = Services.MediaService.WithResult().Save(contentItem.PersistedContent, (int)Security.CurrentUser.Id); + var saveStatus = Services.MediaService.Save(contentItem.PersistedContent, (int)Security.CurrentUser.Id); //return the updated model var display = ContextMapper.Map(contentItem.PersistedContent, UmbracoContext); @@ -694,7 +694,7 @@ namespace Umbraco.Web.Editors f.SetValue(Constants.Conventions.Media.File, fileName, fs); } - var saveResult = mediaService.WithResult().Save(f, Security.CurrentUser.Id); + var saveResult = mediaService.Save(f, Security.CurrentUser.Id); if (saveResult == false) { AddCancelMessage(tempFiles,