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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<VersionPrefix>17.0.0</VersionPrefix>
<VersionPrefix>18.0.0</VersionPrefix>
<Authors>Kevin Jump</Authors>
<Company>Jumoo</Company>

Expand Down
18 changes: 9 additions & 9 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@
</ItemGroup>
<!-- umbraco libraries for packages -->
<ItemGroup>
<PackageVersion Include="Umbraco.Cms.Core" Version="18.0.0-beta1" />
<PackageVersion Include="Umbraco.Cms.Web.Website" Version="18.0.0-beta1" />
<PackageVersion Include="Umbraco.Cms.Api.Management" Version="18.0.0-beta1" />
<PackageVersion Include="Umbraco.Cms.Core" Version="18.0.0-rc2" />
<PackageVersion Include="Umbraco.Cms.Web.Website" Version="18.0.0-rc2" />
<PackageVersion Include="Umbraco.Cms.Api.Management" Version="18.0.0-rc2" />
</ItemGroup>
<!-- source link -->
<ItemGroup>
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.201" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="10.0.300" />
</ItemGroup>
<!-- testing -->
<ItemGroup>
<PackageVersion Include="Umbraco.Cms.Tests" Version="18.0.0-beta1" />
<PackageVersion Include="Umbraco.Cms.Tests.Integration" Version="18.0.0-beta1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.5.1" />
<PackageVersion Include="Umbraco.Cms.Tests" Version="18.0.0-rc2" />
<PackageVersion Include="Umbraco.Cms.Tests.Integration" Version="18.0.0-rc2" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="18.6.0" />
<PackageVersion Include="NUnit3TestAdapter" Version="6.2.0" />
<PackageVersion Include="coverlet.collector" Version="8.0.1" />
<PackageVersion Include="coverlet.collector" Version="10.0.1" />
</ItemGroup>
<!-- command line -->
<ItemGroup>
<PackageVersion Include="NJsonSchema" Version="11.5.2" />
<PackageVersion Include="NJsonSchema" Version="11.6.1" />
<PackageVersion Include="CommandLineParser" Version="2.9.1" />
</ItemGroup>
</Project>
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();
}
}
6 changes: 3 additions & 3 deletions uSync.AutoTemplates/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net10.0": {
"Umbraco.Cms.Core": {
"type": "Direct",
"requested": "[18.0.0-beta2, )",
"resolved": "18.0.0-beta2",
"contentHash": "Qp9B8+Zq+sA2UVuQQ4k6QIVGmiadii5t1uwaiPng1SObLz9anaz6hdcDVX7ihctGBK1lxuGofSm9fk7OK3Uhfw==",
"requested": "[18.0.0-rc2, )",
"resolved": "18.0.0-rc2",
"contentHash": "aJU2hB4I3eJSNPCzx7HbnF9+GuHFSUINo4qlXuywE1Tk/1ctfTvCYqewGbPU3uJEgSAvOm6OD/j94zTlg9b1OA==",
"dependencies": {
"Microsoft.Extensions.Caching.Abstractions": "10.0.7",
"Microsoft.Extensions.Caching.Memory": "10.0.7",
Expand Down
11 changes: 11 additions & 0 deletions uSync.BackOffice/BackOfficeConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public static class Priorites
/// </summary>
public const int Macros = USYNC_RESERVED_LOWER + 70;

/// <summary>
/// Elements Priority.
/// </summary>
public const int Elements = USYNC_RESERVED_LOWER + 190;

/// <summary>
/// Media priority
/// </summary>
Expand Down Expand Up @@ -259,5 +264,11 @@ public static class Handlers
public const string WebhookHandler = "WebhookHandler";


/// <summary>
/// Handler for Element (Library) items
/// </summary>
public const string ElementHandler = "ElementHandler";


}
}
19 changes: 19 additions & 0 deletions uSync.BackOffice/Cache/CacheLifecycleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class CacheLifecycleManager :
INotificationAsyncHandler<ContentSavingNotification>,
INotificationAsyncHandler<ContentDeletingNotification>,
INotificationAsyncHandler<ContentMovingNotification>,
INotificationAsyncHandler<ElementSavingNotification>,
INotificationAsyncHandler<ElementDeletingNotification>,
INotificationAsyncHandler<ElementMovingNotification>,
INotificationAsyncHandler<MediaSavingNotification>,
INotificationAsyncHandler<MediaSavedNotification>,
INotificationAsyncHandler<MediaDeletedNotification>
Expand Down Expand Up @@ -95,6 +98,22 @@ public CacheLifecycleManager(
/// </summary>
public Task HandleAsync(ContentMovingNotification notification, CancellationToken c) => ClearOnEvents();

/// <summary>
/// clear the cache on the Umbraco Element Saving notification
/// </summary>
public Task HandleAsync(ElementSavingNotification notification, CancellationToken c) => ClearOnEvents();

/// <summary>
/// clear the cache on the Umbraco Element Deleting notification
/// </summary>
public Task HandleAsync(ElementDeletingNotification notification, CancellationToken c) => ClearOnEvents();

/// <summary>
/// clear the cache on the Element Moving notification
/// </summary>
public Task HandleAsync(ElementMovingNotification notification, CancellationToken c) => ClearOnEvents();


/// <summary>
/// Clear the cache on the Umbraco Media Saving notification
/// </summary>
Expand Down
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);
}
1 change: 0 additions & 1 deletion uSync.BackOffice/Services/SyncActionService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using uSync.BackOffice.Configuration;
using uSync.BackOffice.Extensions;
using uSync.BackOffice.Models;
using uSync.BackOffice.SyncHandlers;
using uSync.BackOffice.SyncHandlers.Models;

