Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix GetAsync not work when option is AllVersion #11433

Closed
wants to merge 7 commits into from

Conversation

hyzx86
Copy link
Contributor

@hyzx86 hyzx86 commented Mar 25, 2022

Fixes #16027

x.ContentItemId == contentItemId &&
x.Published == false &&
x.Latest == true)
x.ContentItemId == contentItemId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think better to not take into account soft deleted items having both Published = Latest = false.

x.ContentItemId == contentItemId && (x.Latest || x.Published)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really, if you select AllVersion but it is still restricted. It's confusing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I think better to not take into account soft deleted items having both Published = Latest = false.

@jtkech Yes, you are right, if you want to get different versions, you need to specify the version number.

Copy link
Contributor

@Skrypt Skrypt Mar 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to have a DeletedVersion option then too I think.

x.ContentItemId == contentItemId && (!x.Latest && !x.Published)

But maybe not necessary for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the current content state is a little bit too complicated. For example, as a new person, you need to look up code or documentation to fully understand what the state means

@sebastienros
Copy link
Member

Can you describe what "doesn't work" so we can recommend the best approach? Maybe open an issue?

@Skrypt
Copy link
Contributor

Skrypt commented Mar 29, 2022

Retrieving AllVersions all at once with the ContentManager.

@jtkech
Copy link
Member

jtkech commented Mar 29, 2022

Or as I understood, return any active version, maybe in priority the published version if it exists, or a draft version if it exists, that' why here the suggested code uses contentItemId && (x.Latest || x.Published).

But currently it then uses FirstOrDefaultAsync(), so it may return a draft whereas a published version exists.

Maybe it should use ListAsync() allowing to return a published version in priority.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 30, 2022

Yes, it is the same problem as this one,
#11447

Because my program uses SPA mode, much of the data manipulation is done through the Api
Initially I thought the draft state would be saved as the new ContentItemId,
It turns out there may be something wrong with the data I'm transferring, so the new ContentItemId is generated because the POST API/content doesn't seem to have any validation.
It might need to exclude two status fields (latest, published)(I can't remember),
For simplicity, I've implemented an API similar to the Graphql mutation myself
It can directly convert Graphql query results to Contentitem and then update the content

https://github.com/EasyOC/EasyOC/blob/eb1dc57f37491296823b633c30dc30806613e573/src/Modules/EasyOC.OrchardCore.ContentExtentions/AppServices/ContentManagementAppService.cs#L67

@hyzx86 hyzx86 closed this Mar 30, 2022
@hyzx86
Copy link
Contributor Author

hyzx86 commented Mar 30, 2022

Can you describe what "doesn't work" so we can recommend the best approach? Maybe open an issue?

mean is this filter option is never used in this method, But now it seems that just changing this doesn't make much sense, because if no filtering conditions are attached, a ContentItem will be obtained randomly (or with a minimum ID), so at least one ContentVersionId needs to be specified here

image

@hyzx86
Copy link
Contributor Author

hyzx86 commented Apr 1, 2022

Since this option doesn't serve any purpose, can we remove it?
It only has one reference in the Graphql status filter
This option does not return any data

public static VersionOptions AllVersions { get { return new VersionOptions { IsAllVersions = true }; } }

@hyzx86 hyzx86 reopened this Apr 1, 2022
@jtkech
Copy link
Member

jtkech commented Apr 1, 2022

Maybe we could have used AllVersions for the GetAsync() that returns a collection, currently we use a bool latest = false parameter, false meaning return all published, true all latest regardless there are published or not. So yes here we could have used AlVersions but we would need a new method to not break the existing one.

For the GetAsync that returns only one item, hmm maybe we could have used an AnyVersion with the behavior I described here #11433 (comment), but was just an idea, maybe too confusing ;)

So yes, if we keep the existing code I agree with you, maybe better to just get rid of the AllVersions option, or as said above and if we think it is worth, maybe use it for a GetAsync that returns a collection of items.

Note: Here we are talking about active versions (Published or Latest), Published and Latest are not versions in themselves but properties of a given version (related to a given contentItemVersionId), a content item having some versions but no active versions is a soft removed item.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 8, 2022

#11447

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 8, 2022

@jtkech
This is a very embarrassing question for me, if I want to rewrite GetAsync(id,option) , I need call BuildNewVersionAsync
But since it is not public, I have to copy this method to my ContentManager

contentItem = await BuildNewVersionAsync(contentItem);

But even if I copied it, I found ContentElement.Data is not open either

buildingContentItem.Data = new JObject(existingContentItem.Data);

Finally, I wrote l index query directly by referring to the code in AdminController
If so, what is the meaning of ContentManager

var checkedContentItems = await _session.Query<ContentItem, ContentItemIndex>().Where(x => x.DocumentId.IsIn(itemIds) && x.Latest).ListAsync(_contentManager);

@jtkech
Copy link
Member

jtkech commented Sep 8, 2022

Finally, I wrote l index query directly by referring to the code in AdminController
If so, what is the meaning of ContentManager

It allows to call the contentManager LoadAsync() on each contentItem which call handlers to activate correctly items if not yet done by looking at the contentManagerSession cache.

@hyzx86
Copy link
Contributor Author

hyzx86 commented Sep 8, 2022

Yes, I see. I mean, the current implementation of content manager is not complete enough

@jtkech
Copy link
Member

jtkech commented Sep 8, 2022

As additional info, as it is done when using content manager GetAsync(), activating item meaning activating item parts/fields

Copy link
Contributor

This pull request has merge conflicts. Please resolve those before requesting a review.

@@ -262,12 +262,12 @@ public class VersionOptions
/// <summary>
/// Gets all versions.
/// </summary>
public static VersionOptions AllVersions { get { return new VersionOptions { IsAllVersions = true }; } }
public static VersionOptions AnyVersion { get { return new VersionOptions { IsAnyVersions = true }; } }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the property but with [Obsolete], telling people to use this, so they'll know what's up instead of wondering after a build error.

More importantly though, I think the intent here is indeed to return all the versions of a content item. So, while this might not make sense for GetAsync(IEnumerable<string> contentItemIds, VersionOptions options), it does for GetAsync(string id, VersionOptions options). So, I don't think this should be changed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide unit tests.

@Piedone
Copy link
Member

Piedone commented May 16, 2024

We should rather remove VersionOptions.AllVersions, see comments from #16027 (comment)

@Piedone Piedone closed this May 16, 2024
@hyzx86 hyzx86 deleted the fixGetContentItemAllVersion branch June 13, 2024 06:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove VersionOptions.AllVersions
6 participants