Browse Source

Deletion handling improved

pull/1/head
Sebastian 9 years ago
parent
commit
6afced66ee
  1. 4
      src/Squidex.Read.MongoDb/Contents/MongoContentEntity.cs
  2. 11
      src/Squidex.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs
  3. 5
      src/Squidex.Read.MongoDb/Contents/Visitors/FindExtensions.cs
  4. 4
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs
  5. 10
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs
  6. 3
      src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs
  7. 2
      src/Squidex/app/features/content/pages/content/content-field.component.html
  8. 1
      src/Squidex/project.json

4
src/Squidex.Read.MongoDb/Contents/MongoContentEntity.cs

@ -28,10 +28,6 @@ namespace Squidex.Read.MongoDb.Contents
{ {
private ContentData contentData; private ContentData contentData;
[BsonRequired]
[BsonElement]
public bool IsDeleted { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement]
public bool IsPublished { get; set; } public bool IsPublished { get; set; }

11
src/Squidex.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs

@ -111,22 +111,19 @@ namespace Squidex.Read.MongoDb.Contents
}); });
} }
protected Task On(ContentDeleted @event, EnvelopeHeaders headers) protected Task On(FieldDeleted @event, EnvelopeHeaders headers)
{ {
return ForSchemaIdAsync(@event.SchemaId.Id, collection => return ForSchemaIdAsync(@event.SchemaId.Id, collection =>
{ {
return collection.UpdateAsync(@event, headers, x => return collection.UpdateManyAsync(new BsonDocument(), Update.Unset(new StringFieldDefinition<MongoContentEntity>($"Data.{@event.FieldId}")));
{
x.IsDeleted = true;
});
}); });
} }
protected Task On(FieldDeleted @event, EnvelopeHeaders headers) protected Task On(ContentDeleted @event, EnvelopeHeaders headers)
{ {
return ForSchemaIdAsync(@event.SchemaId.Id, collection => return ForSchemaIdAsync(@event.SchemaId.Id, collection =>
{ {
return collection.UpdateManyAsync(new BsonDocument(), Update.Unset(new StringFieldDefinition<MongoContentEntity>($"Data.{@event.FieldId}"))); return collection.DeleteOneAsync(x => x.Id == headers.AggregateId());
}); });
} }

5
src/Squidex.Read.MongoDb/Contents/Visitors/FindExtensions.cs

