Changed IContentType on IContent to a more simple class with lesser properties
This commit is contained in:
@@ -127,7 +127,7 @@ namespace Umbraco.Core
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns properties that do not belong to a group
|
||||
/// </summary>
|
||||
@@ -156,15 +156,15 @@ namespace Umbraco.Core
|
||||
.Contains(property.PropertyTypeId));
|
||||
}
|
||||
|
||||
public static IContentTypeComposition GetContentType(this IContentBase contentBase)
|
||||
{
|
||||
if (contentBase == null) throw new ArgumentNullException(nameof(contentBase));
|
||||
|
||||
if (contentBase is IContent content) return content.ContentType;
|
||||
if (contentBase is IMedia media) return media.ContentType;
|
||||
if (contentBase is IMember member) return member.ContentType;
|
||||
throw new NotSupportedException("Unsupported IContentBase implementation: " + contentBase.GetType().FullName + ".");
|
||||
}
|
||||
// public static IContentTypeComposition GetContentType(this IContentBase contentBase)
|
||||
// {
|
||||
// if (contentBase == null) throw new ArgumentNullException(nameof(contentBase));
|
||||
//
|
||||
// if (contentBase is IContent content) return content.ContentType;
|
||||
// if (contentBase is IMedia media) return media.ContentType;
|
||||
// if (contentBase is IMember member) return member.ContentType;
|
||||
// throw new NotSupportedException("Unsupported IContentBase implementation: " + contentBase.GetType().FullName + ".");
|
||||
// }
|
||||
|
||||
#region SetValue for setting file contents
|
||||
|
||||
@@ -174,7 +174,7 @@ namespace Umbraco.Core
|
||||
/// <remarks>This really is for FileUpload fields only, and should be obsoleted. For anything else,
|
||||
/// you need to store the file by yourself using Store and then figure out
|
||||
/// how to deal with auto-fill properties (if any) and thumbnails (if any) by yourself.</remarks>
|
||||
public static void SetValue(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
|
||||
public static void SetValue(this IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
|
||||
{
|
||||
if (filename == null || filestream == null) return;
|
||||
|
||||
@@ -183,24 +183,25 @@ namespace Umbraco.Core
|
||||
if (string.IsNullOrWhiteSpace(filename)) return;
|
||||
filename = filename.ToLower(); // fixme - er... why?
|
||||
|
||||
SetUploadFile(content, propertyTypeAlias, filename, filestream, culture, segment);
|
||||
SetUploadFile(content,contentTypeService, propertyTypeAlias, filename, filestream, culture, segment);
|
||||
}
|
||||
|
||||
private static void SetUploadFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
|
||||
private static void SetUploadFile(this IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null)
|
||||
{
|
||||
var property = GetProperty(content, propertyTypeAlias);
|
||||
var property = GetProperty(content, contentTypeService, propertyTypeAlias);
|
||||
var oldpath = property.GetValue(culture, segment) is string svalue ? MediaFileSystem.GetRelativePath(svalue) : null;
|
||||
var filepath = MediaFileSystem.StoreFile(content, property.PropertyType, filename, filestream, oldpath);
|
||||
property.SetValue(MediaFileSystem.GetUrl(filepath), culture, segment);
|
||||
}
|
||||
|
||||
// gets or creates a property for a content item.
|
||||
private static Property GetProperty(IContentBase content, string propertyTypeAlias)
|
||||
private static Property GetProperty(IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias)
|
||||
{
|
||||
var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));
|
||||
if (property != null) return property;
|
||||
|
||||
var propertyType = content.GetContentType().CompositionPropertyTypes
|
||||
var contentType = contentTypeService.Get(content.ContentTypeId);
|
||||
var propertyType = contentType.CompositionPropertyTypes
|
||||
.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));
|
||||
if (propertyType == null)
|
||||
throw new Exception("No property type exists with alias " + propertyTypeAlias + ".");
|
||||
@@ -226,9 +227,10 @@ namespace Umbraco.Core
|
||||
/// the "folder number" that was assigned to the previous file referenced by the property,
|
||||
/// if any.</para>
|
||||
/// </remarks>
|
||||
public static string StoreFile(this IContentBase content, string propertyTypeAlias, string filename, Stream filestream, string filepath)
|
||||
public static string StoreFile(this IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string filepath)
|
||||
{
|
||||
var propertyType = content.GetContentType()
|
||||
var contentType = contentTypeService.Get(content.ContentTypeId);
|
||||
var propertyType = contentType
|
||||
.CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias));
|
||||
if (propertyType == null) throw new ArgumentException("Invalid property type alias " + propertyTypeAlias + ".");
|
||||
return MediaFileSystem.StoreFile(content, propertyType, filename, filestream, filepath);
|
||||
|
||||
Reference in New Issue
Block a user