Orchard cms get latest version of content item even if it removed

263 Views Asked by At

I'm using Orchard 1.7

In Orchard, when a content item is removed, it don't actually deleted from database, the cms just only set Published & Latest value of all versions of content item to 0, it still can be retrieved

And my problem is: I have a user that was removed (this user was modified many times, especially the Title)

Case 1: I use cms.Get(userId, VersionOptions.AllVersions).As<TitlePart>()

Case 2: I use myItem.As<CommonPart>().Owner.As<TitlePart>()

And the result is it always returns the title of the first version of this user, I want it return the latest version (the largest version number) of it.

So, where in Orchard should I modify to resolve this ?

1

There are 1 best solutions below

0
ViRuSTriNiTy On

I had this issue too. Here is my solution to query the recent version of a deleted user by using the content manager:

Orchard.Users.Models.UserPart lUserPart = mContentManager
  .Query<Orchard.Users.Models.UserPart,
    Orchard.Users.Models.UserPartRecord>(VersionOptions.AllVersions)
  .Where(u => u.NormalizedUserName == lowerName) // taken from Orchard.Users.Services.MembershipService.GetUser()
  .List()
  .LastOrDefault(); // LastOrDefault() to get version with highest version number