Skip to content

Commit 3d22696

Browse files
Do not update current client and some refactorings.
1 parent 5c7ed75 commit 3d22696

File tree

18 files changed

+143
-84
lines changed

18 files changed

+143
-84
lines changed

cli/Squidex.CLI/Squidex.CLI/Commands/App_OpenLibrary.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public async Task Authors(ImportArguments arguments)
5757
{
5858
var session = configuration.StartSession(arguments.App);
5959

60-
using (var stream = new FileStream(arguments.File, FileMode.Open))
60+
await using (var stream = new FileStream(arguments.File, FileMode.Open))
6161
{
6262
var importer = new AuthorImporter(session);
6363

cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,31 @@ public sealed class InArguments : AppArguments
9494
[Option(ShortName = "t", LongName = "targets", Description = "The targets to sync, e.g. schemas, workflows, app, rules.")]
9595
public string[] Targets { get; set; }
9696

97+
[Option(ShortName = "l", LongName = "language", Description = "The content language to synchronize.")]
98+
public string[] Languages { get; set; }
99+
97100
[Option(LongName = "delete", Description = "Use this flag to also delete entities.")]
98101
public bool Delete { get; set; }
99102

100103
[Option(LongName = "recreate", Description = "Use this flag to also recreate entities.")]
101104
public bool Recreate { get; set; }
102105

106+
[Option(LongName = "update-current-client", Description = "Also update the client that is used during the sync process.")]
107+
public bool UpdateCurrentClient { get; set; }
108+
103109
[Option(LongName = "emulate", Description = "Use this flag to not make any updates and to emulate the changes.")]
104110
public bool Emulate { get; set; }
105111

106112
public SyncOptions ToOptions()
107113
{
108-
return new SyncOptions { Delete = Delete, Recreate = Recreate, Targets = Targets };
114+
return new SyncOptions
115+
{
116+
Delete = Delete,
117+
Recreate = Recreate,
118+
Languages = Languages,
119+
Targets = Targets,
120+
UpdateCurrentClient = UpdateCurrentClient
121+
};
109122
}
110123

111124
public sealed class Validator : AbstractValidator<InArguments>

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/FileSystem/Emedded/EmbeddedFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public IFile GetFile(FilePath path)
3333
{
3434
var relativePath = GetRelativePath(path);
3535

36-
return new EmbeddedFile(assembly, path.Elements.Last(), relativePath, path.ToString());
36+
return new EmbeddedFile(assembly, path.Elements[^1], relativePath, path.ToString());
3737
}
3838

3939
public IEnumerable<IFile> GetFiles(FilePath path, string extension)

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/OpenLibrary/AuthorImporter.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,27 @@ public async Task ImportAsync(Stream stream)
4242

4343
var json = JObject.Parse(x.Json);
4444

45-
if (json.TryGetValue("name", out var name))
45+
if (json.TryGetValue("name", StringComparison.Ordinal, out var name))
4646
{
4747
data.Name = GetString(name);
4848
}
4949

50-
if (json.TryGetValue("birth_date", out var birthdate))
50+
if (json.TryGetValue("birth_date", StringComparison.Ordinal, out var birthdate))
5151
{
5252
data.Birthdate = GetString(birthdate);
5353
}
5454

55-
if (json.TryGetValue("bio", out var bio))
55+
if (json.TryGetValue("bio", StringComparison.Ordinal, out var bio))
5656
{
5757
data.Bio = GetString(bio);
5858
}
5959

60-
if (json.TryGetValue("personal_name", out var personalName))
60+
if (json.TryGetValue("personal_name", StringComparison.Ordinal, out var personalName))
6161
{
6262
data.PersonalName = GetString(personalName);
6363
}
6464

65-
if (json.TryGetValue("wikipedia", out var wikipedia))
65+
if (json.TryGetValue("wikipedia", StringComparison.Ordinal, out var wikipedia))
6666
{
6767
data.Wikipedia = GetString(wikipedia);
6868
}

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/App/AppRoleModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ public sealed class AppRoleModel
1414
{
1515
[Required]
1616
public List<string> Permissions { get; set; }
17+
18+
public Dictionary<string, object> Properties { get; set; }
1719
}
1820
}

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/App/AppSynchronizer.cs

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8+
using System;
89
using System.Collections.Generic;
910
using System.Threading.Tasks;
1011
using Squidex.CLI.Commands.Implementation.FileSystem;
@@ -44,11 +45,7 @@ await log.DoSafeAsync("Exporting clients", async () =>
4445

4546
foreach (var client in clients.Items)
4647
{
47-
model.Clients[client.Name] = new AppClientModel
48-
{
49-
Name = client.Name,
50-
Role = client.Role
51-
};
48+
model.Clients[client.Name] = client.ToModel();
5249
}
5350
});
5451

