News:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu

Create topic Background tasks

Started by mickjav, April 28, 2024, 08:45:07 AM

Previous topic - Next topic

mickjav

I am looking at using some code from @vbgamer45 gallery pro, there is a section I'm not sure if I need or not I'm using 2.1.14, so I suspect I don't need the $notifyData section.

I'm trying to understand the background_tasks and whether I need it or not.

Different Members will be posting through a custom UI, these posts will only be the topic post all replies will be del with in the normal way.

Does this  background_tasks take care of letting members know when a new reply has been added?


if (function_exists("notifyMembersBoard"))
            {
                $notifyData = array(
                            'body' =>$msgOptions['body'],
                            'subject' => $msgOptions['subject'],
                            'name' => $user_info['name'],
                            'poster' => $user_info['id'],
                            'msg' => $msgOptions['id'],
                            'board' =>  $rowcat['id_board'],
                            'topic' => $topicOptions['id'],
                        );
                notifyMembersBoard($notifyData);
                    }
                    else
                    {
                     // for 2.1
                    $smcFunc['db_insert']('',
                        '{db_prefix}background_tasks',
                        array('task_file' => 'string', 'task_class' => 'string', 'task_data' => 'string', 'claimed_time' => 'int'),
                        array('$sourcedir/tasks/CreatePost-Notify.php', 'CreatePost_Notify_Background', $smcFunc['json_encode'](array(
                            'msgOptions' => $msgOptions,
                            'topicOptions' => $topicOptions,
                            'posterOptions' => $posterOptions,
                            'type' =>  $topicOptions['id'] ? 'reply' : 'topic',
                        )), 0),
                        array('id_task')
                    );


                    }

Many thanks in advance mick

Arantor

I don't really understand the question.

If the goal is 'people fill in a form and this creates a topic and you want the usual notifications to be sent about that topic based on the usual rules of notifications', just pass in $msgOptions['send_notifications'] as true to createPost() and it'll do the rest for you.

If the goal is to do some custom special notifications based on a post being created, then no, none of that is what you want. Or if you want it to do something *else* when this form is processed, also no.

Background tasks are just things that get put in a queue to be run 'later'. The idea is that you can acknowledge the user's request for creation of new post, then return a response to the user immediately without having to wait for all of the notifications to be sent there and then (like you used to have to wait for all notifications/emails to go out before the save post routine would return to you)

CreatePost-Notify takes a given created post, looks for the usual notifications based on topic/board, plus quotes and mentions, and does the appropriate work.

So the question is: instead of asking 'is this how I do a thing' how about explaining what the thing is that you're trying to do *first*?

mickjav

Think I understand now thanks

I won't bother to comment of rest

regards

Advertisement: