Automattic / Automattic/aggregator
$aggregator not in global scope causing fatal error in class-aggregate.php
- Dominant language
- PHP
- Stars
- 21
- Forks
- 6
- PR merge metrics
- No merged PRs in 30d
Description
Whenever the `save_post` action is triggered we end up with a fatal 500 error, caught by Query Monitor that results from attempting to pull a non-global variable as global. This is 500ing on our local installs and causing posts not to update if an aggregator job is triggering.
The issue comes from using `$aggregator` as a global in class-aggregate.php [line 40](https://github.com/Automattic/aggregator/blob/master/class-aggregate.php#L40). The variable is not available within global scope which leads to class variable resolving as `null` when called.
I'd recommend either calling the `Aggregator` class anew when loading the `Aggregate` class or using a static instance of the class and not relying on globals because globals kinda suck.
**Error and Trace:**
```
Xdebug: Fatal error: Uncaught Error: Call to a member function get_portals() on null in /srv/www/thesun/wp-content/plugins/aggregator/class-aggregate.php:992
Stack trace:
#0 /srv/www/thesun/wp-includes/plugin.php(524): Aggregate->save_post(1373719, Object(WP_Post))
#1 /srv/www/thesun/wp-includes/post.php(3409): do_action('save_post', 1373719, Object(WP_Post), true)
#2 /srv/www/thesun/wp-includes/post.php(3482): wp_insert_post(Array, false)
#3 /srv/www/thesun/wp-admin/includes/post.php(376): wp_update_post(Array)
#4 /srv/www/thesun/wp-admin/post.php(193): edit_post()
#5 {main} thrown in /srv/www/thesun/wp-content/plugins/aggregator/class-aggregate.php on line 992.
Output triggered in /srv/www/thesun/wp-content/mu-plugins/query-monitor/collectors/php_errors.php on line 143
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in class-aggregate.php at line 40 and follow how the $aggregator dependency is initialized before save_post reaches line 992. Reproduce the failure by triggering save_post and inspect the Aggregator class usage. Done means the get_portals() call no longer operates on null and posts update successfully when an aggregator job triggers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100