mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
committed by
Nicholas Mayne
parent
1e9d14ac2c
commit
790cb0204b
@@ -88,18 +88,10 @@ namespace Orchard.MediaLibrary.Controllers {
|
||||
|
||||
try {
|
||||
_mediaLibraryService.RenameFolder(viewModel.FolderPath, viewModel.Name);
|
||||
|
||||
var segments = viewModel.FolderPath.Split(new char[] {Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}, StringSplitOptions.RemoveEmptyEntries).ToArray();
|
||||
var newFolderPath = String.Join(Path.DirectorySeparatorChar.ToString(), segments.Take(segments.Length - 1).Union(new [] { viewModel.Name }));
|
||||
|
||||
foreach (var media in Services.ContentManager.Query().ForPart<MediaPart>().Where<MediaPartRecord>(m => m.FolderPath.StartsWith(viewModel.FolderPath)).List()) {
|
||||
media.FolderPath = newFolderPath + media.FolderPath.Substring(viewModel.FolderPath.Length);
|
||||
}
|
||||
Services.Notifier.Information(T("Media folder renamed"));
|
||||
}
|
||||
catch (ArgumentException argumentException) {
|
||||
Services.Notifier.Error(T("Editing Folder failed: {0}", argumentException.Message));
|
||||
Services.TransactionManager.Cancel();
|
||||
catch (Exception exception) {
|
||||
Services.Notifier.Error(T("Editing Folder failed: {0}", exception.Message));
|
||||
return View(viewModel);
|
||||
}
|
||||
|
||||
|
||||
@@ -49,65 +49,70 @@ namespace Orchard.MediaLibrary.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<MediaPart> GetMediaContentItems(string folderPath, int skip, int count, string order, string mediaType, VersionOptions versionOptions = null) {
|
||||
var query = _orchardServices.ContentManager.Query<MediaPart>(versionOptions);
|
||||
|
||||
if (!String.IsNullOrEmpty(mediaType)) {
|
||||
query = query.ForType(new[] { mediaType });
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(folderPath)) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath == folderPath);
|
||||
}
|
||||
|
||||
switch(order) {
|
||||
case "title":
|
||||
return query.Join<TitlePartRecord>()
|
||||
.OrderBy(x => x.Title)
|
||||
.Slice(skip, count)
|
||||
.ToArray();
|
||||
|
||||
case "modified":
|
||||
return query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.ModifiedUtc)
|
||||
.Slice(skip, count)
|
||||
.ToArray();
|
||||
|
||||
case "published":
|
||||
return query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.PublishedUtc)
|
||||
.Slice(skip, count)
|
||||
.ToArray();
|
||||
|
||||
default:
|
||||
return query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.CreatedUtc)
|
||||
.Slice(skip, count)
|
||||
.ToArray();
|
||||
}
|
||||
return BuildGetMediaContentItemsQuery(_orchardServices.ContentManager, folderPath, order: order, mediaType: mediaType, versionOptions: versionOptions)
|
||||
.Slice(skip, count);
|
||||
}
|
||||
|
||||
public IEnumerable<MediaPart> GetMediaContentItems(int skip, int count, string order, string mediaType, VersionOptions versionOptions = null) {
|
||||
return GetMediaContentItems(null, skip, count, order, mediaType);
|
||||
return GetMediaContentItems(null, skip, count, order, mediaType, versionOptions);
|
||||
}
|
||||
|
||||
public int GetMediaContentItemsCount(string folderPath, string mediaType, VersionOptions versionOptions = null) {
|
||||
var query = _orchardServices.ContentManager.Query<MediaPart>(versionOptions);
|
||||
|
||||
if (!String.IsNullOrEmpty(mediaType)) {
|
||||
query = query.ForType(new[] { mediaType });
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(folderPath)) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath == folderPath);
|
||||
}
|
||||
|
||||
return query.Count();
|
||||
return BuildGetMediaContentItemsQuery(_orchardServices.ContentManager, folderPath, mediaType: mediaType, versionOptions: versionOptions)
|
||||
.Count();
|
||||
}
|
||||
|
||||
public int GetMediaContentItemsCount(string mediaType, VersionOptions versionOptions = null) {
|
||||
return GetMediaContentItemsCount(null, mediaType, versionOptions);
|
||||
}
|
||||
|
||||
private static IContentQuery<MediaPart> BuildGetMediaContentItemsQuery(
|
||||
IContentManager contentManager, string folderPath = null, bool recursive = false, string order = null, string mediaType = null, VersionOptions versionOptions = null) {
|
||||
|
||||
var query = contentManager.Query<MediaPart>(versionOptions);
|
||||
|
||||
if (!String.IsNullOrEmpty(mediaType)) {
|
||||
query = query.ForType(new[] { mediaType });
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(folderPath)) {
|
||||
if (recursive) {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath.StartsWith(folderPath));
|
||||
}
|
||||
else {
|
||||
query = query.Join<MediaPartRecord>().Where(m => m.FolderPath == folderPath);
|
||||
}
|
||||
}
|
||||
|
||||
switch (order) {
|
||||
case "title":
|
||||
query = query.Join<TitlePartRecord>()
|
||||
.OrderBy(x => x.Title)
|
||||
.Join<MediaPartRecord>();
|
||||
break;
|
||||
|
||||
case "modified":
|
||||
query = query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.ModifiedUtc)
|
||||
.Join<MediaPartRecord>();
|
||||
break;
|
||||
|
||||
case "published":
|
||||
query = query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.PublishedUtc)
|
||||
.Join<MediaPartRecord>();
|
||||
break;
|
||||
|
||||
default:
|
||||
query = query.Join<CommonPartRecord>()
|
||||
.OrderByDescending(x => x.CreatedUtc)
|
||||
.Join<MediaPartRecord>();
|
||||
break;
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
public MediaPart ImportMedia(Stream stream, string relativePath, string filename) {
|
||||
return ImportMedia(stream, relativePath, filename, null);
|
||||
}
|
||||
@@ -267,7 +272,21 @@ namespace Orchard.MediaLibrary.Services {
|
||||
Argument.ThrowIfNullOrEmpty(folderPath, "folderPath");
|
||||
Argument.ThrowIfNullOrEmpty(newFolderName, "newFolderName");
|
||||
|
||||
_storageProvider.RenameFolder(folderPath, _storageProvider.Combine(Path.GetDirectoryName(folderPath), newFolderName));
|
||||
try {
|
||||
var segments = folderPath.Split(new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries).ToArray();
|
||||
var newFolderPath = String.Join(Path.DirectorySeparatorChar.ToString(), segments.Take(segments.Length - 1).Union(new[] { newFolderName }));
|
||||
|
||||
var mediaParts = BuildGetMediaContentItemsQuery(_orchardServices.ContentManager, folderPath, true).List();
|
||||
foreach (var mediaPart in mediaParts) {
|
||||
mediaPart.FolderPath = newFolderPath + mediaPart.FolderPath.Substring(folderPath.Length);
|
||||
}
|
||||
|
||||
_storageProvider.RenameFolder(folderPath, _storageProvider.Combine(Path.GetDirectoryName(folderPath), newFolderName));
|
||||
}
|
||||
catch (Exception) {
|
||||
_orchardServices.TransactionManager.Cancel();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user