/**
* Internal function to execute the command.
*
* @param InputInterface $input The input to inject into the command.
* @param OutputInterface $output The output to inject into the command.
*
* @return integer The command exit code
*
* @since 4.0.0
*/
protected function doExecute(InputInterface $input, OutputInterface $output) : int
{
$this->configureIO($input, $output);
$extensionId = $this->cliInput->getArgument('extensionId');
$response = $this->ioStyle->ask('Are you sure you want to remove this extension?', 'yes/no');
if (strtolower($response) === 'yes') {
// Get an installer object for the extension type
$installer = Installer::getInstance();
$row = new \Joomla\CMS\Table\Extension(Factory::getDbo());
if ((int) $extensionId === 0 || !$row->load($extensionId)) {
$this->ioStyle->error("Extension with ID of {$extensionId} not found.");
return self::REMOVE_NOT_FOUND;
}
// Do not allow to uninstall locked extensions.
if ((int) $row->locked === 1) {
$this->ioStyle->error(Text::sprintf('COM_INSTALLER_UNINSTALL_ERROR_LOCKED_EXTENSION', $row->name, $extensionId));
return self::REMOVE_LOCKED;
}
if ($row->type) {
if (!$installer->uninstall($row->type, $extensionId)) {
$this->ioStyle->error('Extension not removed.');
return self::REMOVE_FAILED;
}
$this->ioStyle->success('Extension removed!');
return self::REMOVE_SUCCESSFUL;
}
return self::REMOVE_INVALID_TYPE;
} elseif (strtolower($response) === 'no') {
$this->ioStyle->note('Extension not removed.');
return self::REMOVE_ABORT;
}
$this->ioStyle->warning('Invalid response');
return self::REMOVE_INVALID_RESPONSE;
}