Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
saved comment's ID
anyone knows how to get the ID of a comment just after being saved?
I assume that knowing it before is at least approximate, but I just can't achieve to get it after saving.
thanks
I assume that knowing it before is at least approximate, but I just can't achieve to get it after saving.
thanks
0
This discussion has been closed.
Comments
CommentManager::SaveComment()
method on line 289. The relevant delegate to hook in to would be"CommentManager"->"PostSaveNewComment"
. However, something is not right in that block of code...In PHP5 it should work fine (because PHP5 doesn't implicitly clone objects), but PHP4 would duplicate the
$Comment
object (on line 348 of the same file). Perhaps a dev could look in to why it was done this way...It's been like this since Vanilla 0.9.2, maybe earlier.
It's interesting to me because a Delegate Parameter for the
$SaveComment
object is set, but the new comment ID (after the object is saved), is set on the$Comment
object. I think what should be done (in short) is$this->DelegateParameters['Comment'] = &$SaveComment;
be changed to$this->DelegateParameters['Comment'] = &$Comment;
Some more thought needs to be done here though...0.9.2 didn't even have delegation, so I think using $SaveComment on the DelegateParameter is purely by accident. $Comment is set back to $SaveComment further down on both sides of the IF (lines 338 and 439) so replacing every $SaveComment with $Comment and removing the three copying lines should have no effect other than making PHP 5 and older versions of PHP work the same.
I can run this by Mark to make sure, just to be safe.
// Comments
for I confess though that I even forget to document my code sometimes...- 'PostSaveNewComment' delegate of the Comment Manager, or
- the 'PostSaveComment' of the DiscussionForm?
because the one of the CommentManager doesn't delegate the comment, so i don't know how to access its properties (specially its ID)sorry for the ignorance :P
The trick is that the &$Comment doesn't just return the comment object, but a pointer to that object, and the pointer is set about 30 lines above that. So your extension will look at where that pointer points, which happens to be the same comment object that just got the ID assigned.
Try it out!