diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj b/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj
index 2a88f828f..80b4bd1c9 100644
--- a/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj
+++ b/src/Orchard.Web/Modules/Orchard.Localization/Orchard.Localization.csproj
@@ -121,6 +121,9 @@
+
+
+
@@ -195,6 +198,8 @@
+
+
10.0
diff --git a/src/Orchard.Web/Modules/Orchard.Localization/Services/LocalizationService.cs b/src/Orchard.Web/Modules/Orchard.Localization/Services/LocalizationService.cs
index 7d8c75c76..b0e1fccb5 100644
--- a/src/Orchard.Web/Modules/Orchard.Localization/Services/LocalizationService.cs
+++ b/src/Orchard.Web/Modules/Orchard.Localization/Services/LocalizationService.cs
@@ -41,7 +41,7 @@ namespace Orchard.Localization.Services {
return null;
}
- if (localized?.Culture.Culture == culture) return localized;
+ if (localized.Culture?.Culture == culture) return localized;
return GetLocalizationsQuery(localized, versionOptions)
.Where(localization => localization.CultureId == cultureRecord.Id)
@@ -74,35 +74,10 @@ namespace Orchard.Localization.Services {
var localized = content.As();
return GetLocalizationsQuery(localized, versionOptions)
- .Where(l => l.Id != localized.Id) // Exclude the current content.
+ .Where(localization => localization.Id != localized.Id) // Exclude the current content.
.List();
}
-
- private IContentQuery GetLocalizationsQuery(LocalizationPart localizationPart, VersionOptions versionOptions) {
- var masterId = localizationPart.HasTranslationGroup ?
- localizationPart.Record.MasterContentItemId : localizationPart.Id;
-
- var query = versionOptions == null ?
- _contentManager.Query(localized.ContentItem.ContentType) :
- _contentManager.Query(versionOptions, localized.ContentItem.ContentType);
-
- int contentItemId = localized.ContentItem.Id;
-
- if (localized.HasTranslationGroup) {
- int masterContentItemId = localized.MasterContentItem.ContentItem.Id;
-
- query = query.Where(localization =>
- localization.Id != contentItemId && // Exclude the content
- (localization.Id == masterContentItemId || localization.MasterContentItemId == masterContentItemId));
- }
- else {
- query = query.Where(localization => localization.MasterContentItemId == contentItemId);
- }
-
- return query.List().ToList();
- }
-
public bool TryGetRouteForUrl(string url, out AutoroutePart route) {
route = _contentManager.Query()
.ForVersion(VersionOptions.Published)
@@ -145,5 +120,23 @@ namespace Orchard.Localization.Services {
return localizedRoute != null;
}
+
+ ///
+ /// Warning: May contain more than one localization of the same culture.
+ ///
+ private IContentQuery GetLocalizationsQuery(LocalizationPart localizationPart, VersionOptions versionOptions) {
+ var masterId = localizationPart.HasTranslationGroup
+ ? localizationPart.Record.MasterContentItemId
+ : localizationPart.Id;
+
+ var query = _contentManager.Query(localizationPart.ContentItem.ContentType);
+
+ if (versionOptions == null) {
+ query = query.ForVersion(versionOptions);
+ }
+
+ return query
+ .Where(localization => localization.Id == masterId || localization.MasterContentItemId == masterId);
+ }
}
}
diff --git a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs
index 23df7a2a7..fc61e3c63 100644
--- a/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs
+++ b/src/Orchard.Web/Modules/Orchard.MediaLibrary/Controllers/ClientStorageController.cs
@@ -4,6 +4,7 @@ using System.IO;
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement;
+using Orchard.ContentManagement.Handlers;
using Orchard.FileSystems.Media;
using Orchard.Localization;
using Orchard.Logging;
@@ -186,13 +187,15 @@ namespace Orchard.MediaLibrary.Controllers {
if (mediaItemsUsingTheFile == 1) { // if the file is referenced only by the deleted media content, the file too can be removed.
try {
_mediaLibraryService.DeleteFile(replaceMedia.FolderPath, replaceMedia.FileName);
- } catch (ArgumentException) { // File not found by FileSystemStorageProvider is thrown as ArgumentException.
+ }
+ catch (ArgumentException) { // File not found by FileSystemStorageProvider is thrown as ArgumentException.
statuses.Add(new {
error = T("Error when deleting file to replace: file {0} does not exist in folder {1}. Media has been updated anyway.", replaceMedia.FileName, replaceMedia.FolderPath).Text,
progress = 1.0
});
}
- } else {
+ }
+ else {
// it changes the media file name
replaceMedia.FileName = filename;
}