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

PrimaryImage with null Media in ISearch.SavePostAsync #2035

Closed
hadrian625 opened this issue Dec 14, 2023 · 2 comments
Closed

PrimaryImage with null Media in ISearch.SavePostAsync #2035

hadrian625 opened this issue Dec 14, 2023 · 2 comments

Comments

@hadrian625
Copy link

hadrian625 commented Dec 14, 2023

We are using a custom implementation of the ISearch interface to index the content from Piranha CMS. Among other data, we are indexing also the primary image for posts. In the past, the "post" argument of the ISearch.SavePostAsync had in its PrimaryImage property the field "Media" filled in, so we could get the url of the image and store it in our indexing service.
I don't know when this changed, but we got a bug from the customer, that after any change is published/saved on the post in Piranha CMS Manager, the search indexed data no longer has an image.

Looking into this I discovered that the "post" arg from ISearch.SavePostAsync no longer has the Media filled in. I tracked this call to Piranha.Services.PostService.SaveAsync(T model, bool isDraft) where T : PostBase.
That class wasn't changed since a long time, so the fact that the PrimaryImage field on the post does not have its Media property filled in is not from here.
But I know this worked in the past, since we had image urls in our search service indexed data
How can this be solved in a correct manner?

As a workaround, now we use the App.Hooks.Posts.RegisterOnBeforeSave to register a custom hook that loads the Media field in the PrimaryImage from post. It uses IContentFactory.InitFieldAsync(post.PrimaryImage), which is the same approach used where retrieving a post from Piranha.Services.PostService.GetByIdAsync(Guid id, IList blogPages) where T : PostBase -> OnLoadAsync

if (model.PrimaryImage.Id.HasValue) { await _factory.InitFieldAsync(model.PrimaryImage).ConfigureAwait(false); }

Does anyone know what changed in the Piranha library that caused this issue to show up? I am not sure how it should be resolved though.

We are using Piranha 10.4

@tidyui
Copy link
Member

tidyui commented Apr 1, 2024

Hi there! I've investigated the code that is responsible for saving a post from the manager UI. The following javascript code is responsible for sending the updated model to the server, which only includes the id of the media. I can't see that this has been handled differently in the past with git blame.

https://github.com/PiranhaCMS/piranha.core/blob/master/core/Piranha.Manager/assets/src/js/piranha.postedit.js#L218

The deserialized model is then passed to Piranha.Manager.Services.PostService which sets the model and calls the main Api for saving the post. Here the deserialized model (which only contains id for primary image) is assigned. I can't find any changes in this area either using git blame.

https://github.com/PiranhaCMS/piranha.core/blob/master/core/Piranha.Manager/Services/PostService.cs#L282

So I can't locate any changes in the code that would've included the actual media content previously.

@tidyui
Copy link
Member

tidyui commented May 15, 2024

Closing due to lack of activity

@tidyui tidyui closed this as completed May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants