forked from joomla/joomla-cms
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request joomla#11 from bosunski/milestone_two
Milestone two
- Loading branch information
Showing
8 changed files
with
640 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 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\Console\AbstractCommand; | ||
use Joomla\CMS\Installer\InstallerHelper; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
/** | ||
* Console command for checking if there are pending extension updates | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
class ExtensionInstallCommand extends AbstractCommand | ||
{ | ||
/** | ||
* Stores the Input Object | ||
* @var | ||
* @since 4.0 | ||
*/ | ||
private $cliInput; | ||
|
||
/** | ||
* SymfonyStyle Object | ||
* @var | ||
* @since 4.0 | ||
*/ | ||
private $ioStyle; | ||
|
||
/** | ||
* Configures the IO | ||
* | ||
* @return void | ||
* | ||
* @since 4.0 | ||
*/ | ||
private function configureIO() | ||
{ | ||
$this->cliInput = $this->getApplication()->getConsoleInput(); | ||
$this->ioStyle = new SymfonyStyle($this->getApplication()->getConsoleInput(), $this->getApplication()->getConsoleOutput()); | ||
} | ||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @return integer The exit code for the command. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public function execute(): int | ||
{ | ||
$this->configureIO(); | ||
|
||
$from = $this->cliInput->getArgument('from'); | ||
|
||
if ($from === 'path') | ||
{ | ||
$result = $this->processPathInstallation($this->cliInput->getOption('path')); | ||
|
||
if (!$result) | ||
{ | ||
$this->ioStyle->error('Unable to install extension'); | ||
} | ||
else | ||
{ | ||
$this->ioStyle->success('Extension installed successfully.'); | ||
} | ||
} | ||
elseif ($from === 'url') | ||
{ | ||
$result = $this->processUrlInstallation($this->cliInput->getOption('url')); | ||
|
||
if (!$result) | ||
{ | ||
$this->ioStyle->error('Unable to install extension'); | ||
} | ||
else | ||
{ | ||
$this->ioStyle->success('Extension installed successfully.'); | ||
} | ||
} | ||
else | ||
{ | ||
$this->ioStyle->error('Invalid argument supplied for command.'); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
/** | ||
* Initialise the command. | ||
* | ||
* @return void | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
protected function initialise() | ||
{ | ||
$this->setName('extension:install'); | ||
$this->addArgument( | ||
'from', | ||
InputArgument::REQUIRED, | ||
'From where do you want to install? (path OR url)' | ||
); | ||
|
||
$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 = "The <info>%command.name%</info> is used for installing extensions \n | ||
--path=<path_to_extension> OR --url=<url_to_download_extension> \n | ||
<info>php %command.full_name%</info>"; | ||
|
||
$this->setHelp($help); | ||
} | ||
|
||
/** | ||
* Used for installing extension from a path | ||
* | ||
* @param string $path Path to the extension zip file | ||
* | ||
* @return bool|int | ||
* | ||
* @since 4.0 | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function processPathInstallation($path) | ||
{ | ||
if (!file_exists($path)) | ||
{ | ||
$this->ioStyle->error('The file path specified does not exist.'); | ||
exit(2); | ||
} | ||
|
||
$tmp_path = $this->getApplication()->get('tmp_path'); | ||
$tmp_path = $tmp_path . '/' . basename($path); | ||
$package = InstallerHelper::unpack($path, true); | ||
|
||
if ($package['type'] === false) | ||
{ | ||
return false; | ||
} | ||
|
||
$jInstaller = Installer::getInstance(); | ||
$result = $jInstaller->install($package['extractdir']); | ||
InstallerHelper::cleanupInstall($tmp_path, $package['extractdir']); | ||
|
||
return $result; | ||
} | ||
|
||
|
||
/** | ||
* Used for installing extension from a URL | ||
* | ||
* @param string $url URL to the extension zip file | ||
* | ||
* @return bool | ||
* | ||
* @since 4.0 | ||
* | ||
* @throws \Exception | ||
*/ | ||
public function processUrlInstallation($url) | ||
{ | ||
$filename = InstallerHelper::downloadPackage($url); | ||
|
||
$tmp_path = $this->getApplication()->get('tmp_path'); | ||
|
||
$path = $tmp_path . '/' . basename($filename); | ||
$package = InstallerHelper::unpack($path, true); | ||
|
||
if ($package['type'] === false) | ||
{ | ||
return false; | ||
} | ||
|
||
$jInstaller = Installer::getInstance(); | ||
$result = $jInstaller->install($package['extractdir']); | ||
InstallerHelper::cleanupInstall($path, $package['extractdir']); | ||
|
||
return $result; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
/** | ||
* Joomla! Content Management System | ||
* | ||
* @copyright Copyright (C) 2005 - 2017 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\MVC\Factory\MVCFactory; | ||
use Joomla\CMS\Table\Table; | ||
use Joomla\Console\AbstractCommand; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
|
||
/** | ||
* Console command for checking if there are pending extension updates | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
class ExtensionRemoveCommand extends AbstractCommand | ||
{ | ||
/** | ||
* Configures the IO | ||
* | ||
* @return void | ||
* | ||
* @since 4.0 | ||
*/ | ||
private function configureIO() | ||
{ | ||
$this->cliInput = $this->getApplication()->getConsoleInput(); | ||
$this->ioStyle = new SymfonyStyle($this->getApplication()->getConsoleInput(), $this->getApplication()->getConsoleOutput()); | ||
} | ||
|
||
|
||
/** | ||
* Execute the command. | ||
* | ||
* @return integer The exit code for the command. | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
public function execute(): int | ||
{ | ||
$this->configureIO(); | ||
$extension_id = (int) $this->cliInput->getArgument('extension_id'); | ||
|
||
$extension = $this->getExtension($extension_id); | ||
|
||
if (!$extension->load($extension_id)) | ||
{ | ||
$this->ioStyle->error("Extension with ID of $extension_id not found."); | ||
return 0; | ||
} | ||
|
||
$response = $this->ioStyle->ask('Are you sure you want to remove this extension?', 'yes/no'); | ||
|
||
if (strtolower($response) === 'yes') | ||
{ | ||
if ($extension->type && $extension->type != 'language') | ||
{ | ||
$installer = Installer::getInstance(); | ||
$result = $installer->uninstall($extension->type, $extension_id); | ||
if ($result) | ||
{ | ||
$this->ioStyle->success('Extension removed!'); | ||
} | ||
} | ||
} | ||
elseif (strtolower($response) === 'no') | ||
{ | ||
$this->ioStyle->note('Extension not removed.'); | ||
return 0; | ||
} | ||
else | ||
{ | ||
$this->ioStyle->warning('Invalid response'); | ||
return 2; | ||
} | ||
return 0; | ||
} | ||
|
||
/** | ||
* Initialise the command. | ||
* | ||
* @return void | ||
* | ||
* @since 4.0.0 | ||
*/ | ||
protected function initialise() | ||
{ | ||
$this->setName('extension:remove'); | ||
$this->addArgument( | ||
'extension_id', | ||
InputArgument::REQUIRED, | ||
'ID of extension to be removed (run extension:list command to check)' | ||
); | ||
|
||
$this->setDescription('Removes an extension'); | ||
|
||
$help = "The <info>%command.name%</info> Removes an extension \n <info>php %command.full_name%</info>"; | ||
$this->setHelp($help); | ||
} | ||
|
||
/** | ||
* Gets the extension from DB | ||
* | ||
* @param integer $extension_id ID of extension to be removed | ||
* | ||
* @return bool | ||
* | ||
* @since 4.0 | ||
*/ | ||
protected function getExtension($extension_id) | ||
{ | ||
$row = Table::getInstance('extension'); | ||
return $row; | ||
} | ||
} |
Oops, something went wrong.