I'm using Fivestar rating as a core function of my site. Everything works - people can register, log in and rate what they want to rate but users are getting the following error message multiple times across many pages of the site:

Notice: Undefined property: stdClass::$uid in _fivestar_allow_vote() (line 1015 of /home/destin77/public_html/sites/all/modules/fivestar/fivestar.module).
Notice: Undefined property: stdClass::$uid in _fivestar_allow_vote() (line 1017 of /home/destin77/public_html/sites/all/modules/fivestar/fivestar.module).
Notice: Undefined property: stdClass::$uid in _fivestar_allow_vote() (line 1015 of /home/destin77/public_html/sites/all/modules/fivestar/fivestar.module).
Notice: Undefined property: stdClass::$uid in _fivestar_allow_vote() (line 1017 of /home/destin77/public_html/sites/all/modules/fivestar/fivestar.module).

This is the first site in Drupal I have ever built. It works. It looks good. But how do I get rid of this error message? It will turn users off - for sure. I have searched for it, and nothing comes up. What do I do?

Please, please help!

Comments

mmjvb’s picture

JBtakenote’s picture

This solution seems to be corrected 8 years ago, and I have a much newer version of FiveStar. I don't see it as an error that comes up in issues. What am I missing?

mmjvb’s picture

Can't match the error to the Stable or Development release. How does your version of the function look like?

JBtakenote’s picture

My Fivestar is version 7.x-2.2 I don't think there's been an update for a while.

mmjvb’s picture

Doubt that it is that version: line 1015 is empty and there is no line 1017.

Correction:
1015 return $entity->uid != $user->uid;

JBtakenote’s picture

I'm new at Drupal - this is my first site - and I don't code. That version information is from the modules page on my admin. When I expand the Fivestar listing, it's what appears above the list of required modules and required by modules.

Can you explain in a bit more detail what information you need if that isn't it?

Many thanks

mmjvb’s picture

1070   // Check that we have entity details, allow if not.
1071   if (!isset($element['#settings']['entity_id']) || !isset($element['#settings']['entity_type'])) {
1072     return TRUE;
1073   }
1074   $entity_id = $element['#settings']['entity_id'];
1075   $entity = entity_load($element['#settings']['entity_type'], array($entity_id));
1076   $entity = $entity[$entity_id];
1077   $uid1 = $entity->uid;
1078   $uid2 = $user->uid;
1079   return $entity->uid != $user->uid;
1080 }

Suspect 1077 and 1079 are the lines reported. Both reference $entity->uid. Looks like $entity has no property uid, which probably means line 1075 doesn't provide an array with $entity_id as index. Unfortunately it doesn't test that and return true. As is done when the values are not set.
This is apart from the fact lines 1077 and 1078 are redundant. Those variables are not used.

mmjvb’s picture

// Check that we have entity details, allow if not.
  if (!isset($element['#settings']['entity_id']) || !isset($element['#settings']['entity_type'])) {
    return TRUE;
  }
  $entity_id = $element['#settings']['entity_id'];
  $entity = entity_load($element['#settings']['entity_type'], array($entity_id));
  if (!isset($entity($entity_id)->uid)) {
    return TRUE;
  }
  return $entity($entity_id)->uid != $user->uid;

Only replaced the lines after the line with entity_load.

EDIT
Maybe if (!isset($entity($entity_id))) { is better.

ressa’s picture

See https://www.drupal.org/node/1036982#comment-10220137

But of course, try also to find the reason for the warnings.

calefilm’s picture

This removed the error for me. 

I created a new fivestar field in my taxonomy vocabulary (i.e. "Restaurants"), that I am having users reference from a Review Your Restaurant node.

In the end, I want users to create a Review Your Restaurant node that references a term while rating that term.  Upon a user submitting their restaurant review (using Entity Reference Term), the term ratings are averaged under each term.

So when I, the admin, go to the term page and see the average score 3.5 out of 5 stars (10 votes), i receive that same error.  I have applied the fixes above with no luck.  However, I noticed the error disappears if I edit the field and select: "Allow users to vote on their own content."