public function discussionController_commentOptions_handler($sender, $args) {
if (
!Gdn::session()->checkPermission(
'Vanilla.Discussions.Edit',
true,
'Category',
$args['Discussion']->PermissionCategoryID
)
) {
return;
}
$args['CommentOptions']['ChangeAuthor'] = [
'Label' => t('Change Author'),
'Url' => '/discussion/author?commentid='.$args['Comment']->CommentID,
'Class' => 'ChangeAuthor'
];
}
/**
* Handle discussion option menu Change Author action.
*/
public function discussionController_author_create($sender, $args) {
$requestArguments = $sender->Request->getRequestArguments('get');
$recordType = 'discussion';
$discussionID = val('discussionid', $requestArguments, '');
if ($discussionID === '') {
$commentID = val('commentid', $requestArguments, '');
$comment = $sender->CommentModel->getID($commentID);
if (!$comment) {
throw NotFoundException('Comment');
}
$discussionID = $comment->DiscussionID;
$recordType = 'comment';
}
$discussion = $sender->DiscussionModel->getID($discussionID);
if (!$discussion) {
throw notFoundException('Discussion');
}
// Check edit permission
$sender->permission(
'Vanilla.Discussions.Edit',
true,
'Category',
$discussion->PermissionCategoryID
);
do {
if (!$sender->Form->authenticatedPostBack()) {
break;
}
// Change the author
$user = Gdn::userModel()->getByUsername(
trim($sender->Form->getFormValue('Author', ''))
);
if (!is_object($user)) {
$sender->Form->addError('No user with that name was found.');
break;
}
if (${"$recordType"}->InsertUserID == $user->UserID) {
$sender->Form->addError(
'That user is already the '.$recordType.' author.'
);
break;
}
switch ($recordType) {
case 'comment':
$sender->CommentModel->setField($commentID, 'InsertUserID', $user->UserID);
// Update users' comment counts
$sender->CommentModel->updateUser($comment->InsertUserID);
$sender->CommentModel->updateUser($user->UserID, true); // Increment
redirect(discussionUrl($discussion).'#Comment_'.$commentID);
break;
case 'discussion':
$sender->DiscussionModel->setField($discussionID, 'InsertUserID', $user->UserID);
// Update users' discussion counts
$sender->DiscussionModel->UpdateUserDiscussionCount($discussion->InsertUserID);
$sender->DiscussionModel->UpdateUserDiscussionCount($user->UserID, true); // Increment
redirect(discussionUrl($discussion));
break;
default:
break;
}
} while (false);
// Form to change the author
$sender->setData('Title', $discussion->Name);
$sender->render('changeauthor', '', 'plugins/AuthorSelector');
}
But I've seen that I forgot updating discussions comment counts.
And trying my code on my test forum with enabled cache, gives me strange behavior with the comment count. CommentModel->updateUser doesn't update the cached user, while the DiscussionModel does. Don't know if this can be considered an issue or not. @Linc: what is your opinion on that?
In a blog-like setup, the person creating a discussion might actually be someone like an editor, which is the scenario I envisioned for this addon. I don't understand the use case of changing a comment's author.
Sorry, I could have been more clearer:
discussionModel->updateUserDiscussionCount() makes a call to userModel->updateUserCache while commentModel->updateUser does not. Is that worth making a pull request?
@Linc said:
I don't understand the use case of changing a comment's author.
Me either.
@R_J said:
Sorry, I could have been more clearer:
discussionModel->updateUserDiscussionCount() makes a call to userModel->updateUserCache while commentModel->updateUser does not.
@Linc said:
I don't understand the use case of changing a comment's author.
Thank you @Linc to take time to reply... We (graphical & musical artists collective) 're using Vanilla as a classic forums board, so I would like change personal name of one of us to our crew name for example ;-) if it's understandable in English...
Ah, so maybe more of a group account, where folks can do a "Post As..." option and change to the collective before posting, a la Facebook page management. That feature makes sense. Adding the retroactive switching to this plugin makes less sense.
Comments
No easy way; but there is a way. Fork it and add the necessary code!
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
lol
I was even thinking about a pull request:
But I've seen that I forgot updating discussions comment counts.
And trying my code on my test forum with enabled cache, gives me strange behavior with the comment count.
CommentModel->updateUser
doesn't update the cached user, while the DiscussionModel does. Don't know if this can be considered an issue or not. @Linc: what is your opinion on that?In a blog-like setup, the person creating a discussion might actually be someone like an editor, which is the scenario I envisioned for this addon. I don't understand the use case of changing a comment's author.
Sorry, I could have been more clearer:
discussionModel->updateUserDiscussionCount() makes a call to userModel->updateUserCache while commentModel->updateUser does not. Is that worth making a pull request?
Me either.
insightful
Always.
Search first
Check out the Documentation! We are always looking for new content and pull requests.
Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.
Great reply ;-) many thanks @hgtonight and @R_J then I 'll try it A.S.A.P.
Thank you @Linc to take time to reply... We (graphical & musical artists collective) 're using Vanilla as a classic forums board, so I would like change personal name of one of us to our crew name for example ;-) if it's understandable in English...
Ah, so maybe more of a group account, where folks can do a "Post As..." option and change to the collective before posting, a la Facebook page management. That feature makes sense. Adding the retroactive switching to this plugin makes less sense.