Hello,
I currently have some custom php code which is designed to add a specified user to a database, and it was working, but now it has stopped for whatever reason. (Did I accidentally delete something?)
Anyways, here's the code:
<?php
error_reporting(E_ALL);
require_once '../config.core.php';
require_once MODX_CORE_PATH.'model/modx/modx.class.php';
$modx = new modX();
$modx->initialize('web');
$modx->getService('error','error.modError', '', '');
function userPurchasedItem($item_id, $payment_amount, $payer_email, $username) {
global $modx;
//mail('[email protected]', 'Just received a purchase!', 'The user: '.$username.' at '.$payer_email.' has just purchased an item for $'.$payment_amount.' ID: '.$item_id);
$myUser = $modx->getObject('modUser', array('username'=>$username));
if ($myUser) {
$myUser->save();
$myUser->joinGroup($item_id);
echo 'It is set!'; // This is being printed when I run the test code
$cm = $modx->getCacheManager();
$cm->refresh();
} else {
mail('[email protected]', 'Error Assigning group', 'Something went wrong when assigning the user '.$username.' who purchased the item '.$item_id.' for'.$payment_amount);
die('No User');
}
}
?>
Which is being called by:
<?php
include('userPurchase.php');
userPurchasedItem('4', '25', '[email protected]', 'muffinjello');
?>
Since my echo
is working, I'm thinking it's more of something MODx specific that's tripping up my code. Clearing the cache is required in order for the user to join the new group (without relogging). Any help is reaaaallly appreciated!