mirror of https://github.com/Squidex/squidex.git
19 changed files with 177 additions and 24 deletions
@ -0,0 +1,22 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System.Collections.Generic; |
||||
|
using Squidex.Infrastructure; |
||||
|
|
||||
|
namespace Squidex.Domain.Apps.Entities.Assets |
||||
|
{ |
||||
|
public static class AssetSlug |
||||
|
{ |
||||
|
private static readonly HashSet<char> Dot = new HashSet<char>(new[] { '.' }); |
||||
|
|
||||
|
public static string ToAssetSlug(this string value) |
||||
|
{ |
||||
|
return value.Slugify(Dot); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
// ==========================================================================
|
||||
|
// Squidex Headless CMS
|
||||
|
// ==========================================================================
|
||||
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
||||
|
// All rights reserved. Licensed under the MIT license.
|
||||
|
// ==========================================================================
|
||||
|
|
||||
|
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
using Squidex.Domain.Apps.Entities.Assets; |
||||
|
using Squidex.Domain.Apps.Entities.Assets.State; |
||||
|
using Squidex.Infrastructure.Migrations; |
||||
|
using Squidex.Infrastructure.States; |
||||
|
|
||||
|
namespace Migrate_01.Migrations |
||||
|
{ |
||||
|
public sealed class CreateAssetSlugs : IMigration |
||||
|
{ |
||||
|
private readonly ISnapshotStore<AssetState, Guid> stateForAssets; |
||||
|
|
||||
|
public CreateAssetSlugs(ISnapshotStore<AssetState, Guid> stateForAssets) |
||||
|
{ |
||||
|
this.stateForAssets = stateForAssets; |
||||
|
} |
||||
|
|
||||
|
public Task UpdateAsync() |
||||
|
{ |
||||
|
return stateForAssets.ReadAllAsync(async (state, version) => |
||||
|
{ |
||||
|
state.FileNameSlug = state.FileName.ToAssetSlug(); |
||||
|
|
||||
|
await stateForAssets.WriteAsync(state.Id, state, version, version); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue