Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions uSync.AutoTemplates/AutoTemplateComposer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Umbraco.Cms.Core.Composing;
using System.Linq;

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

namespace uSync.AutoTemplates;
Expand All @@ -7,6 +9,8 @@ public class AutoTemplateComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.AdduSyncAutoTemplates();
// only load when the backoffice is enabled.
if (builder.Services.Any(s => s.ServiceType == typeof(IBackOfficeEnabledMarker)))
builder.AdduSyncAutoTemplates();
}
}
4 changes: 3 additions & 1 deletion uSync.BackOffice/Extensions/uSyncActionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ public static void UpdateActions<TObject>(this List<uSyncAction> actions, Guid k
public static bool RequiresSave<TObject>(this SyncAttempt<TObject> attempt)
=> attempt.Success && attempt.Change > Core.ChangeType.NoChange && !attempt.Saved && attempt.Item != null;


/// <summary>
/// return the uSyncAction as an ActionView (used in the controllers)
/// </summary>
public static uSyncActionView AsActionView(this uSyncAction action)
{
var msg = string.IsNullOrWhiteSpace(action.Message) is false
Expand Down
18 changes: 16 additions & 2 deletions uSync.BackOffice/HealthChecks/SyncFolderIntegrityChecks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;

Expand All @@ -20,8 +21,10 @@ namespace uSync.BackOffice.HealthChecks;
Group = "uSync")]
public class SyncFolderIntegrityChecks : HealthCheck
{
private readonly ISyncConfigService _configService;
private readonly ISyncFileService _fileService;
private readonly ISyncConfigService? _configService;
private readonly ISyncFileService? _fileService;

public SyncFolderIntegrityChecks() { }

/// <summary>
/// Constructor
Expand All @@ -41,6 +44,9 @@ public override HealthCheckStatus ExecuteAction(HealthCheckAction action)
/// <inheritdoc/>
public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync()
{
if (_configService is null || _fileService is null)
return Task.FromResult(Enumerable.Empty<HealthCheckStatus>());

var items = new List<HealthCheckStatus>
{
CheckuSyncFolder(),
Expand All @@ -52,6 +58,9 @@ public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync()

private HealthCheckStatus CheckuSyncFolder()
{
if (_configService is null || _fileService is null)
return new HealthCheckStatus("Unable to check uSync folder integrity");

var root = _fileService.GetAbsPath(_configService.GetWorkingFolder());

if (_fileService.DirectoryExists(root) is false)
Expand Down Expand Up @@ -85,6 +94,8 @@ private HealthCheckStatus CheckuSyncFolder()

private List<string> CheckFolder(string folder)
{
if (_fileService is null) return [];

var _keys = new Dictionary<Guid, string>();

var clashes = new List<string>();
Expand Down Expand Up @@ -128,6 +139,9 @@ private List<string> CheckFolder(string folder)

private HealthCheckStatus CheckConfigFolderValidity()
{
if (_configService is null || _fileService is null)
return new HealthCheckStatus("Unable to check uSync folder integrity");

var root = _fileService.GetAbsPath(_configService.GetWorkingFolder());

if (_fileService.DirectoryExists(root) is false)
Expand Down
12 changes: 12 additions & 0 deletions uSync.BackOffice/Services/ISyncVersionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,20 @@

namespace uSync.BackOffice.Services;

/// <summary>
/// Controls the version file we write to disk on syncs (used to warn if sync is old)
/// </summary>
public interface ISyncVersionFileService
{
/// <summary>
/// get the Sync file version information for a folder.
/// </summary>
Task<SyncFileVersionCheckResult> GetSyncFileInfo(string folder);

/// <summary>
/// write the version information to disk.
/// </summary>
/// <param name="folder"></param>
/// <returns></returns>
Task WriteVersionFileAsync(string folder);
}
14 changes: 14 additions & 0 deletions uSync.BackOffice/Services/SyncVersionFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,23 @@ private bool HmacValuesMatch(XElement node)
}
}

/// <summary>
/// results of a check of the version file
/// </summary>
public class SyncFileVersionCheckResult
{
/// <summary>
/// the sync on disk is current to the current format we are writing.
/// </summary>
public bool IsCurrent { get; set; }

/// <summary>
/// the version we are writing to disk
/// </summary>
public string? FormatVersion { get; set; }

/// <summary>
/// the hmac value for the folders matches. (reserved)
/// </summary>
public bool HmacMatch { get; set; }
}
5 changes: 2 additions & 3 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1005,10 +1005,9 @@ protected virtual async Task<SyncAttempt<XElement>> Export_DoExportAsync(TObject
await syncFileService.SaveXElementAsync(attempt.Item, filename);
}

if (config.CreateClean && await HasChildrenAsync(item))
{
if (config.CreateClean)
await CreateCleanFileAsync(GetItemKey(item), filename);
}

}
else
{
Expand Down
3 changes: 3 additions & 0 deletions uSync.BackOffice/uSyncBackOffice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace uSync.BackOffice;
/// </summary>
public class uSync
{
/// <summary>
/// assembly version for uSync
/// </summary>
public static Version Version => typeof(uSync).Assembly.GetName().Version ?? new Version(15, 0, 0);

/// <summary>
Expand Down
18 changes: 13 additions & 5 deletions uSync.BackOffice/uSyncBackOfficeComposer.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

using Microsoft.Extensions.Logging;

using System.Linq;

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;

using uSync.Core.Extensions;

namespace uSync.BackOffice;

/// <summary>
Expand All @@ -12,10 +18,12 @@ public class uSyncBackOfficeComposer : IComposer
/// <inheritdoc/>
public void Compose(IUmbracoBuilder builder)
{
// the composers add uSync, but the extension methods
// will only add the values if uSync hasn't already
// been added, so you can for example add uSync to your
// startup.cs file. and then the composers don't fire
builder.AdduSync();
if (builder.IsUmbracoBackOfficeEnabled() is true) {
// the composers add uSync, but the extension methods
// will only add the values if uSync hasn't already
// been added, so you can for example add uSync to your
// startup.cs file. and then the composers don't fire
builder.AdduSync();
}
}
}
5 changes: 3 additions & 2 deletions uSync.Backoffice.Management.Api/ApiComposer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using uSync.Backoffice.Management.Api.Configuration;
using uSync.Backoffice.Management.Api.Services;
using uSync.BackOffice;
using uSync.Core.Extensions;

namespace uSync.Backoffice.Management.Api;

Expand All @@ -15,10 +16,10 @@ public class ApiComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// builder.Services.AddSingleton<IOperationIdHandler, uSyncCustomOperationHandler>();
if (builder.IsUmbracoBackOfficeEnabled() is false)
return;

builder.AddSyncOpenApi();

builder.Services.AddSingleton<ISyncManagementCache, uSyncManagementCache>();
builder.Services.AddSingleton<ISyncManagementService, uSyncManagementService>();
}
Expand Down
9 changes: 7 additions & 2 deletions uSync.Backoffice.Management.Client/uSyncManifestReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

using uSync.BackOffice.Configuration;
using uSync.BackOffice.Extensions;
using uSync.Core.Extensions;

namespace uSync.Backoffice.Management.Client;

Expand All @@ -18,8 +19,12 @@ public class uSyncManifestComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddSingleton<IPackageManifestReader, uSyncManifestReader>();
builder.Services.AddSingleton<IPackageManifestReader, SyncSectionManifestReader>();
if (builder.IsUmbracoBackOfficeEnabled())
{
// only load this when the backoffice is enabled.
builder.Services.AddSingleton<IPackageManifestReader, uSyncManifestReader>();
builder.Services.AddSingleton<IPackageManifestReader, SyncSectionManifestReader>();
}
}
}

Expand Down
9 changes: 9 additions & 0 deletions uSync.Core/Extensions/SyncBuilderExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Umbraco.Cms.Core.DependencyInjection;

namespace uSync.Core.Extensions;

public static class SyncBuilderExtensions
{
public static bool IsUmbracoBackOfficeEnabled(this IUmbracoBuilder builder)
=> builder.Services.Any(s => s.ServiceType == typeof(IBackOfficeEnabledMarker));
}
Loading