XF 1.5 Programmatically merge topics

GPA-R

Active member
Hi,

I haven't really found anything related so am starting a new topic.

I would like to programmatically merge topics. I have a list with the source ID and the Destination ID.

So I need to write a script to merge N topics to a topic. Can anyone give me any direction towards which functionality I need to look?

Thanks in advance

(not sure if it would be more appropriate to move it to https://xenforo.com/community/forums/xenforo-development-discussions.34/)
 
Last edited:
I've seen that. I've tried the following without luck

PHP:
$startTime = microtime(true);
$fileDir = dirname(__FILE__) . '/xf';

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$threadModel = XenForo_Model::create( 'XenForo_Model_Thread' );

// Merge topic with ID 1&2 into 3
$threads = $threadModel->getModelFromCache('XenForo_Model_Thread')->mergeThreads(array(1,2),3);
 
Oh. My suggestion was for XenForo 2.0. You are doing 1.5. I missed that, sorry.

Take a look at:
PHP:
public function mergeThreads(array $threads, $targetThreadId, array $options = array())
It looks like the $threads array has to be keyed by the ID and actually contain arrays of the thread info from the database, so I suggest you use:
PHP:
$startTime = microtime(true);
$fileDir = dirname(__FILE__) . '/xf';

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

$threadModel = XenForo_Model::create( 'XenForo_Model_Thread' );

// Merge topic with ID 1&2 into 3
$threads = $threadModel->mergeThreads($threadModel->getThreadsByIds(array(1,2,3)),3);

Also, note that the target thread has to be part of the $threads array.
 
Back
Top Bottom