- md5
- 1370ab79c297d343a470809ee31f2a8f
- sha1
- cbd4f4ad3c87faa630c23f79eb508422a9d9076d
- sha256
- 969a09b34e89542df931c68a917863cd1bb92bf102f35c29a17ad9adede69425
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
<?php
/**
* Joomla! Content Management System
*
* @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\CMS\Console;
defined('JPATH_PLATFORM') or die;
use Joomla\CMS\Installer\Installer;
use Joomla\CMS\Installer\InstallerHelper;
use Joomla\Console\Command\AbstractCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Console command for installing extensions
*
* @since 4.0.0
*/
class ExtensionInstallCommand extends AbstractCommand
{
/**
* The default command name
*
* @var string
* @since 4.0
*/
protected static $defaultName = 'extension:install';
/**
* Stores the Input Object
* @var InputInterface
* @since 4.0
*/
private $cliInput;
/**
* SymfonyStyle Object
* @var SymfonyStyle
* @since 4.0
*/
private $ioStyle;
/**
* Exit Code For installation failure
* @since
*/
public const INSTALLATION_FAILED = 1;
/**
* Exit Code For installation Success
* @since
*/
public const INSTALLATION_SUCCESSFUL = 0;
/**
* Configures the IO
*
* @param InputInterface $input Console Input
* @param OutputInterface $output Console Output
*
* @return void
*
* @since 4.0
*
*/
private function configureIO(InputInterface $input, OutputInterface $output): void
{
$this->cliInput = $input;
$this->ioStyle = new SymfonyStyle($input, $output);
}
/**
* Initialise the command.
*
* @return void
*
* @since 4.0.0
*/
protected function configure(): void
{
$this->addOption('path', null, InputOption::VALUE_REQUIRED, 'The path to the extension');
$this->addOption('url', null, InputOption::VALUE_REQUIRED, 'The url to the extension');
$this->setDescription('Installs an extension from a URL or from a Path.');
$help = <<<'EOF'
The <info>%command.name%</info> is used to install extensions
<info>php %command.full_name%</info>
You must provide one of the following options to the command:
--path: The path on your local filesystem to the install package
--url: The URL from where the install package should be downloaded
<info>php %command.full_name% --path=<path_to_file></info>
<info>php %command.full_name% --url=<url_to_file></info>
EOF;
$this->setHelp($help);
}
/**
* Used for installing extension from a path
*
* @param string $path Path to the extension zip file
*
* @return boolean
*
* @since 4.0
*
* @throws \Exception
*/
public function processPathInstallation($path): bool
{
if (!file_exists($path))
{
$this->ioStyle->warning('The file path specified does not exist.');
return false;
}
$tmpPath = $this->getApplication()->get('tmp_path');
$tmpPath = $tmpPath . '/' . basename($path);
$package = InstallerHelper::unpack($path, true);
if ($package['type'] === false)
{
return false;
}
$jInstaller = Installer::getInstance();
$result = $jInstaller->install($package['extractdir']);
InstallerHelper::cleanupInstall($tmpPath, $package['extractdir']);
return $result;
}
/**
* Used for installing extension from a URL
*
* @param string $url URL to the extension zip file
*
* @return boolean
*
* @since 4.0
*
* @throws \Exception
*/
public function processUrlInstallation($url): bool
{
$filename = InstallerHelper::downloadPackage($url);
$tmpPath = $this->getApplication()->get('tmp_path');
$path = $tmpPath . '/' . basename($filename);
$package = InstallerHelper::unpack($path, true);
if ($package['type'] === false)
{
return false;
}
$jInstaller = new Installer;
$result = $jInstaller->install($package['extractdir']);
InstallerHelper::cleanupInstall($path, $package['extractdir']);
return $result;
}
/**
* 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
*
* @throws \Exception
* @since 4.0.0
*/
protected function doExecute(InputInterface $input, OutputInterface $output): int
{
$this->configureIO($input, $output);
if ($path = $this->cliInput->getOption('path'))
{
$result = $this->processPathInstallation($path);
if (!$result)
{
$this->ioStyle->error('Unable to install extension');
return self::INSTALLATION_FAILED;
}
$this->ioStyle->success('Extension installed successfully.');
return self::INSTALLATION_SUCCESSFUL;
}
elseif ($url = $this->cliInput->getOption('url'))
{
$result = $this->processUrlInstallation($url);
if (!$result)
{
$this->ioStyle->error('Unable to install extension');
return self::INSTALLATION_FAILED;
}
$this->ioStyle->success('Extension installed successfully.');
return self::INSTALLATION_SUCCESSFUL;
}
$this->ioStyle->error('Invalid argument supplied for command.');
return self::INSTALLATION_FAILED;
}
}
No other release has this exact content. See every version of this file.