No idea what could be happening here, see the code below, it fails at the line $profile_data = $profile->toArray(); seemingly randomly, I double checked the ids against the database tables id and profiles, it should have been creating the profile object [the user did exist with a record in modx_user_attributes]
there are about 20 users, only three were failing to create the object, I finally disabled those users and everything worked fine. So I tried to recreate one of the users... this is where it gets weird. Two other users started failing to create the profile object, existing users, not the one I had just created!
No IDEA what could be happening to cause this! HELP!!
$sql = "SELECT
u.*, ua.*, us.*, ux.*, u.id as id, ua.id as uaid, us.id as usid, ux.id as uxid
FROM `modx_users` u
LEFT JOIN `modx_user_attributes` ua ON ua.internalKey = u.id
LEFT JOIN `modx_gssi_user_ext_data` ux ON ux.internalKey = u.id
LEFT JOIN `modx_session` us ON us.id = ua.sessionid
WHERE ( ua.blocked = 0 AND u.active = 1 and u.id != 1)
ORDER BY u.id asc ";
$results = $modx->query($sql);
if (is_object($results)) {
$users = $results->fetchAll(PDO::FETCH_ASSOC);
if(count($users) <= 0){
return;
}
}
echo '<pre>';print_r($users);echo '</pre>';
foreach ($users as $user) {
$uid = $user['id'];
$myuser = $modx->getObject('modUser', $uid);
$profile = $modx->getObject('modUserProfile', $uid);
if(!is_object($profile)){echo 'not an object for id ' . $uid;}
$profile_data = $profile->toArray();
$detail = $myuser->toArray();
$account = array_merge($profile_data, $detail);
if($myuser->isMember(array('Customers'))){ //Customers, Staff
$customeroutput .= $modx->getChunk('dashCurrentActiveUserRowTpl',$account);
}else{
$staffoutput .= $modx->getChunk('dashCurrentActiveStaffRowTpl',$account);
}
//echo '<pre>';print_r($staffoutput);echo '</pre>';
//echo '<pre>';print_r($customeroutput);echo '</pre>';
}