Skip to content

Commit

Permalink
better progress messages during migration. (bye bye sims messages)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Nov 23, 2023
1 parent 64f3e56 commit 28f1b59
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';

function dashboardController($q,
uSyncMigrationService, uSync8DashboardService,
uSyncMigrationService, uSyncHub,
editorService, notificationsService, navigationService) {

var vm = this;
Expand All @@ -26,6 +26,7 @@

vm.$onInit = function () {
vm.loading = false;
InitHub();
navigationService.syncTree({ tree: "uSyncMigrations", path: "-1" });
}

Expand Down Expand Up @@ -112,6 +113,8 @@
vm.step = 'migrating';
vm.working = true;

vm.migrationStatus.clientId = getClientId();

uSyncMigrationService.migrate(vm.migrationStatus)
.then(function (result) {
vm.state = 'success';
Expand Down Expand Up @@ -149,6 +152,46 @@
vm.step = 'start';
}
}

////// SignalR things
function InitHub() {
uSyncHub.initHub(function (hub) {

vm.hub = hub;

vm.hub.on('add', function (data) {
vm.status = data;
console.log('add', data);
});

vm.hub.on('update', function (update) {
console.log('update', update);

var percentage = 0;
if (vm.update !== undefined && vm.update.percentage !== undefined) {
percentage = vm.update.percentage;
}

vm.update = update;

if (update.total > 0) {
vm.update.percentage = Math.round((update.count / update.total) * 100);
}
else {
vm.update.percentage = percentage;
}
});

vm.hub.start();
});
}

function getClientId() {
if ($.connection !== undefined) {
return $.connection.connectionId;
}
return "";
}
}

angular.module('umbraco').controller('uSyncMigrationDashboardController', dashboardController);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>
<umb-button action="vm.showValidation = !vm.showValidation"
label-key="usyncmigrate_showValidation"
button-style="link"></umb-button>

</div>
</div>
</umb-control-group>
Expand Down Expand Up @@ -142,7 +142,7 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>
</usync-migration-results>
</div>
</div>

<div ng-if="vm.sourceValid && !vm.migrationStatus.migrated">
<div class="flex justify-center flex-column items-center">
<umb-button action="vm.migrate()"
Expand All @@ -162,9 +162,16 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>
<div ng-if="vm.step == 'migrating'">

<div ng-if="vm.working">
<usync-migration-messages working="vm.working"></usync-migration-messages>
<umb-load-indicator>xxxxx</umb-load-indicator>
<div style="position: absolute; top: 55%; left: 0; width: 100%; display:flex; align-items: center; flex-direction:column;">
<div>{{vm.update.message}}</div>
<div style="width:50%;margin-top:30px;">
<umb-progress-bar percentage="{{vm.update.percentage}}"
size="m"
color="secondary"></umb-progress-bar>
</div>
</div>
</div>

</div>

<div ng-if="vm.step == 'migrated'">
Expand Down Expand Up @@ -199,11 +206,11 @@ <h2><localize key="usyncmigrate_convertTitle"></localize></h2>

<umb-editor-footer>
<umb-editor-footer-content-left>
<umb-button ng-if="vm.step != 'init'"
action="vm.goBack()"
label-key="general_back"
icon="icon-arrow-left"
button-style="link"></umb-button>
<umb-button ng-if="vm.step != 'init'"
action="vm.goBack()"
label-key="general_back"
icon="icon-arrow-left"
button-style="link"></umb-button>
</umb-editor-footer-content-left>
</umb-editor-footer>
</umb-editor-view>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
vm.$onInit = function () {

getHandlerGroups();
InitHub();
// InitHub();
}

// work out what import options we have
Expand Down Expand Up @@ -125,6 +125,8 @@

