- md5
- 899213aef30b0dcc510312607e1a0237
- sha1
- 64726b4e0e3820108b90ee3383e200e62a341c5c
- sha256
- 8d6b4e6e5d4c626b5ad3c27a1eec4c03437e86873b9c38fb056a5a2425cb48b3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
<?php
/**
* Joomla! Content Management System
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Console;
use Joomla\CMS\Table\Extension;
use Joomla\Console\Command\AbstractCommand;
use Joomla\Database\DatabaseAwareTrait;
use Joomla\Database\DatabaseInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* Console command to enable extensions
*
* @since 6.1.0
*/
class ExtensionEnableCommand extends AbstractCommand
{
use DatabaseAwareTrait;
/**
* The default command name
*
* @var string
* @since 6.1.0
*/
protected static $defaultName = 'extension:enable';
/**
* @var InputInterface
* @since 6.1.0
*/
private $cliInput;
/**
* @var SymfonyStyle
* @since 6.1.0
*/
private $ioStyle;
/**
* Exit Code for extensions already enabled\disabled
* @since 6.1.0
*/
public const ENABLE_NOCHANGE = 3;
/**
* Exit Code for extensions enable\disable failure
* @since 6.1.0
*/
public const ENABLE_FAILED = 1;
/**
* Exit Code for extensions not found
* @since 6.1.0
*/
public const ENABLE_NOT_FOUND = 2;
/**
* Exit Code for extensions enable\disable success
* @since 6.1.0
*/
public const ENABLE_SUCCESSFUL = 0;
/**
* Command constructor.
*
* @param DatabaseInterface $db The database
*
* @since 6.1.0
*/
public function __construct(DatabaseInterface $db)
{
parent::__construct();
$this->setDatabase($db);
}
/**
* Configures the IO
*
* @param InputInterface $input Console Input
* @param OutputInterface $output Console Output
*
* @return void
*
* @since 6.1.0
*
*/
private function configureIO(InputInterface $input, OutputInterface $output): void
{
$this->cliInput = $input;
$this->ioStyle = new SymfonyStyle($input, $output);
}
/**
* Initialise the command.
*
* @return void
*
* @since 6.1.0
*/
protected function configure(): void
{
$this->addArgument(
'extensionId',
InputArgument::REQUIRED,
'ID of extension to be enabled (run extension:list command to check)'
);
$help = "<info>%command.name%</info> is used to enable an extension.
\nThe command requires one argument, the ID of the extension to enable.
\nYou may find this ID by running the <info>extension:list</info> command.
\nUsage: <info>php %command.full_name% <extension_id></info>";
$this->setDescription('Enable an extension');
$this->setHelp($help);
}
/**
* 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 6.1.0
*/
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$this->configureIO($input, $output);
$commandSelected = $input->getFirstArgument();
$extensionId = $this->cliInput->getArgument('extensionId');
$this->ioStyle->title('Enable Extension');
// Get a table object for the extension type
$table = new Extension($this->getDatabase());
if ((int) $extensionId === 0 || !$table->load($extensionId)) {
$this->ioStyle->error("Extension with ID of $extensionId not found.");
return self::ENABLE_NOT_FOUND;
}
$type = ucfirst($table->type);
if ($table->enabled === 1) {
$this->ioStyle->warning("$type with ID of $extensionId $table->name already is enabled.");
return self::ENABLE_NOCHANGE;
}
$table->enabled = 1;
if (!$table->store()) {
$this->ioStyle->error("$type with ID of $extensionId $table->name not enabled.");
return self::ENABLE_FAILED;
}
$this->ioStyle->success("$type with ID of $extensionId $table->name enabled.");
return self::ENABLE_SUCCESSFUL;
}
}
The same content is in 29 releases, Joomla 6.1.0-alpha3 to 6.2.1-rc1. See them all, or every version of this file.