Skip to content

Commit 8c03d02

Browse files
committed
Completely removed all EntityInserted<>, EntityUpdated<> and EntityDeleted<> shit. We were using DbSaveHooks anyway, which provides a much more powerful and way faster pub-sub mechanism for database operations.
1 parent 5056751 commit 8c03d02

63 files changed

Lines changed: 33 additions & 906 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* AmazonPay: The plugin has been changed to new "Login with Amazon" services. A registration at Amazon and new access data are necessary for its use. The old access data can no longer be used.
66
* (Dev) Calls to cache methods `Keys()` and `RemoveByPattern()` require glob chars to be present now (supported glob-styles see [https://redis.io/commands/keys](https://redis.io/commands/keys)). Previously these methods appended `*` to the passed pattern, which made pattern matching rather unflexible.
77
* (Dev) Hook framework now passes `IHookedEntity` interface instead of `HookedEntity` class
8+
* (Dev) Completely removed all `EntityInserted<T>`, `EntityUpdated<T>` and `EntityDeleted<T>` legacy events. We were using DbSaveHooks anyway, which provides a much more powerful and way faster pub-sub mechanism for database operations.
89

910
### Highlights
1011
* Multi-configurable rounding of order total ("cash rounding"). Can be adjusted and activated separately for each currency and payment method.

src/Libraries/SmartStore.Core/Data/Hooks/HookedEntity.cs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Data.Entity.Infrastructure;
3+
using EfState = System.Data.Entity.EntityState;
34

45
namespace SmartStore.Core.Data.Hooks
56
{
@@ -35,6 +36,14 @@ public interface IHookedEntity
3536
/// </summary>
3637
/// <param name="propertyName">Name of the property</param>
3738
bool IsPropertyModified(string propertyName);
39+
40+
/// <summary>
41+
/// Gets a value indicating whether the entity is in soft deleted state.
42+
/// This is the case when the entity is an instance of <see cref="ISoftDeletable"/>
43+
/// and the value of its <c>Deleted</c> property is true AND has changed since tracking.
44+
/// But when the entity is not in modified state the snapshot comparison is omitted.
45+
/// </summary>
46+
bool IsSoftDeleted { get; }
3847
}
3948

4049
public class HookedEntity : IHookedEntity
@@ -80,7 +89,7 @@ public EntityState State
8089
}
8190
set
8291
{
83-
Entry.State = (System.Data.Entity.EntityState)((int)value);
92+
Entry.State = (EfState)((int)value);
8493
}
8594
}
8695

@@ -109,5 +118,21 @@ public bool IsPropertyModified(string propertyName)
109118

110119
return false;
111120
}
121+
122+
public bool IsSoftDeleted
123+
{
124+
get
125+
{
126+
var entity = Entry.Entity as ISoftDeletable;
127+
if (entity != null)
128+
{
129+
return Entry.State == EfState.Modified
130+
? entity.Deleted && IsPropertyModified("Deleted")
131+
: entity.Deleted;
132+
}
133+
134+
return false;
135+
}
136+
}
112137
}
113138
}

src/Libraries/SmartStore.Core/Events/CommonMessages/EntityDeleted.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Libraries/SmartStore.Core/Events/CommonMessages/EntityInserted.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/Libraries/SmartStore.Core/Events/CommonMessages/EntityUpdated.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/Libraries/SmartStore.Core/Events/IEventPublisher.cs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,4 @@ public interface IEventPublisher
55
{
66
void Publish<T>(T eventMessage);
77
}
8-
9-
public static class IEventPublisherExtensions
10-
{
11-
public static void EntityInserted<T>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity
12-
{
13-
eventPublisher.Publish(new EntityInserted<T>(entity));
14-
}
15-
16-
public static void EntityUpdated<T>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity
17-
{
18-
eventPublisher.Publish(new EntityUpdated<T>(entity));
19-
}
20-
21-
public static void EntityDeleted<T>(this IEventPublisher eventPublisher, T entity) where T : BaseEntity
22-
{
23-
eventPublisher.Publish(new EntityDeleted<T>(entity));
24-
}
25-
}
268
}

