Skip to content

Commit

Permalink
Fix logging migration.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Apr 12, 2024
1 parent c089d81 commit f3ecaf1
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions uSync.BackOffice/Boot/LogViewerMigration.cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
using System;
using System.Linq;

using Umbraco.Cms.Core.Logging.Viewer;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Infrastructure.Migrations;

namespace uSync.BackOffice.Boot;
internal class LogViewerMigration : MigrationBase
{
private static string _uSyncLogQuery = "StartsWith(SourceContext, 'uSync')";

private readonly ILogViewerConfig _logViewerConfig;
private readonly ILogViewerService _logViewerService;

public LogViewerMigration(
ILogViewerConfig config,
ILogViewerService logViewerService,
IMigrationContext context) : base(context)
{
_logViewerConfig = config;
_logViewerService = logViewerService;
}

protected override void Migrate()
{
var existing = _logViewerConfig.GetSavedSearches()
.FirstOrDefault(x => x.Query.StartsWith(_uSyncLogQuery, StringComparison.OrdinalIgnoreCase));
var name = "Find all uSync Log Entries";

var existing = _logViewerService.GetSavedLogQueryByNameAsync(name).Result;
if (existing != null) return;

_logViewerConfig.AddSavedSearch("Find all uSync Log Entries", _uSyncLogQuery);

_logViewerService
.AddSavedLogQueryAsync(name, _uSyncLogQuery).Wait();

}
}

0 comments on commit f3ecaf1

Please sign in to comment.