- md5
- 8a9fd4088e791e367d199d5db4b8600a
- sha1
- 4e5a15ffe7f347c9884f99187ab4b363b64f4d72
- sha256
- a48402be9bdcf85c13a5d66e3d9f6150fd102ef2f601e3b1295a946b3169276d
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
<?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\Component\Templates\Administrator\Table\StyleTable;
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 disable extensions
*
* @since 6.1.0
*/
class ExtensionDisableCommand extends AbstractCommand
{
use DatabaseAwareTrait;
/**
* The default command name
*
* @var string
* @since 6.1.0
*/
protected static $defaultName = 'extension:disable';
/**
* @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 DISABLE_NOCHANGE = 3;
/**
* Exit Code for extensions enable\disable failure
* @since 6.1.0
*/
public const DISABLE_FAILED = 1;
/**
* Exit Code for disable parent template with child failure
* @since 6.1.0
*/
public const DISABLE_WITHCHILD_NOT_PERMITTED = 5;
/**
* Exit Code for disable home template failure
* @since 6.1.0
*/
public const DISABLE_HOME_NOT_PERMITTED = 6;
/**
* Exit Code for extensions protected enable\disable failure
* @since 6.1.0
*/
public const DISABLE_PROTECTED = 4;
/**
* Exit Code for extensions not found
* @since 6.1.0
*/
public const DISABLE_NOT_FOUND = 2;
/**
* Exit Code for extensions enable\disable success
* @since 6.1.0
*/
public const DISABLE_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 disabled (run extension:list command to check)'
);
$help = "<info>%command.name%</info> is used to disable an extension.
\nThe command requires one argument, the ID of the extension to disable.
\nYou may find this ID by running the <info>extension:list</info> command.
\nUsage: <info>php %command.full_name% <extension_id></info>";
$this->setDescription('Disable 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);
$extensionId = $this->cliInput->getArgument('extensionId');
$this->ioStyle->title('Disable 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::DISABLE_NOT_FOUND;
}
if ($table->type === 'template') {
$style = new StyleTable($this->getDatabase());
if ($style->load(['template' => $table->element, 'client_id' => $table->client_id, 'home' => 1])) {
$this->ioStyle->note("Template with ID of $extensionId $table->element is home.");
return self::DISABLE_HOME_NOT_PERMITTED;
}
// Parent template cannot be disabled if there are children
if ($style->load(['parent' => $table->element, 'client_id' => $table->client_id])) {
$this->ioStyle->note("Template with ID of $extensionId $table->element have child.");
return self::DISABLE_WITHCHILD_NOT_PERMITTED;
}
}
$type = ucfirst($table->type);
if ($table->protected === 1) {
$this->ioStyle->error("$type with ID of $extensionId $table->name is protectd.");
return self::DISABLE_PROTECTED;
}
if ($table->enabled === 0) {
$this->ioStyle->warning("$type with ID of $extensionId $table->name already is disabled.");
return self::DISABLE_NOCHANGE;
}
$table->enabled = 0;
if (!$table->store()) {
$this->ioStyle->error("$type with ID of $extensionId $table->name not disabled.");
return self::DISABLE_FAILED;
}
$this->ioStyle->success("$type with ID of $extensionId $table->name disabled.");
return self::DISABLE_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.