src/Libraries/SmartStore.Core/SmartStore.Core.csproj

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,6 @@
398398
<Compile Include="Domain\Polls\PollAnswer.cs" />
399399
<Compile Include="Domain\Polls\Poll.cs" />
400400
<Compile Include="Domain\Orders\BestsellersReportLine.cs" />
401-
<Compile Include="Events\CommonMessages\EntityDeleted.cs" />
402-
<Compile Include="Events\CommonMessages\EntityInserted.cs" />
403-
<Compile Include="Events\CommonMessages\EntityUpdated.cs" />
404401
<Compile Include="Extensions\ConversionExtensions.cs" />
405402
<Compile Include="Extensions\DateTimeExtensions.cs" />
406403
<Compile Include="Extensions\DictionaryExtensions.cs" />
Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
namespace SmartStore.Data.Migrations
22
{
33
using System;
4-
using System.Linq;
5-
using System.Data.Entity;
6-
using System.Collections.Generic;
74
using System.Data.Entity.Migrations;
8-
using Core.Domain.Catalog;
95
using Setup;
10-
using Core;
116
using Utilities;
127

138
public partial class ProductMainPictureId : DbMigration, IDataSeeder<SmartObjectContext>
@@ -30,59 +25,6 @@ public bool RollbackOnFailure
3025
public void Seed(SmartObjectContext context)
3126
{
3227
DataNormalizer.FixProductMainPictureIds(context, true);
33-
34-
//var query = context.Set<Product>()
35-
// .AsNoTracking()
36-
// .Where(x => x.MainPictureId == null)
37-
// .OrderBy(x => x.Id)
38-
// .Select(x => x.Id);
39-
40-
//int pageIndex = 0;
41-
//PagedList<int> productIds = null;
42-
43-
//while (true)
44-
//{
45-
// productIds = new PagedList<int>(query, pageIndex, 1000);
46-
47-
// var map = GetPoductPictureMap(context, productIds);
48-
49-
// using (var tx = context.Database.BeginTransaction())
50-
// {
51-
// foreach (var kvp in map)
52-
// {
53-
// context.ExecuteSqlCommand("Update [Product] Set [MainPictureId] = {0} WHERE [Id] = {1}", false, null, kvp.Value, kvp.Key);
54-
// }
55-
56-
// if (map.Any())
57-
// {
58-
// context.SaveChanges();
59-
// tx.Commit();
60-
// }
61-
// }
62-
63-
// if (!productIds.HasNextPage)
64-
// break;
65-
//}
6628
}
67-
68-
//private IDictionary<int, int> GetPoductPictureMap(SmartObjectContext context, IEnumerable<int> productIds)
69-
//{
70-
// var map = new Dictionary<int, int>();
71-
72-
// var query = from pp in context.Set<ProductPicture>().AsNoTracking()
73-
// where productIds.Contains(pp.ProductId)
74-
// group pp by pp.ProductId into g
75-
// select new
76-
// {
77-
// ProductId = g.Key,
78-
// PictureIds = g.OrderBy(x => x.DisplayOrder)
79-
// .Take(1)
80-
// .Select(x => x.PictureId)
81-
// };
82-
83-
// map = query.ToList().ToDictionary(x => x.ProductId, x => x.PictureIds.First());
84-
85-
// return map;
86-
//}
8729
}
8830
}

src/Libraries/SmartStore.Services/Affiliates/AffiliateService.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,6 @@ public virtual void InsertAffiliate(Affiliate affiliate)
8989
throw new ArgumentNullException("affiliate");
9090

9191
_affiliateRepository.Insert(affiliate);
92-
93-
//event notification
94-
_eventPublisher.EntityInserted(affiliate);
9592
}
9693

9794
/// <summary>
@@ -104,9 +101,6 @@ public virtual void UpdateAffiliate(Affiliate affiliate)
104101
throw new ArgumentNullException("affiliate");
105102

106103
_affiliateRepository.Update(affiliate);
107-
108-
//event notification
109-
_eventPublisher.EntityUpdated(affiliate);
110104
}
111105

112106
#endregion

src/Libraries/SmartStore.Services/Blogs/BlogService.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,6 @@ public virtual void DeleteBlogPost(BlogPost blogPost)
6363
throw new ArgumentNullException("blogPost");
6464

6565
_blogPostRepository.Delete(blogPost);
66-
67-
//event notification
68-
_services.EventPublisher.EntityDeleted(blogPost);
6966
}
7067

7168
/// <summary>
@@ -226,9 +223,6 @@ public virtual void InsertBlogPost(BlogPost blogPost)
226223
throw new ArgumentNullException("blogPost");
227224

228225
_blogPostRepository.Insert(blogPost);
229-
230-
//event notification
231-
_services.EventPublisher.EntityInserted(blogPost);
232226
}
233227

234228
/// <summary>
@@ -241,9 +235,6 @@ public virtual void UpdateBlogPost(BlogPost blogPost)
241235
throw new ArgumentNullException("blogPost");
242236

243237
_blogPostRepository.Update(blogPost);
244-
245-
//event notification
246-
_services.EventPublisher.EntityUpdated(blogPost);
247238
}
248239

249240
/// <summary>

0 commit comments

Comments
 (0)