@ -55,10 +55,7 @@ namespace Squidex.Read.MongoDb.Contents.Visitors
public static FilterDefinition<MongoContentEntity> BuildQuery(ODataUriParser query, Schema schema, bool nonPublished) public static FilterDefinition<MongoContentEntity> BuildQuery(ODataUriParser query, Schema schema, bool nonPublished)
{ {
var filters = new List<FilterDefinition<MongoContentEntity>> var filters = new List<FilterDefinition<MongoContentEntity>>();
{
Filter.Eq(x => x.IsDeleted, false)
};
if (!nonPublished) if (!nonPublished)
{ {

4
src/Squidex.Read.MongoDb/Schemas/MongoSchemaEntity.cs

@ -33,10 +33,6 @@ namespace Squidex.Read.MongoDb.Schemas
[BsonElement] [BsonElement]
public string Schema { get; set; } public string Schema { get; set; }
[BsonRequired]
[BsonElement]
public bool IsDeleted { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement]
public Guid AppId { get; set; } public Guid AppId { get; set; }

10
src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository.cs

@ -54,14 +54,14 @@ namespace Squidex.Read.MongoDb.Schemas
public async Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId) public async Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId)
{ {
var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); var entities = await Collection.Find(s => s.AppId == appId).ToListAsync();
return entities.OfType<ISchemaEntity>().ToList(); return entities.OfType<ISchemaEntity>().ToList();
} }
public async Task<IReadOnlyList<ISchemaEntityWithSchema>> QueryAllWithSchemaAsync(Guid appId) public async Task<IReadOnlyList<ISchemaEntityWithSchema>> QueryAllWithSchemaAsync(Guid appId)
{ {
var entities = await Collection.Find(s => s.AppId == appId && !s.IsDeleted).ToListAsync(); var entities = await Collection.Find(s => s.AppId == appId).ToListAsync();
entities.ForEach(x => x.DeserializeSchema(serializer)); entities.ForEach(x => x.DeserializeSchema(serializer));
@ -71,7 +71,7 @@ namespace Squidex.Read.MongoDb.Schemas
public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid appId, string name) public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid appId, string name)
{ {
var entity = var entity =
await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted) await Collection.Find(s => s.Name == name && s.AppId == appId)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
entity?.DeserializeSchema(serializer); entity?.DeserializeSchema(serializer);
@ -82,7 +82,7 @@ namespace Squidex.Read.MongoDb.Schemas
public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId) public async Task<ISchemaEntityWithSchema> FindSchemaAsync(Guid schemaId)
{ {
var entity = var entity =
await Collection.Find(s => s.Id == schemaId && !s.IsDeleted) await Collection.Find(s => s.Id == schemaId)
.FirstOrDefaultAsync(); .FirstOrDefaultAsync();
entity?.DeserializeSchema(serializer); entity?.DeserializeSchema(serializer);
@ -93,7 +93,7 @@ namespace Squidex.Read.MongoDb.Schemas
public async Task<Guid?> FindSchemaIdAsync(Guid appId, string name) public async Task<Guid?> FindSchemaIdAsync(Guid appId, string name)
{ {
var entity = var entity =
await Collection.Find(s => s.Name == name & s.AppId == appId && !s.IsDeleted) await Collection.Find(s => s.Name == name & s.AppId == appId)
.Project<MongoSchemaEntity>(Projection.Include(x => x.Id)).FirstOrDefaultAsync(); .Project<MongoSchemaEntity>(Projection.Include(x => x.Id)).FirstOrDefaultAsync();
return entity?.Id; return entity?.Id;

3
src/Squidex.Read.MongoDb/Schemas/MongoSchemaRepository_EventHandling.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver;
using Squidex.Core.Schemas; using Squidex.Core.Schemas;
using Squidex.Events; using Squidex.Events;
using Squidex.Events.Schemas; using Squidex.Events.Schemas;
@ -91,7 +92,7 @@ namespace Squidex.Read.MongoDb.Schemas
protected async Task On(SchemaDeleted @event, EnvelopeHeaders headers) protected async Task On(SchemaDeleted @event, EnvelopeHeaders headers)
{ {
await Collection.UpdateAsync(@event, headers, s => s.IsDeleted = true); await Collection.DeleteOneAsync(x => x.Id == headers.AggregateId());
SchemaSaved?.Invoke(@event.AppId, @event.SchemaId); SchemaSaved?.Invoke(@event.AppId, @event.SchemaId);
} }

2
src/Squidex/app/features/content/pages/content/content-field.component.html

@ -3,7 +3,7 @@
{{field|displayName:'properties.label':'name'}} <span class="field-required" [class.hidden]="!field.properties.isRequired">*</span> {{field|displayName:'properties.label':'name'}} <span class="field-required" [class.hidden]="!field.properties.isRequired">*</span>
</label> </label>
<span class="field-disabled" *ngIf="fieldForm.disabled">Disabled</span> <span class="field-disabled" *ngIf="field.isDisabled">Disabled</span>
<div [formGroup]="fieldForm"> <div [formGroup]="fieldForm">
<div *ngIf="field.properties.isLocalizable"> <div *ngIf="field.properties.isLocalizable">

1
src/Squidex/project.json

@ -31,7 +31,6 @@
"Squidex.Core": "1.0.0-*", "Squidex.Core": "1.0.0-*",
"Squidex.Events": "1.0.0-*", "Squidex.Events": "1.0.0-*",
"Squidex.Infrastructure": "1.0.0-*", "Squidex.Infrastructure": "1.0.0-*",
"Squidex.Infrastructure.GoogleCloud": "1.0.0-*",
"Squidex.Infrastructure.MongoDb": "1.0.0-*", "Squidex.Infrastructure.MongoDb": "1.0.0-*",
"Squidex.Infrastructure.Redis": "1.0.0-*", "Squidex.Infrastructure.Redis": "1.0.0-*",
"Squidex.Read": "1.0.0-*", "Squidex.Read": "1.0.0-*",

Loading…
Cancel
Save