-
Notifications
You must be signed in to change notification settings - Fork 336
Description
Bug Description
In the past few days, several fatal errors were reported in the plugin repository:
- https://wordpress.org/support/topic/fatal-error-1-2-0/
- https://wordpress.org/support/topic/fatal-error-due-to-sitekit-update-attempt/
- https://wordpress.org/support/topic/triggered-a-fatal-error-10/
Each of them points to code locations that are not actually relevant for version 1.2.0, so I'm not quite sure what was causing it, whether it was just a partially failed download - which I cannot imagine, especially given that this was just now reported 3 times in a short period.
@swissspidy mentioned that there can be potential issues on upgrade as a result of using file_exists() checks (see ampproject/amp-wp#2670). We're using the function twice in our plugin code (in loader.php), and we should be able to eliminate the need for them. Given the error messages from the three support tickets, I don't think this is the actual problem here, but it's still something worth improving.
A more likely cause could be that OpCache is not properly reset and does not detect the updated files, so that it partially loads old files (see WP core ticket https://core.trac.wordpress.org/ticket/36455).
Let's explore this a bit further and according fixes.
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- There should be no
file_exists()checks inloader.php:- The one in
autoload_classes()should simply be removed because that classmap should only include classes for files that exist. - In order to remove the one in
autoload_vendor_files(), we need to fix how we generate thethird-party/vendor/autoload_files.phpfile. At the moment, it is simply copied from the main Composer output (done incomposer.json), which results in it including also dependencies that are only relevant for development. Let's implement it in a way that only the three files relevant for production are included.
- The one in
opcache_reset()should be called (if available) after Site Kit has been updated (see https://core.trac.wordpress.org/attachment/ticket/36455/36455.5.diff for possible approach).
Implementation Brief
- Remove
file_exists()condition in\Google\Site_Kit\autoload_classes() - Remove
file_exists()condition in\Google\Site_Kit\autoload_vendor_files() - Add
@composer dump-autoload --no-devas a step between@autoload-third-partyand copyingautoload_files.phpin theprefix-dependenciesComposer script- This results in the
autoload_files.phpcontaining an array of only the 3 files needed - We don't load the main
vendor/autoload.phpso this shouldn't affect anything else
- This results in the
- Add a new
googlesitekit_opcache_resetfunction in the plugin's entrypoint file- Wrapper for
opcache_reset()with additional checks to see if it is safely callable - Added in PHP 5.5, there is need to check if the function exists now that min PHP is 5.6.
- Hook this on the core
upgrader_process_completeaction
- Wrapper for
Changelog entry
- Fix partly outdated PHP files being served due to OpCache issues currently not addressed by WordPress core.