You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A callback registered using Api.Hooks.Comments.RegisterOnAfterSave gets a Piranha.Models.Comment with the field ContentId set to all zeroes.
Steps to reproduce:
Install a fresh Razor template
Add the following line at bottom of Startup.cs: App.Hooks.Comments.RegisterOnAfterSave(c => Console.WriteLine(c.ContentId));
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.
The text was updated successfully, but these errors were encountered:
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.
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.
A callback registered using
Api.Hooks.Comments.RegisterOnAfterSave
gets aPiranha.Models.Comment
with the fieldContentId
set to all zeroes.Steps to reproduce:
Startup.cs
:App.Hooks.Comments.RegisterOnAfterSave(c => Console.WriteLine(c.ContentId));
Output of application:
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.
The text was updated successfully, but these errors were encountered: