Email address save error....

Environment
OS: Linux
DB: MySQL 5.6
PHP: 7.x
SuiteCRM: 7.9.14
Browser: Chrome

Issue
After upgrading from 7.9.7 to 7.9.14, I am receiving the follow error from custom code Ive created:

Sat Feb 24 17:02:32 2018 [6314][1][ERROR] Invalid Referrer: expected the Save action to be called from the User’s Profile Edit View
Sat Feb 24 17:02:32 2018 [6314][1][ERROR] Email address save error

Here is a snippit of my code…

    	$userBean = new User();
    	$userBean->retrieve_by_string_fields(array('user_name' => $userRow['email_address'], 'emp_id_c' => $userRow['employee_id']));

    	$userBean->last_name = $userRow['last_name'];
    	$userBean->first_name = $userRow['first_name'];
    	$userBean->emp_id_c = $userRow['employee_id'];
    	$userBean->emp_type_c = $userRow['employee_type'];
    	$userBean->emp_job_title_c = $userRow['employee_jobtitle'];
    	$userBean->phone_work = $userRow['work_phone'];
    	$userBean->phone_mobile = $userRow[''];
    	$userBean->email1 = $userRow['email_address'];
    
    	$userBean->status = $userRow['user_status'];
    	$userBean->employee_status = 'Active';
    	$userBean->setPreference('ut', 1);
    	$userBean->setPreference('timef', 'h:i A');
    	$userBean->setPreference('viewed_tour',1);
    	$userBean->save();

Request
If anyone has any thoughts on the fix, would be greatly appreciated.

Thanks,
Rod

1 Like

There seems to be a sanity check (or security check?) here

https://github.com/salesagility/SuiteCRM/blob/master/include/SugarEmailAddress/SugarEmailAddress.php#L260-L266

It’s not expecting to be called from custom PHP code. Maybe you can try just overriding that check? But it’s there for some reason, so the less you change it, the better.

Maybe just tweak the condition inside the function

https://github.com/salesagility/SuiteCRM/blob/master/include/SugarEmailAddress/SugarEmailAddress.php#L495-L503

Try to send it something in the $request and then test for it there.

1 Like

Thank you that helped.

It’s new code that was added as I never received the error until I upgrade from 7.9.7 to 7.9.14.
I’ll post a question as to why it was added and if there any thoughts on supporting creating Users via custom PHP code.

So, is there a resolution for this bug?

I’m having the same problem – I can’t even change one field in a User from custom code.

Something a little (or a lot) more explicit that “try sending it something in the $request and test for it there” might be helpful.

The reason I was vague in my answer is because I don’t really know how to do this myself.

But if you try seeing what you have in $request in this part


        if (!$this->isUserProfileEditViewPageSaveAction($request)) {
            $GLOBALS['log']->error('Invalid Referrer: '.
                'expected the Save action to be called from the User\'s Profile Edit View');
            return false;
        }

Try to see what is different when you call it from custom code, and adjust that condition to avoid stopping the function. Let’s hope it doesn’t break further ahead in the function. If you want, you can simply skip this check altogether. You’ll have to evaluate what consequences this might have, but it probably just errors out in an uglier way when called from the user’s profile Edit view.

1 Like

Here’s code that seems to work to workaround this problem, so you don’t have to read a bunch of source code like I did:


// Work around a bug (https://bit.ly/2IowT7V)
$save_tmp = array(isset($_REQUEST['page'])?$_REQUEST['page']:NULL, $_REQUEST['module'], $_REQUEST['action']);
list($_REQUEST['page'], $_REQUEST['module'], $_REQUEST['action']) = array('EditView', 'Users', 'Save');
if (empty($userBean->save()))
     $GLOBALS['log']->error("Error saving User id={$userBean->id}");
else
     $GLOBALS['log']->debug("User id={$userBean->id} saved OK");
list($_REQUEST['page'], $_REQUEST['module'], $_REQUEST['action']) = $save_tmp;
3 Likes

FYI: They just committed a fix. I expect it’ll be in the next release.

1 Like

Cool, can you please post a link to that PR?

Hi Rod
I’m also getting the Email address save error in SuiteCRM v7.13.1
any luck working this out?
Thanks

David

@David_iTeks, I am getting ‘Email address save error’ on SuiteCRM v7.13.
Whenever a user logged in, I am getting this error in CRM log.

[FATAL] User username has logged in.
[FATAL] Email address save error

I don’t know if anyone able to resolve this.

@jefflevene

Could you share link of your fix?