Skip to content

Commit

Permalink
New Content Action to define how a content item should be processed.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jun 14, 2022
1 parent 882e598 commit 624a147
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cli/Squidex.CLI/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/Squidex/squidex/</PackageProjectUrl>
<PackageTags>Squidex HeadlessCMS</PackageTags>
<Version>8.17</Version>
<Version>8.18</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

namespace Squidex.CLI.Commands.Implementation.Sync
{
public enum ContentAction
{
Upsert,
UpsertPatch,
Create,
Update,
Patch
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
DoNotScript = true,
DoNotValidate = false,
DoNotValidateWorkflow = true,
Jobs = model.Contents.Select(x => x.ToUpsert(schemas, options.PatchContent)).ToList()
Jobs = model.Contents.Select(x => x.ToUpsert(schemas, options.ContentAction)).ToList()
};

var contentIdAssigned = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Contents
{
public static class Extensions
{
public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas, bool patch)
public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas, ContentAction action)
{
var result = SimpleMapper.Map(model, new BulkUpdateJob { Patch = patch });
var result = SimpleMapper.Map(model, new BulkUpdateJob());

#pragma warning disable CS0618 // Type or member is obsolete
var singleton = schemas.Items.Find(x => x.Name == model.Schema && (x.IsSingleton || x.Type == SchemaType.Singleton));
Expand All @@ -26,6 +26,22 @@ public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas
result.Id = singleton.Id;
}

switch (action)
{
case ContentAction.UpsertPatch:
result.Patch = true;
break;
case ContentAction.Create:
result.Type = BulkUpdateType.Create;
break;
case ContentAction.Update:
result.Type = BulkUpdateType.Update;
break;
case ContentAction.Patch:
result.Type = BulkUpdateType.Patch;
break;
}

result.Data = model.Data;

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public sealed class SyncOptions

public string[] Languages { get; set; }

public ContentAction ContentAction { get; set; }

public bool Delete { get; set; }

public bool Recreate { get; set; }

public bool PatchContent { get; set; }

public bool UpdateCurrentClient { get; set; }
}
}
12 changes: 11 additions & 1 deletion cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public sealed class InArguments : AppArguments
[Option("language", Description = "The content language to synchronize.")]
public string[] Languages { get; set; }

[Option("content-action", Description = "Defines how to handle content.")]
public ContentAction ContentAction { get; set; }

[Option("delete", Description = "Use this flag to also delete entities.")]
public bool Delete { get; set; }

Expand All @@ -131,7 +134,14 @@ public sealed class InArguments : AppArguments

public SyncOptions ToOptions()
{
return SimpleMapper.Map(this, new SyncOptions());
var result = SimpleMapper.Map(this, new SyncOptions());

if (PatchContent)
{
result.ContentAction = ContentAction.UpsertPatch;
}

return result;
}

public sealed class Validator : AbstractValidator<InArguments>
Expand Down

0 comments on commit 624a147

Please sign in to comment.