From 720e529474ce679f2b09fb0b1065984923a29f87 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Tue, 27 Apr 2021 09:59:51 +0200 Subject: [PATCH] Remove a bunch of template related, unreferenced methods from file service and template repository (#9876) --- .../Repositories/ITemplateRepository.cs | 20 +--- src/Umbraco.Core/Services/IFileService.cs | 51 +--------- .../Implement/TemplateRepository.cs | 92 ------------------- .../Services/Implement/FileService.cs | 72 --------------- .../Repositories/TemplateRepositoryTest.cs | 7 -- 5 files changed, 2 insertions(+), 240 deletions(-) diff --git a/src/Umbraco.Core/Persistence/Repositories/ITemplateRepository.cs b/src/Umbraco.Core/Persistence/Repositories/ITemplateRepository.cs index 24c83ff29d..7e6a81864c 100644 --- a/src/Umbraco.Core/Persistence/Repositories/ITemplateRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/ITemplateRepository.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.IO; using Umbraco.Cms.Core.Models; @@ -11,17 +11,8 @@ namespace Umbraco.Cms.Core.Persistence.Repositories IEnumerable GetAll(params string[] aliases); IEnumerable GetChildren(int masterTemplateId); - IEnumerable GetChildren(string alias); IEnumerable GetDescendants(int masterTemplateId); - IEnumerable GetDescendants(string alias); - - /// - /// Validates a - /// - /// to validate - /// True if Script is valid, otherwise false - bool ValidateTemplate(ITemplate template); /// /// Gets the content of a template as a stream. @@ -29,14 +20,5 @@ namespace Umbraco.Cms.Core.Persistence.Repositories /// The filesystem path to the template. /// The content of the template. Stream GetFileContentStream(string filepath); - - /// - /// Sets the content of a template. - /// - /// The filesystem path to the template. - /// The content of the template. - void SetFileContent(string filepath, Stream content); - - long GetFileSize(string filepath); } } diff --git a/src/Umbraco.Core/Services/IFileService.cs b/src/Umbraco.Core/Services/IFileService.cs index bcf2a0caee..1f4d33388c 100644 --- a/src/Umbraco.Core/Services/IFileService.cs +++ b/src/Umbraco.Core/Services/IFileService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using Umbraco.Cms.Core.Models; @@ -154,13 +154,6 @@ namespace Umbraco.Cms.Core.Services /// The object matching the identifier, or null. ITemplate GetTemplate(Guid id); - /// - /// Gets the template descendants - /// - /// - /// - IEnumerable GetTemplateDescendants(string alias); - /// /// Gets the template descendants /// @@ -168,20 +161,6 @@ namespace Umbraco.Cms.Core.Services /// IEnumerable GetTemplateDescendants(int masterTemplateId); - /// - /// Gets the template children - /// - /// - /// - IEnumerable GetTemplateChildren(string alias); - - /// - /// Gets the template children - /// - /// - /// - IEnumerable GetTemplateChildren(int masterTemplateId); - /// /// Saves a /// @@ -209,13 +188,6 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user deleting the template void DeleteTemplate(string alias, int userId = Constants.Security.SuperUserId); - /// - /// Validates a - /// - /// to validate - /// True if template is valid, otherwise false - bool ValidateTemplate(ITemplate template); - /// /// Saves a collection of objects /// @@ -223,27 +195,6 @@ namespace Umbraco.Cms.Core.Services /// Optional id of the user void SaveTemplate(IEnumerable templates, int userId = Constants.Security.SuperUserId); - /// - /// Gets the content of a template as a stream. - /// - /// The filesystem path to the template. - /// The content of the template. - Stream GetTemplateFileContentStream(string filepath); - - /// - /// Sets the content of a template. - /// - /// The filesystem path to the template. - /// The content of the template. - void SetTemplateFileContent(string filepath, Stream content); - - /// - /// Gets the size of a template. - /// - /// The filesystem path to the template. - /// The size of the template. - long GetTemplateFileSize(string filepath); - /// /// Gets the content of a stylesheet as a stream. /// diff --git a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs index 3aad92a012..cd42bd5dd5 100644 --- a/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs +++ b/src/Umbraco.Infrastructure/Persistence/Repositories/Implement/TemplateRepository.cs @@ -449,16 +449,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement } } - public void SetFileContent(string filepath, Stream content) - { - GetFileSystem(filepath).AddFile(filepath, content, true); - } - - public long GetFileSize(string filepath) - { - return GetFileSystem(filepath).GetSize(filepath); - } - private IFileSystem GetFileSystem(string filepath) { var ext = Path.GetExtension(filepath); @@ -507,14 +497,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement return children; } - public IEnumerable GetChildren(string alias) - { - //return from base.GetAll, this is all cached - return base.GetMany().Where(x => alias.IsNullOrWhiteSpace() - ? x.MasterTemplateAlias.IsNullOrWhiteSpace() - : x.MasterTemplateAlias.InvariantEquals(alias)); - } - public IEnumerable GetDescendants(int masterTemplateId) { //return from base.GetAll, this is all cached @@ -541,30 +523,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement return descendants; } - public IEnumerable GetDescendants(string alias) - { - var all = base.GetMany().ToArray(); - var descendants = new List(); - if (alias.IsNullOrWhiteSpace() == false) - { - var parent = all.FirstOrDefault(x => x.Alias.InvariantEquals(alias)); - if (parent == null) return Enumerable.Empty(); - //recursively add all children - AddChildren(all, descendants, parent.Alias); - } - else - { - descendants.AddRange(all.Where(x => x.MasterTemplateAlias.IsNullOrWhiteSpace())); - foreach (var parent in descendants) - { - //recursively add all children with a level - AddChildren(all, descendants, parent.Alias); - } - } - //return the list - it will be naturally ordered by level - return descendants; - } - private void AddChildren(ITemplate[] all, List descendants, string masterAlias) { var c = all.Where(x => x.MasterTemplateAlias.InvariantEquals(masterAlias)).ToArray(); @@ -577,56 +535,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement } } - /// - /// Validates a - /// - /// to validate - /// True if Script is valid, otherwise false - public bool ValidateTemplate(ITemplate template) - { - // get path - // TODO: templates should have a real Path somehow - but anyways - // are we using Path for something else?! - var path = template.VirtualPath; - - // get valid paths - var validDirs = new[] { Cms.Core.Constants.SystemDirectories.MvcViews }; - - // get valid extensions - var validExts = new List(); - validExts.Add("cshtml"); - validExts.Add("vbhtml"); - - // validate path and extension - var validFile = _ioHelper.VerifyEditPath(path, validDirs); - var validExtension = _ioHelper.VerifyFileExtension(path, validExts); - return validFile && validExtension; - } - - private static IEnumerable CreateChildren(TemplateNode parent, IEnumerable childTemplates, ITemplate[] allTemplates) - { - var children = new List(); - foreach (var childTemplate in childTemplates) - { - var template = allTemplates.Single(x => x.Id == childTemplate.Id); - var child = new TemplateNode(template) - { - Parent = parent - }; - - //add to our list - children.Add(child); - - //get this node's children - var local = childTemplate; - var kids = allTemplates.Where(x => x.MasterTemplateAlias.InvariantEquals(local.Alias)); - - //recurse - child.Children = CreateChildren(child, kids, allTemplates); - } - return children; - } - #endregion /// diff --git a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs index 68a02fa478..0a01f345dc 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/FileService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/FileService.cs @@ -460,14 +460,6 @@ namespace Umbraco.Cms.Core.Services.Implement } } - public IEnumerable GetTemplateDescendants(string alias) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.GetDescendants(alias); - } - } - /// /// Gets the template descendants /// @@ -481,32 +473,6 @@ namespace Umbraco.Cms.Core.Services.Implement } } - /// - /// Gets the template children - /// - /// - /// - public IEnumerable GetTemplateChildren(string alias) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.GetChildren(alias); - } - } - - /// - /// Gets the template children - /// - /// - /// - public IEnumerable GetTemplateChildren(int masterTemplateId) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.GetChildren(masterTemplateId); - } - } - /// /// Saves a /// @@ -607,44 +573,6 @@ namespace Umbraco.Cms.Core.Services.Implement } } - /// - /// Validates a - /// - /// to validate - /// True if Script is valid, otherwise false - public bool ValidateTemplate(ITemplate template) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.ValidateTemplate(template); - } - } - - public Stream GetTemplateFileContentStream(string filepath) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.GetFileContentStream(filepath); - } - } - - public void SetTemplateFileContent(string filepath, Stream content) - { - using (var scope = ScopeProvider.CreateScope()) - { - _templateRepository.SetFileContent(filepath, content); - scope.Complete(); - } - } - - public long GetTemplateFileSize(string filepath) - { - using (var scope = ScopeProvider.CreateScope(autoComplete: true)) - { - return _templateRepository.GetFileSize(filepath); - } - } - private string GetViewContent(string fileName) { if (fileName.IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs index 646367c99a..f9587179dd 100644 --- a/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs +++ b/src/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/TemplateRepositoryTest.cs @@ -374,13 +374,10 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act IEnumerable childrenById = repository.GetChildren(created[1].Id); - IEnumerable childrenByAlias = repository.GetChildren(created[1].Alias); // Assert Assert.AreEqual(2, childrenById.Count()); Assert.AreEqual(2, childrenById.DistinctBy(x => x.Id).Count()); - Assert.AreEqual(2, childrenByAlias.Count()); - Assert.AreEqual(2, childrenByAlias.DistinctBy(x => x.Id).Count()); } } @@ -418,14 +415,10 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Persistence.Repos // Act IEnumerable descendantsById = repository.GetDescendants(created[1].Id); - IEnumerable descendantsByAlias = repository.GetDescendants(created[1].Alias); // Assert Assert.AreEqual(3, descendantsById.Count()); Assert.AreEqual(3, descendantsById.DistinctBy(x => x.Id).Count()); - - Assert.AreEqual(3, descendantsByAlias.Count()); - Assert.AreEqual(3, descendantsByAlias.DistinctBy(x => x.Id).Count()); } }