Skip to content

Commit

Permalink
Fixing merge
Browse files Browse the repository at this point in the history
  • Loading branch information
BenedekFarkas committed Apr 19, 2024
1 parent 0bce8e6 commit 23fb9df
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<Compile Include="Services\LocalizationService.cs" />
<Compile Include="Services\TransliterationService.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\EditLocalizationViewModel.cs" />
<Compile Include="ViewModels\CreateTransliterationViewModel.cs" />
Expand Down Expand Up @@ -195,6 +198,8 @@
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<Content Include="Views\UserCultureSelector.cshtml" />
<Content Include="Views\DefinitionTemplates\LocalizationCultureNeutralitySettings.cshtml" />
</ItemGroup>
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class LocalizationService : ILocalizationService {
return null;
}

if (localized?.Culture.Culture == culture) return localized;
if (localized.Culture?.Culture == culture) return localized;

return GetLocalizationsQuery(localized, versionOptions)
.Where<LocalizationPartRecord>(localization => localization.CultureId == cultureRecord.Id)
Expand Down Expand Up @@ -74,35 +74,10 @@ public class LocalizationService : ILocalizationService {
var localized = content.As<LocalizationPart>();

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();
}


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) {
route = _contentManager.Query<AutoroutePart, AutoroutePartRecord>()
.ForVersion(VersionOptions.Published)
Expand Down Expand Up @@ -145,5 +120,23 @@ public class LocalizationService : ILocalizationService {

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Linq;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Handlers;
using Orchard.FileSystems.Media;
using Orchard.Localization;
using Orchard.Logging;
Expand Down Expand Up @@ -186,13 +187,15 @@ public class ClientStorageController : Controller {
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;
}
Expand Down

0 comments on commit 23fb9df

Please sign in to comment.