Skip to content

Commit

Permalink
New method to enrich contents with defaults.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Dec 22, 2023
1 parent 90ee44b commit 96f4f7b
Show file tree
Hide file tree
Showing 16 changed files with 73 additions and 141 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 @@ -15,6 +15,6 @@
<PackageTags>Squidex HeadlessCMS</PackageTags>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
<Version>12.1</Version>
<Version>12.2</Version>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Runtime.Serialization;

namespace Squidex.CLI.Commands.Implementation;

[Serializable]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,22 @@ public void Dispose()

public void WriteLine(string message, params object[] args)
{
Console.WriteLine(message, args);

if (consoleTop >= 0)
{
Console.SetCursorPosition(0, consoleTop);
}

Console.WriteLine(message, args);
}

public void WriteLine(string message)
{
Console.WriteLine(message);

if (consoleTop >= 0)
{
Console.SetCursorPosition(0, consoleTop);
}

Console.WriteLine(message);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
Expand Down
9 changes: 1 addition & 8 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,8 @@

namespace Squidex.CLI.Commands;

public partial class App
public partial class App(ILogger log)
{
private readonly ILogger log;

public App(ILogger log)
{
this.log = log;
}

[Command("info", Description = "Shows information about the CLI.")]
public void Info()
{
Expand Down
14 changes: 1 addition & 13 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,8 @@ public partial class App
{
[Command("ai", Description = "Uses AI commands.")]
[Subcommand]
public sealed class AI
public sealed class AI(IConfigurationService configuration, IConfigurationStore configurationStore, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly IConfigurationStore configurationStore;
private readonly ILogger log;

public AI(IConfigurationService configuration, IConfigurationStore configurationStore, ILogger log)
{
this.configuration = configuration;
this.configurationStore = configurationStore;

this.log = log;
}

[Command("generate-contents", Description = "Generates content items and the corresponding schema.",
ExtendedHelpText =
@"Use descriptions with the following syntax:
Expand Down
12 changes: 1 addition & 11 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Apps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,8 @@ public partial class App
{
[Command("apps", Description = "Manages apps.")]
[Subcommand]
public sealed class Apps
public sealed class Apps(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Apps(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("list", Description = "List all schemas.")]
public async Task List(ListArguments arguments)
{
Expand Down
12 changes: 1 addition & 11 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Assets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,8 @@ public partial class App
{
[Command("assets", Description = "Manages assets.")]
[Subcommand]
public sealed class Assets
public sealed class Assets(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Assets(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("import", Description = "Import all files from the source folder.")]
public async Task Import(ImportArguments arguments)
{
Expand Down
12 changes: 1 addition & 11 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Backup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,8 @@ public sealed partial class App
{
[Command("backup", Description = "Manage backups.")]
[Subcommand]
public sealed class Backup
public sealed class Backup(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Backup(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("create", Description = "Create and download an backup.")]
public async Task Create(CreateArguments arguments)
{
Expand Down
12 changes: 1 addition & 11 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,8 @@ public partial class App
{
[Command("config", Description = "Manage configurations.")]
[Subcommand]
public sealed class Config
public sealed class Config(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Config(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("list", Description = "Shows the current configuration.")]
public void List(ListArguments arguments)
{
Expand Down
71 changes: 57 additions & 14 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Contents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@

using System.Globalization;
using CommandDotNet;
using ConsoleTables;
using CsvHelper;
using CsvHelper.Configuration;
using FluentValidation;
using Squidex.CLI.Commands.Implementation;
using Squidex.CLI.Commands.Implementation.AI;
using Squidex.CLI.Commands.Implementation.ImExport;
using Squidex.CLI.Commands.Implementation.TestData;
using Squidex.CLI.Commands.Implementation.Utils;
using Squidex.CLI.Configuration;
using Squidex.ClientLibrary;
using static Squidex.CLI.Commands.App.AI;

#pragma warning disable MA0048 // File name must match type name

Expand All @@ -30,18 +27,8 @@ public partial class App

[Command("contents", Description = "Manage contents.")]
[Subcommand]
public sealed class Contents
public sealed class Contents(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Contents(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("generate", Description = "Generates test data.")]
public async Task GenerateDummies(GenerateDummiesArguments arguments)
{
Expand Down Expand Up @@ -81,6 +68,49 @@ await Task.WhenAll(
}
}

[Command("enrich-defaults", Description = "Enrich the content items with its defaults.")]
public async Task EnrichDefaults(EnrichDefaultsArguments arguments)
{
var session = configuration.StartSession(arguments.App);

var line = log.WriteSameLine();

var idsRequest = new List<string>();
var idsTotal = 0;

async Task BulkUpdateAsync()
{
if (idsRequest.Count == 0)
{
return;
}

var request = new BulkUpdate
{
Jobs = idsRequest.Select(x => new BulkUpdateJob { Id = x, Type = BulkUpdateType.EnrichDefaults }).ToList()
};

await session.Client.DynamicContents(arguments.Schema).BulkUpdateAsync(request);

idsTotal += idsRequest.Count;
idsRequest.Clear();

line.WriteLine("Contents handled: {0}", idsTotal);
}

await session.Client.DynamicContents(arguments.Schema).GetAllAsync(async content =>
{
idsRequest.Add(content.Id);

if (idsRequest.Count >= 200)
{
await BulkUpdateAsync();
}
}, context: QueryContext.Default.Unpublished(arguments.Unpublished));

await BulkUpdateAsync();
}

[Command("import", Description = "Import the content to a schema.",
ExtendedHelpText =
@"Use the following format to define fields from the CSV/JSON file:
Expand Down Expand Up @@ -406,5 +436,18 @@ public Validator()
}
}
}

public sealed class EnrichDefaultsArguments : AppArguments
{
[Operand("schema", Description = "The name of the schema.")]
public string Schema { get; set; }

[Option('u', "unpublished", Description = "Handle unpublished content.")]
public bool Unpublished { get; set; }

public sealed class Validator : AbstractValidator<EnrichDefaultsArguments>
{
}
}
}
}
9 changes: 1 addition & 8 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Log.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,8 @@ public sealed partial class App
{
[Command("log", Description = "Analyze request log.")]
[Subcommand]
public sealed class Log
public sealed class Log(ILogger log)
{
private readonly ILogger log;

public Log(ILogger log)
{
this.log = log;
}

[Command("analyze", Description = "Analyzes request log files.")]
public void Analyze(AnalyzeArguments arguments)
{
Expand Down
15 changes: 1 addition & 14 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using Squidex.CLI.Commands.Implementation.OpenLibrary;
using Squidex.CLI.Commands.Implementation.Sync;
using Squidex.CLI.Configuration;
using Squidex.ClientLibrary;

#pragma warning disable MA0048 // File name must match type name

Expand All @@ -21,20 +20,8 @@ public sealed partial class App
{
[Command("openlib", Description = "Openlibrary example.")]
[Subcommand]
public sealed class OpenLibrary
public sealed class OpenLibrary(IConfigurationService configuration, Synchronizer synchronizer, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly Synchronizer synchronizer;
private readonly ILogger log;

public OpenLibrary(IConfigurationService configuration, Synchronizer synchronizer, ILogger log)
{
this.configuration = configuration;
this.synchronizer = synchronizer;

this.log = log;
}

[Command("generate", Description = "Generate the necessary schemas.")]
public async Task New(NewArguments arguments)
{
Expand Down
12 changes: 1 addition & 11 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Schemas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,8 @@ public partial class App
{
[Command("schemas", Description = "Manage schemas.")]
[Subcommand]
public sealed class Schemas
public sealed class Schemas(IConfigurationService configuration, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly ILogger log;

public Schemas(IConfigurationService configuration, ILogger log)
{
this.configuration = configuration;

this.log = log;
}

[Command("list", Description = "List all schemas.")]
public async Task List(ListArguments arguments)
{
Expand Down
14 changes: 1 addition & 13 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,8 @@ public sealed partial class App
{
[Command("sync", Description = "Synchronizes apps.")]
[Subcommand]
public sealed class Sync
public sealed class Sync(IConfigurationService configuration, Synchronizer synchronizer, ILogger log)
{
private readonly IConfigurationService configuration;
private readonly Synchronizer synchronizer;
private readonly ILogger log;

public Sync(IConfigurationService configuration, Synchronizer synchronizer, ILogger log)
{
this.configuration = configuration;
this.synchronizer = synchronizer;

this.log = log;
}

[Command("new", Description = "Creates a new folder with sample files how to create an app from json files.")]
public async Task New(NewArgument arguments)
{
Expand Down
9 changes: 1 addition & 8 deletions cli/Squidex.CLI/Squidex.CLI/Commands/App_Twitter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,8 @@ public sealed partial class App
{
[Command("twitter", Description = "Manage twitter.")]
[Subcommand]
public sealed class Twitter
public sealed class Twitter(ILogger log)
{
private readonly ILogger log;

public Twitter(ILogger log)
{
this.log = log;
}

[Command("auth", Description = "Starts the authentication.")]
public async Task Auth(AuthArguments arguments)
{
Expand Down

0 comments on commit 96f4f7b

Please sign in to comment.