XF 2.3 Extending thread creation

Sysnative

Well-known member
Hi,

I'm running into an issue extending the Forum class - what I'm trying to achieve is to automatically add a reply after a thread is created. I'm trying to extend the "finalizeThreadCreate" method in the Forum class.

I have some code which is currently doing nothing as far as I can tell. Two questions on this:

1. Should I be approaching this differently?
2. How can I best debug class extensions to determine where the issue is?

PHP:
class Forum extends XFCP_Forum
{
    protected function finalizeThreadCreate(\XF\Service\Thread\CreatorService $creator)
    {
        parent::finalizeThreadCreate($creator);
        $forum = $creator->getForum();
        $HelperForumId = $this->options()->sysnatHelperBotForumId;

        if($forum->node_id == $HelperForumId){
            $userId = $this->options()->sysnativeHelperBotUserId;
            $thread = $creator->getThread();
            $user = \XF::em()->find('XF:User', $userId);
            $message = $this->error(\XF::phrase('sysnative_helper_bot_first_post'));
            \XF::asVisitor($user, function () use ($thread, $message) {
                $replier = \XF::service('XF:Thread\Replier', $thread);
                $replier->setMessage($message);
                $replier->setIsAutomated();
                $replier->save();
            });
        }
    }
}
 
Okay disregard - I was extending the wrong class (trying to extend Admin Forum creation rather than the Pub ForumController.

Still curious if anyone has a better suggestion or approach.
 
Question -

If I want to post an automated reply to a thread on thread creation, but still trigger notifications on the response (email + alert) - is there a better class for me to extend to do this?

At the moment extending the ForumController finalizeThreadCreate class works, but doesn't generate any notifications that a new post has been added.
 
This idea is kinda like the Auto Posting Bots on Reddit.

The do help cut down on moderation, but they can get annoying.

If the purpose of the auto reply is to make sure people include the right information, then making it mandatory with custom user fields can prevent the problems.
 
Back
Top Bottom