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
19 changes: 16 additions & 3 deletions uSync.Core/Serialization/Serializers/ContentSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,15 @@ public override Task<OperationResult> SaveWithSchedulesAsync(IContent item, int
}

public override Task SaveAsync(IEnumerable<IContent> items)
=> Task.FromResult(contentService.Save(items));
=> uSyncTaskHelper.FromResultOf(() =>
{
var result = contentService.Save(items);
if (result.Success is false)
{
throw new InvalidOperationException(
$"Could not save content items: {result.Result}");
}
});

public override async Task SaveItemAsync(IContent item)
=> await SaveItemAsync(item, -1);
Expand All @@ -184,11 +192,16 @@ public override Task SaveItemAsync(IContent item, int userId)
{
try
{
contentService.Save(item, userId);
var result = contentService.Save(item, userId);
if (result.Success is false)
{
throw new InvalidOperationException(
$"Could not save content {item.Name}: {result.Result}");
}
}
catch (ArgumentNullException ex)
{
// we can get thrown a null argument exception by the notifier,
// we can get thrown a null argument exception by the notifier,
// which is non critical! but we are ignoring this error. ! <= 8.1.5
if (!ex.Message.Contains("siteUri")) throw;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1352,13 +1352,14 @@ public override async Task SaveItemAsync(TObject item)
return;
}

if (item.Id <= 0)
{
await _baseService.CreateAsync(item, Constants.Security.SuperUserKey);
}
else
var attempt = item.Id <= 0
? await _baseService.CreateAsync(item, Constants.Security.SuperUserKey)
: await _baseService.UpdateAsync(item, Constants.Security.SuperUserKey);

if (attempt.Success is false)
{
await _baseService.UpdateAsync(item, Constants.Security.SuperUserKey);
throw new InvalidOperationException(
$"Could not save {typeof(TObject).Name} {item.Alias}: {attempt.Result}");
}

//if (item.IsDirty()) _baseService.Save(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,12 @@ public override async Task<SyncAttempt<IContentType>> DeserializeSecondPassAsync
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Saving in Serializer because item is dirty [{properties}]", dirty);

await _contentTypeService.UpdateAsync(item, Constants.Security.SuperUserKey);
var attempt = await _contentTypeService.UpdateAsync(item, Constants.Security.SuperUserKey);
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not save content type {item.Alias}: {attempt.Result}");
}
}

await CleanFolderAsync(item, node);
Expand Down
13 changes: 9 additions & 4 deletions uSync.Core/Serialization/Serializers/DataTypeSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,10 +368,15 @@ public override async Task SaveItemAsync(IDataType item)
// see : https://github.com/umbraco/Umbraco-CMS/issues/19732
// if (item.IsDirty() is false) return;

if (item.HasIdentity is true)
await _dataTypeService.UpdateAsync(item, Constants.Security.SuperUserKey);
else
await _dataTypeService.CreateAsync(item, Constants.Security.SuperUserKey);
var attempt = item.HasIdentity is true
? await _dataTypeService.UpdateAsync(item, Constants.Security.SuperUserKey)
: await _dataTypeService.CreateAsync(item, Constants.Security.SuperUserKey);

if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not save data type {item.Name}: {attempt.Status}");
}
}

public override async Task SaveAsync(IEnumerable<IDataType> items)
Expand Down
14 changes: 12 additions & 2 deletions uSync.Core/Serialization/Serializers/DomainSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,12 @@ public override async Task SaveItemAsync(IDomain item)
})
};

await _domainService.UpdateDomainsAsync(contentKey.Result, updateModel);
var attempt = await _domainService.UpdateDomainsAsync(contentKey.Result, updateModel);
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not save domain {item.DomainName}: {attempt.Status}");
}
}

private sealed class DomainSyncModel
Expand All @@ -362,7 +367,12 @@ public override async Task DeleteItemAsync(IDomain item)
var existing = await _domainService.GetAssignedDomainsAsync(contentKey.Result, true);
var remaining = existing.Where(x => x.Key != item.Key).Select(x => new DomainModel { DomainName = x.DomainName, IsoCode = x.LanguageIsoCode! });

await _domainService.UpdateDomainsAsync(contentKey.Result, new DomainsUpdateModel { Domains = remaining });
var attempt = await _domainService.UpdateDomainsAsync(contentKey.Result, new DomainsUpdateModel { Domains = remaining });
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not remove domain {item.DomainName}: {attempt.Status}");
}
}

public override string ItemAlias(IDomain item)
Expand Down
30 changes: 27 additions & 3 deletions uSync.Core/Serialization/Serializers/MediaSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,37 @@ private static string GetFilePath(string? value)
}

public override Task SaveAsync(IEnumerable<IMedia> items)
=> uSyncTaskHelper.FromResultOf(() => { return _mediaService.Save(items); });
=> uSyncTaskHelper.FromResultOf(() =>
{
var attempt = _mediaService.Save(items);
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not save media items: {attempt.Result?.Result}");
}
});

public override Task SaveItemAsync(IMedia item)
=> uSyncTaskHelper.FromResultOf(() => { return _mediaService.Save(item); });
=> uSyncTaskHelper.FromResultOf(() =>
{
var attempt = _mediaService.Save(item);
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not save media {item.Name}: {attempt.Result?.Result}");
}
});

public override Task DeleteItemAsync(IMedia item)
=> uSyncTaskHelper.FromResultOf(() => { return _mediaService.Delete(item); });
=> uSyncTaskHelper.FromResultOf(() =>
{
var attempt = _mediaService.Delete(item);
if (attempt.Success is false)
{
throw new InvalidOperationException(
$"Could not delete media {item.Name}: {attempt.Result?.Result}");
}
});

protected override Task<SyncParentItem?> FindParentByIdAsync(int id)
{
Expand Down
16 changes: 14 additions & 2 deletions uSync.Core/Serialization/Serializers/TemplateSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -355,19 +355,31 @@ public override async Task SaveItemAsync(ITemplate item)
logger.LogDebug("Saving: {alias} {path}", item.Alias, item.Path);

var result = await _templateService.UpdateAsync(item, userKey);

if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Update Template Result: [{key}] {result} {status}", item.Key, result.Success, result.Status);

if (result.Success is false)
{
throw new InvalidOperationException(
$"Could not save template {item.Alias}: {result.Status}");
}
}
else
{
if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Creating: {alias} {path}", item.Alias, item.Path);

var result = await _templateService.CreateAsync(item.Name ?? item.Alias, item.Alias, item.Content, userKey, item.Key);

if (logger.IsEnabled(LogLevel.Debug))
logger.LogDebug("Update Template Result: [{key}] {result} {status}", item.Key, result.Success, result.Status);

if (result.Success is false)
{
throw new InvalidOperationException(
$"Could not save template {item.Alias}: {result.Status}");
}
}
}

Expand Down
Loading