Problem/Motivation
When updating from 10.25 to 10.30 or 10.31 (on two populated installations) - I had errors updating the database.
The issue turned out to be this:
"Call to a member function getFieldValue() on null in /var/www/social/html/profiles/contrib/social/modules/social_features/social_event/modules/social_event_invite/social_event_invite.tokens.inc on line 88"
If I just make sure $message isn't null, I can successfully update the database.
replace
$event_enrollment = $storage->load($message->getFieldValue('field_message_related_object', 'target_id'));
with
if ($message){
$event_enrollment = $storage->load($message->getFieldValue('field_message_related_object', 'target_id'));
}
If I remove this check after updating, I get the same error (getFieldValue() on null) when I try to enroll in an event. So it's not just a problem on updating the database.
This change gets things working for me, but I'm not sure why it's only an issue on older existing sites and I don't know if a bigger fix is necessary as to why $message is null.
Steps to reproduce
Updating from social 10.25 to 10.30 or 10.31 (perhaps with events with enrollments?)
Proposed resolution
Make sure adding the if ($message) is an appropriate solution.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 3246751-6.patch | 1.28 KB | milos.kroulik |
Comments
Comment #2
ressinelHello @dereks
I cannot reproduce this. Could you provide more information?
Comment #3
dereks commented@Ressinel - I didn't have trouble on a fresh install on the same box, but two sites that have been running Open Social for a few years, with my own occasional tweaks, wouldn't update. So it's probably something I did - I just don't know what.
Is there any harm in just checking if $message is null? Or is that a necessary variable, and will break things elsewhere if it's missing?
Comment #4
skatheeth commentedHello All,
I am also facing the same exact issue reported by @dereks above.
When updating from 10.25 to 10.30 or 10.31 I am getting this error:
This same error comes from many other files like the ones listed below as all of them call this function "getFieldValue"
Can someone please help on this issue.
Error: Call to undefined method Drupal\message\Entity\Message::getFieldValue() in Drupal\social_activity\EmailTokenServices->getRelatedObject() (line 76 of profiles\contrib\social\modules\social_features\social_activity\src\EmailTokenServices.php)
SOLUTION : core\lib\Drupal\Core\Entity\ContentEntityBase.php file have a function missing which was present in earlier version before running composer update. Once i re-added the function it solved the issue.
Does Open Social manipulates this code in CORE? Because as per record ContentEntityBase.php has not been changed in 2 years
Comment #5
milos.kroulik commentedPerhaps there should be an issue for each problem? Regarding the missing
method - it was added by patches in https://www.drupal.org/project/drupal/issues/2580551. Perhaps OS used patch from that issue and in 10.3 no longer does so?
Comment #6
milos.kroulik commentedTemporary patch fixing the missing
messagekey.Comment #7
bmango commentedWow, perfect timing! The patch worked perfectly. I was upgrading from 10.3.1 to 10.3.2 and got this error.
The patch also fixed another update for social_group_update_10308 which had the same error: Call to a member function getFieldValue() on null.
Thanks so much for the patch.
Comment #8
ronaldtebrake commented@#5 we indeed use that patch, and we still do in 10.3 & will be in 11
See: https://github.com/goalgorilla/open_social/blob/main/composer.json#L41
In this case I think the provided patch should be something we can add, it's at least some good defensive measurement.
We might need to think about what we want to do if the actual message isn't there as this will likely just render the token itself, but in this way it at least doesn't break.
Comment #9
ressinel@milos.kroulik Thanks for your patch!
I have created PR with your changes but made some adjustments: https://github.com/goalgorilla/open_social/pull/2633
Comment #10
ressinelComment #11
ressinelComment #12
milos.kroulik commentedThis needs further fix, because current solution still throws a notice:
Undefined index: message social_event_invite.tokens.inc:83Something like this is needed at line 83:
Comment #13
tbsiqueira