EntityMetadataWrapperException: Unable to get the data property roles as the parent data structure is not set.

ambidex
Forums
EntityMetadataWrapperException: Unable to get the data property roles as the parent data structure is not set. This is an error we encountered when we try to update the courses within a class. I've seem to tracked this down to the 'rules_class_courses_changed' rule. When digging around a bit deeper I found out there were some leftover memberships for users that do not longer exist. I'm not sure how these users got deleted without their membership being deleted, though I do know this is the culprit. I was not able to build in a check into the rule to check if the users is actually existent, so I wrote a workaround to execute once that will recurse all classes and check the membership for existing users. If the user does not exist, it will delete the membership. function purge_non_existent_users_from_classes() { $counter = 0; $classes = node_load_multiple(array(), array('type' => 'class')); foreach ($classes as $class_node) { // Get all class courses $opigno_class_courses = field_get_items('node', $class_node, 'opigno_class_courses'); $course_nodes = array(); foreach ($opigno_class_courses as $course_nid) { $course_nodes[$course_nid['target_id']] = node_load($course_nid['target_id']); } // Get class users $uids = og_get_group_members_properties($class_node, array(), 'members', 'node'); $users = user_load_multiple($uids); $non_existent = array_diff($uids, array_keys($users)); $membership_delete_ids = array(); foreach ($non_existent as $uid) { $group_membership = og_get_membership('node', $class_node->nid, 'user', $uid); $membership_delete_ids[] = $group_membership->id; } if (!empty($membership_delete_ids)) $counter += count($membership_delete_ids); og_membership_delete_multiple($membership_delete_ids); } drupal_set_message('Removed ' . $counter . ' non-existing user memberships'); } So I'm left with a few questions: Should the rules check if the membership have existent users before trying to alter them? How do those memberships keep existing when the user is not existent anymore? I'm in the dark.
Profile picture for user James Aparicio
James Aparicio

Hi ambidex,

Hi ambidex,

When you ran the script, did it it find any $non_existant?

Best regards

ambidex

Hi James,

Hi James, Yes, it found 2 classes with $non_existent (with a lot of non-existent users). We have a lot more classes then that, which makes me wonder why those two, though I do not know of anything that should differentiate those from the others.
Profile picture for user James Aparicio
James Aparicio

Are you sure that at not

Are you sure that at no point in the past someone deleted users programmatically ( incorrectly )  or directly from the database?

Best regards