After entering an email id and a message, then clicking on Invite button the below warning comes up along with the Fatal Error.

"Error

The website encountered an unexpected error. Please try again later.

Warning: unserialize() expects parameter 1 to be string, array given in invite_get_remaining_invites() (line 703 of /var/www/sites/all/modules/invite/invite.module).
Recoverable fatal error: Object of class stdClass could not be converted to string in DatabaseStatementBase->execute() (line 2039 of /var/www/includes/database/database.inc)."

CommentFileSizeAuthor
#7 invite-1054392.patch495 byteshadsie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

hadsie’s picture

Title: Fatal error when trying to send an Invite » Warning: unserialize() expects parameter 1 to be string, array given
bnoice’s picture

Subscribe (from the dupe issue)

jacov’s picture

subscribing

jacov’s picture

The fix I believe is basically removing the unserialize function on line 698 of modules/invite/invite.module

Details, below...

Problem is here:

/**
 * Calculate the remaining invites of a user.
 *
 * @param $account
 *   A user object.
 * @return
 *   The number of remaining invites.
 */
function invite_get_remaining_invites($account) {
  if ($account->uid == 1) {
    return INVITE_UNLIMITED;
  }
 
  $data = unserialize($account->data);
  if (isset($data['invites'])) {
 

Fix is here:

/**
 * Calculate the remaining invites of a user.
 *
 * @param $account
 *   A user object.
 * @return
 *   The number of remaining invites.
 */
function invite_get_remaining_invites($account) {
  if ($account->uid == 1) {
    return INVITE_UNLIMITED;
  }
 
  // Check user property for remaining invites.
  // $data = unserialize($account->data);
  $data = $account->data;
  if (isset($data['invites'])) {
 
sw3b’s picture

Nice work thanks !

danielm’s picture

Hello,

I put patch #4, When I go to the URL "http://www.yourdomain.com/invite" to invite a new friend, the following error message appeared:

Warning: unserialize() expects parameter 1 to be string, array given in invite_get_remaining_invites() (line 699 of /var/www/public/sites/all/modules/invite/invite.module).

This only appears when logged in as a normal registered user and not as the administrator (i.e. UID = 1).

Thank you for your help

Sincerely
Daniel

hadsie’s picture

Priority: Critical » Major
Status: Active » Needs review
FileSize
495 bytes

Here's the fix rolled into a patch. Note that this patch is generated from a codebase that has already had the patches from #1124708: To the maintainers -- Can we get some D7 patches applied to code? applied.

glekli’s picture

Status: Needs review » Fixed

Committed. Also updated is the method the data is saved into the user object.
Thanks for the fix.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.