function report(group) {

InitHub();

if (vm.working === true) return;
vm.progress = 'reporting';

Expand Down Expand Up @@ -161,6 +163,8 @@

function importItems(group) {

InitHub();

var folder = vm.folder;

if (vm.working === true) return;
Expand Down Expand Up @@ -327,6 +331,9 @@
////// SignalR things

function InitHub() {

if (vm.hub != null) { return; }

uSyncHub.initHub(function (hub) {

vm.hub = hub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
vm.working = true;
vm.state = 'busy';
vm.progress = 'migrating'
vm.options.clientId = getClientId();

doMigrationMessages();
// doMigrationMessages();

uSyncMigrationService.migrate(vm.options)
.then(function (result) {
Expand Down Expand Up @@ -382,8 +383,6 @@
$timeout(function () { doMigrationMessages(); }, 2281);
}
}


}

angular.module('umbraco')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

using uSync.BackOffice;
using uSync.Migrations.Core.Models;

namespace uSync.Migrations.Core.Configuration.Models;
Expand Down Expand Up @@ -65,6 +66,11 @@ public class MigrationOptions
/// Mapping of old to new content type aliases
/// </summary>
public IDictionary<string, string>? ReplacementAliases { get; set; }

/// <summary>
/// client id for signalR
/// </summary>
public uSyncCallbacks? Callbacks { get; set; }
}

[JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))]
Expand Down
3 changes: 2 additions & 1 deletion uSync.Migrations.Core/Context/MigratorsContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using uSync.Migrations.Core.Migrators;
using uSync.BackOffice;
using uSync.Migrations.Core.Migrators;

namespace uSync.Migrations.Core.Context;

Expand Down
16 changes: 15 additions & 1 deletion uSync.Migrations.Core/Context/SyncMigrationContext.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace uSync.Migrations.Core.Context;
using uSync.BackOffice;

namespace uSync.Migrations.Core.Context;

/// <summary>
/// A uSync migration context, lets us keep a whole list of things in memory while we do the migration.
Expand Down Expand Up @@ -86,4 +88,16 @@ public int GetId(Guid key)
public void Dispose()
{ }


/// <summary>
/// the callback functions for sending information to the client.
/// </summary>
public uSyncCallbacks? Callbacks { get; set; }

public void SendUpdate(string message, int count, int total)
{
Callbacks?.Update(message, count, total);
}


}
11 changes: 9 additions & 2 deletions uSync.Migrations.Core/Handlers/MigrationHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ public virtual void PrepareMigrations(SyncMigrationContext context)
{
Stopwatch sw = Stopwatch.StartNew();

_logger.LogInformation("[{type}] Preparing Migration {source}", typeof(TObject).Name, context.Metadata.SourceFolder);
var typeName = typeof(TObject).Name;

context.SendUpdate($"Preparing : {typeName}", 0, 0);

_logger.LogInformation("[{type}] Preparing Migration {source}", typeName, context.Metadata.SourceFolder);
var files = GetSourceFiles(context.Metadata.SourceFolder);
if (files == null)
{
Expand Down Expand Up @@ -152,7 +156,8 @@ private IEnumerable<MigrationMessage> MigrateFolder(string folder, int level, Sy

var messages = new List<MigrationMessage>();

foreach (var file in files)

foreach(var file in files)
{
try
{
Expand All @@ -170,6 +175,8 @@ private IEnumerable<MigrationMessage> MigrateFolder(string folder, int level, Sy
continue;
}

context.SendUpdate($"Migrating {alias}", 0, 0);

var target = MigrateFile(source, level, context);

if (target != null)
Expand Down
7 changes: 7 additions & 0 deletions uSync.Migrations.Core/Models/MigrationStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,12 @@ public class MigrationStatus
/// the profile we are going to use for this migration
/// </summary>
public string? Plan { get; set; }


/// <summary>
/// SignalR client id, can be used to send messages back to the client.
/// </summary>
public string ClientId { get; set; } = string.Empty;

}

Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ public SyncMigratingNotification(XElement xml, SyncMigrationContext context)
Context = context;
LegacyXml = xml;
}
}
}
19 changes: 16 additions & 3 deletions uSync.Migrations.Core/Services/SyncMigrationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ public MigrationResults MigrateFiles(MigrationOptions options)

if (success == true && results.Any())
{
migrationContext.SendUpdate("Copying to final folder", 9, 10);

// here...
_logger.LogInformation("Copying from working to folder {targetRoot}", targetRoot);

Expand All @@ -156,6 +158,8 @@ public MigrationResults MigrateFiles(MigrationOptions options)
sw.Stop();
_logger.LogInformation("Migration Complete {success} {count} ({elapsed}ms)", success, results.Count(), sw.ElapsedMilliseconds);

migrationContext.SendUpdate("Migration complete", 10, 10);

return new MigrationResults
{
Success = success,
Expand Down Expand Up @@ -183,10 +187,14 @@ private IEnumerable<MigrationMessage> MigrateFromDisk(Guid migrationId, string s
// maybe replace with a Dictionary<string, MigrationMessage> (with `ItemType` as the key)?
var results = new List<MigrationMessage>();

foreach (var handler in handlers)
for(int i =0; i < handlers.Count; i++)
{
_logger.LogInformation("Migrating {handler} files", handler.GetType().Name);
results.AddRange(handler.DoMigration(migrationContext));
var handlerName = handlers[i].GetType().Name;

migrationContext.SendUpdate($"Migrating {handlerName}", i, handlers.Count);
_logger.LogInformation("Migrating {handler} files", handlerName);

results.AddRange(handlers[i].DoMigration(migrationContext));
}

return results;
Expand All @@ -200,6 +208,9 @@ private SyncMigrationContext PrepareContext(Guid migrationId, string sourceRoot,
var siteFolderIsSameAsWebsite = siteFolder.Equals(_migrationFileService.GetWebSitePath("/"));

var context = new SyncMigrationContext(migrationId, sourceRoot, siteFolder, siteFolderIsSameAsWebsite, options.SourceVersion);
context.Callbacks = options.Callbacks;

context.SendUpdate("Preparing Migration", 0, 10);

if (options.BlockListViews)
{
Expand Down Expand Up @@ -240,6 +251,8 @@ private SyncMigrationContext PrepareContext(Guid migrationId, string sourceRoot,
options.ReplacementAliases?
.ForEach(kvp => context.ContentTypes.AddReplacementAlias(kvp.Key, kvp.Value));

context.SendUpdate("Preparing Migration handlers", 5,10);

// let the handlers run through their prep (populate all the lookups)
GetHandlers(options.SourceVersion)?
.OrderBy(x => x.Priority)
Expand Down
Loading

0 comments on commit 28f1b59

Please sign in to comment.