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

ContentId of Comments not set in OnAfterSave hook #1338

Closed
jensbrak opened this issue Sep 17, 2020 · 4 comments
Closed

ContentId of Comments not set in OnAfterSave hook #1338

jensbrak opened this issue Sep 17, 2020 · 4 comments
Assignees
Milestone

Comments

@jensbrak
Copy link
Contributor

jensbrak commented Sep 17, 2020

A callback registered using Api.Hooks.Comments.RegisterOnAfterSave gets a Piranha.Models.Comment with the field ContentId set to all zeroes.

Steps to reproduce:

  1. Install a fresh Razor template
  2. Add the following line at bottom of Startup.cs:
    App.Hooks.Comments.RegisterOnAfterSave(c => Console.WriteLine(c.ContentId));
  3. Run the template and submit a valid comment on any post

Output of application:

dotnet run
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: https://localhost:5001
info: Microsoft.Hosting.Lifetime[0]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\src\piranhatest
00000000-0000-0000-0000-000000000000

The same goes for comments posted with moderation turned on in manager, the first time the callback for OnAfterSave is called (user posted the comment). The second time the callback is called (admin approved comment) the field ContentId has a seemingly valid value.

@tidyui tidyui added this to the Version 9.0 milestone Sep 18, 2020
@jensbrak
Copy link
Contributor Author

Another observation: The hook for CommentValidation could use the ContentId of the comment to get information about the content the comment belongs to. However, here too the ContentId is zoroed, so there's no use for it in the Validation hook.

@jensbrak
Copy link
Contributor Author

I have a PR fixing this. The ContentId is never assigned to the comment when the comment is added. The fix is to simply let the Page and Post services assign it, just as they ensure that date and comment id are valid. Perhaps the calling methods should do this (too or instead?) but it seems more logical to mr to have the services check for it and assign.

@tidyui
Copy link
Member

tidyui commented Sep 28, 2020

It just looks like the repository is responsible for making the connection which is wrong. The ContentId of the comment should set here for posts (and in the same location for pages). https://github.com/PiranhaCMS/piranha.core/blob/master/core/Piranha/Services/PostService.cs#L623

@jensbrak
Copy link
Contributor Author

Yes, exactly what I did. Works fine now. Just gonna do a PR för it as soon as I can.

tidyui added a commit that referenced this issue Sep 28, 2020
Fix of issue #1338: ContentId not properly set
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