AndyB
Well-known member
Hello,
In my Birthday thread add-on I would like to be able to create a thread using creator. I can extend my own controller or extend forum controller. The code below works great as long as I'm logged in, but calling the same code via Cron entries or by a not logged in user I get an error.
Here's the PHP code:
This is the error message if I run the code as not logged in.
Thank you.
In my Birthday thread add-on I would like to be able to create a thread using creator. I can extend my own controller or extend forum controller. The code below works great as long as I'm logged in, but calling the same code via Cron entries or by a not logged in user I get an error.
Here's the PHP code:
PHP:
foreach ($userIds as $user)
{
$titleNew = str_replace('{username}', $user['username'], $title);
$messageNew = str_replace('{username}', $user['username'], $message);
$em = \XF::em();
$forum = $em->find('XF:Forum', $forum);
$creator = \XF::app()->service('XF:Thread\Creator', $forum, 'Node');
$creator->setContent($titleNew, $messageNew);
$thread = $creator->save();
$userId = $user['user_id'];
$user = \XF::app()->find('XF:User', $userId);
$alertRepo = \XF::app()->repository('XF:UserAlert');
$alertRepo->alert($user, $starterUserId, $starterUsername, 'post', $thread->first_post_id, 'mention');
}
This is the error message if I run the code as not logged in.
Thank you.