Fixing merge

This commit is contained in:
Benedek Farkas 2024-04-19 15:34:59 +02:00
parent 0bce8e634b
commit 23fb9dff92
3 changed files with 30 additions and 29 deletions

View File

@ -121,6 +121,9 @@
<Compile Include="Services\LocalizationService.cs" /> <Compile Include="Services\LocalizationService.cs" />
<Compile Include="Services\TransliterationService.cs" /> <Compile Include="Services\TransliterationService.cs" />
<Compile Include="Events\TransliterationSlugEventHandler.cs" /> <Compile Include="Events\TransliterationSlugEventHandler.cs" />
<Compile Include="Services\Utils.cs" />
<Compile Include="Settings\LocalizationCultureNeutralityEditorEvents.cs" />
<Compile Include="Settings\LocalizationCultureNeutralitySettings.cs" />
<Compile Include="ViewModels\ContentLocalizationsViewModel.cs" /> <Compile Include="ViewModels\ContentLocalizationsViewModel.cs" />
<Compile Include="ViewModels\EditLocalizationViewModel.cs" /> <Compile Include="ViewModels\EditLocalizationViewModel.cs" />
<Compile Include="ViewModels\CreateTransliterationViewModel.cs" /> <Compile Include="ViewModels\CreateTransliterationViewModel.cs" />
@ -195,6 +198,8 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="packages.config" /> <None Include="packages.config" />
<Content Include="Views\UserCultureSelector.cshtml" />
<Content Include="Views\DefinitionTemplates\LocalizationCultureNeutralitySettings.cshtml" />
</ItemGroup> </ItemGroup>
<PropertyGroup> <PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion> <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>

View File

@ -41,7 +41,7 @@ namespace Orchard.Localization.Services {
return null; return null;
} }
if (localized?.Culture.Culture == culture) return localized; if (localized.Culture?.Culture == culture) return localized;
return GetLocalizationsQuery(localized, versionOptions) return GetLocalizationsQuery(localized, versionOptions)
.Where<LocalizationPartRecord>(localization => localization.CultureId == cultureRecord.Id) .Where<LocalizationPartRecord>(localization => localization.CultureId == cultureRecord.Id)
@ -74,35 +74,10 @@ namespace Orchard.Localization.Services {
var localized = content.As<LocalizationPart>(); var localized = content.As<LocalizationPart>();
return GetLocalizationsQuery(localized, versionOptions) return GetLocalizationsQuery(localized, versionOptions)
.Where<LocalizationPartRecord>(l => l.Id != localized.Id) // Exclude the current content. .Where<LocalizationPartRecord>(localization => localization.Id != localized.Id) // Exclude the current content.
.List(); .List();
} }
private IContentQuery<LocalizationPart> GetLocalizationsQuery(LocalizationPart localizationPart, VersionOptions versionOptions) {
var masterId = localizationPart.HasTranslationGroup ?
localizationPart.Record.MasterContentItemId : localizationPart.Id;
var query = versionOptions == null ?
_contentManager.Query<LocalizationPart>(localized.ContentItem.ContentType) :
_contentManager.Query<LocalizationPart>(versionOptions, localized.ContentItem.ContentType);
int contentItemId = localized.ContentItem.Id;
if (localized.HasTranslationGroup) {
int masterContentItemId = localized.MasterContentItem.ContentItem.Id;
query = query.Where<LocalizationPartRecord>(localization =>
localization.Id != contentItemId && // Exclude the content
(localization.Id == masterContentItemId || localization.MasterContentItemId == masterContentItemId));
}
else {
query = query.Where<LocalizationPartRecord>(localization => localization.MasterContentItemId == contentItemId);
}
return query.List().ToList();
}
public bool TryGetRouteForUrl(string url, out AutoroutePart route) { public bool TryGetRouteForUrl(string url, out AutoroutePart route) {
route = _contentManager.Query<AutoroutePart, AutoroutePartRecord>() route = _contentManager.Query<AutoroutePart, AutoroutePartRecord>()
.ForVersion(VersionOptions.Published) .ForVersion(VersionOptions.Published)
@ -145,5 +120,23 @@ namespace Orchard.Localization.Services {
return localizedRoute != null; return localizedRoute != null;
} }
/// <summary>
/// Warning: May contain more than one localization of the same culture.
/// </summary>
private IContentQuery<LocalizationPart> GetLocalizationsQuery(LocalizationPart localizationPart, VersionOptions versionOptions) {
var masterId = localizationPart.HasTranslationGroup
? localizationPart.Record.MasterContentItemId
: localizationPart.Id;
var query = _contentManager.Query<LocalizationPart>(localizationPart.ContentItem.ContentType);
if (versionOptions == null) {
query = query.ForVersion(versionOptions);
}
return query
.Where<LocalizationPartRecord>(localization => localization.Id == masterId || localization.MasterContentItemId == masterId);
}
} }
} }

View File

@ -4,6 +4,7 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.ContentManagement; using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.FileSystems.Media; using Orchard.FileSystems.Media;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; 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. if (mediaItemsUsingTheFile == 1) { // if the file is referenced only by the deleted media content, the file too can be removed.
try { try {
_mediaLibraryService.DeleteFile(replaceMedia.FolderPath, replaceMedia.FileName); _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 { 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, 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 progress = 1.0
}); });
} }
} else { }
else {
// it changes the media file name // it changes the media file name
replaceMedia.FileName = filename; replaceMedia.FileName = filename;
} }