@@ -60,12 +57,7 @@ await log.DoSafeAsync("Exporting languages", async () =>
6057

6158
foreach (var language in languages.Items)
6259
{
63-
model.Languages[language.Iso2Code] = new UpdateLanguageDto
64-
{
65-
Fallback = language.Fallback,
66-
IsMaster = language.IsMaster,
67-
IsOptional = language.IsOptional
68-
};
60+
model.Languages[language.Iso2Code] = language.ToModel();
6961
}
7062
});
7163

@@ -77,10 +69,7 @@ await log.DoSafeAsync("Exporting Roles", async () =>
7769

7870
foreach (var role in roles.Items)
7971
{
80-
model.Roles[role.Name] = new AppRoleModel
81-
{
82-
Permissions = role.Permissions
83-
};
72+
model.Roles[role.Name] = role.ToModel();
8473
}
8574
});
8675

@@ -128,7 +117,7 @@ private async Task SynchronizeClientsAsync(AppModel model, SyncOptions options,
128117
{
129118
var generatedClientId = $"{session.App}:{client.Id}";
130119

131-
if (model.Clients.ContainsKey(client.Id) || session.ClientId.Equals(generatedClientId))
120+
if (model.Clients.ContainsKey(client.Id) || session.ClientId.Equals(generatedClientId, StringComparison.Ordinal))
132121
{
133122
continue;
134123
}
@@ -157,18 +146,23 @@ await log.DoSafeAsync($"Client '{clientId}' creating", async () =>
157146
});
158147
}
159148

160-
foreach (var (clientId, value) in model.Clients)
149+
foreach (var (clientId, client) in model.Clients)
161150
{
162151
var existing = current.Items.Find(x => x.Id == clientId);
163152

164-
if (existing == null || value.JsonEquals(existing))
153+
if (existing == null || client.JsonEquals(existing))
154+
{
155+
continue;
156+
}
157+
158+
if (!options.UpdateCurrentClient && session.ClientId.Equals(clientId, StringComparison.Ordinal))
165159
{
166160
continue;
167161
}
168162

169163
await log.DoSafeAsync($"Client '{clientId}' updating", async () =>
170164
{
171-
var request = new UpdateClientDto { Role = value.Role };
165+
var request = client.ToUpdate();
172166

173167
await session.Apps.PutClientAsync(session.App, clientId, request);
174168
});
@@ -212,20 +206,18 @@ await log.DoSafeAsync($"Language '{isoCode}' creating", async () =>
212206
});
213207
}
214208

215-
foreach (var (isoCode, value) in model.Languages)
209+
foreach (var (isoCode, language) in model.Languages)
216210
{
217211
var existing = current.Items.Find(x => x.Iso2Code == isoCode);
218212

219-
if (existing == null || value.JsonEquals(existing))
213+
if (existing == null || language.JsonEquals(existing))
220214
{
221215
continue;
222216
}
223217

224218
await log.DoSafeAsync($"Language '{isoCode}' updating", async () =>
225219
{
226-
var request = value;
227-
228-
await session.Apps.PutLanguageAsync(session.App, isoCode, request);
220+
await session.Apps.PutLanguageAsync(session.App, isoCode, language);
229221
});
230222
}
231223
}
@@ -270,18 +262,18 @@ await log.DoSafeAsync($"Role '{roleName}' creating", async () =>
270262
});
271263
}
272264

273-
foreach (var (roleName, value) in model.Roles)
265+
foreach (var (roleName, role) in model.Roles)
274266
{
275267
var existing = current.Items.Find(x => x.Name == roleName);
276268

277-
if (existing == null || value.JsonEquals(existing))
269+
if (existing == null || role.JsonEquals(existing))
278270
{
279271
continue;
280272
}
281273

282274
await log.DoSafeAsync($"Role '{roleName}' updating", async () =>
283275
{
284-
var request = new UpdateRoleDto { Permissions = value.Permissions };
276+
var request = role.ToUpdate();
285277

286278
await session.Apps.PutRoleAsync(session.App, roleName, request);
287279
});
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ==========================================================================
2+
// Squidex Headless CMS
3+
// ==========================================================================
4+
// Copyright (c) Squidex UG (haftungsbeschraenkt)
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using Squidex.ClientLibrary.Management;
9+
10+
namespace Squidex.CLI.Commands.Implementation.Sync.App
11+
{
12+
public static class Extensions
13+
{
14+
public static AppRoleModel ToModel(this RoleDto role)
15+
{
16+
return new AppRoleModel { Permissions = role.Permissions, Properties = role.Properties };
17+
}
18+
19+
public static UpdateRoleDto ToUpdate(this AppRoleModel model)
20+
{
21+
return new UpdateRoleDto { Permissions = model.Permissions, Properties = model.Properties };
22+
}
23+
24+
public static AppClientModel ToModel(this ClientDto client)
25+
{
26+
return new AppClientModel { Name = client.Name, Role = client.Role };
27+
}
28+
29+
public static UpdateClientDto ToUpdate(this AppClientModel model)
30+
{
31+
return new UpdateClientDto { Name = model.Name, Role = model.Role };
32+
}
33+
34+
public static UpdateLanguageDto ToModel(this AppLanguageDto language)
35+
{
36+
return new UpdateLanguageDto
37+
{
38+
Fallback = language.Fallback,
39+
IsMaster = language.IsMaster,
40+
IsOptional = language.IsOptional
41+
};
42+
}
43+
}
44+
}

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
128128
{
129129
var parentId = await tree.GetIdAsync(asset.FolderPath);
130130

131-
request.Jobs.Add(asset.ToMoveJob(parentId));
132-
request.Jobs.Add(asset.ToAnnotateJob());
131+
request.Jobs.Add(asset.ToMove(parentId));
132+
request.Jobs.Add(asset.ToAnnotate());
133133
}
134134

135135
var assetIndex = 0;

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Assets/Extensions.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,31 @@ public static string GetFileHash(this IFile file, string fileName)
7474
}
7575
}
7676

