500 Internal Server Error when trying to add new member [solved]

Silverstripe Version: 3.7.2

Question:

We recently upgraded our SilverStripe install from 3.1 to 3.7.2. The server was also upgraded from Ubuntu 14.04 to Ubuntu 18.04. Which also means that PHP was upgraded from version 5.x to 7.2.

Most of the problems related to the upgrade has been sorted out, but here’s an issue that we have not been able to solve yet:

When trying to add add a new member (via /admin, “Security” and “Add Member”), after inputing the user data and clicking “Create” - it hangs for 30 seconds before getting an “Internal Server Error” message.

The PHP error log reads:

PHP Fatal error:  Maximum execution time of 30 seconds exceeded in /var/www/framework/security/PasswordEncryptor.php on line 183, referer: https://www.ourwebsite.com/admin/security/EditForm/field/Members/item/new

I have tried to adjust the both the PHP max_execution_time and the memory_limit higher, but then it just hangs for a longer time - never finishing.

Could someone point me in the right direction? How can i debug the problem?

Have you modified Member with any DataExtensions maybe?

That’s it, thank you very much. We have a CustomMember-extension. Just tried to disable it, and when doing that the Add Member-function works as expected without errors. Great!

Follow-up question:

Any clues on why the following CustomMember-extension shouldn’t work on SilverStripe 3.7.2 With PHP 7.2?

class CustomMember extends DataExtension {
	
	public function onAfterWrite() {
		parent::onAfterWrite();
		
		$changed = $this->owner->getChangedFields();
		
		if(isset($changed['ID']) && $changed['ID']['before']==0) {
			
			$e = SS_Object::create('MemberDecorator_SignupEmail');

			$group = null;
			$redirect = "";
			$linktext = "Set password and login here";
			
			if(isset($_POST['DirectGroups']) && count($_POST['DirectGroups']) > 0) {

				foreach($_POST['DirectGroups'] as $groupId) {
					
					$group = Group::get_by_id("Group", $groupId);

					if($group && strlen($group->SignupLoginUrl) > 0) {
						$redirect = urlencode($group->SignupLoginUrl);

						if($group->SignupEmailSender) {
							$e->setFrom($group->SignupEmailSender);
						}

						if($group->SignupEmailSubject) {
							$e->setSubject($group->SignupEmailSubject);
						}

						if($group->SignupLoginText) {
							$linktext = $group->SignupLoginText;
						}

						break;
					}
				}
			}
			
			$token = $this->owner->generateAutologinTokenAndStoreHash();
			
			$url = Security::getPasswordResetLink($this->owner, $token).'&BackURL='.$redirect;
			$url = str_replace("Security/changepassword", "home/setupuser", $url);
			
			$e->PasswordResetLink = $url;
			$e->PasswordResetText = $linktext;

			$e->populateTemplate(array(
				'Member' =>$this->owner,
				'Group' =>$group
			));
			$e->setTo($this->owner->Email);
			$e->send();
		}
	}
}

class MemberDecorator_SignupEmail extends Email {
	protected $ss_template = 'SignupEmail';
	
	public function __construct($from = null, $to = null, $subject = null, $body = null, $bounceHandlerURL = null, $cc = null, $bcc = null) {
		$subject = "Website User";
		$from = 'noreply@ourwebsite.com';
		
		parent::__construct($from, $to, $subject, $body, $bounceHandlerURL, $cc, $bcc);
	}

}

$token = $this->owner->generateAutologinTokenAndStoreHash();
$url = Security::getPasswordResetLink($this->owner, $token).'&BackURL='.$redirect;

I haven’t looked at the code, but I’m guessing that one of those two lines is causing another write on your Member, which is causing a never ending loop.

Great, thank you again.

You are right, it was the first line that caused the problem.

I replaced

$token = $this->owner->generateAutologinTokenAndStoreHash().

with

$member = Member::get()->where("Email = '".Convert::raw2sql($_POST['Email'])."'")->first().
$token = $member->generateAutologinTokenAndStoreHash();

and this seems to have fixed the problem for us. Even though i don’t quite understand why this would work while the use of $this->owner doesn’t.

Anyways, thank you very much for helping out! Everything working as expected now :smiley: