XF 2.0 Move thread in cron

AndyB

Well-known member
In an add-on called Move thread, I would like to move threads in a cron entry.

In the following code:

PHP:
foreach ($threads AS $k => $v)
{
	$targetNodeId = $destinationForum;
	$targetForum = \XF::app()->em()->find('XF:Forum', $targetNodeId);

	$finder = \XF::finder('XF:Thread');
	$thread = $finder
		->where('thread_id', '=', $v['thread_id'])
		->fetchOne();			

	\XF::app()->setupThreadMove($thread, $targetForum)->move($targetForum);
}


I'm getting the following error message:

Code:
An exception occurred: [Error] Call to undefined method XF\Admin\App::move() in src/addons/Andy/AutoMove/XF/Cron/AutoMove.php on line 85

What is the correct code needed to move a thread in a cron?

Thank you.
 
Got it.

PHP:
foreach ($threads AS $k => $v)
{
	$targetNodeId = $destinationForum;
	$targetForum = \XF::app()->em()->find('XF:Forum', $targetNodeId);

	$finder = \XF::finder('XF:Thread');
	$thread = $finder
		->where('thread_id', '=', $v['thread_id'])
		->fetchOne();
	
	$mover = \XF::app()->service('XF:Thread\Mover', $thread);
	$mover->move($targetForum);
}
 
  • Like
Reactions: LPH
Top Bottom