77-
public static BulkUpdateAssetsJobDto ToMoveJob(this AssetModel model, string parentId)
77+
public static BulkUpdateAssetsJobDto ToMove(this AssetModel model, string parentId)
7878
{
79-
return new BulkUpdateAssetsJobDto
80-
{
81-
Id = model.Id,
82-
Type = BulkUpdateAssetType.Move,
83-
ParentId = parentId
84-
};
79+
var bulkJob = model.ToJob(BulkUpdateAssetType.Move);
80+
81+
bulkJob.ParentId = parentId;
82+
83+
return bulkJob;
8584
}
8685

87-
public static BulkUpdateAssetsJobDto ToAnnotateJob(this AssetModel model)
86+
public static BulkUpdateAssetsJobDto ToAnnotate(this AssetModel model)
8887
{
89-
return new BulkUpdateAssetsJobDto
90-
{
91-
Id = model.Id,
92-
Type = BulkUpdateAssetType.Annotate,
93-
FileName = model.FileName,
94-
ParentId = null,
95-
Permanent = false,
96-
IsProtected = model.IsProtected,
97-
Metadata = model.Metadata,
98-
Slug = model.Slug,
99-
Tags = model.Tags
100-
};
88+
var bulkJob = model.ToJob(BulkUpdateAssetType.Annotate);
89+
90+
bulkJob.FileName = model.FileName;
91+
bulkJob.Metadata = model.Metadata;
92+
bulkJob.IsProtected = model.IsProtected;
93+
bulkJob.Slug = model.Slug;
94+
bulkJob.Tags = model.Tags;
95+
96+
return bulkJob;
97+
}
98+
99+
private static BulkUpdateAssetsJobDto ToJob(this AssetModel model, BulkUpdateAssetType type)
100+
{
101+
return new BulkUpdateAssetsJobDto { Id = model.Id, Type = type };
101102
}
102103

103104
public static async Task<AssetModel> ToModelAsync(this AssetDto asset, FolderTree folders)

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
114114
DoNotScript = true,
115115
DoNotValidate = false,
116116
DoNotValidateWorkflow = true,
117-
Jobs = model.Contents.Select(x => x.ToJob(schemas)).ToList()
117+
Jobs = model.Contents.Select(x => x.ToUpsert(schemas)).ToList()
118118
};
119119

120120
var contentIdAssigned = false;

cli/Squidex.CLI/Squidex.CLI/Commands/Implementation/Sync/Contents/Extensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace Squidex.CLI.Commands.Implementation.Sync.Contents
1616
{
1717
public static class Extensions
1818
{
19-
public static BulkUpdateJob ToJob(this ContentModel model, SchemasDto schemas)
19+
public static BulkUpdateJob ToUpsert(this ContentModel model, SchemasDto schemas)
2020
{
2121
var id = model.Id;
2222

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ==========================================================================
2+
// Squidex Headless CMS
3+
// ==========================================================================
4+
// Copyright (c) Squidex UG (haftungsbeschraenkt)
5+
// All rights reserved. Licensed under the MIT license.
6+
// ==========================================================================
7+
8+
using System;
9+
using Squidex.ClientLibrary;
10+
11+
namespace Squidex.CLI.Commands.Implementation.Sync.Rules
12+
{
13+
public static class Extensions
14+
{
15+
public static UpdateExtendableRuleDto ToUpdate(this RuleModel model)
16+
{
17+
return new UpdateExtendableRuleDto { Action = model.Action, Trigger = model.Trigger, Name = model.Name };
18+
}
19+
20+
public static CreateExtendableRuleDto ToCreate(this RuleModel model)
21+
{
22+
return new CreateExtendableRuleDto { Action = model.Action, Trigger = model.Trigger };
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)