Back to ExtensionRemoveCommand class

Method doExecute

protected int
doExecute
(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output)
Internal function to execute the command.
Parameters
  • \Symfony\Component\Console\Input\InputInterface $input The input to inject into the command.
  • \Symfony\Component\Console\Output\OutputInterface $output The output to inject into the command.
Returns
  • int The command exit code
Since
  • 4.0.0

Method doExecute - Source code

/**
 * 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;
}