Using Datawriter to move a thread, but thread loses it's prefix

Marcel

Active member
This is a followon from this question :
http://xenforo.com/community/thread...ads-works-with-all-prefixes-except-one.64489/

I started the whole plugin again from scratch. I now have the other part of the plugin running fine (One click assign a particular prefix to a thread).
I've integrated the cron job as per the above link, and it works.
It moves the relevant threads (For some reason the code on the above link wouldn't actually select the threads with prefixId of 1).
Anway, it works. However, it removes the thread's prefix upon move.

here's the relevant part of the function that is called to move the threads.

Code:
$threads = $threadModel->getThreads($conditionals, $fetchOptions);
        // $threads now contains all our results, so let's run through and deal with them on a thread by thread basis
        // firstly, make sure there were some results. We don't want to be bothering if there was nothing found!
        if ($threads)
        {
            // go through $threads, and put just one thread into $thread
            foreach ($threads as $thread)
            {
                // instantiate the datawriter as $dw
                $dw = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
                // point this new datawriter to the thread we're currently dealing with
                $dw->setExistingData($thread);
                // change the information contained in it (IE, our destination forum)
                $dw->set('node_id', $msOptions['destForum']);
                $dw->set('prefix_id', $msOptions['prefix']);
                // now save it
                $dw->save();
                // done! now either end the foreach loop, or go back and do the next thread we found
            }
        }

I don't actually want to change the prefix at all, but if I leave it out, it still strips it. It's more than likely me doing something that Im not supposed to be doing, or doing it the wrong way. Could anyone help? Thanks.
 
I just took a quick look at the Discussion DataWriter.

Prefixes can only be used in the forums you specify when setting up the prefix. The prefix you're using doesn't appear to be set up to be used in the destination forum so this behavior is expected. The Discussion DataWriter is purposefully removing that prefix ID on pre save.

You should either carry on doing what you're doing and forcing the prefix, or you should make sure that prefix is usable in the destination forum.
 
Hi Chris, thanks for the reply.

I've just checked again, and the destination forum was indeed missing. I assume if I remove the relevant line setting the prefix from the code, it will now carry it over.

As it was, it wasn't carrying the prefix over whether I forced it or not.
I could have swore the prefix was set up to be used in the destination forum. Infact I double checked the other day, I'm sure of it. We manually move threads there and it keeps the prefix, so I thought if the prefix stays on a manual move....then surely it would stay on a cron job.

Anyway, two days and two silly mistakes I made :D
That damn dog! :p
 
Back
Top Bottom