2021-05-05T11:44:00.002-07:00
When you are developing a plugin and are writing an uninstaller for it to clean up your attributes and models, you might notice that it hangs on removing code from Magento Code base:
It then blinks, and hangs and does nothing for a long time, no matter how long you wait. In this blog post, I will try to explain the cause and a solution for the problem. For the solution, scroll down to the end, where the Solution header is.
$output->writeln('<info>Removing code from Magento codebase:</info>');
$packages = [];
/** @var \Magento\Framework\Module\PackageInfo $packageInfo */
$packageInfo = $this->objectManager->get(\Magento\Framework\Module\PackageInfoFactory::class)->create();
foreach ($modules as $module) {
$packages[] = $packageInfo->getPackageName($module);
}
$this->remove->remove($packages);
If we check what is called in the code of the factory, versus what is in the constructor of the MagentoComposerApplication
Factory code:
public function create()
{
return new MagentoComposerApplication($this->pathToComposerHome, $this->pathToComposerJson);
}
public function __construct(
$pathToComposerHome,
$pathToComposerJson,
Application $consoleApplication = null,
ConsoleArrayInputFactory $consoleArrayInputFactory = null,
BufferedOutput $consoleOutput = null
)
When this is null, a new BufferedOutput() is made. This BufferedOutput collects all the strings that are outputted during the composer actions, but not output it to STDOUT. This effectively hides all the actions behind a curtain of mystery. When the command is finished running it returns all collected input.
return $this->consoleOutput->fetch();
If you would type gibberish and press enter a few times you will see the actual error output, and see that it tries to request the access keys to repo.magento.com, as the output is then outputted by an Exception handler instead of the void.
Loading composer repositories with package information
"Warning from repo.magento.com: You haven't provided your Magento authentication keys. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Authentication required (repo.magento.com):
Username:
Password:
Warning from repo.magento.com: Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
Warning from repo.magento.com: Your Magento authentication keys are invalid. Please double-check your keys in your Marketplace account. For instructions, visit https://devdocs.magento.com/guides/v2.3/install-gde/prereq/connect-auth.html
In RemoteFilesystem.php line 748:
Invalid credentials for 'https://repo.magento.com/packages.json, aborting.