Notice: Trying to get property of non-object in uc_roles_cron() line 42 /ubercart/uc_roles/uc_roles.module

    if (!is_array($account->roles) || !count($account->roles)) {

to

    if ($account && (!is_array($account->roles) || !count($account->roles))) {

The reason this error exists is that the uc_roles_expirations table has a user id that no longer exists

Hope this helps.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet’s picture

FileSize
602 bytes

I attached the wrong patch and message:( see this one.

I removed the role expiration if the user doesn't exist

Status: Needs review » Needs work

The last submitted patch, uc_roles.module.patch, failed testing.

longwave’s picture

Can you reupload your patch? Both links give 404 for me, seems drupal.org has been having some trouble in the past couple of hours.

joelpittet’s picture

FileSize
600 bytes

I have attached again but just in case here is the code:

--- a/sites/all/modules/ubercart/uc_roles/uc_roles.module
+++ b/sites/all/modules/ubercart/uc_roles/uc_roles.module
@@ -38,8 +38,14 @@ function uc_roles_cron() {
   foreach ($result as $expiration) {
     $account = user_load($expiration->uid);
 
+    // Cleanup if this user was deleted.
+    if (!$account) {
+      uc_roles_delete($expiration->uid, $expiration->rid);
+      continue;
+    }
+
     // User has to contain roles to manage.
-    if (!is_array($account->roles) || !count($account->roles)) {
+    if (!is_array($account->roles) || !count($account->roles)) {
       continue;
     }
 
joelpittet’s picture

Wonder if it doesn't like the patch format...

wodenx’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, uc_roles.module-cron-user-fix-1402106.patch, failed testing.

TR’s picture

Can we address #911350: uc_roles_cron() does not scale (horribly) at the same time please? I'd prefer to combine these into one issue, because any patch here will get lost when that routine gets refactored, and any refactoring needs to be aware of the above.

TR’s picture

Status: Needs work » Closed (duplicate)

Closing in favor of getting this all done in #911350: uc_roles_cron() does not scale (horribly). Please contribute to that issue if you want to get this resolved.

mariagwyn’s picture

Is this really a duplicate? The issue you reference is for 6.x, this is for 7.x

longwave’s picture

The fix will be the same, so it's best to work on the fix in 7.x where development is most active, then backport it to 6.x.