ElkArte Community

Elk Development => Bug Reports => Topic started by: Acido on November 20, 2023, 11:02:13 am

Title: [1.1.9] Open Graph / Schema.org metadata bug
Post by: Acido on November 20, 2023, 11:02:13 am
If you enable the Open Graph / Schema.org metadata function added in 1.1.9, there is an issue if listing a post where a user has been deleted as they will become a guest user and no longer have a href defined and the page will generate the following error when loading:

Code: [Select]
Notice: Undefined index: href

    Undefined index: href
    PHP Fatal error: Uncaught exception 'ErrorException' with message 'Undefined index: href' in /var/www/test/sources/subs/Metadata.integrate.php:238
    Stack trace:
    #0 /var/www/test/sources/subs/Metadata.integrate.php(238): error_handler(integer, string, string, integer, array)
    #1 /var/www/test/sources/subs/Metadata.integrate.php(106): getPostSchema()
    #2 /var/www/test/sources/subs/Metadata.integrate.php(76): setContext()
    #3 /var/www/test/sources/Hooks.class.php(110): prepare_topic_metadata(integer)
    #4 /var/www/test/sources/Subs.php(1434): hook(string, array)
    #5 /var/www/test/sources/SiteDispatcher.class.php(366): call_integration_hook(string, array)
    #6 /var/www/test/index.php(136): dispatch()
    #7 /var/www/test/index.php(66): elk_main()
    #8 {main}
    thrown in /var/www/test/sources/subs/Metadata.integrate.php on line 238

I fixed it by doing this modification but something better maybe required?

Code: (from) [Select]
'url' => $this->data['member']['href']
Code: (to) [Select]
'url' => empty($this->data['member']['href']) ? null : $this->data['member']['href']
Title: Re: [1.1.9] Open Graph / Schema.org metadata bug
Post by: Spuds on December 03, 2023, 11:41:01 am
Thank you for the report, and even more so for the fix :adhesive_bandage: I'll get this added to 1.1.10
Title: Re: [1.1.9] Open Graph / Schema.org metadata bug
Post by: tino on December 03, 2023, 01:21:19 pm
Depending on the lowest PHP version supported the null coalesce function is more concise.

https://www.php.net/manual/en/migration70.new-features.php
Title: Re: [1.1.9] Open Graph / Schema.org metadata bug
Post by: Spuds on December 03, 2023, 06:16:23 pm
Agreed ... that is what I did on my local, and used a blank string for the url vs null
Title: Re: [1.1.9] Open Graph / Schema.org metadata bug
Post by: Acido on December 31, 2023, 01:38:19 pm
Quote from: Spuds – Agreed ... that is what I did on my local, and used a blank string for the url vs null

Yeah was considering that as well. The reason i used null was because i was looking over the other metadata generated and noticed there were null's in other places, so figured to keep it in line :)