|
|
@ -116,9 +116,9 @@ namespace Squidex.Domain.Apps.Write.Contents |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
{ |
|
|
{ |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var scriptContext = CreateScriptContext(content, command); |
|
|
var scriptContext = CreateScriptContext(content, command, "Publish"); |
|
|
|
|
|
|
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptPublish, "publish content"); |
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptChange, "publish content"); |
|
|
|
|
|
|
|
|
content.Publish(command); |
|
|
content.Publish(command); |
|
|
}); |
|
|
}); |
|
|
@ -129,35 +129,53 @@ namespace Squidex.Domain.Apps.Write.Contents |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
{ |
|
|
{ |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var scriptContext = CreateScriptContext(content, command); |
|
|
var scriptContext = CreateScriptContext(content, command, "Unpublish"); |
|
|
|
|
|
|
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptUnpublish, "unpublish content"); |
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptChange, "unpublish content"); |
|
|
|
|
|
|
|
|
content.Unpublish(command); |
|
|
content.Unpublish(command); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected Task On(DeleteContent command, CommandContext context) |
|
|
protected Task On(ArchiveContent command, CommandContext context) |
|
|
{ |
|
|
{ |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
{ |
|
|
{ |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
var scriptContext = CreateScriptContext(content, command); |
|
|
var scriptContext = CreateScriptContext(content, command, "Archive"); |
|
|
|
|
|
|
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptDelete, "delete content"); |
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptChange, "archive content"); |
|
|
|
|
|
|
|
|
content.Delete(command); |
|
|
content.Archive(command); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
protected Task On(RestoreContent command, CommandContext context) |
|
|
protected Task On(RestoreContent command, CommandContext context) |
|
|
{ |
|
|
{ |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, content => |
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
{ |
|
|
{ |
|
|
|
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
|
|
|
var scriptContext = CreateScriptContext(content, command, "Restore"); |
|
|
|
|
|
|
|
|
|
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptChange, "restore content"); |
|
|
|
|
|
|
|
|
content.Restore(command); |
|
|
content.Restore(command); |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected Task On(DeleteContent command, CommandContext context) |
|
|
|
|
|
{ |
|
|
|
|
|
return handler.UpdateAsync<ContentDomainObject>(context, async content => |
|
|
|
|
|
{ |
|
|
|
|
|
var schemaAndApp = await ResolveSchemaAndAppAsync(command); |
|
|
|
|
|
var scriptContext = CreateScriptContext(content, command, "Delete"); |
|
|
|
|
|
|
|
|
|
|
|
scriptEngine.Execute(scriptContext, schemaAndApp.SchemaEntity.ScriptDelete, "delete content"); |
|
|
|
|
|
|
|
|
|
|
|
content.Delete(command); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public async Task HandleAsync(CommandContext context, Func<Task> next) |
|
|
public async Task HandleAsync(CommandContext context, Func<Task> next) |
|
|
{ |
|
|
{ |
|
|
if (!await this.DispatchActionAsync(context.Command, context)) |
|
|
if (!await this.DispatchActionAsync(context.Command, context)) |
|
|
@ -200,9 +218,14 @@ namespace Squidex.Domain.Apps.Write.Contents |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private static ScriptContext CreateScriptContext(ContentDomainObject content, ContentCommand command, NamedContentData data = null) |
|
|
private static ScriptContext CreateScriptContext(ContentDomainObject content, ContentCommand command, string operation) |
|
|
|
|
|
{ |
|
|
|
|
|
return new ScriptContext { ContentId = content.Id, OldData = content.Data, User = command.User, Operation = operation }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static ScriptContext CreateScriptContext(ContentDomainObject content, ContentCommand command, NamedContentData data) |
|
|
{ |
|
|
{ |
|
|
return new ScriptContext { ContentId = content.Id, Data = data, OldData = content.Data, User = command.User }; |
|
|
return new ScriptContext { ContentId = content.Id, OldData = content.Data, User = command.User, Data = data }; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private async Task<(ISchemaEntity SchemaEntity, IAppEntity AppEntity)> ResolveSchemaAndAppAsync(SchemaCommand command) |
|
|
private async Task<(ISchemaEntity SchemaEntity, IAppEntity AppEntity)> ResolveSchemaAndAppAsync(SchemaCommand command) |
|
|
|