XF 1.5 Get post_id from thread_id (please!) in Cron Callback

ForestForTrees

Well-known member
Hi folks,

This is a bit of a newbie question, but I'd be super grateful if you could help out.

Within a simple Cron Callback, if I have a thread_id, how do I get the post_id for the first post in the thread?

It's is simple as that. For background, see the following:

I've got the following cron entry:
1504308198537.webp
The Callback, runMoveThreads is super simple. It gathers all the threads in a given subforum:
1504308298551.webp
It then moves those threads, one by one, to a new subforum. It is based on code from @Fuhrmann's tutorial on how to make a Cron Entry to move threads. I've been using it for years, so I know it works.

I'd like to change the post date for the first post in each of the found threads. For that, I need the post_id of the the first post in the thread.

Given the above code and the context of a cron job, how do I find the post_id of the first post of the thread?

The code I will be calling afteward is taken directly from @AndyB 's wonderful Change Date addon, so it is solid, too:
1504308623301.webp
(Okay, I lie, there is a bit of code after that that updates xf_forum if the thread is now the most recent one, but I can handle that.)

For the right person, this is probably a trivial, single line of code, but I'm afraid that I don't know the inner workings of XF. I'm under a lot of time pressure and would be super grateful for the help.
 
Thanks for your help!

That was wonderfully simple. I was worried it might involve a XenForo_Application::get, XenForo_Model::create, a cache call or something like. I don't know how to set up a PHP debugger and wouldn't know where to look.

The code is running now and works great.
 
Back
Top Bottom