namespace uSync.BackOffice.Services;
Expand Down
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; }
}
50 changes: 4 additions & 46 deletions uSync.BackOffice/SyncHandlers/Handlers/ContentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace uSync.BackOffice.SyncHandlers.Handlers;
/// </summary>
[SyncHandler(uSyncConstants.Handlers.ContentHandler, "Content", "Content", uSyncConstants.Priorites.Content
, Icon = "icon-document", IsTwoPass = true, EntityType = UdiEntityType.Document)]
public class ContentHandler : ContentHandlerBase<IContent>, ISyncHandler,
public class ContentHandler : PublishableContentHandlerBase<IContent>, ISyncHandler,

INotificationAsyncHandler<SavedNotification<IContent>>,
INotificationAsyncHandler<DeletedNotification<IContent>>,
Expand Down Expand Up @@ -77,34 +77,10 @@ public ContentHandler(
protected override Task<bool> HasChildrenAsync(IContent item)
=> Task.FromResult(_contentService.HasChildren(item.Id));

/// <summary>
/// Get child items
/// </summary>
/// <remarks>
/// The core method works for all services, (using entities) - but if we look up
/// the actual type for content and media, we save ourselves an extra lookup later on
/// and this speeds up the itteration by quite a bit (onle less db trip per item).
/// </remarks>
protected override Task<IEnumerable<IEntity>> GetChildItemsAsync(IEntity? parent)
{
return uSyncTaskHelper.FromResultOf<IEnumerable<IEntity>>(() =>
{
if (parent is null) return _contentService.GetRootContent();

var items = new List<IContent>();
const int pageSize = 5000;
var page = 0;
var total = long.MaxValue;
while (page * pageSize < total)
{
items.AddRange(_contentService.GetPagedChildren(parent.Id, page++, pageSize, out total));
}
return items;

});
}
protected override IEnumerable<IEntity> GetRootItems()
=> _contentService.GetRootContent();

/// <summary>
/// <summary>
/// Handle the publish events for content
/// </summary>
/// <remarks>
Expand Down Expand Up @@ -143,22 +119,4 @@ public async Task HandleAsync(ContentUnpublishedNotification notification, Cance
await ProcessItem(notification, item, handlerFolders);
}
}

private async Task ProcessItem(EnumerableObjectNotification<IContent> notification, IContent item, string[] handlerFolders)
{
try
{
var attempts = await ExportAsync(item, handlerFolders, DefaultConfig);
foreach (var attempt in attempts.Where(x => x.Success))
{
if (attempt.FileName is null) continue;
await this.CleanUpAsync(item, attempt.FileName, handlerFolders.Last());
}
}
catch (Exception ex)
{
logger.LogWarning(ex, "Failed to create uSync export file");
notification.Messages.Add(new EventMessage("uSync", $"Failed to create export file : {ex.Message}", EventMessageType.Warning));
}
}
}
15 changes: 9 additions & 6 deletions uSync.BackOffice/SyncHandlers/Handlers/ContentHandlerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
using uSync.Core;
using uSync.Core.Serialization;

using uSyncCoreConstants = uSync.Core.uSyncConstants;

namespace uSync.BackOffice.SyncHandlers.Handlers;

/// <summary>
Expand Down Expand Up @@ -103,8 +105,9 @@ protected override async Task<bool> ShouldImportAsync(XElement node, HandlerSett
private static bool ShouldImportTrashedItem(XElement node, HandlerSettings config)
{
// unless the setting is explicit we don't import trashed items.
var trashed = node.Element("Info")?.Element("Trashed").ValueOrDefault(false);
if (trashed.GetValueOrDefault(false) && !config.GetSetting("ImportTrashed", false)) return false;
var isTrashed = node.IsTrashed();
if (isTrashed && !config.GetSetting(uSyncCoreConstants.DefaultSettings.ImportTrashed,
uSyncCoreConstants.DefaultSettings.ImportTrashed_Default)) return false;

return true;
}
Expand All @@ -116,7 +119,7 @@ private bool ImportPaths(XElement node, HandlerSettings config)

if (include.Length > 0)
{
var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
var path = node.GetPath();
if (!string.IsNullOrWhiteSpace(path) && !include.Any(x => path.InvariantStartsWith(x)))
{
if (logger.IsEnabled(LogLevel.Debug))
Expand All @@ -130,7 +133,7 @@ private bool ImportPaths(XElement node, HandlerSettings config)
.Split([','], StringSplitOptions.RemoveEmptyEntries);
if (exclude.Length > 0)
{
var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
var path = node.GetPath();
if (!string.IsNullOrWhiteSpace(path) && exclude.Any(x => path.InvariantStartsWith(x)))
{
if (logger.IsEnabled(LogLevel.Debug))
Expand Down Expand Up @@ -183,8 +186,8 @@ protected override async Task<bool> ShouldExportAsync(XElement node, HandlerSett
if (!await base.ShouldExportAsync(node, config)) return false;

// We export trashed items by default, (but we don't import them by default)
var trashed = node.Element("Info")?.Element("Trashed").ValueOrDefault(false);
if (trashed.GetValueOrDefault(false) && !config.GetSetting<bool>("ExportTrashed", true)) return false;
var isTrashed = node.IsTrashed();
if (isTrashed && !config.GetSetting<bool>("ExportTrashed", true)) return false;

if (config.GetSetting("RulesOnExport", false))
{
Expand Down
Loading