KCGaming
Member
I have been trying to get a thread created when a usergroup promotion is done.
I have edited the cron in /library/XenForo/CronEntry/UserGroupPromotion.php
I read somewhere this worked but believe it might be for an earlier version off Xenforo
Can someone please point me in the right direction for 1.2 Xenforo as this creates an error when run
"Undefined index: title"
I have edited the cron in /library/XenForo/CronEntry/UserGroupPromotion.php
I read somewhere this worked but believe it might be for an earlier version off Xenforo
PHP:
<?php
/**
* Cron entry for executing user group promotions.
*/
class XenForo_CronEntry_UserGroupPromotion
{
/**
* Runs the cron-based check for new promotions that users should be awarded.
*/
public static function runPromotions()
{
/* @var $promotionModel XenForo_Model_UserGroupPromotion */
$promotionModel = XenForo_Model::create('XenForo_Model_UserGroupPromotion');
$promotions = $promotionModel->getPromotions(array(
'active' => 1
));
if (!$promotions)
{
return;
}
/* @var $userModel XenForo_Model_User */
$userModel = XenForo_Model::create('XenForo_Model_User');
$users = $userModel->getUsers(array(
'user_state' => 'valid',
'is_banned' => 0,
'last_activity' => array('>', XenForo_Application::$time - 2 * 3600)
), array(
'join' => XenForo_Model_User::FETCH_USER_FULL
));
$userPromotionStates = $promotionModel->getPromotionStatesByUserIds(array_keys($users));
foreach ($users AS $userId => $user)
{
$promotionModel->updatePromotionsForUser(
$user,
isset($userPromotionStates[$userId]) ? $userPromotionStates[$userId] : array(),
$promotions
);
/**
Post a Thread addon
*/
$forumId = "57";
$username = "Admin";
$userid = "1";
$subjet = $user['username']." Has been Promoted to ".$promotions['title'];
$message = "Congradulations ".$user['username']." on your promtion to ".$promotions['title'].", your dedication to the clan is appreciated and you have earnt this promtion keep up the good work";
$writer = XenForo_DataWriter::create('XenForo_DataWriter_Discussion_Thread');
$writer->set('user_id', $userid);
$writer->set('username', $username);
$writer->set('title', $subjet);
$postWriter = $writer->getFirstMessageDw();
$postWriter->set('message', $message);
$writer->set('node_id', $forumId);
$writer->preSave();
$writer->save();
$thread = $writer->getMergedData();
}
}
}
Can someone please point me in the right direction for 1.2 Xenforo as this creates an error when run
"Undefined index: title"