Add revised clear-compiled artisan command #5727
Merged
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.
Issue
The command
php artisan clear-compiled
artisan command is run (on the command line or programmatically) it flushes the package manifest.This is an issue since the licensed packages are loaded based on the package manifest and if that file is cleared, it will attempt to load all installed packages, including custom ones, which triggers a fatal error.
Reproduction Steps
php artisan license:update {licenseFile}
command and ensure it runs successfullyphp artisan upgrade
{"errors":{"username":["cURL error 3: URL rejected: No host part in the URL (see https:\/\/curl.haxx.se\/libcurl\/c\/libcurl-errors.html) for \/api\/1.0\/\/integratingpm3onpm4\/user?username=admin"]}}
This happens because one of the custom packages has a
UserObserver
listening for user activities and is triggered by one of the upgrade migrations updating user information. TheUserObserver
looks for specific environment variables to be set and if they’re not found, it callsdie()
which immediately kills the process.The greater problem is that the custom package’s service provider was being loaded in the first place. There are two programmatic calls to the
clear-compiled
artisan command, one in an upgrade migration and one in package-cdata.Solution
Create a customized version of the php artisan clear-compiled command programmatically and runphp artisan package:discover
to ensure it is rebuilt before continuing.Listen for clear-compiled and optimize:clear commands and return package:discover
How to Test
php artisan clear-compiled
command and check through thebootstrap/cache/packages.php
file to ensure it contains only licensed packages.Related Tickets & Packages
Code Review Checklist