Autoloader: fix the fatal that occurs during plugin update #16279
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix the fatal that occurs during plugin update. The fatal occurs because, during a plugin update, a function in the just-installed version of
autoload_functions.php
is called. However, that file had already been loaded, so the just-installed version of the file isn't available.Fixes #16273
Changes proposed in this Pull Request:
upgrader_post_install
callback function,reset_maps_after_update
, to theautoload_functions.php
file.reset_maps_after_update
, callset_up_autoloader
to reset the autoloader after a plugin update.Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions:
Cause a fatal error during a plugin update
jetpack
folder and rename thejetpack-dev
folder tojetpack
.jetpack.php
file to < 8.6.1.upgrader_process_complete
hook fires. Note that the snippet uses thePre_Connection_JITM
class, which is not loaded when Jetpack is connected.wp-content/plugins/jetpack.zip
.Create the source zip file for the Jetpack update using a command like
zip -r jetpack.zip jetpack
. The file name and location must match the source zip file in theupgrader_package_options
hook callback. If you use the snippet in step 5, the source file path must bewp-content/plugins/jetpack.zip
.In
jetpack/vendor/composer/jetpack_autoload_classmap.php
, change the file name for thePre_Connection_JITM
class.Change the namespace of the autoloader files. Get the namespace from the
vendor/autoload_functions.php
file. It will be something like:namespace Automattic\Jetpack\Autoloader\jp659a3ca3ee216d6e4c3d3ab24194e47z;
find . -type f -exec sed -i 's/jp659a3ca3ee216d6e4c3d3ab24194e47z/jp659a3ca3ee216d6e4c3d3ab24194e47a/g' {} +
Navigate to wp-admin -> Plugins. An update should be available for Jetpack. Click update now.
The update should fail and a fatal error should be generated in the debug log because the set_up_autoloader() function in the newly installed namespace can't be found. The error should look like:
[24-Jun-2020 15:00:11 UTC] PHP Fatal error: Uncaught Error: Call to undefined function Automattic\Jetpack\Autoloader\jpc74400305ae47f17074763a083b7f93f\set_up_autoloader() in wp-content/plugins/jetpack-dev/vendor/autoload_packages.php:14
Test the fix
Proposed changelog entry for your changes: