generated from Kentico/repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace all references to migration toolkit by migration tool
Refactor: Replace all references to migration toolkit by migration tool
- Loading branch information
Showing
2,675 changed files
with
76,555 additions
and
76,537 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...it.Source/Auxiliary/EntityIdentityImpl.cs → ...ol.Source/Auxiliary/EntityIdentityImpl.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...oolkit.Source/Auxiliary/NodeXmlAdapter.cs → ...n.Tool.Source/Auxiliary/NodeXmlAdapter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
KVA/Migration.Tool.Source/Behaviors/CommandConstraintBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
using MediatR; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Migration.Tool.Common.Abstractions; | ||
using Migration.Tool.Common.MigrationProtocol; | ||
using Migration.Tool.Source.Model; | ||
|
||
namespace Migration.Tool.Source.Behaviors; | ||
|
||
public class CommandConstraintBehavior<TRequest, TResponse>( | ||
ILogger<CommandConstraintBehavior<TRequest, TResponse>> logger, | ||
IMigrationProtocol protocol, | ||
ModelFacade modelFacade) | ||
: IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : IRequest<TResponse> | ||
where TResponse : CommandResult | ||
{ | ||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
{ | ||
try | ||
{ | ||
bool criticalCheckPassed = PerformChecks(request); | ||
if (!criticalCheckPassed) | ||
{ | ||
return (TResponse)(CommandResult)new CommandCheckFailedResult(criticalCheckPassed); | ||
} | ||
} | ||
catch (Exception ex) | ||
{ | ||
protocol.CommandError<TRequest, TResponse>(ex, request); | ||
logger.LogCritical(ex, "Error occured while checking command constraints"); | ||
return (TResponse)(CommandResult)new CommandCheckFailedResult(false); | ||
} | ||
|
||
return await next(); | ||
} | ||
|
||
private bool PerformChecks(TRequest request) | ||
{ | ||
bool criticalCheckPassed = true; | ||
|
||
var sourceSites = modelFacade.SelectAll<ICmsSite>() | ||
.ToList(); | ||
|
||
foreach (var site in sourceSites) | ||
{ | ||
criticalCheckPassed &= CheckSite(sourceSites, site.SiteID); | ||
} | ||
|
||
|
||
if (request is ICultureReliantCommand cultureReliantCommand) | ||
{ | ||
var cultures = modelFacade.SelectAll<ICmsCulture>().ToList(); | ||
var siteCultures = modelFacade.SelectAll<ICmsSiteCulture>().ToList(); | ||
criticalCheckPassed &= CheckCulture(cultureReliantCommand, sourceSites, cultures, siteCultures); | ||
} | ||
|
||
return criticalCheckPassed; | ||
} | ||
|
||
private bool CheckSite(List<ICmsSite> sourceSites, int sourceSiteId) | ||
{ | ||
bool criticalCheckPassed = true; | ||
if (sourceSites.All(s => s.SiteID != sourceSiteId)) | ||
{ | ||
var supportedSites = sourceSites.Select(x => new { x.SiteName, x.SiteID }).ToArray(); | ||
string supportedSitesStr = string.Join(", ", supportedSites.Select(x => x.ToString())); | ||
logger.LogCritical("Unable to find site with ID '{SourceSiteId}'. Check --siteId parameter. Supported sites: {SupportedSites}", sourceSiteId, | ||
supportedSitesStr); | ||
protocol.Append(HandbookReferences.CommandConstraintBroken("Site exists") | ||
.WithMessage("Check program argument '--siteId'") | ||
.WithData(new { sourceSiteId, AvailableSites = supportedSites })); | ||
criticalCheckPassed = false; | ||
} | ||
|
||
return criticalCheckPassed; | ||
} | ||
|
||
private bool CheckCulture(ICultureReliantCommand cultureReliantCommand, List<ICmsSite> sourceSites, List<ICmsCulture> cultures, List<ICmsSiteCulture> cmsSiteCultures) | ||
{ | ||
bool criticalCheckPassed = true; | ||
string cultureCode = cultureReliantCommand.CultureCode; | ||
|
||
foreach (var site in sourceSites) | ||
{ | ||
string?[] siteCultures = cmsSiteCultures | ||
.Where(x => x.SiteID == site.SiteID) | ||
.Select(x => cultures.FirstOrDefault(c => c.CultureID == x.CultureID)?.CultureCode) | ||
.Where(x => !string.IsNullOrWhiteSpace(x)) | ||
.ToArray(); | ||
|
||
if (!siteCultures.Contains(cultureCode.ToLowerInvariant())) | ||
{ | ||
string supportedCultures = string.Join(", ", siteCultures); | ||
logger.LogCritical("Unable to find culture '{Culture}' mapping to site '{SiteId}'. Check --culture parameter. Supported cultures for site: {SupportedCultures}", cultureCode, | ||
site.SiteID, supportedCultures); | ||
protocol.Append(HandbookReferences.CommandConstraintBroken("Culture is mapped to site") | ||
.WithMessage("Check program argument '--culture'") | ||
.WithData(new { cultureCode, site.SiteID, SiteCultures = supportedCultures })); | ||
criticalCheckPassed = false; | ||
} | ||
} | ||
|
||
return criticalCheckPassed; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
KVA/Migration.Tool.Source/Behaviors/RequestHandlingBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System.Diagnostics; | ||
|
||
using MediatR; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Migration.Tool.Common.Abstractions; | ||
using Migration.Tool.Common.MigrationProtocol; | ||
|
||
namespace Migration.Tool.Source.Behaviors; | ||
|
||
public class RequestHandlingBehavior<TRequest, TResponse>( | ||
ILogger<RequestHandlingBehavior<TRequest, TResponse>> logger, | ||
IMigrationProtocol protocol) : IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : IRequest<TResponse> | ||
where TResponse : CommandResult | ||
{ | ||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
{ | ||
var sw = Stopwatch.StartNew(); | ||
logger.LogInformation("Handling {CommandName}", typeof(TRequest).Name); | ||
try | ||
{ | ||
protocol.CommandRequest<TRequest, TResponse>(request); | ||
var response = await next(); | ||
protocol.CommandFinished(request, response); | ||
return response; | ||
} | ||
catch (Exception ex) | ||
{ | ||
protocol.CommandError<TRequest, TResponse>(ex, request); | ||
logger.LogError(ex, "Error occured"); | ||
throw; | ||
} | ||
finally | ||
{ | ||
logger.LogInformation("Handled {CommandName} in elapsed: {Elapsed}", typeof(TRequest).Name, sw.Elapsed); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
KVA/Migration.Tool.Source/Behaviors/XbKApiContextBehavior.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using CMS.Base; | ||
using CMS.Membership; | ||
|
||
using MediatR; | ||
|
||
using Microsoft.Extensions.Logging; | ||
|
||
using Migration.Tool.Common.Abstractions; | ||
using Migration.Tool.Common.MigrationProtocol; | ||
using Migration.Tool.KXP.Api; | ||
|
||
namespace Migration.Tool.Source.Behaviors; | ||
|
||
public class XbKApiContextBehavior<TRequest, TResponse>( | ||
ILogger<XbKApiContextBehavior<TRequest, TResponse>> logger, | ||
IMigrationProtocol protocol, | ||
KxpApiInitializer initializer) | ||
: IPipelineBehavior<TRequest, TResponse> | ||
where TRequest : IRequest<TResponse> | ||
where TResponse : CommandResult | ||
{ | ||
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) | ||
{ | ||
initializer.EnsureApiIsInitialized(); | ||
|
||
var defaultAdmin = UserInfoProvider.ProviderObject.Get(UserInfoProvider.DEFAULT_ADMIN_USERNAME); | ||
if (defaultAdmin == null) | ||
{ | ||
protocol.Append(HandbookReferences | ||
.MissingRequiredDependency<UserInfo>() | ||
.WithMessage($"Target XbK doesn't contain default administrator account ('{UserInfoProvider.DEFAULT_ADMIN_USERNAME}'). Default administrator account is required for migration.") | ||
); | ||
throw new InvalidOperationException($"Target XbK doesn't contain default administrator account ('{UserInfoProvider.DEFAULT_ADMIN_USERNAME}')"); | ||
} | ||
|
||
using (new CMSActionContext(defaultAdmin) { User = defaultAdmin, UseGlobalAdminContext = true }) | ||
{ | ||
logger.LogInformation("Using CMSActionContext of user '{UserName}'", UserInfoProvider.DEFAULT_ADMIN_USERNAME); | ||
return await next(); | ||
} | ||
} | ||
} |
Oops, something went wrong.